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

svn commit: r1211615 - in /incubator/rat/whisker/trunk/apache-whisker-xml/src: main/java/org/apache/rat/whisker/fromxml/ main/java/org/apache/rat/whisker/out/ test/java/org/apache/rat/whisker/fromxml/

Author: rdonkin
Date: Wed Dec  7 20:11:54 2011
New Revision: 1211615

URL: http://svn.apache.org/viewvc?rev=1211615&view=rev
Log:
Moved with-license collect to builder

Modified:
    incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java
    incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/WithinDirectory.java
    incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderWithLicenseTest.java

Modified: incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java?rev=1211615&r1=1211614&r2=1211615&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java Wed Dec  7 20:11:54 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.rat.whisker.fromxml;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -255,4 +256,22 @@ public class JDomBuilder {
         return results;
     }
 
+    /**
+     * Collects child with-licenses.
+     * @param licenses not null
+     * @param organisations not null
+     * @param parent not null
+     * @return not null, possibly empty
+     */
+    @SuppressWarnings("unchecked")
+    public Collection<WithLicense> withLicenses(Map<String, License> licenses,
+            Map<String, Organisation> organisations, Element parent) {
+        final List<WithLicense> results = new ArrayList<WithLicense>();
+        for (Element withLicenseElement: (List<Element>) parent.getChildren("with-license")) {
+            results.add(new JDomBuilder().withLicense(withLicenseElement, licenses, organisations));
+        }
+        Collections.sort(results);
+        return results;
+    }
+
 }

Modified: incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/WithinDirectory.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/WithinDirectory.java?rev=1211615&r1=1211614&r2=1211615&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/WithinDirectory.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/WithinDirectory.java Wed Dec  7 20:11:54 2011
@@ -18,10 +18,7 @@
  */
 package org.apache.rat.whisker.out;
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.rat.whisker.fromxml.JDomBuilder;
@@ -47,23 +44,6 @@ public class WithinDirectory implements 
         return new JDomBuilder().collectByOrganisations(element.getChild("public-domain"), organisations);
     }
 
-
-    /**
-     * @param licenses
-     * @param element
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    private static Collection<WithLicense> licenses(Map<String, License> licenses,
-            Map<String, Organisation> organisations, Element element) {
-        final List<WithLicense> results = new ArrayList<WithLicense>();
-        for (Element withLicenseElement: (List<Element>) element.getChildren("with-license")) {
-            results.add(new JDomBuilder().withLicense(withLicenseElement, licenses, organisations));
-        }
-        Collections.sort(results);
-        return results;
-    }
-
     
     private final Element element;
     private final Collection<WithLicense> licenses;
@@ -76,7 +56,7 @@ public class WithinDirectory implements 
             Map<String, Organisation> organisations) {
         super();
         this.element = element;
-        this.licenses = licenses(licenses, organisations, element);
+        this.licenses = new JDomBuilder().withLicenses(licenses, organisations, element);
         this.publicDomain = publicDomain(organisations, element);
     }
     

Modified: incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderWithLicenseTest.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderWithLicenseTest.java?rev=1211615&r1=1211614&r2=1211615&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderWithLicenseTest.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderWithLicenseTest.java Wed Dec  7 20:11:54 2011
@@ -18,18 +18,19 @@
  */
 package org.apache.rat.whisker.fromxml;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import junit.framework.TestCase;
+
 import org.apache.rat.whisker.model.License;
 import org.apache.rat.whisker.model.Organisation;
 import org.apache.rat.whisker.model.WithLicense;
 import org.jdom.CDATA;
 import org.jdom.Element;
 
-import junit.framework.TestCase;
-
 /**
  * 
  */
@@ -268,4 +269,39 @@ public class JDomBuilderWithLicenseTest 
             // expected
         }
     }
+    
+    public void testBuildCollectWithLicenses() throws Exception {
+        for (int i=0; i<256; i++) {
+            checkCollectWithLicenses(i);
+        }
+    }
+
+    /**
+     * @param numberOfWithLicenses
+     */
+    private void checkCollectWithLicenses(final int numberOfWithLicenses) {
+        final String id = "an ID";
+        final Map<String, License> licenses = new HashMap<String, License>();
+        final Map<String, Organisation> organisations = new HashMap<String, Organisation>();
+        final Element parent = new Element("within");
+        
+        for(int i=0;i<numberOfWithLicenses;i++) {
+            addWithLicense(id + i, licenses, parent);            
+        }
+        
+        final Collection<WithLicense> results = subject.withLicenses(licenses, organisations, parent);
+        assertNotNull("Builder should build", results);
+        assertEquals("Builder should build one with-license for each child", numberOfWithLicenses, results.size());
+    }
+
+    /**
+     * @param id
+     * @param licenses
+     * @param parent
+     */
+    private void addWithLicense(final String id,
+            final Map<String, License> licenses, final Element parent) {
+        addLicenseTo(licenses, id);
+        parent.addContent(new Element("with-license").setAttribute("id", id));
+    }
 }