Author: sebb
Date: Sun May 19 18:58:42 2013
New Revision: 1484335
URL: http://svn.apache.org/r1484335
Log:
RAT-138 RAT runs very slowly on some input
Fix AppliedApacheSoftwareLicense
Added:
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/bad/
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/bad/aasl20bad1.txt
(with props)
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/bad/aasl20bad2.txt
(with props)
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/good/
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/good/aasl20good1.txt
(with props)
Modified:
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20.java
creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20Test.java
Modified:
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20.java
URL:
http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20.java?rev=1484335&r1=1484334&r2=1484335&view=diff
==============================================================================
---
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20.java
(original)
+++
creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20.java
Sun May 19 18:58:42 2013
@@ -18,8 +18,6 @@
*/
package org.apache.rat.analysis.license;
-import java.util.regex.Pattern;
-
import org.apache.rat.analysis.RatHeaderAnalysisException;
import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
@@ -44,12 +42,11 @@ public class AppliedApacheSoftwareLicens
+ "See the License for the specific language governing permissions
and\n"
+ "limitations under the License.\n";
- protected static final Pattern LICENSE_PATTERN = Pattern.compile(".*" +
prune(ASL20_LICENSE_DEFN) + ".*", Pattern.CASE_INSENSITIVE);
-
- private StringBuilder buffer = new StringBuilder();
+ private final FullTextMatchingLicense textMatcher;
public AppliedApacheSoftwareLicense20() {
super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_ASL,
MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_APACHE_LICENSE_VERSION_2_0,"");
+ textMatcher = new
FullTextMatchingLicense(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_ASL,
MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_APACHE_LICENSE_VERSION_2_0,"",ASL20_LICENSE_DEFN);
}
public AppliedApacheSoftwareLicense20(String copyrightOwner) {
@@ -61,12 +58,7 @@ public class AppliedApacheSoftwareLicens
public boolean match(Document subject, String s) throws
RatHeaderAnalysisException {
boolean result = false;
if (isCopyrightMatch()) {
- buffer.append(prune(s));
- if (LICENSE_PATTERN.matcher(buffer).matches()) {
- reportOnLicense(subject);
- return true;
- }
- return false;
+ return textMatcher.match(subject, s); // will report the match if
it has occurred
}
else {
matchCopyright(s);
@@ -77,6 +69,6 @@ public class AppliedApacheSoftwareLicens
@Override
public void reset() {
super.reset();
- buffer.setLength(0);
+ textMatcher.reset();
}
}
Modified:
creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20Test.java
URL:
http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20Test.java?rev=1484335&r1=1484334&r2=1484335&view=diff
==============================================================================
---
creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20Test.java
(original)
+++
creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/license/AppliedApacheSoftwareLicense20Test.java
Sun May 19 18:58:42 2013
@@ -89,4 +89,14 @@ public class AppliedApacheSoftwareLicens
assertFalse("Applied ASL2.0 license should not be matched", result);
license.reset();
}
+ @Test(timeout=2000) // may need to be adjusted if many more files are added
+ public void goodFiles() throws Exception {
+ DirectoryScanner.testFilesInDir("appliedASL20/good", license, true);
+ }
+
+ @Test(timeout=2000) // may need to be adjusted if many more files are added
+ public void baddFiles() throws Exception {
+ DirectoryScanner.testFilesInDir("appliedASL20/bad", license, false);
+ }
+
}
Added:
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/bad/aasl20bad1.txt
URL:
http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/bad/aasl20bad1.txt?rev=1484335&view=auto
==============================================================================
---
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/bad/aasl20bad1.txt
(added)
+++
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/bad/aasl20bad1.txt
Sun May 19 18:58:42 2013
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2012-2013 BarFoo. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the \"License\");
+ * you may not use this file except in compliance with the License.
+ *
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an \"AS IS\" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ Wrong copyright holder
\ No newline at end of file
Propchange:
creadur/rat/trunk/apache-rat-core/src/test/resources/appliedASL20/bad/aasl20bad1.txt
------------------------------------------------------------------------------
svn:eol-style = native