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

Nicolas Capponi
05.03.2015 adaeb1b6755da35bb87dac1192edad313096c865
fix checkstyle issues for new maven plugins
3 files modified
178 ■■■■■ changed files
opendj-sdk/opendj-concat-schema-maven-plugin/src/main/java/org/forgerock/maven/ConcatSchemaMojo.java 113 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-logref-doc-maven-plugin/src/main/java/org/forgerock/maven/GenerateMessageFileMojo.java 44 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-manifest-classpath-maven-plugin/src/main/java/org/forgerock/maven/GenerateManifestClassPathMojo.java 21 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-concat-schema-maven-plugin/src/main/java/org/forgerock/maven/ConcatSchemaMojo.java
@@ -43,9 +43,8 @@
import org.apache.maven.project.MavenProject;
/**
 * Concatenates the contents of the files in the schema directory to create a
 * base schema that may be used during the upgrade process. Each element will
 * also include the X-SCHEMA-FILE extension to indicate the source schema file.
 * Concatenates the contents of the files in the schema directory to create a base schema that may be used during the
 * upgrade process. Each element will also include the X-SCHEMA-FILE extension to indicate the source schema file.
 * <p>
 * There is a single goal that generates the base schema.
 * <p>
@@ -68,8 +67,7 @@
    private String schemaDirectory;
    /**
     * The directory path of the concatenated schema file to create.
     * Must be in ${project.build.directory}
     * The directory path of the concatenated schema file to create. Must be in ${project.build.directory}
     */
    @Parameter(required=true)
    private String outputDirectory;
@@ -80,15 +78,13 @@
    @Parameter(required=true)
    private String outputFile;
    /** {@inheritDoc} */
    public void execute() throws MojoExecutionException, MojoFailureException
    {
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
      String projectBuildDir = project.getBuild().getDirectory();
      String outputFilePath = outputDirectory + System.getProperty("file.separator") + outputFile;
      if (!outputDirectory.contains(projectBuildDir))
      {
        if (!outputDirectory.contains(projectBuildDir)) {
        String errorMsg = String.format("outputDirectory parameter (%s) must be included "
            + "in ${project.build.directory} (%s)", outputDirectory, projectBuildDir);
        getLog().error(errorMsg);
@@ -101,15 +97,12 @@
      // Get a sorted list of the files in the schema directory.
      TreeSet<String> schemaFileNames = new TreeSet<String>();
      for (File f : new File(schemaDirectory).listFiles())
      {
        if (f.isFile())
        {
        for (File f : new File(schemaDirectory).listFiles()) {
            if (f.isFile()) {
          schemaFileNames.add(f.getName());
        }
      }
      // Create a set of lists that will hold the schema elements read from the
      // files.
      LinkedList<String> attributeTypes    = new LinkedList<String>();
@@ -123,101 +116,70 @@
      // Open each of the files in order and read the elements that they contain,
      // appending them to the appropriate lists.
      for (String name : schemaFileNames)
      {
        for (String name : schemaFileNames) {
        // Read the contents of the file into a list with one schema element per
        // list element.
        LinkedList<StringBuilder> lines = new LinkedList<StringBuilder>();
        try
        {
          BufferedReader reader = new BufferedReader(new FileReader(
                                           new File(schemaDirectory, name)));
            try {
                BufferedReader reader = new BufferedReader(new FileReader(new File(schemaDirectory, name)));
          String line = reader.readLine();
          while (line != null)
          {
                while (line != null) {
            curLineNumber++;
            if (line.length() > 0 && !line.startsWith("#"))
            {
              if (line.startsWith(" "))
              {
                    if (line.length() > 0 && !line.startsWith("#")) {
                        if (line.startsWith(" ")) {
                lines.getLast().append(line.substring(1));
              }
              else
              {
                        } else {
                lines.add(new StringBuilder(line));
              }
            }
            line = reader.readLine();
          }
          reader.close();
        }
        catch (Exception e)
        {
            getLog().error(String.format(
                "Error while reading schema file %s at line %d: %s", name, curLineNumber, e.getMessage()));
            } catch (Exception e) {
                getLog().error(
                        String.format("Error while reading schema file %s at line %d: %s", name, curLineNumber,
                                e.getMessage()));
            throw new MojoExecutionException(e.getMessage());
        }
        // Iterate through each line in the list.  Find the colon and get the
        // attribute name at the beginning.  If it's someting that we don't
        // recognize, then skip it.  Otherwise, add the X-SCHEMA-FILE extension
        // and add it to the appropriate schema element list.
        for (StringBuilder buffer : lines)
        {
            for (StringBuilder buffer : lines) {
          // Get the line and add the X-SCHEMA-FILE extension to the end of it.
          // All of them should end with " )" but some might have the parenthesis
          // crammed up against the last character so deal with that as well.
          String line = buffer.toString().trim();
          if (line.endsWith(" )"))
          {
                if (line.endsWith(" )")) {
           line = line.substring(0, line.length() - 1) + "X-SCHEMA-FILE '" + name + "' )";
          }
          else if (line.endsWith(")"))
          {
                } else if (line.endsWith(")")) {
           line = line.substring(0, line.length() - 1) + " X-SCHEMA-FILE '" + name + "' )";
          }
          else
          {
                } else {
            continue;
          }
          String lowerLine = line.toLowerCase();
          if (lowerLine.startsWith("attributetypes:"))
          {
                if (lowerLine.startsWith("attributetypes:")) {
            attributeTypes.add(line);
          }
          else if (lowerLine.startsWith("objectclasses:"))
          {
                } else if (lowerLine.startsWith("objectclasses:")) {
            objectClasses.add(line);
          }
          else if (lowerLine.startsWith("nameforms:"))
          {
                } else if (lowerLine.startsWith("nameforms:")) {
            nameForms.add(line);
          }
          else if (lowerLine.startsWith("ditcontentrules:"))
          {
                } else if (lowerLine.startsWith("ditcontentrules:")) {
            ditContentRules.add(line);
          }
          else if (lowerLine.startsWith("ditstructurerules:"))
          {
                } else if (lowerLine.startsWith("ditstructurerules:")) {
            ditStructureRules.add(line);
          }
          else if (lowerLine.startsWith("matchingruleuse:"))
          {
                } else if (lowerLine.startsWith("matchingruleuse:")) {
            matchingRuleUses.add(line);
          }
          else if (lowerLine.startsWith("ldapsyntaxes:"))
          {
                } else if (lowerLine.startsWith("ldapsyntaxes:")) {
            ldapSyntaxes.add(line);
          }
        }
      }
      // Write the resulting output to the merged schema file.
      try
      {
        try {
        BufferedWriter writer = new BufferedWriter(new FileWriter(outputFilePath));
        writer.write("dn: cn=schema");
        writer.newLine();
@@ -237,20 +199,15 @@
        writeSchemaElements(matchingRuleUses, writer);
        writer.close();
      }
      catch (Exception e)
      {
        getLog().error(String.format(
            "Error while writing concatenated schema file %s:  %s", outputFile, e.getMessage()));
        } catch (Exception e) {
            getLog().error(
                    String.format("Error while writing concatenated schema file %s:  %s", outputFile, e.getMessage()));
        throw new MojoExecutionException(e.getMessage());
      }
    }
    private void writeSchemaElements(LinkedList<String> schemaElements, BufferedWriter writer) throws IOException {
        for (String line : schemaElements)
        {
        for (String line : schemaElements) {
          writer.write(line);
          writer.newLine();
        }
opendj-sdk/opendj-logref-doc-maven-plugin/src/main/java/org/forgerock/maven/GenerateMessageFileMojo.java
@@ -54,7 +54,8 @@
import org.forgerock.util.Utils;
/**
 * Generates xml files containing representations of messages found in properties files.
 * Generates xml files containing representations of messages found in
 * properties files.
 * <p>
 * There is a single goal that generates xml files.
 * <p>
@@ -88,8 +89,8 @@
    private List<String> messageFileNames;
    /**
     * The path and file name of the log message reference file path which will be copied in
     * the output directory with generated log reference files.
     * The path and file name of the log message reference file path which will
     * be copied in the output directory with generated log reference files.
     */
    @Parameter(required=true)
    private String logMessageReferenceFilePath;
@@ -108,15 +109,14 @@
     * of where the source are generated, the package name and the
     * DESCRIPTORS_REG value.
     */
    private static String REGISTRY_FILE_NAME;
    private static String registryFileName;
    /**
     * One-line descriptions for log reference categories.
     */
    private static HashMap<String, String> CATEGORY_DESCRIPTIONS;
    private static final HashMap<String, String> CATEGORY_DESCRIPTIONS = new HashMap<String, String>();
    static {
        CATEGORY_DESCRIPTIONS = new HashMap<String, String>();
        CATEGORY_DESCRIPTIONS.put("ACCESS_CONTROL", "Access Control.");
        CATEGORY_DESCRIPTIONS.put("ADMIN", "the administration framework.");
        CATEGORY_DESCRIPTIONS.put("ADMIN_TOOL", "the tool like the offline" + " installer and uninstaller.");
@@ -146,7 +146,7 @@
    private static final String DESCRIPTORS_REG = "descriptors.reg";
    /** Message giving formatting rules for string keys. */
    public static String KEY_FORM_MSG = ".\n\nOpenDJ message property keys must be of the form\n\n"
    public static final String KEY_FORM_MSG = ".\n\nOpenDJ message property keys must be of the form\n\n"
            + "\t\'[CATEGORY]_[SEVERITY]_[DESCRIPTION]_[ORDINAL]\'\n\n";
    private static final String ERROR_SEVERITY_IDENTIFIER_STRING = "ERR_";
@@ -220,6 +220,7 @@
         *
         * @return See {@link java.lang.Comparable#compareTo(Object)}.
         */
        @Override
        public int compareTo(MessageRefEntry mre) {
            if (this.ordinal == null || mre.ordinal == null) {
                return 0;
@@ -293,8 +294,8 @@
        private String getVariablelistHead() {
            StringBuilder builder = new StringBuilder(getXMLPreamble());
            builder.append(" <variablelist xml:id=\"log-ref-").append(this.category).append("\" ")
                   .append(getBaseElementAttrs()).append(">").append(EOL)
                   .append("  <title>Log Message Category: ").append(category).append("</title>").append(EOL);
                    .append(getBaseElementAttrs()).append(">").append(EOL).append("  <title>Log Message Category: ")
                    .append(category).append("</title>").append(EOL);
            return builder.toString();
        }
@@ -359,6 +360,7 @@
        }
        /** {@inheritDoc} */
        @Override
        public String toString() {
            StringBuilder builder = new StringBuilder(description);
            if (ordinal != null) {
@@ -369,6 +371,7 @@
        }
        /** {@inheritDoc} */
        @Override
        public int compareTo(MessagePropertyKey k) {
            if (ordinal == k.ordinal) {
                return description.compareTo(k.description);
@@ -383,8 +386,12 @@
     * For maven exec plugin execution. Generates for all included message files
     * (sample.properties), a xml log ref file (log-ref-sample.xml)
     *
     * @throws Exception
     * @throws MojoExecutionException
     *          if a problem occurs
     * @throws MojoFailureException
     *          if a problem occurs
     */
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        String projectBuildDir = project.getBuild().getDirectory();
@@ -408,8 +415,8 @@
        copyLogMessageReferenceFile();
    }
    private void generateLogReferenceFile(File source, File dest, String globalCategory) throws MojoExecutionException {
    private void generateLogReferenceFile(File source, File dest, String globalCategory)
            throws MojoExecutionException {
        PrintWriter destWriter = null;
        try {
            // Decide whether to generate messages based on modification times
@@ -439,8 +446,7 @@
                messageRefEntries.add(new MessageRefEntry(msgKey.toString(), msgKey.getOrdinal(), formatString));
            }
            destWriter.println(messageRefEntries.isEmpty() ?
                            "<!-- No message for this category -->"
            destWriter.println(messageRefEntries.isEmpty() ? "<!-- No message for this category -->"
                          : new MessageRefCategory(globalCategory, messageRefEntries).toXML());
            getLog().info(dest.getPath() + " has been successfully generated");
            getLog().debug("Message Generated: " + errorMessages.size());
@@ -455,7 +461,6 @@
        }
    }
    private Map<MessagePropertyKey, String> loadErrorProperties(Properties properties) throws Exception {
        Map<MessagePropertyKey, String> errorMessage = new TreeMap<MessagePropertyKey, String>();
        for (Object propO : properties.keySet()) {
@@ -475,7 +480,6 @@
        return errorMessage;
    }
    private boolean isOverwriteNeeded(File source, File dest) {
        boolean needsOverwrite = this.overwrite || source.lastModified() > dest.lastModified();
        if (dest.exists() && needsOverwrite) {
@@ -526,14 +530,16 @@
     *
     * @param dest
     *            File destination
     * @throws Exception
     *          If a problem occurs
     */
    public void checkDestJava(File dest) throws Exception {
        File descriptorsRegFile = new File(dest.getParentFile(), DESCRIPTORS_REG);
        if (REGISTRY_FILE_NAME != null) {
        if (registryFileName != null) {
            // if REGISTRY_FILE_NAME is already set, ensure that we computed the
            // same one
            File prevDescriptorsRegFile = new File(REGISTRY_FILE_NAME);
            File prevDescriptorsRegFile = new File(registryFileName);
            if (!prevDescriptorsRegFile.equals(descriptorsRegFile)) {
                throw new Exception("Error processing " + dest
                        + ": all messages must be located in the same package thus "
@@ -541,7 +547,7 @@
                        + new File(prevDescriptorsRegFile.getParent(), dest.getName()));
            }
        } else {
            REGISTRY_FILE_NAME = descriptorsRegFile.getCanonicalPath();
            registryFileName = descriptorsRegFile.getCanonicalPath();
        }
    }
opendj-sdk/opendj-manifest-classpath-maven-plugin/src/main/java/org/forgerock/maven/GenerateManifestClassPathMojo.java
@@ -25,6 +25,8 @@
 */
package org.forgerock.maven;
import static java.lang.String.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@@ -43,15 +45,16 @@
import org.apache.maven.project.MavenProject;
/**
 * Generate a class path suitable for the Class-Path header of a Manifest file, allowing to filter
 * on included jars, using excludes/includes properties.
 * Generate a class path suitable for the Class-Path header of a Manifest file, allowing to filter on included jars,
 * using excludes/includes properties.
 * <p>
 * There is a single goal that generates a property given by 'classPathProperty' parameter, with the generated
 * classpath as the value.
 * There is a single goal that generates a property given by 'classPathProperty' parameter, with the generated classpath
 * as the value.
 *
 * @Checkstyle:ignoreFor 3
 */
@Mojo(name="generate", defaultPhase=LifecyclePhase.VALIDATE, requiresDependencyResolution=ResolutionScope.COMPILE_PLUS_RUNTIME)
@Mojo(name = "generate", defaultPhase = LifecyclePhase.VALIDATE,
    requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
public final class GenerateManifestClassPathMojo extends AbstractMojo {
    private static final int MAX_LINE_LENGTH = 72;
@@ -82,13 +85,13 @@
    private List<String> includes;
    /**
     * Name of product jar, e.g. "OpenDJ"
     * Name of product jar, e.g. "OpenDJ".
     */
    @Parameter
    private String productJarName;
    /**
     * List of supported locales, separated by a ","
     * List of supported locales, separated by a ",".
     * <p>
     * Example: "fr,es,de"
     */
@@ -96,10 +99,12 @@
    private String supportedLocales;
    /** {@inheritDoc} */
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        try {
            String classPath = getClasspath();
            getLog().info(String.format("Setting the classpath property: [%s] (debug to see actual value)", classPathProperty));
            getLog().info(
                    format("Setting the classpath property: [%s] (debug to see actual value)", classPathProperty));
            getLog().debug(String.format("Setting the classpath property %s to:\n%s", classPathProperty, classPath));
            project.getProperties().put(classPathProperty, classPath);
        } catch (DependencyResolutionRequiredException e) {