ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r691531 - in /ant/ivy/core/trunk: ./ src/java/org/apache/ivy/plugins/parser/m2/ test/java/org/apache/ivy/plugins/parser/m2/
Date Wed, 03 Sep 2008 07:52:47 GMT
Author: xavier
Date: Wed Sep  3 00:52:46 2008
New Revision: 691531

URL: http://svn.apache.org/viewvc?rev=691531&view=rev
Log:
IMPROVEMENT: Parse license information in poms (IVY-892)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=691531&r1=691530&r2=691531&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Wed Sep  3 00:52:46 2008
@@ -84,6 +84,7 @@
 - NEW: Add transitive dependency version and branch override mechanism (IVY-784)
 - NEW: Add new packager resolver (IVY-829) (thanks to Archie Cobbs)
 
+- IMPROVEMENT: Parse license information in poms (IVY-892)
 - IMPROVEMENT: Change 'alwaysUseExactRevision' default value to false (IVY-891)
 - IMPROVEMENT: Better and more homogeneous relative paths handling (IVY-387) 
 - IMPROVEMENT: undeprecate configure task (IVY-849)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java?rev=691531&r1=691530&r2=691531&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
Wed Sep  3 00:52:46 2008
@@ -37,6 +37,7 @@
 import org.apache.ivy.core.module.descriptor.DefaultExcludeRule;
 import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
 import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
+import org.apache.ivy.core.module.descriptor.License;
 import org.apache.ivy.core.module.descriptor.MDArtifact;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.descriptor.OverrideDependencyDescriptorMediator;
@@ -213,6 +214,11 @@
         ivyModuleDescriptor.setDescription(description);
     }
 
+    public void setLicenses(License[] licenses) {
+        for (int i = 0; i < licenses.length; i++) {
+            ivyModuleDescriptor.addLicense(licenses[i]);
+        }
+    }
 
     public void addMainArtifact(String artifactId, String packaging) {
         String ext;

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java?rev=691531&r1=691530&r2=691531&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
Wed Sep  3 00:52:46 2008
@@ -122,6 +122,7 @@
             
             mdBuilder.setHomePage(domReader.getHomePage());
             mdBuilder.setDescription(domReader.getDescription());
+            mdBuilder.setLicenses(domReader.getLicenses());
 
             ModuleRevisionId relocation = domReader.getRelocation();
             

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java?rev=691531&r1=691530&r2=691531&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java Wed Sep  3
00:52:46 2008
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -26,6 +27,7 @@
 import java.util.Map;
 
 import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.module.descriptor.License;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.plugins.repository.Resource;
@@ -55,6 +57,10 @@
     private static final String VERSION = "version";
     private static final String DESCRIPTION = "description";
     private static final String HOMEPAGE = "url";
+    private static final String LICENSES = "licenses";
+    private static final String LICENSE = "license";
+    private static final String LICENSE_NAME = "name";
+    private static final String LICENSE_URL = "url";
     private static final String PARENT = "parent";
     private static final String SCOPE = "scope";
     private static final String CLASSIFIER = "classifier";
@@ -178,6 +184,26 @@
         return val.trim();
     }
 
+    public License[] getLicenses() {
+        Element licenses = getFirstChildElement(projectElement, LICENSES);
+        if (licenses == null) {
+            return new License[0];
+        }
+        licenses.normalize();
+        List/*<License>*/ lics = new ArrayList();
+        for (Iterator it = getAllChilds(licenses).iterator(); it.hasNext();) {
+            Element license = (Element) it.next();
+            if (LICENSE.equals(license.getNodeName())) {
+                String name = getFirstChildText(license, LICENSE_NAME);
+                String url = getFirstChildText(license, LICENSE_URL);
+                if (name != null || url != null) {
+                    lics.add(new License(name, url));
+                }
+            }
+        }
+        return (License[]) lics.toArray(new License[lics.size()]);
+    }
+
     
     public ModuleRevisionId getRelocation() {
         Element distrMgt = getFirstChildElement(projectElement, DISTRIBUTION_MGT);

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java?rev=691531&r1=691530&r2=691531&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
Wed Sep  3 00:52:46 2008
@@ -28,6 +28,7 @@
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
 import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
+import org.apache.ivy.core.module.descriptor.License;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
@@ -510,10 +511,21 @@
 
         assertEquals("http://mule.mulesource.org", md.getHomePage());
         assertEquals("Mule is a simple yet robust and highly scalable Integration and ESB
services "
-        		+ "framework. It is designed\n        as a light-weight, event-driven component
" 
-        		+ "technology that handles communication with disparate systems\n        " 
-        		+ "transparently providing a simple component interface.", 
-        		md.getDescription().replaceAll("\r\n", "\n").replace('\r', '\n'));
+                + "framework. It is designed\n        as a light-weight, event-driven component
" 
+                + "technology that handles communication with disparate systems\n       
" 
+                + "transparently providing a simple component interface.", 
+                md.getDescription().replaceAll("\r\n", "\n").replace('\r', '\n'));
+    }
+    
+    public void testLicense() throws Exception {
+        ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(
+            settings, getClass().getResource("spring-hibernate3-2.0.2.pom"), false);
+
+        License[] licenses = md.getLicenses();
+        assertNotNull(licenses);
+        assertEquals(1, licenses.length);
+        assertEquals("The Apache Software License, Version 2.0", licenses[0].getName());
+        assertEquals("http://www.apache.org/licenses/LICENSE-2.0.txt", licenses[0].getUrl());
     }
     
     public void testDependencyManagment() throws ParseException, IOException {



Mime
View raw message