Author: maartenc
Date: Tue Mar 13 15:39:55 2007
New Revision: 517916

URL: http://svn.apache.org/viewvc?view=rev&rev=517916
Log:
IMPROVE: Generated XML reports now contains more information about the resolved 
module

Added:
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml
Modified:
    
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java
    
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
    
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java

Modified: 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java?view=diff&rev=517916&r1=517915&r2=517916
==============================================================================
--- 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java
 (original)
+++ 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java
 Tue Mar 13 15:39:55 2007
@@ -28,6 +28,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.cache.ArtifactOrigin;
@@ -100,6 +101,15 @@
                out.println("\t<info");
                out.println("\t\torganisation=\""+mrid.getOrganisation()+"\"");
                out.println("\t\tmodule=\""+mrid.getName()+"\"");
+               out.println("\t\trevision=\""+mrid.getRevision()+"\"");
+               if (mrid.getBranch() != null) {
+                       out.println("\t\tbranch=\""+mrid.getBranch()+"\"");
+               }
+               Map extraAttributes = mrid.getExtraAttributes();
+               for (Iterator it = extraAttributes.entrySet().iterator(); 
it.hasNext(); ) {
+                       Map.Entry entry = (Entry) it.next();
+                       out.println("\t\textra-" + entry.getKey() + "=\"" + 
entry.getValue() + "\"");
+               }
                out.println("\t\tconf=\""+report.getConfiguration()+"\"");
                out.println("\t\tconfs=\""+StringUtils.join(confs, ", ")+"\"");
                
out.println("\t\tdate=\""+Ivy.DATE_FORMAT.format(report.getDate())+"\"/>");
@@ -141,7 +151,7 @@
                 if (md != null && md.getHomePage() != null) {
                     details.append(" 
homepage=\"").append(md.getHomePage()).append("\"");
                 }
-                Map extraAttributes = 
md!=null?md.getExtraAttributes():dep.getResolvedId().getExtraAttributes();
+                extraAttributes = 
md!=null?md.getExtraAttributes():dep.getResolvedId().getExtraAttributes();
                 for (Iterator iterator = extraAttributes.keySet().iterator(); 
iterator.hasNext();) {
                     String attName = (String)iterator.next();
                     details.append(" 
extra-").append(attName).append("=\"").append(extraAttributes.get(attName)).append("\"");

Modified: 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java?view=diff&rev=517916&r1=517915&r2=517916
==============================================================================
--- 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
 (original)
+++ 
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
 Tue Mar 13 15:39:55 2007
@@ -21,8 +21,10 @@
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
@@ -45,6 +47,7 @@
         private List _defaultMrids;
         private List _realMrids;
                private List _artifacts;
+               private ModuleRevisionId _mRevisionId;
                private File _report;
                SaxXmlReportParser(File report) {
                _artifacts = new ArrayList();
@@ -114,6 +117,21 @@
                         String ext = attributes.getValue("ext");
                                                Artifact artifact = new 
DefaultArtifact(_mrid, _pubdate, artifactName, type, ext, 
ExtendableItemHelper.getExtraAttributes(attributes, "extra-"));
                         _revisionArtifacts.add(artifact);
+                    } else if ("info".equals(qName)) {
+                       String organisation = 
attributes.getValue("organisation");
+                       String name = attributes.getValue("module");
+                       String branch = attributes.getValue("branch");
+                       String revision = attributes.getValue("revision");
+                       Map extraAttributes = new HashMap();
+                       for (int i = 0; i < attributes.getLength(); i++) {
+                               String attName = attributes.getQName(i);
+                               if (attName.startsWith("extra-")) {
+                                       String extraAttrName = 
attName.substring(6);
+                                       String extraAttrValue = 
attributes.getValue(i);
+                                       extraAttributes.put(extraAttrName, 
extraAttrValue);
+                               }
+                       }
+                       _mRevisionId = 
ModuleRevisionId.newInstance(organisation, name, branch, revision, 
extraAttributes);
                     }
                 }
 
@@ -139,10 +157,12 @@
                public List getModuleRevisionIds() {
                        return _mrids;
                }
-
         public List getRealModuleRevisionIds() {
             return _realMrids;
         }
+        public ModuleRevisionId getResolvedModule() {
+               return _mRevisionId;
+        }
     }
     
     private SaxXmlReportParser parser = null;
@@ -172,6 +192,12 @@
     
     public ModuleRevisionId[] getRealDependencyRevisionIds() {
        return 
(ModuleRevisionId[])parser.getRealModuleRevisionIds().toArray(new 
ModuleRevisionId[parser.getRealModuleRevisionIds().size()]);
+    }
+    /**
+     * Returns the <tt>ModuleRevisionId</tt> of the resolved module.
+     */
+    public ModuleRevisionId getResolvedModule() {
+       return parser.getResolvedModule();
     }
 }
 

Modified: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java?view=diff&rev=517916&r1=517915&r2=517916
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java
 (original)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java
 Tue Mar 13 15:39:55 2007
@@ -76,6 +76,30 @@
         assertTrue("XML doesn't contain artifact location attribute", 
xml.indexOf(expectedLocation) != -1);
         assertTrue("XML doesn't contain artifact is-local attribute", 
xml.indexOf(expectedIsLocal) != -1);
        }
+       
+       public void testWriteModuleInfo() throws Exception {
+        ResolveReport report = _ivy.resolve(new 
File("test/java/org/apache/ivy/plugins/report/ivy-with-info.xml").toURL(),
+                       getResolveOptions(new String[] 
{"default"}).setValidate(false));
+        assertNotNull(report);
+        
+               ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+               XmlReportOutputter outputter = new XmlReportOutputter();
+               outputter.output(report.getConfigurationReport("default"), 
buffer);
+               buffer.flush();
+               String xml = buffer.toString();
+               
+               String orgAttribute = "organisation=\"org1\"";
+               String modAttribute = "module=\"mod1\"";
+               String revAttribute = "revision=\"1.0\"";
+               String extra1Attribute = "extra-blabla=\"abc\"";
+               String extra2Attribute = "extra-blabla2=\"123\"";
+               
+        assertTrue("XML doesn't contain organisation attribute", 
xml.indexOf(orgAttribute) != -1);
+        assertTrue("XML doesn't contain module attribute", 
xml.indexOf(modAttribute) != -1);
+        assertTrue("XML doesn't contain revision attribute", 
xml.indexOf(revAttribute) != -1);
+        assertTrue("XML doesn't contain extra attribute 1", 
xml.indexOf(extra1Attribute) != -1);
+        assertTrue("XML doesn't contain extra attribute 2", 
xml.indexOf(extra2Attribute) != -1);
+       }
     
     private ResolveOptions getResolveOptions(String[] confs) {
                return new 
ResolveOptions().setConfs(confs).setCache(CacheManager.getInstance(_ivy.getSettings(),
 _cache));

Added: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java?view=auto&rev=517916
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java
 (added)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java
 Tue Mar 13 15:39:55 2007
@@ -0,0 +1,78 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ivy.plugins.report;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.ivy.Ivy;
+import org.apache.ivy.core.cache.CacheManager;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.ResolveReport;
+import org.apache.ivy.core.resolve.ResolveOptions;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Delete;
+
+public class XmlReportParserTest extends TestCase {
+       private final Ivy _ivy;
+    private File _cache;
+
+    public XmlReportParserTest() throws Exception {
+        _ivy = new Ivy();
+        _ivy.configure(new File("test/repositories/ivyconf.xml"));
+    }
+
+    protected void setUp() throws Exception {
+        createCache();
+    }
+
+    private void createCache() {
+        _cache = new File("build/cache");
+        _cache.mkdirs();
+    }
+    
+    protected void tearDown() throws Exception {
+        cleanCache();
+    }
+
+    private void cleanCache() {
+        Delete del = new Delete();
+        del.setProject(new Project());
+        del.setDir(_cache);
+        del.execute();
+    }
+    
+    public void testGetResolvedModule() throws Exception {
+        ResolveReport report = _ivy.resolve(new 
File("test/java/org/apache/ivy/plugins/report/ivy-with-info.xml").toURL(),
+                       getResolveOptions(new String[] 
{"default"}).setValidate(false).setResolveId("testGetResolvedModule"));
+        assertNotNull(report);
+
+        ModuleRevisionId modRevId = 
report.getModuleDescriptor().getModuleRevisionId();
+        
+        XmlReportParser parser = new XmlReportParser();
+        
parser.parse(_ivy.getCacheManager(_cache).getConfigurationResolveReportInCache("testGetResolvedModule",
 "default"));
+        ModuleRevisionId parsedModRevId = parser.getResolvedModule();
+        
+        assertEquals("Resolved module doesn't equals parsed module", modRevId, 
parsedModRevId);
+    }
+    
+    private ResolveOptions getResolveOptions(String[] confs) {
+               return new 
ResolveOptions().setConfs(confs).setCache(CacheManager.getInstance(_ivy.getSettings(),
 _cache));
+       }
+}

Added: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml?view=auto&rev=517916
==============================================================================
--- 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml
 (added)
+++ 
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml
 Tue Mar 13 15:39:55 2007
@@ -0,0 +1,10 @@
+<ivy-module version="1.0">
+       <info organisation="org1"
+              module="mod1"
+              revision="1.0"
+              status="integration"
+              publication="20041101110000"
+              blabla="abc"
+              blabla2="123"
+       />
+</ivy-module>


Reply via email to