RAT-177 Converted arrays to list

* Converted array elements into an unmodifiable collection.
* Using lists instead of arrays to ease copy/addAll().



git-svn-id: https://svn.apache.org/repos/asf/creadur/rat/trunk@1625380 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/apache-rat-core/src/main/java/org/apache/rat/Defaults.java b/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
index 44b9bf6..9ff57c1 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
@@ -22,6 +22,7 @@
 import org.apache.rat.analysis.generation.GeneratedLicenseNotRequired;
 import org.apache.rat.analysis.generation.JavaDocLicenseNotRequired;
 import org.apache.rat.analysis.license.ApacheSoftwareLicense20;
+import org.apache.rat.analysis.license.CDDL1License;
 import org.apache.rat.analysis.license.DojoLicenseHeader;
 import org.apache.rat.analysis.license.GPL1License;
 import org.apache.rat.analysis.license.GPL2License;
@@ -34,7 +35,9 @@
 import org.apache.rat.analysis.util.HeaderMatcherMultiplexer;
 
 import java.io.InputStream;
-import org.apache.rat.analysis.license.CDDL1License;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 
 
 
@@ -48,8 +51,8 @@
     /**
      * The standard list of licenses to include in the reports.
      */
-    public static final IHeaderMatcher[] DEFAULT_MATCHERS =
-        new IHeaderMatcher[] {
+    public static final List<IHeaderMatcher> DEFAULT_MATCHERS = Collections.unmodifiableList(
+            Arrays.asList(new IHeaderMatcher[] {
             new ApacheSoftwareLicense20(),
             new GPL1License(),
             new GPL2License(),
@@ -63,7 +66,7 @@
             new DojoLicenseHeader(),
             new TMF854LicenseHeader(),
             new CDDL1License(),
-    };
+            }));
     
     public static final String PLAIN_STYLESHEET = "org/apache/rat/plain-rat.xsl";
     
diff --git a/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java b/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java
index 917accb..ed3eb73 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java
@@ -22,15 +22,17 @@
 import org.apache.rat.analysis.RatHeaderAnalysisException;
 import org.apache.rat.api.Document;
 
+import java.util.List;
+
 /**
  * Delegates to an ordered set of matchers.
  *
  */
 public final class HeaderMatcherMultiplexer implements IHeaderMatcher {
 
-    private final IHeaderMatcher[] matchers;
+    private final List<IHeaderMatcher> matchers;
 
-    public HeaderMatcherMultiplexer(final IHeaderMatcher[] matchers) {
+    public HeaderMatcherMultiplexer(final List<IHeaderMatcher> matchers) {
         this.matchers = matchers;
     }
 
diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
index 9456b13..1ed6e69 100644
--- a/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
+++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
@@ -26,6 +26,8 @@
 import org.apache.rat.document.MockLocation;
 import org.apache.rat.report.claim.impl.xml.MockClaimReporter;
 
+import java.util.Arrays;
+
 public class MatcherMultiplexerTest extends TestCase {
 
     private static final String LINE_ONE = "Line One";
@@ -42,8 +44,7 @@
         super.setUp();
         matcherOne = new MockLicenseMatcher();
         matcherTwo = new MockLicenseMatcher();
-        IHeaderMatcher[] matchers = {matcherOne, matcherTwo};
-        multiplexer = new HeaderMatcherMultiplexer(matchers);
+        multiplexer = new HeaderMatcherMultiplexer(Arrays.<IHeaderMatcher>asList(matcherOne, matcherTwo));
         reporter = new MockClaimReporter();
     }
 
diff --git a/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java b/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
index b179d9b..0a00d7f 100644
--- a/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
+++ b/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
@@ -19,25 +19,6 @@
  * under the License.
  */
 
-import static org.apache.rat.mp.ExclusionHelper.addEclipseDefaults;
-import static org.apache.rat.mp.ExclusionHelper.addIdeaDefaults;
-import static org.apache.rat.mp.ExclusionHelper.addMavenDefaults;
-import static org.apache.rat.mp.ExclusionHelper.addPlexusAndScmDefaults;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.transform.TransformerConfigurationException;
-
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -54,6 +35,24 @@
 import org.apache.rat.report.IReportable;
 import org.apache.rat.report.claim.ClaimStatistic;
 import org.codehaus.plexus.util.DirectoryScanner;
+
+import javax.xml.transform.TransformerConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.apache.rat.mp.ExclusionHelper.addEclipseDefaults;
+import static org.apache.rat.mp.ExclusionHelper.addIdeaDefaults;
+import static org.apache.rat.mp.ExclusionHelper.addMavenDefaults;
+import static org.apache.rat.mp.ExclusionHelper.addPlexusAndScmDefaults;
 /**
  * Abstract base class for Mojos, which are running Rat.
  */
@@ -205,13 +204,13 @@
      *             An error in the plugin configuration was detected.
      * @throws MojoExecutionException
      *             An error occurred while calculating the result.
-     * @return Array of license matchers to use
+     * @return list of license matchers to use
      */
-    protected IHeaderMatcher[] getLicenseMatchers()
+    protected List<IHeaderMatcher> getLicenseMatchers()
             throws MojoFailureException, MojoExecutionException {
-        final List<IHeaderMatcher> list = new ArrayList<IHeaderMatcher>();
+        final List<IHeaderMatcher> matchers = new ArrayList<IHeaderMatcher>();
         if (licenses != null) {
-            list.addAll(Arrays.asList(licenses));
+            matchers.addAll(Arrays.asList(licenses));
         }
 
         if (licenseMatchers != null) {
@@ -219,14 +218,14 @@
                 final String className = spec.getClassName();
                 final IHeaderMatcher headerMatcher = newInstance(
                         IHeaderMatcher.class, className);
-                list.add(headerMatcher);
+                matchers.add(headerMatcher);
             }
         }
 
         if (addDefaultLicenseMatchers) {
-            list.addAll(Arrays.asList(Defaults.DEFAULT_MATCHERS));
+            matchers.addAll(Defaults.DEFAULT_MATCHERS);
         }
-        return list.toArray(new IHeaderMatcher[list.size()]);
+        return matchers;
     }
 
     private <T> T newInstance(final Class<T> clazz, final String className)
diff --git a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
index 166f3db..df5bb1a 100644
--- a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
+++ b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
@@ -18,32 +18,31 @@
  */ 
 package org.apache.rat.anttasks;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.util.ArrayList;
+ import org.apache.rat.Defaults;
+ import org.apache.rat.ReportConfiguration;
+ import org.apache.rat.analysis.IHeaderMatcher;
+ import org.apache.rat.analysis.util.HeaderMatcherMultiplexer;
+ import org.apache.rat.api.RatException;
+ import org.apache.rat.license.ILicenseFamily;
+ import org.apache.tools.ant.BuildException;
+ import org.apache.tools.ant.Project;
+ import org.apache.tools.ant.Task;
+ import org.apache.tools.ant.taskdefs.LogOutputStream;
+ import org.apache.tools.ant.types.EnumeratedAttribute;
+ import org.apache.tools.ant.types.Resource;
+ import org.apache.tools.ant.types.ResourceCollection;
+ import org.apache.tools.ant.types.resources.Union;
+ import org.apache.tools.ant.util.FileUtils;
 
-import javax.xml.transform.TransformerException;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.LogOutputStream;
-import org.apache.tools.ant.types.EnumeratedAttribute;
-import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.ResourceCollection;
-import org.apache.tools.ant.types.resources.Union;
-import org.apache.tools.ant.util.FileUtils;
-
-import org.apache.rat.Defaults;
-import org.apache.rat.ReportConfiguration;
-import org.apache.rat.analysis.IHeaderMatcher;
-import org.apache.rat.analysis.util.HeaderMatcherMultiplexer;
-import org.apache.rat.api.RatException;
-import org.apache.rat.license.ILicenseFamily;
+ import javax.xml.transform.TransformerException;
+ import java.io.File;
+ import java.io.FileWriter;
+ import java.io.IOException;
+ import java.io.InputStream;
+ import java.io.OutputStreamWriter;
+ import java.io.PrintWriter;
+ import java.util.ArrayList;
+ import java.util.List;
 
 /**
  * A basic Ant task that generates a report on all files specified by
@@ -290,21 +289,15 @@
      * Flattens all nested matchers plus the default matchers (if
      * required) into a single array.
      */
-    private IHeaderMatcher[] getLicenseMatchers() {
-        IHeaderMatcher[] matchers = null;
+    private List<IHeaderMatcher> getLicenseMatchers() {
+        List<IHeaderMatcher> matchers = new ArrayList<IHeaderMatcher>(Defaults.DEFAULT_MATCHERS);
         if (addDefaultLicenseMatchers) {
             int nestedSize = licenseMatchers.size();
-            if (nestedSize == 0) {
-                matchers = Defaults.DEFAULT_MATCHERS;
-            } else {
-                matchers = new IHeaderMatcher[Defaults.DEFAULT_MATCHERS.length
-                                               + nestedSize];
-                licenseMatchers.toArray(matchers);
-                System.arraycopy(Defaults.DEFAULT_MATCHERS, 0, matchers,
-                                 nestedSize, Defaults.DEFAULT_MATCHERS.length);
+            if (nestedSize != 0) {
+                matchers.addAll(licenseMatchers);
             }
         } else {
-            matchers = licenseMatchers.toArray(new IHeaderMatcher[0]);
+            matchers = new ArrayList<IHeaderMatcher>();
         }
         return matchers;
     }