You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by bo...@apache.org on 2011/07/20 11:07:43 UTC

svn commit: r1148659 - in /incubator/rat/main/trunk/apache-rat-tasks/src: main/java/org/apache/rat/anttasks/SubstringLicenseMatcher.java test/resources/antunit/report-bad-configurations.xml

Author: bodewig
Date: Wed Jul 20 09:07:42 2011
New Revision: 1148659

URL: http://svn.apache.org/viewvc?rev=1148659&view=rev
Log:
now act on those REQUIRED claims

Modified:
    incubator/rat/main/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/SubstringLicenseMatcher.java
    incubator/rat/main/trunk/apache-rat-tasks/src/test/resources/antunit/report-bad-configurations.xml

Modified: incubator/rat/main/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/SubstringLicenseMatcher.java
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/SubstringLicenseMatcher.java?rev=1148659&r1=1148658&r2=1148659&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/SubstringLicenseMatcher.java (original)
+++ incubator/rat/main/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/SubstringLicenseMatcher.java Wed Jul 20 09:07:42 2011
@@ -21,6 +21,7 @@ package org.apache.rat.anttasks;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.rat.analysis.license.SimplePatternBasedLicense;
+import org.apache.tools.ant.BuildException;
 
 /**
  * Adapts {@link SimplePatternBasedLicense SimplePatternBasedLicense}
@@ -29,6 +30,7 @@ import org.apache.rat.analysis.license.S
  */
 public class SubstringLicenseMatcher extends SimplePatternBasedLicense {
     private List/*<String>*/ patterns = new ArrayList();
+    private boolean validated = false;
 
     public void addConfiguredPattern(Pattern p) {
         patterns.add(p.getSubstring());
@@ -36,9 +38,28 @@ public class SubstringLicenseMatcher ext
 
     // @Override
     public String[] getPatterns() {
+        validate();
         return (String[]) patterns.toArray(new String[0]);
     }
 
+    private void validate() {
+        if (!validated) {
+            validated  = true;
+            if (patterns.size() == 0) {
+                throw new BuildException("You must specify at least one nested"
+                                         + " pattern.");
+            }
+            if (getLicenseFamilyCategory() == null) {
+                throw new BuildException("The licenseFamilyCategory attribute"
+                                         + " is required.");
+            }
+            if (getLicenseFamilyName() == null) {
+                throw new BuildException("The licenseFamilyName attribute"
+                                         + " is required.");
+            }
+        }
+    }
+
     /**
      * A simple wrapper around a substring.
      */

Modified: incubator/rat/main/trunk/apache-rat-tasks/src/test/resources/antunit/report-bad-configurations.xml
URL: http://svn.apache.org/viewvc/incubator/rat/main/trunk/apache-rat-tasks/src/test/resources/antunit/report-bad-configurations.xml?rev=1148659&r1=1148658&r2=1148659&view=diff
==============================================================================
--- incubator/rat/main/trunk/apache-rat-tasks/src/test/resources/antunit/report-bad-configurations.xml (original)
+++ incubator/rat/main/trunk/apache-rat-tasks/src/test/resources/antunit/report-bad-configurations.xml Wed Jul 20 09:07:42 2011
@@ -76,4 +76,45 @@
     <au:assertLogContains text="Ignoring stylesheet"/>
   </target>
 
+  <target name="testSubstringMatcherRequiresFamilyName">
+    <au:expectfailure
+        expectedMessage="The licenseFamilyName attribute is required.">
+      <rat:report>
+        <file file="${ant.file}"/>
+        <rat:substringMatcher
+            licenseFamilyCategory="YASL1"
+            notes="Interesting License">
+          <pattern substring="exmpl"/>
+        </rat:substringMatcher>
+      </rat:report>
+    </au:expectfailure>
+  </target>
+
+  <target name="testSubstringMatcherRequiresFamilyCategory">
+    <au:expectfailure
+        expectedMessage="The licenseFamilyCategory attribute is required.">
+      <rat:report>
+        <file file="${ant.file}"/>
+        <rat:substringMatcher
+            licenseFamilyName="Yet Another Software License (YASL) 1.0"
+            notes="Interesting License">
+          <pattern substring="exmpl"/>
+        </rat:substringMatcher>
+      </rat:report>
+    </au:expectfailure>
+  </target>
+
+  <target name="testSubstringMatcherRequiresPattern">
+    <au:expectfailure
+        expectedMessage="You must specify at least one nested pattern.">
+      <rat:report>
+        <file file="${ant.file}"/>
+        <rat:substringMatcher
+            licenseFamilyCategory="YASL1"
+            licenseFamilyName="Yet Another Software License (YASL) 1.0"
+            notes="Interesting License">
+        </rat:substringMatcher>
+      </rat:report>
+    </au:expectfailure>
+  </target>
 </project>