mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
03.25.2016 6d85503c79a77f86a02d2fc8cb50cf34aaa8b70a
Code cleanup

Fix javadoc for maven plugin opendj-maven-plugin:generate-config
Also change isExtension parameter default value to be consistent with
the plugin main feature.
Extracts constant and method to help code readability.
4 files modified
59 ■■■■■ changed files
opendj-config/pom.xml 2 ●●●●● patch | view | raw | blame | history
opendj-maven-plugin/src/main/java/org/forgerock/opendj/maven/GenerateConfigMojo.java 53 ●●●●● patch | view | raw | blame | history
opendj-server-example-plugin/pom.xml 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/pom.xml 1 ●●●● patch | view | raw | blame | history
opendj-config/pom.xml
@@ -138,13 +138,11 @@
        <executions>
          <execution>
            <id>generate-config</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-config</goal>
            </goals>
            <configuration>
              <packageName>org.forgerock.opendj.server.config</packageName>
              <isExtension>false</isExtension>
            </configuration>
          </execution>
        </executions>
opendj-maven-plugin/src/main/java/org/forgerock/opendj/maven/GenerateConfigMojo.java
@@ -11,7 +11,7 @@
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2013-2015 ForgeRock AS.
 * Copyright 2013-2016 ForgeRock AS.
 */
package org.forgerock.opendj.maven;
@@ -99,6 +99,8 @@
@Mojo(name = "generate-config", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = COMPILE_PLUS_RUNTIME)
public final class GenerateConfigMojo extends AbstractMojo {
    private static final String CONFIGURATION_FILE_SUFFIX = "Configuration.xml";
    private interface StreamSourceFactory {
        StreamSource newStreamSource() throws IOException;
    }
@@ -119,12 +121,12 @@
    private String packageName;
    /**
     * Package name for which artifacts are generated.
     * {@code true} if this plugin should be used to generate classes
     * for extended configuration (e.g OpenDJ plugins).
     * <p>
     * This relative path is used to locate xml definition files and to locate
     * generated artifacts.
     * If not specified, OpenDJ configuration classes will be generated.
     */
    @Parameter(required = true, defaultValue = "true")
    @Parameter(required = true, defaultValue = "false")
    private Boolean isExtension;
    private final Map<String, StreamSourceFactory> componentDescriptors = new LinkedHashMap<>();
@@ -187,7 +189,9 @@
        // Validate and transform.
        try {
            initializeStylesheets();
            getLog().info("Loading XML descriptors...");
            loadXMLDescriptors();
            getLog().info("Found " + componentDescriptors.size() + " XML descriptors");
            executeValidateXMLDefinitions();
            executeTransformXMLDefinitions();
            getLog().info("Adding source directory \"" + getGeneratedSourcesDirectory() + "\" to build path...");
@@ -418,18 +422,25 @@
        return stylesheetFactory.newTemplates(xslt);
    }
    private void loadXMLDescriptors() throws IOException {
        getLog().info("Loading XML descriptors...");
    private void loadXMLDescriptors() throws IOException, MojoExecutionException {
        final String parentPath = getXMLPackageDirectory();
        final String configFileName = "Configuration.xml";
        if (isExtension) {
            final File dir = new File(parentPath);
            dir.listFiles(new FileFilter() {
            loadXMLDescriptorsFromFolder(parentPath);
            return;
        }
        final URL url = getClass().getClassLoader().getResource(parentPath);
        loadXMLDescriptorsFromJar(parentPath, ((JarURLConnection) url.openConnection()).getJarFile());
    }
    private void loadXMLDescriptorsFromFolder(final String parentPath) {
        final File folder = new File(parentPath);
        folder.listFiles(new FileFilter() {
                @Override
                public boolean accept(final File path) {
                    final String name = path.getName();
                    if (path.isFile() && name.endsWith(configFileName)) {
                        final String key = name.substring(0, name.length() - configFileName.length());
                if (path.isFile() && name.endsWith(CONFIGURATION_FILE_SUFFIX)) {
                    final String key = name.substring(0, name.length() - CONFIGURATION_FILE_SUFFIX.length());
                        componentDescriptors.put(key, new StreamSourceFactory() {
                            @Override
                            public StreamSource newStreamSource() {
@@ -440,19 +451,19 @@
                    return true; // Don't care about the result.
                }
            });
        } else {
            final URL dir = getClass().getClassLoader().getResource(parentPath);
            final JarURLConnection connection = (JarURLConnection) dir.openConnection();
            final JarFile jar = connection.getJarFile();
    }
    private void loadXMLDescriptorsFromJar(final String parentPath, final JarFile jar) throws IOException {
            final Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                final JarEntry entry = entries.nextElement();
                final String name = entry.getName();
                if (name.startsWith(parentPath) && name.endsWith(configFileName)) {
            if (name.startsWith(parentPath) && name.endsWith(CONFIGURATION_FILE_SUFFIX)) {
                    final int startPos = name.lastIndexOf('/') + 1;
                    final int endPos = name.length() - configFileName.length();
                    final String key = name.substring(startPos, endPos);
                    componentDescriptors.put(key, new StreamSourceFactory() {
                final int endPos = name.length() - CONFIGURATION_FILE_SUFFIX.length();
                componentDescriptors.put(name.substring(startPos, endPos), new StreamSourceFactory() {
                        @Override
                        public StreamSource newStreamSource() throws IOException {
                            return new StreamSource(jar.getInputStream(entry));
@@ -461,6 +472,4 @@
                }
            }
        }
        getLog().info("Found " + componentDescriptors.size() + " XML descriptors");
    }
}
opendj-server-example-plugin/pom.xml
@@ -12,7 +12,7 @@
  Header, with the fields enclosed by brackets [] replaced by your own identifying
  information: "Portions Copyright [year] [name of copyright owner]".
  Copyright 2014-2015 ForgeRock AS.
  Copyright 2014-2016 ForgeRock AS.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
@@ -77,6 +77,7 @@
            </goals>
            <configuration>
              <packageName>com.example.opendj</packageName>
              <isExtension>true</isExtension>
            </configuration>
          </execution>
        </executions>
opendj-server-legacy/pom.xml
@@ -564,7 +564,6 @@
            </goals>
            <configuration>
              <packageName>org.forgerock.opendj.server.config</packageName>
              <isExtension>false</isExtension>
            </configuration>
          </execution>