ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r600289 - in /ant/ivy/core/trunk: src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/install/ src/java/org/apache/ivy/core/report/ src/java/org/apache/ivy/core/resolve/ src/java/org/apache/ivy/core/settings/ src/java/org/apache/ivy/p...
Date Sun, 02 Dec 2007 13:51:11 GMT
Author: xavier
Date: Sun Dec  2 05:51:10 2007
New Revision: 600289

URL: http://svn.apache.org/viewvc?rev=600289&view=rev
Log:
- reproduce split cache bug in unit test and fix it (IVY-628)
The problem with that bug was due to bad cache manager use in XmlReportOutputter. 
The problem was due to the use of a File destDir and a CacheManager which is not the one used
by the ResolveEngine. 
Hence I've modified ReportOutputter to use a cache manager instead of a File dest Dir. 
Note that this will break any custom ResolveOutputter since the interface has changed, but
we aren't in API stable mode for Ivy 2.0, and updating a previous outputter will be pretty
easy (you have the "dest dir" available in the cache manager replacing the dest dir as parameter).


Added:
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java   (with
props)
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java
      - copied, changed from r600239, ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java
Removed:
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java
Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRepositoryReport.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ResolveReport.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/ReportOutputter.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRepositoryReport.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRepositoryReport.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRepositoryReport.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRepositoryReport.java Sun Dec  2 05:51:10
2007
@@ -112,7 +112,7 @@
                     .setValidate(doValidate(settings)));
 
             ResolutionCacheManager cacheMgr = getIvyInstance().getCacheManager(cache);
-            new XmlReportOutputter().output(report, cache);
+            new XmlReportOutputter().output(report, cacheMgr);
             if (graph) {
                 gengraph(cacheMgr, md.getModuleRevisionId().getOrganisation(), md
                         .getModuleRevisionId().getName());

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java Sun Dec  2
05:51:10 2007
@@ -154,7 +154,7 @@
             Message.info(":: install resolution report ::");
 
             // output report
-            report.output(settings.getReportOutputters(), cache);
+            resolveEngine.outputReport(report, getCacheManager(cache));
 
             return report;
         } finally {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ResolveReport.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ResolveReport.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ResolveReport.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ResolveReport.java Sun Dec  2 05:51:10
2007
@@ -17,7 +17,7 @@
  */
 package org.apache.ivy.core.report;
 
-import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -27,6 +27,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ivy.core.cache.ResolutionCacheManager;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.resolve.IvyNode;
@@ -86,9 +87,10 @@
         return hasError;
     }
 
-    public void output(ReportOutputter[] outputters, File cache) {
+    public void output(ReportOutputter[] outputters, ResolutionCacheManager cacheMgr) 
+            throws IOException {
         for (int i = 0; i < outputters.length; i++) {
-            outputters[i].output(this, cache);
+            outputters[i].output(this, cacheMgr);
         }
     }
 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java Sun Dec  2
05:51:10 2007
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.net.URL;
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -38,6 +39,7 @@
 import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.core.cache.CacheManager;
 import org.apache.ivy.core.cache.RepositoryCacheManager;
+import org.apache.ivy.core.cache.ResolutionCacheManager;
 import org.apache.ivy.core.event.EventManager;
 import org.apache.ivy.core.event.download.PrepareDownloadEvent;
 import org.apache.ivy.core.event.resolve.EndResolveEvent;
@@ -61,6 +63,7 @@
 import org.apache.ivy.plugins.conflict.ConflictManager;
 import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
 import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry;
+import org.apache.ivy.plugins.report.XmlReportOutputter;
 import org.apache.ivy.plugins.repository.url.URLResource;
 import org.apache.ivy.plugins.resolver.CacheResolver;
 import org.apache.ivy.plugins.resolver.DependencyResolver;
@@ -286,9 +289,13 @@
             }
 
             if (options.isOutputReport()) {
-                outputReport(report, cacheManager.getResolutionCacheRoot());
+                outputReport(report, cacheManager);
             }
 
+            Message.verbose("\tresolve done (" + report.getResolveTime() + "ms resolve -
"
+                    + report.getDownloadTime() + "ms download)");
+            Message.sumupProblems();
+
             eventManager.fireIvyEvent(new EndResolveEvent(md, confs, report));
             return report;
         } catch (RuntimeException ex) {
@@ -300,15 +307,12 @@
         }
     }
 
-    public void outputReport(ResolveReport report, File cache) {
+    public void outputReport(ResolveReport report, ResolutionCacheManager cacheMgr) 
+            throws IOException {
         Message.info(":: resolution report ::");
         report.setProblemMessages(Message.getProblems());
         // output report
-        report.output(settings.getReportOutputters(), cache);
-
-        Message.verbose("\tresolve done (" + report.getResolveTime() + "ms resolve - "
-                + report.getDownloadTime() + "ms download)");
-        Message.sumupProblems();
+        report.output(settings.getReportOutputters(), cacheMgr);
     }
 
     public void downloadArtifacts(ResolveReport report, RepositoryCacheManager cacheManager,

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java Sun Dec  2 05:51:10
2007
@@ -270,8 +270,8 @@
                 + "org.apache.ivy.plugins.matcher.GlobPatternMatcher was not found.");
         }
 
-        addReportOutputter(new XmlReportOutputter());
         addReportOutputter(new LogReportOutputter());
+        addReportOutputter(new XmlReportOutputter());
 
         configureDefaultCircularDependencyStrategies();
 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java Sun
Dec  2 05:51:10 2007
@@ -17,7 +17,7 @@
  */
 package org.apache.ivy.plugins.report;
 
-import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -25,6 +25,7 @@
 import java.util.List;
 
 import org.apache.ivy.core.IvyContext;
+import org.apache.ivy.core.cache.ResolutionCacheManager;
 import org.apache.ivy.core.report.ArtifactDownloadReport;
 import org.apache.ivy.core.report.ConfigurationResolveReport;
 import org.apache.ivy.core.report.ResolveReport;
@@ -42,7 +43,7 @@
         return CONSOLE;
     }
 
-    public void output(ResolveReport report, File destDir) {
+    public void output(ResolveReport report, ResolutionCacheManager cacheMgr) throws IOException
{
         IvySettings settings = IvyContext.getContext().getSettings();
         if (settings.logModulesInUse()) {
             Message.info("\t:: modules in use:");
@@ -99,6 +100,7 @@
             }
         }
 
+        //CheckStyle:MagicNumber| OFF
         char[] sep = new char[69];
         Arrays.fill(sep, '-');
         Message.rawinfo("\t" + new String(sep));
@@ -119,6 +121,7 @@
         line.append("|");
         append(line, "number", 7);
         append(line, "dwnlded", 7);
+        //CheckStyle:MagicNumber| ON
         line.append("|");
         Message.rawinfo(line.toString());
         Message.rawinfo("\t" + new String(sep));
@@ -159,6 +162,7 @@
 
     public void output(ConfigurationResolveReport report) {
         StringBuffer line = new StringBuffer("\t");
+        //CheckStyle:MagicNumber| OFF
         append(line, report.getConfiguration(), 18);
         append(line, String.valueOf(report.getNodesNumber()), 7);
         append(line, String.valueOf(report.getSearchedNodes().length), 7);
@@ -167,6 +171,7 @@
         line.append("|");
         append(line, String.valueOf(report.getArtifactsNumber()), 7);
         append(line, String.valueOf(report.getDownloadedArtifactsReports().length), 7);
+        //CheckStyle:MagicNumber| ON
         line.append("|");
 
         Message.rawinfo(line.toString());

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/ReportOutputter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/ReportOutputter.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/ReportOutputter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/ReportOutputter.java Sun Dec
 2 05:51:10 2007
@@ -17,8 +17,9 @@
  */
 package org.apache.ivy.plugins.report;
 
-import java.io.File;
+import java.io.IOException;
 
+import org.apache.ivy.core.cache.ResolutionCacheManager;
 import org.apache.ivy.core.report.ResolveReport;
 
 /**
@@ -29,7 +30,8 @@
 
     public static final String XML = "xml";
 
-    public abstract void output(ResolveReport report, File destDir);
+    public abstract void output(ResolveReport report, ResolutionCacheManager cacheMgr) 
+            throws IOException;
 
     public abstract String getName();
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java Sun
Dec  2 05:51:10 2007
@@ -21,289 +21,54 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-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;
-import org.apache.ivy.core.cache.CacheManager;
 import org.apache.ivy.core.cache.ResolutionCacheManager;
-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;
-import org.apache.ivy.core.report.ArtifactDownloadReport;
 import org.apache.ivy.core.report.ConfigurationResolveReport;
 import org.apache.ivy.core.report.ResolveReport;
-import org.apache.ivy.core.resolve.IvyNode;
-import org.apache.ivy.core.resolve.IvyNodeCallers.Caller;
-import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData;
 import org.apache.ivy.util.FileUtil;
 import org.apache.ivy.util.Message;
-import org.apache.ivy.util.StringUtils;
-import org.apache.ivy.util.XMLHelper;
 
 /**
- *
+ * A Report outputter implementation using {@link XmlReportWriter} to write xml reports to
the
+ * resolution cache.
  */
 public class XmlReportOutputter implements ReportOutputter {
-
+    private XmlReportWriter writer = new XmlReportWriter();
+    
     public String getName() {
         return XML;
     }
 
-    public void output(ResolveReport report, File destDir) {
+    public void output(ResolveReport report, ResolutionCacheManager cacheMgr) throws IOException
{
         String[] confs = report.getConfigurations();
         for (int i = 0; i < confs.length; i++) {
-            output(report.getConfigurationReport(confs[i]), report.getResolveId(), confs,
destDir);
-        }
-    }
-
-    public void output(ConfigurationResolveReport report, String resolveId, String[] confs,
-            File destDir) {
-        try {
-            destDir.mkdirs();
-            ResolutionCacheManager cacheMgr = new CacheManager(null, destDir);
-            File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, report
-                    .getConfiguration());
-            OutputStream stream = new FileOutputStream(reportFile);
-            output(report, confs, stream);
-            stream.close();
-
-            Message.verbose("\treport for " + report.getModuleDescriptor().getModuleRevisionId()
-                    + " " + report.getConfiguration() + " produced in " + reportFile);
-
-            File reportXsl = new File(destDir, "ivy-report.xsl");
-            File reportCss = new File(destDir, "ivy-report.css");
-            if (!reportXsl.exists()) {
-                FileUtil.copy(XmlReportOutputter.class.getResource("ivy-report.xsl"), reportXsl,
-                    null);
-            }
-            if (!reportCss.exists()) {
-                FileUtil.copy(XmlReportOutputter.class.getResource("ivy-report.css"), reportCss,
-                    null);
-            }
-        } catch (IOException ex) {
-            Message.error("impossible to produce report for " + report.getModuleDescriptor()
+ ": "
-                    + ex.getMessage());
-        }
-    }
-
-    public void output(ConfigurationResolveReport report, OutputStream stream) {
-        output(report, new String[] {report.getConfiguration()}, stream);
-    }
-
-    public void output(
-            ConfigurationResolveReport report, String[] confs, OutputStream stream) {
-        PrintWriter out = new PrintWriter(stream);
-        ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId();
-        out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
-        out.println("<?xml-stylesheet type=\"text/xsl\" href=\"ivy-report.xsl\"?>");
-        out.println("<ivy-report version=\"1.0\">");
-        out.println("\t<info");
-        out.println("\t\torganisation=\"" + XMLHelper.escape(mrid.getOrganisation()) + "\"");
-        out.println("\t\tmodule=\"" + XMLHelper.escape(mrid.getName()) + "\"");
-        out.println("\t\trevision=\"" + XMLHelper.escape(mrid.getRevision()) + "\"");
-        if (mrid.getBranch() != null) {
-            out.println("\t\tbranch=\"" + XMLHelper.escape(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() 
-                + "=\"" + XMLHelper.escape(entry.getValue().toString()) + "\"");
-        }
-        out.println("\t\tconf=\"" + XMLHelper.escape(report.getConfiguration()) + "\"");
-        out.println("\t\tconfs=\"" + XMLHelper.escape(StringUtils.join(confs, ", ")) + "\"");
-        out.println("\t\tdate=\"" + Ivy.DATE_FORMAT.format(report.getDate()) + "\"/>");
-
-        out.println("\t<dependencies>");
-
-        // create a list of ModuleRevisionIds indicating the position for each dependency
-        List dependencies = new ArrayList(report.getModuleRevisionIds());
-
-        for (Iterator iter = report.getModuleIds().iterator(); iter.hasNext();) {
-            ModuleId mid = (ModuleId) iter.next();
-            out.println("\t\t<module organisation=\"" 
-                + XMLHelper.escape(mid.getOrganisation()) + "\"" + " name=\""
-                    + XMLHelper.escape(mid.getName()) + "\"" + " resolver=\""
-                    + XMLHelper.escape(
-                        report.getResolveEngine().getSettings().getResolverName(mid)) + "\">");
-            for (Iterator it2 = report.getNodes(mid).iterator(); it2.hasNext();) {
-                IvyNode dep = (IvyNode) it2.next();
-                ouputRevision(report, out, dependencies, dep);
-            }
-            out.println("\t\t</module>");
-        }
-        out.println("\t</dependencies>");
-        out.println("</ivy-report>");
-        out.flush();
-    }
-
-    private void ouputRevision(ConfigurationResolveReport report, PrintWriter out,
-            List dependencies, IvyNode dep) {
-        Map extraAttributes;
-        ModuleDescriptor md = null;
-        if (dep.getModuleRevision() != null) {
-            md = dep.getModuleRevision().getDescriptor();
-        }
-        StringBuffer details = new StringBuffer();
-        if (dep.isLoaded()) {
-            details.append(" status=\"");
-            details.append(XMLHelper.escape(dep.getDescriptor().getStatus()));
-            details.append("\" pubdate=\"");
-            details.append(Ivy.DATE_FORMAT.format(new Date(dep.getPublication())));
-            details.append("\" resolver=\"");
-            details.append(XMLHelper.escape(
-                dep.getModuleRevision().getResolver().getName()));
-            details.append("\" artresolver=\"");
-            details.append(XMLHelper.escape(
-                dep.getModuleRevision().getArtifactResolver().getName()));
-            details.append("\"");
-        }
-        if (dep.isEvicted(report.getConfiguration())) {
-            EvictionData ed = dep.getEvictedData(report.getConfiguration());
-            if (ed.getConflictManager() != null) {
-                details.append(" evicted=\"").append(
-                    XMLHelper.escape(ed.getConflictManager().toString())).append("\"");
-            } else {
-                details.append(" evicted=\"transitive\"");
-            }
-            details.append(" evicted-reason=\"")
-                .append(XMLHelper.escape(ed.getDetail() == null ? "" : ed.getDetail()))
-                .append("\"");
-        }
-        if (dep.hasProblem()) {
-            details.append(" error=\"").append(
-                XMLHelper.escape(dep.getProblem().getMessage())).append("\"");
-        }
-        if (md != null && md.getHomePage() != null) {
-            details.append(" homepage=\"").append(
-                XMLHelper.escape(md.getHomePage())).append("\"");
-        }
-        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(
-                XMLHelper.escape(extraAttributes.get(attName).toString())).append("\"");
-        }
-        String defaultValue = dep.getDescriptor() != null ? " default=\""
-                + dep.getDescriptor().isDefault() + "\"" : "";
-        int position = dependencies.indexOf(dep.getResolvedId());
-        out.println("\t\t\t<revision name=\""
-                + XMLHelper.escape(dep.getResolvedId().getRevision())
-                + "\""
-                + (dep.getResolvedId().getBranch() == null ? "" : " branch=\""
-                        + XMLHelper.escape(
-                            dep.getResolvedId().getBranch()) + "\"") + details
-                + " downloaded=\"" + dep.isDownloaded() + "\"" + " searched=\""
-                + dep.isSearched() + "\"" + defaultValue + " conf=\""
-                + toString(dep.getConfigurations(report.getConfiguration())) + "\""
-                + " position=\"" + position + "\">");
-        if (md != null) {
-            License[] licenses = md.getLicenses();
-            for (int i = 0; i < licenses.length; i++) {
-                String lurl;
-                if (licenses[i].getUrl() != null) {
-                    lurl = " url=\"" + XMLHelper.escape(licenses[i].getUrl()) + "\"";
-                } else {
-                    lurl = "";
-                }
-                out.println("\t\t\t\t<license name=\"" 
-                    + XMLHelper.escape(licenses[i].getName()) + "\""
-                        + lurl + "/>");
-            }
-        }
-        if (dep.isEvicted(report.getConfiguration())) {
-            EvictionData ed = dep.getEvictedData(report.getConfiguration());
-            Collection selected = ed.getSelected();
-            if (selected != null) {
-                for (Iterator it3 = selected.iterator(); it3.hasNext();) {
-                    IvyNode sel = (IvyNode) it3.next();
-                    out.println("\t\t\t\t<evicted-by rev=\""
-                            + XMLHelper.escape(sel.getResolvedId().getRevision()) + "\"/>");
-                }
-            }
-        }
-        Caller[] callers = dep.getCallers(report.getConfiguration());
-        for (int i = 0; i < callers.length; i++) {
-            StringBuffer callerDetails = new StringBuffer();
-            Map callerExtraAttributes = callers[i].getDependencyDescriptor()
-                    .getExtraAttributes();
-            for (Iterator iterator = callerExtraAttributes.keySet().iterator(); iterator
-                    .hasNext();) {
-                String attName = (String) iterator.next();
-                callerDetails.append(" extra-").append(attName).append("=\"").append(
-                    XMLHelper.escape(
-                        callerExtraAttributes.get(attName).toString())).append("\"");
-            }
-
-            out.println("\t\t\t\t<caller organisation=\""
-                    + XMLHelper.escape(
-                        callers[i].getModuleRevisionId().getOrganisation()) + "\""
-                    + " name=\"" 
-                    + XMLHelper.escape(
-                        callers[i].getModuleRevisionId().getName()) + "\""
-                    + " conf=\"" 
-                    + XMLHelper.escape(
-                        toString(callers[i].getCallerConfigurations())) + "\""
-                    + " rev=\"" 
-                    + XMLHelper.escape(
-                        callers[i].getAskedDependencyId().getRevision()) + "\""
-                    + " callerrev=\"" 
-                    + XMLHelper.escape(
-                        callers[i].getModuleRevisionId().getRevision()) + "\""
-                    + callerDetails + "/>");
-        }
-        ArtifactDownloadReport[] adr = report.getDownloadReports(dep.getResolvedId());
-        out.println("\t\t\t\t<artifacts>");
-        for (int i = 0; i < adr.length; i++) {
-            out.print("\t\t\t\t\t<artifact name=\"" 
-                + XMLHelper.escape(adr[i].getName()) 
-                + "\" type=\"" + XMLHelper.escape(adr[i].getType()) 
-                + "\" ext=\"" + XMLHelper.escape(adr[i].getExt()) + "\"");
-            extraAttributes = adr[i].getArtifact().getExtraAttributes();
-            for (Iterator iterator = extraAttributes.keySet().iterator(); iterator
-                    .hasNext();) {
-                String attName = (String) iterator.next();
-                out.print(" extra-" + attName + "=\"" 
-                    + XMLHelper.escape(extraAttributes.get(attName).toString())
-                                + "\"");
-            }
-            out.print(" status=\"" 
-                + XMLHelper.escape(adr[i].getDownloadStatus().toString()) + "\"");
-            out.print(" size=\"" + adr[i].getSize() + "\"");
-
-            ArtifactOrigin origin = adr[i].getArtifactOrigin();
-            if (origin != null) {
-                out.println(">");
-                out.println("\t\t\t\t\t\t<origin-location is-local=\""
-                        + String.valueOf(origin.isLocal()) + "\"" + " location=\""
-                        + XMLHelper.escape(origin.getLocation()) + "\"/>");
-                out.println("\t\t\t\t\t</artifact>");
-            } else {
-                out.println("/>");
-            }
+            output(report.getConfigurationReport(confs[i]), report.getResolveId(), confs,
cacheMgr);
         }
-        out.println("\t\t\t\t</artifacts>");
-        out.println("\t\t\t</revision>");
     }
 
-    private String toString(String[] strs) {
-        StringBuffer buf = new StringBuffer();
-        for (int i = 0; i < strs.length; i++) {
-            buf.append(strs[i]);
-            if (i + 1 < strs.length) {
-                buf.append(", ");
-            }
+    public void output(ConfigurationResolveReport report, String resolveId, 
+            String[] confs, ResolutionCacheManager cacheMgr) 
+            throws IOException {
+        File reportFile = cacheMgr.getConfigurationResolveReportInCache(
+            resolveId, report.getConfiguration());
+        File reportParentDir = reportFile.getParentFile();
+        reportParentDir.mkdirs();
+        OutputStream stream = new FileOutputStream(reportFile);
+        writer.output(report, confs, stream);
+        stream.close();
+
+        Message.verbose("\treport for " + report.getModuleDescriptor().getModuleRevisionId()
+            + " " + report.getConfiguration() + " produced in " + reportFile);
+
+        File reportXsl = new File(reportParentDir, "ivy-report.xsl");
+        File reportCss = new File(reportParentDir, "ivy-report.css");
+        if (!reportXsl.exists()) {
+            FileUtil.copy(XmlReportOutputter.class.getResource("ivy-report.xsl"), reportXsl,
+                null);
+        }
+        if (!reportCss.exists()) {
+            FileUtil.copy(XmlReportOutputter.class.getResource("ivy-report.css"), reportCss,
+                null);
         }
-        return XMLHelper.escape(buf.toString());
     }
 }

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java?rev=600289&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java Sun Dec
 2 05:51:10 2007
@@ -0,0 +1,260 @@
+/*
+ *  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.OutputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+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;
+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;
+import org.apache.ivy.core.report.ArtifactDownloadReport;
+import org.apache.ivy.core.report.ConfigurationResolveReport;
+import org.apache.ivy.core.resolve.IvyNode;
+import org.apache.ivy.core.resolve.IvyNodeCallers.Caller;
+import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData;
+import org.apache.ivy.util.StringUtils;
+import org.apache.ivy.util.XMLHelper;
+
+/**
+ * XmlReportWriter allows to write ResolveReport in an xml format. 
+ */
+public class XmlReportWriter {
+
+    public void output(ConfigurationResolveReport report, OutputStream stream) {
+        output(report, new String[] {report.getConfiguration()}, stream);
+    }
+
+    public void output(
+            ConfigurationResolveReport report, String[] confs, OutputStream stream) {
+        PrintWriter out = new PrintWriter(stream);
+        ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId();
+        out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
+        out.println("<?xml-stylesheet type=\"text/xsl\" href=\"ivy-report.xsl\"?>");
+        out.println("<ivy-report version=\"1.0\">");
+        out.println("\t<info");
+        out.println("\t\torganisation=\"" + XMLHelper.escape(mrid.getOrganisation()) + "\"");
+        out.println("\t\tmodule=\"" + XMLHelper.escape(mrid.getName()) + "\"");
+        out.println("\t\trevision=\"" + XMLHelper.escape(mrid.getRevision()) + "\"");
+        if (mrid.getBranch() != null) {
+            out.println("\t\tbranch=\"" + XMLHelper.escape(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() 
+                + "=\"" + XMLHelper.escape(entry.getValue().toString()) + "\"");
+        }
+        out.println("\t\tconf=\"" + XMLHelper.escape(report.getConfiguration()) + "\"");
+        out.println("\t\tconfs=\"" + XMLHelper.escape(StringUtils.join(confs, ", ")) + "\"");
+        out.println("\t\tdate=\"" + Ivy.DATE_FORMAT.format(report.getDate()) + "\"/>");
+
+        out.println("\t<dependencies>");
+
+        // create a list of ModuleRevisionIds indicating the position for each dependency
+        List dependencies = new ArrayList(report.getModuleRevisionIds());
+
+        for (Iterator iter = report.getModuleIds().iterator(); iter.hasNext();) {
+            ModuleId mid = (ModuleId) iter.next();
+            out.println("\t\t<module organisation=\"" 
+                + XMLHelper.escape(mid.getOrganisation()) + "\"" + " name=\""
+                    + XMLHelper.escape(mid.getName()) + "\"" + " resolver=\""
+                    + XMLHelper.escape(
+                        report.getResolveEngine().getSettings().getResolverName(mid)) + "\">");
+            for (Iterator it2 = report.getNodes(mid).iterator(); it2.hasNext();) {
+                IvyNode dep = (IvyNode) it2.next();
+                ouputRevision(report, out, dependencies, dep);
+            }
+            out.println("\t\t</module>");
+        }
+        out.println("\t</dependencies>");
+        out.println("</ivy-report>");
+        out.flush();
+    }
+
+    private void ouputRevision(ConfigurationResolveReport report, PrintWriter out,
+            List dependencies, IvyNode dep) {
+        Map extraAttributes;
+        ModuleDescriptor md = null;
+        if (dep.getModuleRevision() != null) {
+            md = dep.getModuleRevision().getDescriptor();
+        }
+        StringBuffer details = new StringBuffer();
+        if (dep.isLoaded()) {
+            details.append(" status=\"");
+            details.append(XMLHelper.escape(dep.getDescriptor().getStatus()));
+            details.append("\" pubdate=\"");
+            details.append(Ivy.DATE_FORMAT.format(new Date(dep.getPublication())));
+            details.append("\" resolver=\"");
+            details.append(XMLHelper.escape(
+                dep.getModuleRevision().getResolver().getName()));
+            details.append("\" artresolver=\"");
+            details.append(XMLHelper.escape(
+                dep.getModuleRevision().getArtifactResolver().getName()));
+            details.append("\"");
+        }
+        if (dep.isEvicted(report.getConfiguration())) {
+            EvictionData ed = dep.getEvictedData(report.getConfiguration());
+            if (ed.getConflictManager() != null) {
+                details.append(" evicted=\"").append(
+                    XMLHelper.escape(ed.getConflictManager().toString())).append("\"");
+            } else {
+                details.append(" evicted=\"transitive\"");
+            }
+            details.append(" evicted-reason=\"")
+                .append(XMLHelper.escape(ed.getDetail() == null ? "" : ed.getDetail()))
+                .append("\"");
+        }
+        if (dep.hasProblem()) {
+            details.append(" error=\"").append(
+                XMLHelper.escape(dep.getProblem().getMessage())).append("\"");
+        }
+        if (md != null && md.getHomePage() != null) {
+            details.append(" homepage=\"").append(
+                XMLHelper.escape(md.getHomePage())).append("\"");
+        }
+        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(
+                XMLHelper.escape(extraAttributes.get(attName).toString())).append("\"");
+        }
+        String defaultValue = dep.getDescriptor() != null ? " default=\""
+                + dep.getDescriptor().isDefault() + "\"" : "";
+        int position = dependencies.indexOf(dep.getResolvedId());
+        out.println("\t\t\t<revision name=\""
+                + XMLHelper.escape(dep.getResolvedId().getRevision())
+                + "\""
+                + (dep.getResolvedId().getBranch() == null ? "" : " branch=\""
+                        + XMLHelper.escape(
+                            dep.getResolvedId().getBranch()) + "\"") + details
+                + " downloaded=\"" + dep.isDownloaded() + "\"" + " searched=\""
+                + dep.isSearched() + "\"" + defaultValue + " conf=\""
+                + toString(dep.getConfigurations(report.getConfiguration())) + "\""
+                + " position=\"" + position + "\">");
+        if (md != null) {
+            License[] licenses = md.getLicenses();
+            for (int i = 0; i < licenses.length; i++) {
+                String lurl;
+                if (licenses[i].getUrl() != null) {
+                    lurl = " url=\"" + XMLHelper.escape(licenses[i].getUrl()) + "\"";
+                } else {
+                    lurl = "";
+                }
+                out.println("\t\t\t\t<license name=\"" 
+                    + XMLHelper.escape(licenses[i].getName()) + "\""
+                        + lurl + "/>");
+            }
+        }
+        if (dep.isEvicted(report.getConfiguration())) {
+            EvictionData ed = dep.getEvictedData(report.getConfiguration());
+            Collection selected = ed.getSelected();
+            if (selected != null) {
+                for (Iterator it3 = selected.iterator(); it3.hasNext();) {
+                    IvyNode sel = (IvyNode) it3.next();
+                    out.println("\t\t\t\t<evicted-by rev=\""
+                            + XMLHelper.escape(sel.getResolvedId().getRevision()) + "\"/>");
+                }
+            }
+        }
+        Caller[] callers = dep.getCallers(report.getConfiguration());
+        for (int i = 0; i < callers.length; i++) {
+            StringBuffer callerDetails = new StringBuffer();
+            Map callerExtraAttributes = callers[i].getDependencyDescriptor()
+                    .getExtraAttributes();
+            for (Iterator iterator = callerExtraAttributes.keySet().iterator(); iterator
+                    .hasNext();) {
+                String attName = (String) iterator.next();
+                callerDetails.append(" extra-").append(attName).append("=\"").append(
+                    XMLHelper.escape(
+                        callerExtraAttributes.get(attName).toString())).append("\"");
+            }
+
+            out.println("\t\t\t\t<caller organisation=\""
+                    + XMLHelper.escape(
+                        callers[i].getModuleRevisionId().getOrganisation()) + "\""
+                    + " name=\"" 
+                    + XMLHelper.escape(
+                        callers[i].getModuleRevisionId().getName()) + "\""
+                    + " conf=\"" 
+                    + XMLHelper.escape(
+                        toString(callers[i].getCallerConfigurations())) + "\""
+                    + " rev=\"" 
+                    + XMLHelper.escape(
+                        callers[i].getAskedDependencyId().getRevision()) + "\""
+                    + " callerrev=\"" 
+                    + XMLHelper.escape(
+                        callers[i].getModuleRevisionId().getRevision()) + "\""
+                    + callerDetails + "/>");
+        }
+        ArtifactDownloadReport[] adr = report.getDownloadReports(dep.getResolvedId());
+        out.println("\t\t\t\t<artifacts>");
+        for (int i = 0; i < adr.length; i++) {
+            out.print("\t\t\t\t\t<artifact name=\"" 
+                + XMLHelper.escape(adr[i].getName()) 
+                + "\" type=\"" + XMLHelper.escape(adr[i].getType()) 
+                + "\" ext=\"" + XMLHelper.escape(adr[i].getExt()) + "\"");
+            extraAttributes = adr[i].getArtifact().getExtraAttributes();
+            for (Iterator iterator = extraAttributes.keySet().iterator(); iterator
+                    .hasNext();) {
+                String attName = (String) iterator.next();
+                out.print(" extra-" + attName + "=\"" 
+                    + XMLHelper.escape(extraAttributes.get(attName).toString())
+                                + "\"");
+            }
+            out.print(" status=\"" 
+                + XMLHelper.escape(adr[i].getDownloadStatus().toString()) + "\"");
+            out.print(" size=\"" + adr[i].getSize() + "\"");
+
+            ArtifactOrigin origin = adr[i].getArtifactOrigin();
+            if (origin != null) {
+                out.println(">");
+                out.println("\t\t\t\t\t\t<origin-location is-local=\""
+                        + String.valueOf(origin.isLocal()) + "\"" + " location=\""
+                        + XMLHelper.escape(origin.getLocation()) + "\"/>");
+                out.println("\t\t\t\t\t</artifact>");
+            } else {
+                out.println("/>");
+            }
+        }
+        out.println("\t\t\t\t</artifacts>");
+        out.println("\t\t\t</revision>");
+    }
+
+    private String toString(String[] strs) {
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < strs.length; i++) {
+            buf.append(strs[i]);
+            if (i + 1 < strs.length) {
+                buf.append(", ");
+            }
+        }
+        return XMLHelper.escape(buf.toString());
+    }
+}

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java Sun Dec  2 05:51:10
2007
@@ -484,6 +484,8 @@
                 "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions(ivy
                 .getSettings(), new String[] {"*"}));
         assertNotNull(report);
+        assertFalse(report.hasError());
+        
         ModuleDescriptor md = report.getModuleDescriptor();
         assertNotNull(md);
         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
@@ -492,6 +494,8 @@
         assertTrue(ivy.getCacheManager(cache).getResolvedIvyFileInCache(mrid)
             .toString().indexOf("workspace") != -1);
         assertTrue(ivy.getCacheManager(cache).getResolvedIvyFileInCache(mrid).exists());
+        assertTrue(ivy.getCacheManager(cache).getConfigurationResolveReportInCache(
+            report.getResolveId(), "default").exists());
 
         // dependencies
         assertTrue(ivy.getCacheManager(cache).getIvyFileInCache(

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java?rev=600289&r1=600288&r2=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java Sun
Dec  2 05:51:10 2007
@@ -23,6 +23,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.ivy.core.cache.ResolutionCacheManager;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.plugins.latest.LatestRevisionStrategy;
@@ -396,7 +397,7 @@
 
     public static class MyOutputter implements ReportOutputter {
 
-        public void output(ResolveReport report, File destDir) {
+        public void output(ResolveReport report, ResolutionCacheManager cacheMgr) {
         }
 
         public String getName() {

Copied: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java
(from r600239, ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java)
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java?p2=ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java&p1=ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java&r1=600239&r2=600289&rev=600289&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/report/XmlReportWriterTest.java Sun
Dec  2 05:51:10 2007
@@ -28,7 +28,7 @@
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.util.CacheCleaner;
 
-public class XmlReportOutputterTest extends TestCase {
+public class XmlReportWriterTest extends TestCase {
     private Ivy _ivy;
 
     private File _cache;
@@ -59,8 +59,8 @@
         assertNotNull(report);
 
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        XmlReportOutputter outputter = new XmlReportOutputter();
-        outputter.output(report.getConfigurationReport("default"), buffer);
+        XmlReportWriter writer = new XmlReportWriter();
+        writer.output(report.getConfigurationReport("default"), buffer);
         buffer.flush();
         String xml = buffer.toString();
 
@@ -83,8 +83,8 @@
         assertNotNull(report);
         
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        XmlReportOutputter outputter = new XmlReportOutputter();
-        outputter.output(report.getConfigurationReport("default"), buffer);
+        XmlReportWriter writer = new XmlReportWriter();
+        writer.output(report.getConfigurationReport("default"), buffer);
         buffer.flush();
         String xml = buffer.toString();
         
@@ -101,8 +101,8 @@
         assertNotNull(report);
 
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        XmlReportOutputter outputter = new XmlReportOutputter();
-        outputter.output(report.getConfigurationReport("default"), buffer);
+        XmlReportWriter writer = new XmlReportWriter();
+        writer.output(report.getConfigurationReport("default"), buffer);
         buffer.flush();
         String xml = buffer.toString();
 



Mime
View raw message