From 1f07f23cbe8663ad7985d7750af15d33bb7a329c Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 09 Feb 2015 09:37:41 +0000
Subject: [PATCH] Fixed SonarQube violations

---
 opendj-manifest-classpath-maven-plugin/src/main/java/org/forgerock/maven/GenerateManifestClassPathMojo.java |   27 +++++++------
 opendj-concat-schema-maven-plugin/src/main/java/org/forgerock/maven/ConcatSchemaMojo.java                   |   12 +++---
 opendj-logref-doc-maven-plugin/src/main/java/org/forgerock/maven/GenerateMessageFileMojo.java               |    8 ++--
 opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/GenerateConfigMojo.java                 |   16 ++++----
 4 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/opendj-concat-schema-maven-plugin/src/main/java/org/forgerock/maven/ConcatSchemaMojo.java b/opendj-concat-schema-maven-plugin/src/main/java/org/forgerock/maven/ConcatSchemaMojo.java
index 21ed0f4..becc11a 100644
--- a/opendj-concat-schema-maven-plugin/src/main/java/org/forgerock/maven/ConcatSchemaMojo.java
+++ b/opendj-concat-schema-maven-plugin/src/main/java/org/forgerock/maven/ConcatSchemaMojo.java
@@ -32,6 +32,7 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.TreeSet;
 
 import org.apache.maven.plugin.AbstractMojo;
@@ -136,10 +137,9 @@
                 }
                 reader.close();
             } 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());
+                getLog().error(String.format(
+                        "Error while reading schema file %s at line %d: %s", name, curLineNumber, e.getMessage()));
+                throw new MojoExecutionException(e.getMessage(), e);
             }
 
             // Iterate through each line in the list. Find the colon and get the
@@ -202,11 +202,11 @@
         } catch (Exception e) {
             getLog().error(
                     String.format("Error while writing concatenated schema file %s:  %s", outputFile, e.getMessage()));
-            throw new MojoExecutionException(e.getMessage());
+            throw new MojoExecutionException(e.getMessage(), e);
         }
     }
 
-    private void writeSchemaElements(LinkedList<String> schemaElements, BufferedWriter writer) throws IOException {
+    private void writeSchemaElements(List<String> schemaElements, BufferedWriter writer) throws IOException {
         for (String line : schemaElements) {
             writer.write(line);
             writer.newLine();
diff --git a/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/GenerateConfigMojo.java b/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/GenerateConfigMojo.java
index b126990..fbe6502 100644
--- a/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/GenerateConfigMojo.java
+++ b/opendj-config-maven-plugin/src/main/java/org/forgerock/opendj/maven/GenerateConfigMojo.java
@@ -21,7 +21,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2013 ForgeRock AS.
+ *      Copyright 2013-2015 ForgeRock AS.
  */
 package org.forgerock.opendj.maven;
 
@@ -106,7 +106,7 @@
  * @requiresDependencyResolution compile+runtime
  */
 public final class GenerateConfigMojo extends AbstractMojo {
-    private static interface StreamSourceFactory {
+    private interface StreamSourceFactory {
         StreamSource newStreamSource() throws IOException;
     }
 
@@ -188,7 +188,7 @@
     };
 
     @Override
-    public final void execute() throws MojoExecutionException {
+    public void execute() throws MojoExecutionException {
         if (getPackagePath() == null) {
             throw new MojoExecutionException("<packagePath> must be set.");
         } else if (!isXMLPackageDirectoryValid()) {
@@ -422,15 +422,15 @@
     private void loadXMLDescriptors() throws IOException {
         getLog().info("Loading XML descriptors...");
         final String parentPath = getXMLPackageDirectory();
+        final String configFileName = "Configuration.xml";
         if (isExtension) {
             final File dir = new File(parentPath);
             dir.listFiles(new FileFilter() {
                 @Override
                 public boolean accept(final File path) {
                     final String name = path.getName();
-                    if (path.isFile() && name.endsWith("Configuration.xml")) {
-                        final String key =
-                                name.substring(0, name.length() - "Configuration.xml".length());
+                    if (path.isFile() && name.endsWith(configFileName)) {
+                        final String key = name.substring(0, name.length() - configFileName.length());
                         componentDescriptors.put(key, new StreamSourceFactory() {
                             @Override
                             public StreamSource newStreamSource() {
@@ -449,9 +449,9 @@
             while (entries.hasMoreElements()) {
                 final JarEntry entry = entries.nextElement();
                 final String name = entry.getName();
-                if (name.startsWith(parentPath) && name.endsWith("Configuration.xml")) {
+                if (name.startsWith(parentPath) && name.endsWith(configFileName)) {
                     final int startPos = name.lastIndexOf('/') + 1;
-                    final int endPos = name.length() - "Configuration.xml".length();
+                    final int endPos = name.length() - configFileName.length();
                     final String key = name.substring(startPos, endPos);
                     componentDescriptors.put(key, new StreamSourceFactory() {
                         @Override
diff --git a/opendj-logref-doc-maven-plugin/src/main/java/org/forgerock/maven/GenerateMessageFileMojo.java b/opendj-logref-doc-maven-plugin/src/main/java/org/forgerock/maven/GenerateMessageFileMojo.java
index e8b151e..492d4db 100644
--- a/opendj-logref-doc-maven-plugin/src/main/java/org/forgerock/maven/GenerateMessageFileMojo.java
+++ b/opendj-logref-doc-maven-plugin/src/main/java/org/forgerock/maven/GenerateMessageFileMojo.java
@@ -427,7 +427,7 @@
                             + " has been previously defined in " + source + KEY_FORM_MSG);
                 }
                 usedOrdinals.add(ordinal);
-                messageRefEntries.add(new MessageRefEntry(msgKey.toString(), msgKey.getOrdinal(), formatString));
+                messageRefEntries.add(new MessageRefEntry(msgKey.toString(), ordinal, formatString));
             }
 
             destWriter.println(messageRefEntries.isEmpty() ? "<!-- No message for this category -->"
@@ -439,7 +439,7 @@
             if (dest.exists()) {
                 dest.deleteOnExit();
             }
-            throw new MojoExecutionException(e.getMessage());
+            throw new MojoExecutionException(e.getMessage(), e);
         } finally {
             Utils.closeSilently(destWriter);
         }
@@ -457,7 +457,7 @@
                     errorMessage.put(key, formatString);
                 }
             } catch (IllegalArgumentException iae) {
-                throw new Exception("invalid property key " + propKey + ": " + iae.getMessage() + KEY_FORM_MSG);
+                throw new Exception("invalid property key " + propKey + ": " + iae.getMessage() + KEY_FORM_MSG, iae);
             }
         }
 
@@ -502,7 +502,7 @@
             getLog().info("log message reference file has been successfully generated");
         } catch (Exception e) {
             throw new MojoExecutionException("Impossible to copy log reference message file into output directory: "
-                    + e.getMessage());
+                    + e.getMessage(), e);
         } finally {
             Utils.closeSilently(input, output);
         }
diff --git a/opendj-manifest-classpath-maven-plugin/src/main/java/org/forgerock/maven/GenerateManifestClassPathMojo.java b/opendj-manifest-classpath-maven-plugin/src/main/java/org/forgerock/maven/GenerateManifestClassPathMojo.java
index ebc75d3..a51d837 100644
--- a/opendj-manifest-classpath-maven-plugin/src/main/java/org/forgerock/maven/GenerateManifestClassPathMojo.java
+++ b/opendj-manifest-classpath-maven-plugin/src/main/java/org/forgerock/maven/GenerateManifestClassPathMojo.java
@@ -110,7 +110,7 @@
         } catch (DependencyResolutionRequiredException e) {
             getLog().error(
                     String.format("Unable to set the classpath property %s, an error occured", classPathProperty));
-            throw new MojoFailureException(e.getMessage());
+            throw new MojoFailureException(e.getMessage(), e);
         }
     }
 
@@ -167,25 +167,29 @@
     private boolean isAccepted(Artifact artifact) {
         String artifactString = artifact.getGroupId() + ":" + artifact.getArtifactId();
         if (includes != null) {
-            for (String included : includes) {
-                if (artifactString.equalsIgnoreCase(included)) {
-                    return true;
-                }
+            if (containsIgnoreCase(includes, artifactString)) {
+                return true;
             }
             if (!includes.isEmpty()) {
                 return false;
             }
         }
-        if (excludes != null) {
-            for (String excluded : excludes) {
-                if (artifactString.equalsIgnoreCase(excluded)) {
-                    return false;
-                }
-            }
+        if (excludes != null
+                && containsIgnoreCase(excludes, artifactString)) {
+            return false;
         }
         return true;
     }
 
+    private boolean containsIgnoreCase(List<String> strings, String toFind) {
+        for (String s : strings) {
+            if (toFind.equalsIgnoreCase(s)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private Artifact findArtifactWithFile(Set<Artifact> artifacts, File file) {
         for (Artifact artifact : artifacts) {
             if (artifact.getFile() != null
@@ -195,5 +199,4 @@
         }
         return null;
     }
-
 }

--
Gitblit v1.10.0