creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pottlin...@apache.org
Subject svn commit: r1625380 - in /creadur/rat/trunk: apache-rat-core/src/main/java/org/apache/rat/ apache-rat-core/src/main/java/org/apache/rat/analysis/util/ apache-rat-core/src/test/java/org/apache/rat/analysis/util/ apache-rat-plugin/src/main/java/org/apac...
Date Tue, 16 Sep 2014 20:22:57 GMT
Author: pottlinger
Date: Tue Sep 16 20:22:57 2014
New Revision: 1625380

URL: http://svn.apache.org/r1625380
Log:
RAT-177 Converted arrays to list

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


Modified:
    creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
    creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java
    creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
    creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
    creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java

Modified: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java?rev=1625380&r1=1625379&r2=1625380&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java (original)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/Defaults.java Tue Sep 16
20:22:57 2014
@@ -22,6 +22,7 @@ import org.apache.rat.analysis.IHeaderMa
 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.license.W
 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 @@ public class Defaults {
     /**
      * 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 @@ public class Defaults {
             new DojoLicenseHeader(),
             new TMF854LicenseHeader(),
             new CDDL1License(),
-    };
+            }));
     
     public static final String PLAIN_STYLESHEET = "org/apache/rat/plain-rat.xsl";
     

Modified: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java?rev=1625380&r1=1625379&r2=1625380&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java
(original)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/util/HeaderMatcherMultiplexer.java
Tue Sep 16 20:22:57 2014
@@ -22,15 +22,17 @@ import org.apache.rat.analysis.IHeaderMa
 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;
     }
 

Modified: creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java?rev=1625380&r1=1625379&r2=1625380&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
(original)
+++ creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/util/MatcherMultiplexerTest.java
Tue Sep 16 20:22:57 2014
@@ -26,6 +26,8 @@ import org.apache.rat.api.Document;
 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 @@ public class MatcherMultiplexerTest exte
         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();
     }
 

Modified: creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java?rev=1625380&r1=1625379&r2=1625380&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
(original)
+++ creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
Tue Sep 16 20:22:57 2014
@@ -19,25 +19,6 @@ package org.apache.rat.mp;
  * 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.license.ILicenseFa
 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 @@ public abstract class AbstractRatMojo ex
      *             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 @@ public abstract class AbstractRatMojo ex
                 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)

Modified: creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java?rev=1625380&r1=1625379&r2=1625380&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java (original)
+++ creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java Tue
Sep 16 20:22:57 2014
@@ -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 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 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 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 @@ public class Report extends Task {
      * 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;
     }



Mime
View raw message