/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt * or http://forgerock.org/license/CDDLv1.0.html. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at legal-notices/CDDLv1_0.txt. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Copyright 2013 ForgeRock AS. */ package org.forgerock.opendj.maven; import java.io.File; import java.util.ArrayList; import java.util.List; import org.apache.commons.io.FilenameUtils; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; import org.twdata.maven.mojoexecutor.MojoExecutor; // @Checkstyle:off /** * Generate configuration classes from XML definition files for OpenDJ server. *
* There is a single goal that generate java sources, manifest files, I18N messages * and cli/ldap profiles. * * @goal generate * @phase generate-sources * @requiresDependencyResolution compile+runtime */ // @Checkstyle:on public class OpendjConfigMojo extends AbstractBuildMojo { /** * Package path in which artefacts are generated. *
* This relative path is used to locate xml definition files and to locate * generated artefacts. * * @parameter default-value="org/forgerock/opendj/admin" * @required */ private String packagePath; /** * Root directory where definitions of configuration as xml files are * located. * * @parameter default-value="${basedir}/src/main/resources/definitions" * @required */ private String xmlDefinitionsRootDir; /** * Directory containing stylesheets (xsl files) to generate code and other * artefacts. * * @parameter default-value="${basedir}/src/main/resources/stylesheets" * @required */ private String xslDir; /** * Root directory containing generated sources for configuration. * * @parameter default-value="${project.build.directory}/generated-sources/admin" * @required */ private String generatedSourcesRootDir; /** * Temporary directory containing generated manifests. *
* There is one manifest file generated by component. It is the * responsability of project that use this plugin to concatenate all * generated files into a single file. * * @parameter default-value="${project.build.directory}/tmp" * @required */ private String generatedManifestsTempDir; /** * Root directory containing generated messages for configuration. * * @parameter default-value="${basedir}/src/main/resources/admin/messages" * @required */ private String generatedMessagesRootDir; /** * Root directory containing generated profiles for configuration. * * @parameter default-value="${project.build.outputDirectory}/admin/profiles" * @required */ private String generatedProfilesRootDir; /** * Returns the package path in which artefacts are generated. *
* The package path is a relative path.
*
* @return the package path
*/
public final String getPackagePath() {
return packagePath;
}
/**
* Returns the root directory for xml configuration files.
*
* @return {@code xmlDefinitionsRootDir}
*/
public final File getXmlDefinitionsRootDirectory() {
return new File(xmlDefinitionsRootDir);
}
/**
* Returns the directory containing xml configuration files.
*
* @return the directory containing xml configuration files
*/
public final File getXmlDefinitionsDirectory() {
return new File(getXmlDefinitionsRootDirectory(), packagePath);
}
/**
* Returns the directory containing xsl files to generate code.
*
* @return {@code xslDir}
*/
public final File getXslDirectory() {
return new File(xslDir);
}
/**
* Returns the temporary directory containing generated manifests.
*
* @return {@code manifestsTempDir}
*/
public final String getGeneratedManifestsTempDirectory() {
return generatedManifestsTempDir;
}
/**
* Returns the directory containing generated sources for configuration.
*
* @return {@code generatedSourcesDir}
*/
public final File getGeneratedSourcesDirectory() {
return new File(generatedSourcesRootDir, getPackagePath());
}
/**
* Returns the directory containing generated messages for configuration.
*
* @return the directory containing generated messages
*/
public final File getGeneratedMessagesDirectory() {
return new File(generatedMessagesRootDir, getPackagePath() + "/" + "meta");
}
/**
* Returns the directory containing generated profile for configuration.
*
* @param profileType
* The type of profile (ldap or cli)
*
* @return the directory containing generated profiles for configuration
*/
public final File getGeneratedProfilesDirectory(String profileType) {
return new File(generatedProfilesRootDir, profileType + "/" + getPackagePath() + "/" + "meta");
}
/**
* Version of xml-maven-plugin to use.
*
* @parameter default-value="1.0"
* @required
*/
private String xmlMavenPluginVersion;
/**
* Returns the version of xml-maven-plugin.
*
* @return {@code xmlMavenPluginVersion}
*/
public final String getXmlMavenPluginVersion() {
return xmlMavenPluginVersion;
}
/**
* {@inheritDoc}
*/
@Override
public final void execute() throws MojoExecutionException {
//checkDirectories();
Executor exec = new Executor();
getLog().info("Validate XML definition files");
exec.validateXmlDefinitionsFiles();
getLog().info("Generate meta, server and client APIs for components...");
exec.generateSourcesAndManifests();
getLog().info("Generate I18N messages and profiles...");
exec.generateMessagesAndProfiles();
}
void checkDirectories() throws MojoExecutionException {
if (getPackagePath() == null) {
throw new MojoExecutionException("