incubator-easyant-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1382146 - in /incubator/easyant/core/trunk/src/main: java/org/apache/easyant/core/report/ java/org/apache/easyant/core/services/ java/org/apache/easyant/core/services/impl/ java/org/apache/easyant/tasks/ resources/org/apache/easyant/
Date Fri, 07 Sep 2012 20:05:59 GMT
Author: jlboudart
Date: Fri Sep  7 20:05:58 2012
New Revision: 1382146

URL: http://svn.apache.org/viewvc?rev=1382146&view=rev
Log:
Add easyant plugin report task

Added:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java
Removed:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XmlEasyAntReportOutputter.java
Modified:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
    incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java?rev=1382146&r1=1382145&r2=1382146&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java Fri Sep  7 20:05:58 2012
@@ -53,80 +53,69 @@ import org.apache.ivy.util.XMLHelper;
 public class XMLEasyAntReportWriter {
 
     static final String REPORT_ENCODING = "UTF-8";
-    private boolean displaySubProperties;
+    private boolean displaySubProperties= false;
 
-    public void output(ConfigurationResolveReport report, OutputStream stream,
-            EasyAntReport easyAntReport) {
-        output(report, new String[] { report.getConfiguration() }, stream,
-                easyAntReport);
+    public void output(EasyAntReport easyAntReport, OutputStream stream) {
+        for (String conf : easyAntReport.getResolveReport().getConfigurations()) {
+            output(easyAntReport, easyAntReport.getResolveReport().getConfigurationReport(conf),stream);
+        }
     }
-
-    public void output(ConfigurationResolveReport report, String[] confs,
-            OutputStream stream, EasyAntReport easyAntReport) {
+    
+    public void output(EasyAntReport easyAntReport,ConfigurationResolveReport report,  OutputStream stream) {
         OutputStreamWriter encodedOutStream;
         try {
-            encodedOutStream = new OutputStreamWriter(stream, REPORT_ENCODING);
+            encodedOutStream = new OutputStreamWriter(stream , REPORT_ENCODING);
         } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(REPORT_ENCODING
-                    + " is not known on your jvm", e);
+            throw new RuntimeException(REPORT_ENCODING + " is not known on your jvm" , e);
         }
         PrintWriter out = new PrintWriter(new BufferedWriter(encodedOutStream));
-        ModuleRevisionId mrid = report.getModuleDescriptor()
-                .getModuleRevisionId();
-        // out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
-        out.println("<?xml version=\"1.0\" encoding=\"" + REPORT_ENCODING
-                + "\"?>");
-        out
-                .println("<?xml-stylesheet type=\"text/xsl\" href=\"easyant-report.xsl\"?>");
+        ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId();
+        //out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
+        out.println("<?xml version=\"1.0\" encoding=\"" + REPORT_ENCODING + "\"?>");
+        out.println("<?xml-stylesheet type=\"text/xsl\" href=\"ivy-report.xsl\"?>");
         out.println("<ivy-report version=\"1.0\">");
-        out.println("    <info");
-        out.println("        organisation=\""
-                + XMLHelper.escape(mrid.getOrganisation()) + "\"");
-        out.println("        module=\"" + XMLHelper.escape(mrid.getName()) + "\"");
-        out.println("        revision=\"" + XMLHelper.escape(mrid.getRevision())
-                + "\"");
+        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("        branch=\"" + XMLHelper.escape(mrid.getBranch())
-                    + "\"");
+            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("        extra-" + entry.getKey() + "=\""
-                    + XMLHelper.escape(entry.getValue().toString()) + "\"");
+            out.println("\t\textra-" + entry.getKey() 
+                + "=\"" + XMLHelper.escape(entry.getValue().toString()) + "\"");
         }
-        out.println("        conf=\"" + XMLHelper.escape(report.getConfiguration())
-                + "\"");
-        out.println("        confs=\""
-                + XMLHelper.escape(StringUtils.join(confs, ", ")) + "\"");
-        out.println("        date=\"" + Ivy.DATE_FORMAT.format(report.getDate())
-                + "\"/>");
+        out.println("\t\tconf=\"" + XMLHelper.escape(report.getConfiguration()) + "\"");
+        out.println("\t\tconfs=\"" + XMLHelper.escape(StringUtils.join(easyAntReport.getResolveReport().getConfigurations(), ", ")) + "\"");
+        out.println("\t\tdate=\"" + Ivy.DATE_FORMAT.format(report.getDate()) + "\"/>");
 
-        out.println("    <dependencies>");
+        out.println("\t<dependencies>");
 
-        // create a list of ModuleRevisionIds indicating the position for each
-        // dependency
+        // 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("        <module organisation=\""
-                    + XMLHelper.escape(mid.getOrganisation()) + "\""
-                    + " name=\"" + XMLHelper.escape(mid.getName()) + "\" >");
+            out.println("\t\t<module organisation=\"" 
+                + XMLHelper.escape(mid.getOrganisation()) + "\"" + " name=\""
+                    + XMLHelper.escape(mid.getName()) + "\">");
             for (Iterator it2 = report.getNodes(mid).iterator(); it2.hasNext();) {
                 IvyNode dep = (IvyNode) it2.next();
-                ouputRevision(report, out, dependencies, dep, easyAntReport);
+                ouputRevision(report, out, dependencies, dep,easyAntReport);
             }
-            out.println("        </module>");
+            out.println("\t\t</module>");
         }
-        out.println("    </dependencies>");
+        out.println("\t</dependencies>");
+        outputEasyAntModuleInfos(easyAntReport,out);
+
         out.println("</ivy-report>");
         out.flush();
     }
 
-    private void ouputRevision(ConfigurationResolveReport report,
-            PrintWriter out, List dependencies, IvyNode dep,
-            EasyAntReport easyAntReport) {
+    private void ouputRevision(ConfigurationResolveReport report, PrintWriter out,
+            List dependencies, IvyNode dep, EasyAntReport easyAntReport) {
         Map extraAttributes;
         ModuleDescriptor md = null;
         if (dep.getModuleRevision() != null) {
@@ -137,102 +126,234 @@ public class XMLEasyAntReportWriter {
             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(Ivy.DATE_FORMAT.format(new Date(dep.getPublication())));
             details.append("\" resolver=\"");
-            details.append(XMLHelper.escape(dep.getModuleRevision()
-                    .getResolver().getName()));
+            details.append(XMLHelper.escape(
+                dep.getModuleRevision().getResolver().getName()));
             details.append("\" artresolver=\"");
-            details.append(XMLHelper.escape(dep.getModuleRevision()
-                    .getArtifactResolver().getName()));
+            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("\"");
+                    XMLHelper.escape(ed.getConflictManager().toString())).append("\"");
             } else {
                 details.append(" evicted=\"transitive\"");
             }
-            details.append(" evicted-reason=\"").append(
-                    XMLHelper.escape(ed.getDetail() == null ? "" : ed
-                            .getDetail())).append("\"");
+            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(
-                    "\"");
+                XMLHelper.escape(dep.getProblem().getMessage())).append("\"");
         }
         if (md != null && md.getHomePage() != null) {
             details.append(" homepage=\"").append(
-                    XMLHelper.escape(md.getHomePage())).append("\"");
+                XMLHelper.escape(md.getHomePage())).append("\"");
         }
-        extraAttributes = md != null ? md.getExtraAttributes() : dep
-                .getResolvedId().getExtraAttributes();
-        for (Iterator iterator = extraAttributes.keySet().iterator(); iterator
-                .hasNext();) {
+        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("\"");
+                XMLHelper.escape(extraAttributes.get(attName).toString())).append("\"");
         }
         String defaultValue = dep.getDescriptor() != null ? " default=\""
                 + dep.getDescriptor().isDefault() + "\"" : "";
         int position = dependencies.indexOf(dep.getResolvedId());
-        out.println("            <revision name=\""
+        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 + "\">");
+                        + 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())
-                            + "\"";
+                    lurl = " url=\"" + XMLHelper.escape(licenses[i].getUrl()) + "\"";
                 } else {
                     lurl = "";
                 }
-                out.println("                <license name=\""
-                        + XMLHelper.escape(licenses[i].getName()) + "\"" + lurl
-                        + "/>");
+                out.println("\t\t\t\t<license name=\"" 
+                    + XMLHelper.escape(licenses[i].getName()) + "\""
+                        + lurl + "/>");
             }
         }
-        if (md != null && md.getDescription() != null) {
-            out.println("                <description>" + md.getDescription()
-                    + "                </description>");
-        }
         outputMetadataArtifact(out, dep);
         outputEvictionInformation(report, out, dep);
         outputCallers(report, out, dep);
         outputArtifacts(report, out, dep);
-        outputEasyAntModuleInfos(report, out, dep, easyAntReport);
-        out.println("            </revision>");
+        out.println("\t\t\t</revision>");
+    }
+
+    private void outputEvictionInformation(ConfigurationResolveReport report, PrintWriter out,
+            IvyNode dep) {
+        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()) + "\"/>");
+                }
+            }
+        }
+    }
+
+    private void outputMetadataArtifact(PrintWriter out, IvyNode dep) {
+        if (dep.getModuleRevision() != null) {
+            MetadataArtifactDownloadReport madr = dep.getModuleRevision().getReport();
+            out.print("\t\t\t\t<metadata-artifact");
+            out.print(" status=\"" 
+                + XMLHelper.escape(madr.getDownloadStatus().toString()) + "\"");
+            out.print(" details=\"" + XMLHelper.escape(madr.getDownloadDetails()) + "\"");
+            out.print(" size=\"" + madr.getSize() + "\"");
+            out.print(" time=\"" + madr.getDownloadTimeMillis() + "\"");
+            if (madr.getLocalFile() != null) {
+                out.print(" location=\"" 
+                    + XMLHelper.escape(madr.getLocalFile().getAbsolutePath()) + "\"");
+            }
+
+            out.print(" searched=\"" + madr.isSearched() + "\"");
+            if (madr.getOriginalLocalFile() != null) {
+                out.print(" original-local-location=\"" 
+                    + XMLHelper.escape(madr.getOriginalLocalFile().getAbsolutePath()) + "\"");
+            }
+
+            ArtifactOrigin origin = madr.getArtifactOrigin();
+            if (origin != null) {
+                out.print(" origin-is-local=\"" + String.valueOf(origin.isLocal()) + "\""); 
+                out.print(" origin-location=\"" + XMLHelper.escape(origin.getLocation()) + "\"");
+            }
+            out.println("/>");
+            
+        }
+    }
+
+    private void outputCallers(ConfigurationResolveReport report, PrintWriter out, IvyNode dep) {
+        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(dep.getData()).getRevision()) + "\""
+                    + " rev-constraint-default=\"" 
+                    + XMLHelper.escape(
+                        callers[i].getDependencyDescriptor()
+                            .getDependencyRevisionId().getRevision()) + "\""
+                    + " rev-constraint-dynamic=\"" 
+                    + XMLHelper.escape(
+                        callers[i].getDependencyDescriptor()
+                            .getDynamicConstraintDependencyRevisionId().getRevision()) + "\""
+                    + " callerrev=\"" 
+                    + XMLHelper.escape(
+                        callers[i].getModuleRevisionId().getRevision()) + "\""
+                    + callerDetails + "/>");
+        }
+    }
+
+    private void outputArtifacts(ConfigurationResolveReport report, PrintWriter out, IvyNode dep) {
+        Map extraAttributes;
+        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(" details=\"" + XMLHelper.escape(adr[i].getDownloadDetails()) + "\"");
+            out.print(" size=\"" + adr[i].getSize() + "\"");
+            out.print(" time=\"" + adr[i].getDownloadTimeMillis() + "\"");
+            if (adr[i].getLocalFile() != null) {
+                out.print(" location=\"" 
+                    + XMLHelper.escape(adr[i].getLocalFile().getAbsolutePath()) + "\"");
+            }
+
+            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>");
+    }
+
+    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());
     }
 
-    private void outputEasyAntModuleInfos(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep, EasyAntReport easyAntReport) {
-        out.println("                <easyant>");
+    public void setDisplaySubProperties(boolean displaySubProperties) {
+        this.displaySubProperties= displaySubProperties;
+        
+    }
+    
+    private void outputEasyAntModuleInfos(EasyAntReport easyAntReport,
+            PrintWriter out) {
+        out.println("\t<easyant>");
         // targets
-        outputTargets(report, out, dep, easyAntReport);
-        outputExtensionPoints(report, out, dep, easyAntReport);
-        outputImportedModules(report, out, dep, easyAntReport);
-        outputParameters(report, out, dep, easyAntReport);
-        outputProperties(report, out, dep, easyAntReport);
-        out.println("                </easyant>");
+        outputTargets(easyAntReport, out);
+        outputExtensionPoints(easyAntReport, out);
+        outputImportedModules(easyAntReport, out);
+        outputParameters(easyAntReport, out);
+        outputProperties(easyAntReport, out);
+        out.println("\t</easyant>");
 
     }
-    private void outputProperties(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep, EasyAntReport easyAntReport) {
-        out.println("                    <properties>");
+    private void outputProperties(EasyAntReport easyAntReport,
+            PrintWriter out) {
+        out.println("\t\t<properties>");
         Map<String, PropertyDescriptor> properties;
         if (displaySubProperties)  {
             properties = easyAntReport.getAvailableProperties();
@@ -244,7 +365,7 @@ public class XMLEasyAntReportWriter {
             PropertyDescriptor propertyDescriptor = entry.getValue();
             
             StringBuffer param= new StringBuffer();
-            param.append("                        <property name=\"");
+            param.append("\t\t\t<property name=\"");
             param.append(propertyDescriptor.getName());
             param.append("\"");
             if (propertyDescriptor.getDescription() != null) {
@@ -269,17 +390,17 @@ public class XMLEasyAntReportWriter {
             out.println(param.toString());
 
         }
-        out.println("                    </properties>");
+        out.println("\t\t</properties>");
     }
 
-    private void outputParameters(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep, EasyAntReport easyAntReport) {
-        out.println("                    <parameters>");
+    private void outputParameters(EasyAntReport easyAntReport,
+            PrintWriter out) {
+        out.println("\t\t<parameters>");
         for (ParameterReport paramReport : easyAntReport.getParameterReports()) {
             StringBuffer param = new StringBuffer();
 
             if (ParameterType.PATH.equals(paramReport.getType())) {
-                param.append("                        <path name=\"");
+                param.append("\t\t\t<path name=\"");
                 param.append(paramReport.getName());
                 param.append("\"");
                 if (paramReport.getDescription() != null) {
@@ -297,18 +418,18 @@ public class XMLEasyAntReportWriter {
             out.println(param);
         }
 
-        out.println("                    </parameters>");
+        out.println("\t\t</parameters>");
     }
 
-    private void outputImportedModules(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep, EasyAntReport easyAntReport) {
-        out.println("                    <imports>");
+    private void outputImportedModules(EasyAntReport easyAntReport,
+            PrintWriter out) {
+        out.println("\t\t<imports>");
         for (ImportedModuleReport importedModuleReport : easyAntReport.getImportedModuleReports()) {
             StringBuffer importedModule = new StringBuffer();
             try {
                 ModuleRevisionId mrid = ModuleRevisionId
                         .parse(importedModuleReport.getModuleMrid());
-                importedModule.append("                        <import organisation=\"")
+                importedModule.append("\t\t\t<import organisation=\"")
                         .append(mrid.getOrganisation()).append("\" name=\"")
                         .append(mrid.getName()).append("\" revision=\"")
                         .append(mrid.getRevision()).append("\" type=\"")
@@ -336,22 +457,22 @@ public class XMLEasyAntReportWriter {
             importedModule.append(">");
             out.println(importedModule.toString());
             if (importedModuleReport.getEasyantReport() != null) {
-                outputEasyAntModuleInfos(report, out, dep, importedModuleReport
-                        .getEasyantReport());
+                outputEasyAntModuleInfos(importedModuleReport
+                        .getEasyantReport(),out);
             }
-            out.println("                        </import>");
+            out.println("\t\t\t</import>");
 
         }
-        out.println("                    </imports>");
+        out.println("\t\t</imports>");
 
     }
 
-    private void outputExtensionPoints(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep, EasyAntReport easyAntReport) {
-        out.println("                    <extension-points>");
+    private void outputExtensionPoints(EasyAntReport easyAntReport,
+            PrintWriter out) {
+        out.println("\t\t<extension-points>");
         for (ExtensionPointReport extensionPointReport : easyAntReport.getExtensionPointReports()) {
             StringBuffer extensionPoint = new StringBuffer();
-            extensionPoint.append("                        <extension-point name=\"").append(
+            extensionPoint.append("\t\t\t<extension-point name=\"").append(
                     extensionPointReport.getName()).append("\"");
             if (extensionPointReport.getDescription() != null) {
                 extensionPoint.append(" description=\"");
@@ -366,15 +487,15 @@ public class XMLEasyAntReportWriter {
             extensionPoint.append("/>");
             out.println(extensionPoint.toString());
         }
-        out.println("                    </phases>");
+        out.println("\t\t</extension-points>");
     }
 
-    private void outputTargets(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep, EasyAntReport easyAntReport) {
-        out.println("                    <targets>");
+    private void outputTargets(EasyAntReport easyAntReport,
+            PrintWriter out) {
+        out.println("\t\t<targets>");
         for (TargetReport targetReport : easyAntReport.getTargetReports()) {
             StringBuffer target = new StringBuffer();
-            target.append("                        <target name=\"").append(
+            target.append("\t\t\t<target name=\"").append(
                     targetReport.getName()).append("\"");
             if (targetReport.getDescription() != null) {
                 target.append(" description=\"");
@@ -392,7 +513,7 @@ public class XMLEasyAntReportWriter {
                 target.append("\"");
             }
             if (targetReport.getExtensionPoint() != null) {
-                target.append(" phase=\"");
+                target.append(" extensionOf=\"");
                 target.append(targetReport.getExtensionPoint());
                 target.append("\"");
             }
@@ -404,171 +525,6 @@ public class XMLEasyAntReportWriter {
             target.append("/>");
             out.println(target.toString());
         }
-        out.println("                    </targets>");
-    }
-
-    private void outputEvictionInformation(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep) {
-        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("                <evicted-by rev=\""
-                            + XMLHelper.escape(sel.getResolvedId()
-                                    .getRevision()) + "\"/>");
-                }
-            }
-        }
-    }
-
-    private void outputMetadataArtifact(PrintWriter out, IvyNode dep) {
-        if (dep.getModuleRevision() != null) {
-            MetadataArtifactDownloadReport madr = dep.getModuleRevision()
-                    .getReport();
-            out.print("                <metadata-artifact");
-            out.print(" status=\""
-                    + XMLHelper.escape(madr.getDownloadStatus().toString())
-                    + "\"");
-            out.print(" details=\""
-                    + XMLHelper.escape(madr.getDownloadDetails()) + "\"");
-            out.print(" size=\"" + madr.getSize() + "\"");
-            out.print(" time=\"" + madr.getDownloadTimeMillis() + "\"");
-            if (madr.getLocalFile() != null) {
-                out.print(" location=\""
-                        + XMLHelper.escape(madr.getLocalFile()
-                                .getAbsolutePath()) + "\"");
-            }
-
-            out.print(" searched=\"" + madr.isSearched() + "\"");
-            if (madr.getOriginalLocalFile() != null) {
-                out.print(" original-local-location=\""
-                        + XMLHelper.escape(madr.getOriginalLocalFile()
-                                .getAbsolutePath()) + "\"");
-            }
-
-            ArtifactOrigin origin = madr.getArtifactOrigin();
-            if (origin != null) {
-                out.print(" origin-is-local=\""
-                        + String.valueOf(origin.isLocal()) + "\"");
-                out.print(" origin-location=\""
-                        + XMLHelper.escape(origin.getLocation()) + "\"");
-            }
-            out.println("/>");
-
-        }
-    }
-
-    private void outputCallers(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep) {
-        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("                <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(
-                            dep.getData()).getRevision())
-                    + "\""
-                    + " rev-constraint-default=\""
-                    + XMLHelper.escape(callers[i].getDependencyDescriptor()
-                            .getDependencyRevisionId().getRevision())
-                    + "\""
-                    + " rev-constraint-dynamic=\""
-                    + XMLHelper.escape(callers[i].getDependencyDescriptor()
-                            .getDynamicConstraintDependencyRevisionId()
-                            .getRevision())
-                    + "\""
-                    + " callerrev=\""
-                    + XMLHelper.escape(callers[i].getModuleRevisionId()
-                            .getRevision()) + "\"" + callerDetails + "/>");
-        }
-    }
-
-    private void outputArtifacts(ConfigurationResolveReport report,
-            PrintWriter out, IvyNode dep) {
-        Map extraAttributes;
-        ArtifactDownloadReport[] adr = report.getDownloadReports(dep
-                .getResolvedId());
-        out.println("                <artifacts>");
-        for (int i = 0; i < adr.length; i++) {
-            out.print("                    <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(" details=\""
-                    + XMLHelper.escape(adr[i].getDownloadDetails()) + "\"");
-            out.print(" size=\"" + adr[i].getSize() + "\"");
-            out.print(" time=\"" + adr[i].getDownloadTimeMillis() + "\"");
-            if (adr[i].getLocalFile() != null) {
-                out.print(" location=\""
-                        + XMLHelper.escape(adr[i].getLocalFile()
-                                .getAbsolutePath()) + "\"");
-            }
-
-            ArtifactOrigin origin = adr[i].getArtifactOrigin();
-            if (origin != null) {
-                out.println(">");
-                out.println("                        <origin-location is-local=\""
-                        + String.valueOf(origin.isLocal()) + "\""
-                        + " location=\""
-                        + XMLHelper.escape(origin.getLocation()) + "\"/>");
-                out.println("                    </artifact>");
-            } else {
-                out.println("/>");
-            }
-        }
-        out.println("                </artifacts>");
-    }
-
-    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());
-    }
-
-    public void setDisplaySubProperties(boolean displaySubProperties) {
-        this.displaySubProperties= displaySubProperties;
-        
+        out.println("\t\t</targets>");
     }
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java?rev=1382146&r1=1382145&r2=1382146&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/PluginService.java Fri Sep  7 20:05:58 2012
@@ -71,11 +71,22 @@ public interface PluginService {
      *            a given moduleRevisionID
      * @param conf
      *            a configuration name
-     * @return an easyantReport an easyantReport
+     * @return an easyantReport 
      * @throws Exception
      */
     EasyAntReport getPluginInfo(ModuleRevisionId moduleRevisionId, String conf)
             throws Exception;
+    
+    /**
+     * Generate an {@link EasyAntReport} for a given pluginIvyFile
+     * @param pluginIvyFile plugin ivy file
+     * @param sourceDirectory source directory 
+     * @param conf a configuration name
+     * @return an {@link EasyAntReport}
+     * @throws Exception
+     */
+    EasyAntReport getPluginInfo(File pluginIvyFile, File sourceDirectory, String conf) throws Exception;
+
 
     /**
      * Return an array of moduleRevisionId that match with given criteria.

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java?rev=1382146&r1=1382145&r2=1382146&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java Fri Sep  7 20:05:58 2012
@@ -29,6 +29,7 @@ import java.util.Properties;
 import org.apache.easyant.core.EasyAntConstants;
 import org.apache.easyant.core.EasyAntEngine;
 import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.easyant.core.ant.ProjectUtils;
 import org.apache.easyant.core.descriptor.EasyAntModuleDescriptor;
 import org.apache.easyant.core.descriptor.PluginDescriptor;
 import org.apache.easyant.core.descriptor.PropertyDescriptor;
@@ -43,6 +44,7 @@ import org.apache.easyant.core.report.Ta
 import org.apache.easyant.core.services.PluginService;
 import org.apache.easyant.tasks.AbstractImport;
 import org.apache.easyant.tasks.Import;
+import org.apache.easyant.tasks.ImportTestModule;
 import org.apache.easyant.tasks.ParameterTask;
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.IvyContext;
@@ -61,6 +63,7 @@ import org.apache.ivy.util.Message;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.ComponentHelper;
 import org.apache.tools.ant.ExtensionPoint;
+import org.apache.tools.ant.Location;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectHelper;
 import org.apache.tools.ant.PropertyHelper;
@@ -103,6 +106,45 @@ public class DefaultPluginServiceImpl im
         ModuleDescriptorParserRegistry.getInstance().addParser(parser);
     }
 
+    public EasyAntReport getPluginInfo(File pluginIvyFile, File sourceDirectory, String conf) throws Exception {
+        IvyContext.pushNewContext().setIvy(ivyInstance);
+        EasyAntReport eaReport = null;
+        try {
+
+            ResolveOptions resolveOptions = new ResolveOptions();
+            resolveOptions.setLog(ResolveOptions.LOG_QUIET);
+            resolveOptions.setConfs(conf.split(","));
+            ResolveReport report = IvyContext.getContext().getIvy().getResolveEngine()
+                    .resolve(pluginIvyFile.toURI().toURL(), resolveOptions);
+            eaReport = new EasyAntReport();
+            eaReport.setResolveReport(report);
+            eaReport.setModuleDescriptor(report.getModuleDescriptor());
+
+            Project project = buildProject(null);
+            
+            // emulate top level project
+            ProjectHelper helper = ProjectHelper.getProjectHelper();
+            helper.getImportStack().addElement(ProjectUtils.emulateMainScript(project));
+            project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
+
+            ImportTestModule importTestModule = new ImportTestModule();
+            importTestModule.setModuleIvy(pluginIvyFile);
+            importTestModule.setSourceDirectory(sourceDirectory);
+            importTestModule.setOwningTarget(ProjectUtils.createTopLevelTarget());
+            importTestModule.setLocation(new Location(ProjectUtils.emulateMainScript(project).getAbsolutePath()));
+            importTestModule.setProject(project);
+            importTestModule.execute();
+
+            analyseProject(project, eaReport, conf);
+        } catch (Exception e) {
+            throw new Exception("An error occured while fetching plugin informations : " + e.getMessage(), e);
+        } finally {
+            IvyContext.popContext();
+        }
+        return eaReport;
+
+    }
+
     public EasyAntReport getPluginInfo(final ModuleRevisionId moduleRevisionId, String conf) throws Exception {
 
         IvyContext.pushNewContext().setIvy(ivyInstance);
@@ -118,12 +160,7 @@ public class DefaultPluginServiceImpl im
             eaReport.setResolveReport(report);
             eaReport.setModuleDescriptor(report.getModuleDescriptor());
 
-            Project project = new Project();
-            project.setNewProperty(EasyAntMagicNames.AUDIT_MODE, "true");
-            project.setNewProperty(EasyAntMagicNames.SKIP_CORE_REVISION_CHECKER, "true");
-            EasyAntEngine eagAntEngine = new EasyAntEngine();
-            eagAntEngine.configureEasyAntIvyInstance(project);
-            project.init();
+            Project project = buildProject(null);
 
             AbstractImport abstractImport = new AbstractImport() {
                 @Override
@@ -153,27 +190,7 @@ public class DefaultPluginServiceImpl im
             // location ?
             abstractImport.execute();
 
-            for (Iterator iterator = project.getTargets().values().iterator(); iterator.hasNext();) {
-                Target target = (Target) iterator.next();
-                handleTarget(eaReport, target);
-                for (int i = 0; i < target.getTasks().length; i++) {
-                    Task task = target.getTasks()[i];
-                    Class taskClass = ComponentHelper.getComponentHelper(project).getComponentClass(task.getTaskType());
-                    if (taskClass == null) {
-                        continue;
-                    }
-                    if (ParameterTask.class.getName().equals(taskClass.getName())) {
-                        handleParameterTask(eaReport, task);
-                    }
-                    if (Property.class.getName().equals(taskClass.getName())) {
-                        handleProperty(eaReport, task);
-                    }
-                    if (Import.class.getName().equals(taskClass.getName())) {
-                        handleImport(conf, eaReport, task);
-                    }
-
-                }
-            }
+            analyseProject(project, eaReport, conf);
         } catch (Exception e) {
             throw new Exception("An error occured while fetching plugin informations : " + e.getMessage(), e);
         } finally {
@@ -183,8 +200,7 @@ public class DefaultPluginServiceImpl im
 
     }
 
-    private void scanAntFile(String conf, EasyAntReport eaReport, Map<String, String> properties, File antFile)
-            throws IOException, Exception {
+    private Project buildProject(Map<String, String> properties) {
         Project project = new Project();
         project.setNewProperty(EasyAntMagicNames.AUDIT_MODE, "true");
         project.setNewProperty(EasyAntMagicNames.SKIP_CORE_REVISION_CHECKER, "true");
@@ -196,11 +212,13 @@ public class DefaultPluginServiceImpl im
             }
         }
         project.init();
-        ProjectHelper.configureProject(project, antFile);
+        return project;
+    }
 
+    private void analyseProject(Project project, EasyAntReport eaReport, String conf) throws IOException, Exception {
         for (Iterator iterator = project.getTargets().values().iterator(); iterator.hasNext();) {
             Target target = (Target) iterator.next();
-            handleTarget(eaReport, target);
+            handleTarget(target, eaReport);
             for (int i = 0; i < target.getTasks().length; i++) {
                 Task task = target.getTasks()[i];
                 Class taskClass = ComponentHelper.getComponentHelper(project).getComponentClass(task.getTaskType());
@@ -208,20 +226,28 @@ public class DefaultPluginServiceImpl im
                     continue;
                 }
                 if (ParameterTask.class.getName().equals(taskClass.getName())) {
-                    handleParameterTask(eaReport, task);
+                    handleParameterTask(task, eaReport);
                 }
                 if (Property.class.getName().equals(taskClass.getName())) {
-                    handleProperty(eaReport, task);
+                    handleProperty(task, eaReport);
                 }
                 if (Import.class.getName().equals(taskClass.getName())) {
-                    handleImport(conf, eaReport, task);
+                    handleImport(task, eaReport, conf);
                 }
 
             }
         }
     }
 
-    private void handleImport(String conf, EasyAntReport eaReport, Task task) throws Exception {
+    private void scanAntFile(File antFile, Map<String, String> properties, EasyAntReport eaReport, String conf)
+            throws IOException, Exception {
+        Project project = buildProject(properties);
+        ProjectHelper.configureProject(project, antFile);
+
+        analyseProject(project, eaReport, conf);
+    }
+
+    private void handleImport(Task task, EasyAntReport eaReport, String conf) throws Exception {
         Map<String, String> attributes = task.getRuntimeConfigurableWrapper().getAttributeMap();
         ImportedModuleReport importedModuleReport = new ImportedModuleReport();
         PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(task.getProject());
@@ -249,11 +275,11 @@ public class DefaultPluginServiceImpl im
     }
 
     /**
-     * @param eaReport
      * @param task
+     * @param eaReport
      * @throws IOException
      */
-    private void handleProperty(EasyAntReport eaReport, Task task) throws IOException {
+    private void handleProperty(Task task, EasyAntReport eaReport) throws IOException {
         Map<String, String> attributes = task.getRuntimeConfigurableWrapper().getAttributeMap();
         if (attributes.get("file") != null) {
             Properties propToLoad = new Properties();
@@ -279,10 +305,10 @@ public class DefaultPluginServiceImpl im
     }
 
     /**
-     * @param eaReport
      * @param task
+     * @param eaReport
      */
-    private void handleParameterTask(EasyAntReport eaReport, Task task) {
+    private void handleParameterTask(Task task, EasyAntReport eaReport) {
         Map<String, String> attributes = task.getRuntimeConfigurableWrapper().getAttributeMap();
         PropertyDescriptor propertyDescriptor = null;
 
@@ -313,10 +339,10 @@ public class DefaultPluginServiceImpl im
     }
 
     /**
-     * @param eaReport
      * @param target
+     * @param eaReport
      */
-    private void handleTarget(EasyAntReport eaReport, Target target) {
+    private void handleTarget(Target target, EasyAntReport eaReport) {
         if (!"".equals(target.getName())) {
             boolean isExtensionPoint = target instanceof ExtensionPoint;
             if (!isExtensionPoint) {
@@ -407,7 +433,7 @@ public class DefaultPluginServiceImpl im
         EasyAntReport eaReport = new EasyAntReport();
 
         if (overrideAntModule != null && overrideAntModule.exists()) {
-            scanAntFile("default", eaReport, null, overrideAntModule);
+            scanAntFile(overrideAntModule, null, eaReport, "default");
         }
         try {
             EasyAntModuleDescriptor md = getEasyAntModuleDescriptor(moduleDescriptor);
@@ -444,7 +470,7 @@ public class DefaultPluginServiceImpl im
         }
 
         if (optionalAntModule != null && optionalAntModule.exists()) {
-            scanAntFile("default", eaReport, null, optionalAntModule);
+            scanAntFile(optionalAntModule, null, eaReport, "default");
         }
 
         return eaReport;

Added: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java?rev=1382146&view=auto
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java (added)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java Fri Sep  7 20:05:58 2012
@@ -0,0 +1,303 @@
+/*
+ *  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.easyant.tasks;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.easyant.core.report.EasyAntReport;
+import org.apache.easyant.core.report.XMLEasyAntReportWriter;
+import org.apache.easyant.core.services.PluginService;
+import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.cache.ResolutionCacheManager;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.settings.IvySettings;
+import org.apache.ivy.util.FileUtil;
+import org.apache.ivy.util.Message;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.XSLTProcess;
+import org.apache.tools.ant.taskdefs.XSLTProcess.Param;
+import org.apache.tools.ant.util.JAXPUtils;
+
+public class PluginReport extends AbstractEasyAntTask {
+
+    private File todir;
+
+    private String conf;
+
+    private File xslFile;
+
+    private String xslext = "html";
+
+    private List<XSLTProcess.Param> params = new ArrayList<XSLTProcess.Param>();
+
+    private File moduleIvyFile;
+
+    private File sourceDirectory;
+
+    private String outputpattern;
+
+    public File getModuleIvyFile() {
+        return moduleIvyFile;
+    }
+
+    public void setModuleIvyFile(File moduleIvyFile) {
+        this.moduleIvyFile = moduleIvyFile;
+    }
+
+    public File getSourceDirectory() {
+        return sourceDirectory;
+    }
+
+    public void setSourceDirectory(File sourceDirectory) {
+        this.sourceDirectory = sourceDirectory;
+    }
+
+    public File getTodir() {
+        return todir;
+    }
+
+    public void setTodir(File todir) {
+        this.todir = todir;
+    }
+
+    public String getConf() {
+        return conf;
+    }
+
+    public void setConf(String conf) {
+        this.conf = conf;
+    }
+
+    public File getXslfile() {
+        return xslFile;
+    }
+
+    public void setXslfile(File xslFile) {
+        this.xslFile = xslFile;
+    }
+
+    public String getOutputpattern() {
+        return outputpattern;
+    }
+
+    public void setOutputpattern(String outputpattern) {
+        this.outputpattern = outputpattern;
+    }
+
+    public String getXslext() {
+        return xslext;
+    }
+
+    public void setXslext(String xslext) {
+        this.xslext = xslext;
+    }
+
+    public void execute() throws BuildException {
+        IvySettings settings = getEasyAntIvyInstance().getSettings();
+
+        conf = getProperty(conf, settings, "ivy.resolved.configurations");
+        if ("*".equals(conf)) {
+            conf = getProperty(settings, "ivy.resolved.configurations");
+        }
+        if (conf == null) {
+            throw new BuildException("no conf provided for ivy report task: "
+                    + "It can either be set explicitely via the attribute 'conf' or "
+                    + "via 'ivy.resolved.configurations' property or a prior call to <resolve/>");
+        }
+        if (todir == null) {
+            String t = getProperty(settings, "ivy.report.todir");
+            if (t != null) {
+                todir = getProject().resolveFile(t);
+            } else {
+                todir = getProject().getBaseDir();
+            }
+        }
+        if (todir != null && todir.exists()) {
+            todir.mkdirs();
+        }
+        outputpattern = getProperty(outputpattern, settings, "ivy.report.output.pattern");
+        if (outputpattern == null) {
+            outputpattern = "[organisation]-[module]-[conf].[ext]";
+        }
+
+        if (todir != null && todir.exists() && !todir.isDirectory()) {
+            throw new BuildException("destination directory should be a directory !");
+        }
+
+        PluginService pluginService = (PluginService) getProject().getReference(
+                EasyAntMagicNames.PLUGIN_SERVICE_INSTANCE);
+
+        try {
+            EasyAntReport easyantReport = pluginService.getPluginInfo(moduleIvyFile, sourceDirectory, conf);
+            ModuleRevisionId moduleRevisionId = easyantReport.getModuleDescriptor().getModuleRevisionId();
+            File reportFile = new File(todir, getOutputPattern(moduleRevisionId, conf, "xml"));
+            todir.mkdirs();
+            OutputStream stream = new FileOutputStream(reportFile);
+            XMLEasyAntReportWriter writer = new XMLEasyAntReportWriter();
+            writer.output(easyantReport, stream);
+            stream.close();
+            genStyled(reportFile, getReportStylePath(),easyantReport);
+        } catch (Exception e) {
+            throw new BuildException("impossible to generate report: " + e, e);
+        }
+    }
+
+    // private void genreport(String[] confs) throws IOException {
+    // genStyled(confs, getReportStylePath(), xslext);
+    // }
+
+    private File getReportStylePath() throws IOException {
+        if (xslFile != null) {
+            return xslFile;
+        }
+        // style should be a file (and not an url)
+        // so we have to copy it from classpath to cache
+        ResolutionCacheManager cacheMgr = getEasyAntIvyInstance().getResolutionCacheManager();
+        File style = new File(cacheMgr.getResolutionCacheRoot(), "ivy-report.xsl");
+        if (!style.exists()) {
+            Message.debug("copying ivy-report.xsl to " + style.getAbsolutePath());
+            FileUtil.copy(XMLEasyAntReportWriter.class.getResourceAsStream("ivy-report.xsl"), style, null);
+        }
+        return style;
+    }
+
+    private String getOutputPattern(ModuleRevisionId moduleRevisionId, String conf, String ext) {
+        return IvyPatternHelper.substitute(outputpattern, moduleRevisionId.getOrganisation(), moduleRevisionId.getName(),
+                moduleRevisionId.getRevision(), "", "", ext, conf, moduleRevisionId.getQualifiedExtraAttributes(), null);
+    }
+
+    private void genStyled(File reportFile, File style, EasyAntReport easyantReport) throws IOException {
+        InputStream xsltStream = null;
+        try {
+            // create stream to stylesheet
+            xsltStream = new BufferedInputStream(new FileInputStream(style));
+            Source xsltSource = new StreamSource(xsltStream, JAXPUtils.getSystemId(style));
+
+            // create transformer
+            TransformerFactory tFactory = TransformerFactory.newInstance();
+            Transformer transformer = tFactory.newTransformer(xsltSource);
+
+            // add the provided XSLT parameters
+            for (Iterator<Param> it = params.iterator(); it.hasNext();) {
+                XSLTProcess.Param param = (XSLTProcess.Param) it.next();
+                transformer.setParameter(param.getName(), param.getExpression());
+            }
+            ModuleRevisionId moduleRevisionId = easyantReport.getModuleDescriptor().getModuleRevisionId();
+            File outFile = new File(todir, getOutputPattern(moduleRevisionId, conf, xslext));
+
+            log("Processing " + reportFile + " to " + outFile);
+
+            // make sure the output directory exist
+            File outFileDir = outFile.getParentFile();
+            if (!outFileDir.exists()) {
+                if (!outFileDir.mkdirs()) {
+                    throw new BuildException("Unable to create directory: " + outFileDir.getAbsolutePath());
+                }
+            }
+
+            InputStream inStream = null;
+            OutputStream outStream = null;
+            try {
+                inStream = new BufferedInputStream(new FileInputStream(reportFile));
+                outStream = new BufferedOutputStream(new FileOutputStream(outFile));
+                StreamResult res = new StreamResult(outStream);
+                Source src = new StreamSource(inStream, JAXPUtils.getSystemId(style));
+                transformer.transform(src, res);
+            } catch (TransformerException e) {
+                throw new BuildException(e);
+            } finally {
+                if (inStream != null) {
+                    try {
+                        inStream.close();
+                    } catch (IOException e) {
+                        // ignore
+                    }
+                }
+                if (outStream != null) {
+                    try {
+                        outStream.close();
+                    } catch (IOException e) {
+                        // ignore
+                    }
+                }
+            }
+        } catch (TransformerConfigurationException e) {
+            throw new BuildException(e);
+        } finally {
+            if (xsltStream != null) {
+                try {
+                    xsltStream.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+        }
+    }
+
+    public XSLTProcess.Param createParam() {
+        XSLTProcess.Param result = new XSLTProcess.Param();
+        params.add(result);
+        return result;
+    }
+
+    private String getProperty(String value, IvySettings ivy, String name) {
+        if (value == null) {
+            return getProperty(ivy, name);
+        } else {
+            value = ivy.substitute(value);
+            Message.debug("parameter found as attribute value: " + name + "=" + value);
+            return value;
+        }
+    }
+
+    private String getProperty(IvySettings ivy, String name) {
+        String val = ivy.getVariable(name);
+        if (val == null) {
+            val = ivy.substitute(getProject().getProperty(name));
+            if (val != null) {
+                Message.debug("parameter found as ant project property: " + name + "=" + val);
+            } else {
+                Message.debug("parameter not found: " + name);
+            }
+        } else {
+            val = ivy.substitute(val);
+            Message.debug("parameter found as ivy variable: " + name + "=" + val);
+        }
+        return val;
+    }
+
+}
\ No newline at end of file

Modified: incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml?rev=1382146&r1=1382145&r2=1382146&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml (original)
+++ incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml Fri Sep  7 20:05:58 2012
@@ -44,6 +44,9 @@
     <taskdef name="checkresolver" classname="org.apache.easyant.tasks.CheckResolver"/>
     <taskdef name="easyant" classname="org.apache.easyant.tasks.EasyAntRunner"/>
     <taskdef name="go-offline"  classname="org.apache.easyant.tasks.GoOffline"/>
+
+    <taskdef name="plugin-report" classname="org.apache.easyant.tasks.PluginReport"/>
+
     
     <presetdef name="include">
         <current:import mode="include" />



Mime
View raw message