From 8ef820bdf73a4eee50b12354e13ae8d2d426c332 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Mon, 30 Dec 2013 21:13:20 +0000
Subject: [PATCH] Checkpoint commit for OPENDJ-1235 : Migrate configuration framework
---
opendj-sdk/opendj-admin/pom.xml | 271 -----------------
opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/AbstractBuildMojo.java | 91 ++++++
opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/package-info.java | 31 ++
opendj-sdk/opendj-config-maven-plugin/pom.xml | 57 +++
opendj-sdk/pom.xml | 12
opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/OpendjConfigMojo.java | 432 ++++++++++++++++++++++++++++
6 files changed, 624 insertions(+), 270 deletions(-)
diff --git a/opendj-sdk/opendj-admin/pom.xml b/opendj-sdk/opendj-admin/pom.xml
index ec4560e..c48a799 100644
--- a/opendj-sdk/opendj-admin/pom.xml
+++ b/opendj-sdk/opendj-admin/pom.xml
@@ -64,12 +64,6 @@
com.sun.security.auth*;resolution:=optional,
*
</opendj.osgi.import>
- <mainResourcesDir>${basedir}/src/main/resources</mainResourcesDir>
- <xmlDefinitionsBaseDir>${mainResourcesDir}/definitions</xmlDefinitionsBaseDir>
- <xmlDefinitionsDir>${xmlDefinitionsBaseDir}/org/forgerock/opendj/admin</xmlDefinitionsDir>
- <adminPackage>org/forgerock/opendj/admin</adminPackage>
- <generatedSourcesDir>${project.build.directory}/generated-sources/admin/${adminPackage}</generatedSourcesDir>
- <xslDir>${mainResourcesDir}/stylesheets</xslDir>
<!-- properties used to generate DynamicConstant class -->
<serverProductName>OpenDJ</serverProductName>
@@ -183,273 +177,22 @@
</execution>
</executions>
</plugin>
- <!-- Validate core components XML definition files
- and generate the components. -->
+ <!-- Validate core components XML definition files and generate the components. -->
<plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>xml-maven-plugin</artifactId>
- <version>1.0</version>
+ <groupId>org.forgerock.opendj</groupId>
+ <artifactId>opendj-config-maven-plugin</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
<executions>
- <!-- Validate core components XML definition files -->
<execution>
- <id>validate-core-components</id>
+ <id>generate-config</id>
<phase>generate-sources</phase>
<goals>
- <goal>validate</goal>
+ <goal>generate</goal>
</goals>
- <configuration>
- <validationSets>
- <validationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <systemId>${xslDir}/admin.xsd</systemId>
- </validationSet>
- </validationSets>
- <catalogs>
- <catalog>${xslDir}/catalog.xml</catalog>
- </catalogs>
- </configuration>
- </execution>
- <execution>
- <id>generate-core-components</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>transform</goal>
- </goals>
- <configuration>
- <transformationSets>
- <!-- Generate introspection API for core administration components. -->
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${generatedSourcesDir}/meta</outputDir>
- <stylesheet>${xslDir}/metaMO.xsl</stylesheet>
- <excludes>
- <exclude>Package.xml</exclude>
- </excludes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^([^/]+)Configuration\.xml$</pattern>
- <replacement>$1CfgDefn.java</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>base-dir</name>
- <value>${xmlDefinitionsBaseDir}</value>
- </parameter>
- </parameters>
- </transformationSet>
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${generatedSourcesDir}/meta</outputDir>
- <stylesheet>${xslDir}/package-info.xsl</stylesheet>
- <includes>
- <include>Package.xml</include>
- </includes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^Package\.xml$</pattern>
- <replacement>package-info.java</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>type</name>
- <value>meta</value>
- </parameter>
- </parameters>
- </transformationSet>
- <!-- Generate server API for core administration components. -->
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${generatedSourcesDir}/server</outputDir>
- <stylesheet>${xslDir}/serverMO.xsl</stylesheet>
- <excludes>
- <exclude>Package.xml</exclude>
- </excludes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^([^/]+)Configuration\.xml$</pattern>
- <replacement>$1Cfg.java</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>base-dir</name>
- <value>${xmlDefinitionsBaseDir}</value>
- </parameter>
- </parameters>
- </transformationSet>
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${generatedSourcesDir}/server</outputDir>
- <stylesheet>${xslDir}/package-info.xsl</stylesheet>
- <includes>
- <include>Package.xml</include>
- </includes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^Package\.xml$</pattern>
- <replacement>package-info.java</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>type</name>
- <value>server</value>
- </parameter>
- </parameters>
- </transformationSet>
- <!-- Generate client API for core administration components. -->
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${generatedSourcesDir}/client</outputDir>
- <stylesheet>${xslDir}/clientMO.xsl</stylesheet>
- <excludes>
- <exclude>Package.xml</exclude>
- </excludes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^([^/]+)Configuration\.xml$</pattern>
- <replacement>$1CfgClient.java</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>base-dir</name>
- <value>${xmlDefinitionsBaseDir}</value>
- </parameter>
- </parameters>
- </transformationSet>
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${generatedSourcesDir}/client</outputDir>
- <stylesheet>${xslDir}/package-info.xsl</stylesheet>
- <includes>
- <include>Package.xml</include>
- </includes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^Package\.xml$</pattern>
- <replacement>package-info.java</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>type</name>
- <value>client</value>
- </parameter>
- </parameters>
- </transformationSet>
- <!-- Generate manifest file for core administration components. -->
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${project.build.directory}/tmp</outputDir>
- <stylesheet>${xslDir}/manifestMO.xsl</stylesheet>
- <excludes>
- <exclude>Package.xml</exclude>
- </excludes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
- <targetExtension>.manifest</targetExtension>
- </fileMapper>
- </fileMappers>
- </transformationSet>
- </transformationSets>
- </configuration>
- </execution>
- <execution>
- <id>generate-core-properties</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>transform</goal>
- </goals>
- <configuration>
- <transformationSets>
- <!-- Generate I18N messages for core administration components. -->
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${mainResourcesDir}/admin/messages/${adminPackage}/meta</outputDir>
- <stylesheet>${xslDir}/messagesMO.xsl</stylesheet>
- <excludes>
- <exclude>Package.xml</exclude>
- </excludes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^([^/]+)Configuration\.xml$</pattern>
- <replacement>$1CfgDefn.properties</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>base-dir</name>
- <value>${xmlDefinitionsBaseDir}</value>
- </parameter>
- </parameters>
- </transformationSet>
- <!-- Generate LDAP profile for core administration components. -->
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${project.build.outputDirectory}/admin/profiles/ldap/${adminPackage}/meta</outputDir>
- <stylesheet>${xslDir}/ldapMOProfile.xsl</stylesheet>
- <excludes>
- <exclude>Package.xml</exclude>
- </excludes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^([^/]+)Configuration\.xml$</pattern>
- <replacement>$1CfgDefn.properties</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>base-dir</name>
- <value>${xmlDefinitionsBaseDir}</value>
- </parameter>
- </parameters>
- </transformationSet>
- <!-- Generate CLI profile for core administration components. -->
- <transformationSet>
- <dir>${xmlDefinitionsDir}</dir>
- <outputDir>${project.build.outputDirectory}/admin/profiles/cli/${adminPackage}/meta</outputDir>
- <stylesheet>${xslDir}/cliMOProfile.xsl</stylesheet>
- <excludes>
- <exclude>Package.xml</exclude>
- </excludes>
- <fileMappers>
- <fileMapper
- implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
- <pattern>^([^/]+)Configuration\.xml$</pattern>
- <replacement>$1CfgDefn.properties</replacement>
- </fileMapper>
- </fileMappers>
- <parameters>
- <parameter>
- <name>base-dir</name>
- <value>${xmlDefinitionsBaseDir}</value>
- </parameter>
- </parameters>
- </transformationSet>
- </transformationSets>
+ <configuration>
</configuration>
</execution>
</executions>
- <dependencies>
- <dependency>
- <!-- no lib => fail, xalan 2.7 => fail, saxon 6.5.3 => ok -->
- <groupId>saxon</groupId>
- <artifactId>saxon</artifactId>
- <version>6.5.3</version>
- </dependency>
- </dependencies>
</plugin>
<!-- Concatenate all single manifest files to a single manifest for
core administration components. -->
diff --git a/opendj-sdk/opendj-config-maven-plugin/pom.xml b/opendj-sdk/opendj-config-maven-plugin/pom.xml
new file mode 100644
index 0000000..d459dbf
--- /dev/null
+++ b/opendj-sdk/opendj-config-maven-plugin/pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.forgerock.opendj</groupId>
+ <artifactId>opendj-project</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>opendj-config-maven-plugin</artifactId>
+ <name>OpenDJ Config Maven Plugin</name>
+ <description>
+ Generation of configuration classes, messages and profiles
+ from xml definition files for opendj server.
+ </description>
+ <packaging>maven-plugin</packaging>
+
+ <properties>
+ <mavenVersion>3.0.4</mavenVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.twdata.maven</groupId>
+ <artifactId>mojo-executor</artifactId>
+ <version>2.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/AbstractBuildMojo.java b/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/AbstractBuildMojo.java
new file mode 100644
index 0000000..bdef6ff
--- /dev/null
+++ b/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/AbstractBuildMojo.java
@@ -0,0 +1,91 @@
+/*
+ * 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 org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.BuildPluginManager;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * AbstractMojo implementation for generation of opendj server configuration
+ * classes.
+ */
+abstract class AbstractBuildMojo extends AbstractMojo {
+
+ /**
+ * The Maven Project.
+ *
+ * @parameter property="project"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * The Maven Session.
+ *
+ * @parameter property="session"
+ * @required
+ * @readonly
+ */
+ private MavenSession session;
+
+ /**
+ * The Maven PluginManager.
+ *
+ * @component
+ * @required
+ */
+ private BuildPluginManager pluginManager;
+
+ /**
+ * The Maven Project.
+ *
+ * @return the project
+ */
+ public MavenProject getProject() {
+ return project;
+ }
+
+ /**
+ * The Maven Session.
+ *
+ * @return the session
+ */
+ public MavenSession getSession() {
+ return session;
+ }
+
+ /**
+ * The Maven PluginManager.
+ *
+ * @return the plugin manager
+ */
+ public BuildPluginManager getPluginManager() {
+ return pluginManager;
+ }
+}
diff --git a/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/OpendjConfigMojo.java b/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/OpendjConfigMojo.java
new file mode 100644
index 0000000..6f1116f
--- /dev/null
+++ b/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/OpendjConfigMojo.java
@@ -0,0 +1,432 @@
+/*
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * 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("<packagePath> must be set.");
+ }
+ if (getXmlDefinitionsDirectory() == null || !getXmlDefinitionsDirectory().exists()) {
+ throw new MojoExecutionException("<xmlDefinitionsRootDir> and <packagePath> must be set and concatenation"
+ + "of the two (with / separator) must correspond to an existing directory.");
+ }
+ if (getXslDirectory() == null || !getXslDirectory().exists()) {
+ throw new MojoExecutionException("<xslDir> must be set and must correspond to an existing directory.");
+ }
+ }
+
+ /**
+ * Execute xml maven plugin with several executions and configurations.
+ */
+ private class Executor extends MojoExecutor {
+
+ private static final String SAXON_LIBRARY_VERSION = "6.5.3";
+
+ private static final String FILE_EXTENSION_MAPPER =
+ "org.codehaus.plexus.components.io.filemappers.FileExtensionMapper";
+
+ private static final String REGEXP_FILE_MAPPER =
+ "org.codehaus.plexus.components.io.filemappers.RegExpFileMapper";
+
+ private static final String CLIENT = "client";
+
+ private static final String SERVER = "server";
+
+ private static final String META = "meta";
+
+ private static final String PROPERTIES_FILE_REPLACEMENT_PATTERN = "$1CfgDefn.properties";
+
+ /** Pattern to identify a xml definition file for java package. */
+ private static final String XML_CONFIG_PACKAGE_FILE_PATTERN = "^Package\\.xml$";
+
+ /** Pattern to identify a xml definition file for java class. */
+ private static final String XML_CONFIG_FILE_PATTERN = "^([^/]+)Configuration\\.xml$";
+
+ /**
+ * Generate sources for configuration.
+ */
+ void generateSourcesAndManifests() throws MojoExecutionException {
+ executeMojo(
+ xmlPlugin(),
+ goal("transform"),
+ configuration(
+ element(name("transformationSets"),
+ transformationSetForClasses(META, "$1CfgDefn.java"),
+ transformationSetForPackage(META),
+ transformationSetForClasses(SERVER, "$1Cfg.java"),
+ transformationSetForPackage(SERVER),
+ transformationSetForClasses(CLIENT, "$1CfgClient.java"),
+ transformationSetForPackage(CLIENT),
+ transformationSetForManifests()
+ )),
+ executionEnvironment(getProject(), getSession(), getPluginManager()));
+ }
+
+ /**
+ * Validate xml configuration files.
+ */
+ void validateXmlDefinitionsFiles() throws MojoExecutionException {
+ executeMojo(
+ xmlPlugin(),
+ goal("validate"),
+ configuration(
+ element(name("validationSets"),
+ element(name("validationSet"),
+ directoryElement(),
+ element(name("systemId"), filePath(getXslDirectory()) + "/" + "admin.xsd"))),
+ element(name("catalogs"),
+ element(name("catalog"), filePath(getXslDirectory()) + "/" + "catalog.xml"))),
+ executionEnvironment(getProject(), getSession(), getPluginManager()));
+ }
+
+ /**
+ * Generate I18N messages and LDAP/CLI profiles for configuration.
+ */
+ void generateMessagesAndProfiles() throws MojoExecutionException {
+ executeMojo(xmlPlugin(),
+ goal("transform"),
+ configuration(
+ element(name("transformationSets"),
+ transformationSetForResource(filePath(getGeneratedMessagesDirectory()), "messagesMO.xsl"),
+ transformationSetForResource(filePath(getGeneratedProfilesDirectory("ldap")),
+ "ldapMOProfile.xsl"),
+ transformationSetForResource(filePath(getGeneratedProfilesDirectory("cli")),
+ "cliMOProfile.xsl")
+ )),
+ executionEnvironment(getProject(), getSession(), getPluginManager()));
+ }
+
+ private Plugin xmlPlugin() {
+ Dependency xsltLibrary = new Dependency();
+ xsltLibrary.setGroupId("saxon");
+ xsltLibrary.setArtifactId("saxon");
+ xsltLibrary.setVersion(SAXON_LIBRARY_VERSION);
+ List<Dependency> deps = new ArrayList<Dependency>();
+ deps.add(xsltLibrary);
+ return plugin(groupId("org.codehaus.mojo"), artifactId("xml-maven-plugin"),
+ version(getXmlMavenPluginVersion()), deps);
+ }
+
+ private MojoExecutor.Element transformationSetForClasses(String type, String patternReplacement) {
+ String xslFileName = type + "MO.xsl";
+ return transformationSetForSource(type, xslFileName, packageElement(false), XML_CONFIG_FILE_PATTERN,
+ patternReplacement, baseDirParameter());
+ }
+
+ private MojoExecutor.Element transformationSetForPackage(String type) {
+ return transformationSetForSource(type, "package-info.xsl", packageElement(true),
+ XML_CONFIG_PACKAGE_FILE_PATTERN, "package-info.java", typeParameter(type));
+ }
+
+ /**
+ * Returns a transformation set element for source code.
+ */
+ private MojoExecutor.Element transformationSetForSource(String finalOutputDir, String xslName,
+ MojoExecutor.Element packageElement, String pattern, String patternReplacement,
+ MojoExecutor.Element parameter) {
+ return element(name("transformationSet"),
+ directoryElement(),
+ outputDirElement(filePath(getGeneratedSourcesDirectory()) + "/" + finalOutputDir),
+ styleSheetElement(xslName),
+ packageElement,
+ element(name("fileMappers"), element(name("fileMapper"),
+ attribute("implementation", REGEXP_FILE_MAPPER),
+ element(name("pattern"), pattern),
+ element(name("replacement"), patternReplacement))),
+ element(name("parameters"), parameter));
+ }
+
+ /**
+ * Returns a transformation set element for manifests.
+ */
+ private MojoExecutor.Element transformationSetForManifests() {
+ return element(name("transformationSet"),
+ directoryElement(),
+ outputDirElement(getGeneratedManifestsTempDirectory()),
+ styleSheetElement("manifestMO.xsl"),
+ packageElement(false),
+ element(name("fileMappers"), element(name("fileMapper"),
+ attribute("implementation", FILE_EXTENSION_MAPPER),
+ element(name("targetExtension"), ".manifest"))));
+ }
+
+ /**
+ * Returns a transformation set element for source code.
+ */
+ private MojoExecutor.Element transformationSetForResource(String outputDir, String xslName) {
+ return element(name("transformationSet"),
+ directoryElement(),
+ outputDirElement(outputDir),
+ styleSheetElement(xslName),
+ packageElement(false),
+ element(name("fileMappers"), element(name("fileMapper"),
+ attribute("implementation", REGEXP_FILE_MAPPER),
+ element(name("pattern"), XML_CONFIG_FILE_PATTERN),
+ element(name("replacement"), PROPERTIES_FILE_REPLACEMENT_PATTERN))),
+ element(name("parameters"), baseDirParameter()));
+
+ }
+
+ private Element outputDirElement(String outputDir) {
+ return element(name("outputDir"), outputDir);
+ }
+
+ private Element styleSheetElement(String xslName) {
+ return element(name("stylesheet"), filePath(getXslDirectory()) + "/" + xslName);
+ }
+
+ private Element directoryElement() {
+ return element(name("dir"), filePath(getXmlDefinitionsDirectory()));
+ }
+
+ private MojoExecutor.Element baseDirParameter() {
+ return element(name("parameter"), element(name("name"), "base-dir"),
+ element(name("value"), filePath(getXmlDefinitionsRootDirectory())));
+ }
+
+ private MojoExecutor.Element typeParameter(String value) {
+ return element(name("parameter"),
+ element(name("name"), "type"),
+ element(name("value"), value));
+ }
+
+ /** Package element either include "package.xml" file or exclude it. */
+ private MojoExecutor.Element packageElement(boolean include) {
+ String tag = include ? "include" : "exclude";
+ String pluralTag = tag + "s";
+ return element(name(pluralTag), element(name(tag), "Package.xml"));
+ }
+
+ /** Returns the string path from the provided file. */
+ private String filePath(File file) {
+ return FilenameUtils.separatorsToUnix(file.getPath());
+ }
+
+ }
+}
diff --git a/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/package-info.java b/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/package-info.java
new file mode 100644
index 0000000..80460e9
--- /dev/null
+++ b/opendj-sdk/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/package-info.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+/**
+ * Classes implementing the maven plugin for generation of configuration classes based on XML definition files.
+ */
+package org.forgerock.opendj.maven;
+
diff --git a/opendj-sdk/pom.xml b/opendj-sdk/pom.xml
index 36c2258..8e657c5 100644
--- a/opendj-sdk/pom.xml
+++ b/opendj-sdk/pom.xml
@@ -89,10 +89,10 @@
</site>
</distributionManagement>
<modules>
- <!--module>opendj-admin</module-->
+ <module>opendj-config-maven-plugin</module>
<module>opendj-core</module>
<module>opendj-grizzly</module>
- <!-- <module>opendj-admin</module> -->
+ <!--module>opendj-admin</module-->
<module>opendj-ldap-sdk</module>
<module>opendj-ldap-toolkit</module>
<module>opendj-ldap-sdk-examples</module>
@@ -117,7 +117,7 @@
<forgerockRestVersion>2.1.0-SNAPSHOT</forgerockRestVersion>
<gaId>UA-23412190-8</gaId>
<!-- OSGi bundles properties -->
- <opendj.osgi.import.additional />
+ <opendj.osgi.import.additional/>
<!--
| Use provide:=true to disallow mixing OpenDJ and ForgeRock resource versions.
| it change the version policy from == + to == =+ [2.0,3) [2.0,2.1)
@@ -134,9 +134,9 @@
-D"pubDate=Publication date: December 31, 1969"
At all other times, the dates should be empty.
-->
- <releaseDate />
+ <releaseDate/>
<softwareReleaseDate>${releaseDate}</softwareReleaseDate>
- <pubDate />
+ <pubDate/>
<publicationDate>${pubDate}</publicationDate>
<checkstyleHeaderLocation>org/forgerock/checkstyle/opendj-java-header</checkstyleHeaderLocation>
<frDocPluginVersion>2.0.0</frDocPluginVersion>
@@ -448,4 +448,4 @@
<distribution>repo</distribution>
</license>
</licenses>
-</project>
+</project>
\ No newline at end of file
--
Gitblit v1.10.0