creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1484128 - /creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java
Date Sat, 18 May 2013 15:34:36 GMT
Author: sebb
Date: Sat May 18 15:34:36 2013
New Revision: 1484128

URL: http://svn.apache.org/r1484128
Log:
RAT-138 RAT runs very slowly on some input
Use String matching by default rather than building patterns

Modified:
    creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java

Modified: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java?rev=1484128&r1=1484127&r2=1484128&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java
(original)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/generation/GeneratedLicenseNotRequired.java
Sat May 18 15:34:36 2013
@@ -27,57 +27,75 @@ import org.apache.rat.api.MetaData;
 
 public class GeneratedLicenseNotRequired implements IHeaderMatcher {
 
-    private static final Pattern[] DEFAULT_PATTERNS = {Pattern.compile(".*generated by Cayenne.*"),
-        Pattern.compile(".*Generated By:JJTree.*"),
-        Pattern.compile(".*Generated By:JavaCC.*"),
-        Pattern.compile(".*THIS FILE IS AUTOMATICALLY GENERATED.*"),
-        Pattern.compile(".*NOTE: this file is autogenerated by XBeans.*"),
-        Pattern.compile(".*This file was automatically generated by .*"),
-        Pattern.compile(".*# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!.*"),
-        Pattern.compile(".*# Microsoft Developer Studio Generated NMAKE File.*"),
-        Pattern.compile(".*# Microsoft Developer Studio Generated Build File.*"),
-        Pattern.compile(".*Generated from configure.ac by autoheader.*"),
-        Pattern.compile(".*generated automatically by aclocal.*"),
-        Pattern.compile(".*build.xml generated by maven from project.xml.*"),
-        Pattern.compile(".*This file was generated by.*"),
-        Pattern.compile(".*This file has been automatically generated..*"),
-        Pattern.compile(".*Automatically generated - do not modify!.*"),
-        Pattern.compile(".*Javadoc style sheet.*"),
-        Pattern.compile(".*SOURCE FILE GENERATATED.*"),
-        Pattern.compile(".*Generated by the Batik.*"),
-        Pattern.compile(".*this file is autogenerated.*"),
-        Pattern.compile(".*This class was autogenerated.*"),
-        Pattern.compile(".*Generated by Maven.*"),
-        Pattern.compile(".*Autogenerated by Thrift.*"),
-        Pattern.compile(".*DO NOT EDIT THIS FILE - it is machine generated.*"),
-        Pattern.compile(".*This class was generated by.*")};
+    private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+    private static final Pattern[] EMPTY_PATTERN_ARRAY = new Pattern[0];
+
+    private static final String[] DEFAULT_PHRASES = {
+        "generated by Cayenne",
+        "Generated By:JJTree",
+        "Generated By:JavaCC",
+        "THIS FILE IS AUTOMATICALLY GENERATED",
+        "NOTE: this file is autogenerated by XBeans",
+        "This file was automatically generated by ",
+        "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!",
+        "# Microsoft Developer Studio Generated NMAKE File",
+        "# Microsoft Developer Studio Generated Build File",
+        "Generated from configure.ac by autoheader",
+        "generated automatically by aclocal",
+        "build.xml generated by maven from project.xml",
+        "This file was generated by",
+        "This file has been automatically generated.",
+        "Automatically generated - do not modify!",
+        "Javadoc style sheet",
+        "SOURCE FILE GENERATATED",
+        "Generated by the Batik",
+        "this file is autogenerated",
+        "This class was autogenerated",
+        "Generated by Maven",
+        "Autogenerated by Thrift",
+        "DO NOT EDIT THIS FILE - it is machine generated",
+        "This class was generated by"};
     
     
+    // Uses either patterns or strings currently (not both)
     private final Pattern[] linePatterns;
-    private final int numberOfPatterns;
+    private final String[] phrases;
     
     public GeneratedLicenseNotRequired() {
-        this(DEFAULT_PATTERNS);
+        this(DEFAULT_PHRASES);
     }
     
     public GeneratedLicenseNotRequired(final Pattern[] linePatterns) {
         this.linePatterns = linePatterns;
-        this.numberOfPatterns = linePatterns.length;
+        this.phrases = EMPTY_STRING_ARRAY;
+    }
+
+    public GeneratedLicenseNotRequired(final String[] lines) {
+        this.linePatterns = EMPTY_PATTERN_ARRAY;
+        this.phrases = lines;
     }
 
     public boolean match(Document subject, String line) throws RatHeaderAnalysisException
{
         boolean result = false;
-        for (int i=0;i<numberOfPatterns;i++) {
-            if (linePatterns[i].matcher(line).matches()) {
+        for (Pattern pat : linePatterns) {
+            if (pat.matcher(line).matches()) {
                 result = true;
                 reportOnLicense(subject);
                 break;
             }
         }
+        for(String phrase : phrases) {
+            if (line.contains(phrase)) {
+                result = true;
+                reportOnLicense(subject);
+                break;
+            }                
+        }
         return result;
     }
 
-    private void reportOnLicense(Document subject) throws RatHeaderAnalysisException {
+    private void reportOnLicense(Document subject) {
         subject.getMetaData().set(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_GEN);
     }
 



Mime
View raw message