Author: xavier
Date: Wed Sep  3 01:19:46 2008
New Revision: 691538

URL: http://svn.apache.org/viewvc?rev=691538&view=rev
Log:
IMPROVEMENT: write home page, description and license info in 
XmlModuleDescriptorWriter. This is useful to be sure we don't lose information 
parsed in poms, license information being especially useful (related to IVY-892)

Added:
    
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-info.xml   
(with props)
    
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-info.xml
   (with props)
Modified:
    
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
    
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java
    
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java?rev=691538&r1=691537&r2=691538&view=diff
==============================================================================
--- 
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
 (original)
+++ 
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
 Wed Sep  3 01:19:46 2008
@@ -37,6 +37,7 @@
 import org.apache.ivy.core.module.descriptor.DependencyDescriptorMediator;
 import org.apache.ivy.core.module.descriptor.ExcludeRule;
 import org.apache.ivy.core.module.descriptor.IncludeRule;
+import org.apache.ivy.core.module.descriptor.License;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import 
org.apache.ivy.core.module.descriptor.OverrideDependencyDescriptorMediator;
 import org.apache.ivy.plugins.matcher.MapMatcher;
@@ -439,8 +440,33 @@
             printExtraAttributes(md, out, "\t\t");
             out.println();
         }
-        if (md.getExtraInfo().size() > 0) {
+        if (requireInnerInfoElement(md)) {
             out.println("\t>");
+            License[] licenses = md.getLicenses();
+            for (int i = 0; i < licenses.length; i++) {
+                License license = licenses[i];
+                out.print("\t\t<license ");
+                if (license.getName() != null) {
+                    out.print("name=\"" + license.getName() + "\" ");
+                }
+                if (license.getUrl() != null) {
+                    out.print("url=\"" + license.getUrl() + "\" ");
+                }
+                out.println("/>");
+            }
+            if (md.getHomePage() != null || md.getDescription() != null) {
+                out.print("\t\t<description");
+                if (md.getHomePage() != null) {
+                    out.print(" homepage=\"" + md.getHomePage() + "\"");
+                }
+                if (md.getDescription() != null && 
md.getDescription().trim().length() > 0) {
+                    out.println(">");
+                    out.println("\t\t" + md.getDescription());
+                    out.println("\t\t</description>");
+                } else {
+                    out.println(" />");
+                }
+            }
             for (Iterator it = md.getExtraInfo().entrySet().iterator(); 
it.hasNext();) {
                 Map.Entry extraDescr = (Map.Entry) it.next();
                 if (extraDescr.getValue() == null 
@@ -462,6 +488,13 @@
 
     }
 
+    private static boolean requireInnerInfoElement(ModuleDescriptor md) {
+        return md.getExtraInfo().size() > 0 
+                || md.getHomePage() != null 
+                || (md.getDescription() != null && 
md.getDescription().trim().length() > 0) 
+                || md.getLicenses().length > 0;
+    }
+
     private static String getConfs(ModuleDescriptor md, Artifact artifact) {
         StringBuffer ret = new StringBuffer();
 

Modified: 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java?rev=691538&r1=691537&r2=691538&view=diff
==============================================================================
--- 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java
 (original)
+++ 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java
 Wed Sep  3 01:19:46 2008
@@ -62,6 +62,23 @@
         assertEquals(expected, wrote);
     }
 
+    public void testInfo() throws Exception {
+        DefaultModuleDescriptor md = (DefaultModuleDescriptor) 
XmlModuleDescriptorParser
+                .getInstance().parseDescriptor(new IvySettings(),
+                    
XmlModuleDescriptorWriterTest.class.getResource("test-info.xml"), true);
+        md.setResolvedPublicationDate(new GregorianCalendar(2005, 4, 1, 11, 0, 
0).getTime());
+        md.setResolvedModuleRevisionId(new 
ModuleRevisionId(md.getModuleRevisionId().getModuleId(),
+                "NONE"));
+        XmlModuleDescriptorWriter.write(md, LICENSE, _dest);
+
+        assertTrue(_dest.exists());
+        String wrote = FileUtil.readEntirely(new BufferedReader(new 
FileReader(_dest))).replaceAll(
+            "\r\n", "\n").replace('\r', '\n');
+        String expected = 
readEntirely("test-write-info.xml").replaceAll("\r\n", "\n").replace(
+            '\r', '\n');
+        assertEquals(expected, wrote);
+    }
+
     public void testDependencies() throws Exception {
         ModuleDescriptor md = 
XmlModuleDescriptorParser.getInstance().parseDescriptor(
             new IvySettings(),

Added: 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-info.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-info.xml?rev=691538&view=auto
==============================================================================
--- 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-info.xml 
(added)
+++ 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-info.xml 
Wed Sep  3 01:19:46 2008
@@ -0,0 +1,27 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you 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.    
+-->
+<ivy-module version="1.0">
+       <info organisation="myorg"
+              module="mymodule">
+               <license name="Apache Sofware License" 
url="http://www.apache.org/licenses/LICENSE-2.0.txt"; />
+               <description homepage="http://myorg.com/mymodule";>
+               My module description.
+               </description>
+       </info>
+</ivy-module>

Propchange: 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-info.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml?rev=691538&r1=691537&r2=691538&view=diff
==============================================================================
--- 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml
 (original)
+++ 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml
 Wed Sep  3 01:19:46 2008
@@ -25,6 +25,11 @@
                publication="20041101110000"
                e:attr1="value1"
        >
+               <license name="MyLicense" 
url="http://www.my.org/mymodule/mylicense.html"; />
+               <description homepage="http://www.my.org/mymodule/";>
+               This module is <b>great</b> !<br/>
+       You can use it especially with myconf1 and myconf2, and myconf4 is not 
too bad too.
+               </description>
                <e:someExtra>56576</e:someExtra>
        </info>
        <configurations>

Added: 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-info.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-info.xml?rev=691538&view=auto
==============================================================================
--- 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-info.xml
 (added)
+++ 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-info.xml
 Wed Sep  3 01:19:46 2008
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you 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.    
+-->
+<ivy-module version="1.0">
+       <info organisation="myorg"
+               module="mymodule"
+               revision="NONE"
+               status="integration"
+               publication="20050501110000"
+       >
+               <license name="Apache Sofware License" 
url="http://www.apache.org/licenses/LICENSE-2.0.txt"; />
+               <description homepage="http://myorg.com/mymodule";>
+               My module description.
+               </description>
+       </info>
+       <configurations>
+               <conf name="default" visibility="public"/>
+       </configurations>
+       <publications>
+               <artifact name="mymodule" type="jar" ext="jar" conf="default"/>
+       </publications>
+</ivy-module>

Propchange: 
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/test-write-info.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to