From f86bb7973bc9be1c6bc481d5adf28c62200db633 Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Fri, 18 Jan 2008 15:23:43 +0000 Subject: [PATCH] =?UTF-8?q?IMPROVEMENT:=20In=20the=20ResolveReport=20class?= =?UTF-8?q?,=20add=20the=20possibility=20to=20filter=20the=20evicted=20mod?= =?UTF-8?q?ule=20while=20getting=20the=20list=20of=20DownloadArtifact=20(I?= =?UTF-8?q?VY-704)=20(thanks=20to=20Nicolas=20Lalev=C3=A9e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@613184 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../module/descriptor/ModuleDescriptor.java | 2 +- .../apache/ivy/core/module/id/ArtifactId.java | 2 + .../core/module/id/ArtifactRevisionId.java | 4 +- .../apache/ivy/core/module/id/ModuleId.java | 4 +- .../ivy/core/module/id/ModuleRevisionId.java | 5 +- .../core/report/ArtifactDownloadReport.java | 4 + .../report/ConfigurationResolveReport.java | 93 +++++++++++++------ .../apache/ivy/core/report/ResolveReport.java | 55 ++++++++--- 9 files changed, 123 insertions(+), 47 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9537c875..3b5ef188 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -71,6 +71,7 @@ for detailed view of each issue, please consult http://issues.apache.org/jira/br - IMPROVEMENT: Flexible cache management (IVY-399 - not completed yet) - IMPROVEMENT: Decrease memory footprint (IVY-662) - IMPROVEMENT: Downgrade Ant version requirement to 1.6 to build Ivy (IVY-687) +- IMPROVEMENT: In the ResolveReport class, add the possibility to filter the evicted module while getting the list of DownloadArtifact (IVY-704) (thanks to Nicolas Lalevée) - FIX: Ivy swallows ParseException when using a latest strategy requiring module descriptors (IVY-702) (thanks to Nicolas Lalevée) - FIX: Problem with cached Ivy files which have extra attributes (IVY-693) diff --git a/src/java/org/apache/ivy/core/module/descriptor/ModuleDescriptor.java b/src/java/org/apache/ivy/core/module/descriptor/ModuleDescriptor.java index 23136f90..128dc20a 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/ModuleDescriptor.java +++ b/src/java/org/apache/ivy/core/module/descriptor/ModuleDescriptor.java @@ -34,7 +34,7 @@ import org.apache.ivy.plugins.version.VersionMatcher; import org.apache.ivy.util.extendable.ExtendableItem; /** - * + * Decriptor of a module. This is the Java representation of an ivy.xml */ public interface ModuleDescriptor extends ExtendableItem, ArtifactInfo { public static final String DEFAULT_CONFIGURATION = "default"; diff --git a/src/java/org/apache/ivy/core/module/id/ArtifactId.java b/src/java/org/apache/ivy/core/module/id/ArtifactId.java index 32eb559c..cfd3a01d 100644 --- a/src/java/org/apache/ivy/core/module/id/ArtifactId.java +++ b/src/java/org/apache/ivy/core/module/id/ArtifactId.java @@ -19,6 +19,8 @@ package org.apache.ivy.core.module.id; /** * Identifies an artifact in a module, without revision information + * + * @see org.apache.ivy.core.module.id */ public class ArtifactId { private ModuleId mid; diff --git a/src/java/org/apache/ivy/core/module/id/ArtifactRevisionId.java b/src/java/org/apache/ivy/core/module/id/ArtifactRevisionId.java index 1db3797a..61491039 100644 --- a/src/java/org/apache/ivy/core/module/id/ArtifactRevisionId.java +++ b/src/java/org/apache/ivy/core/module/id/ArtifactRevisionId.java @@ -23,7 +23,9 @@ import org.apache.ivy.core.IvyPatternHelper; import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; /** - * identifies an artifact in a particular module revision + * Identifies an artifact in a particular module revision + * + * @see org.apache.ivy.core.module.id */ public class ArtifactRevisionId extends UnmodifiableExtendableItem { public static ArtifactRevisionId newInstance(ModuleRevisionId mrid, String name, String type, diff --git a/src/java/org/apache/ivy/core/module/id/ModuleId.java b/src/java/org/apache/ivy/core/module/id/ModuleId.java index 237507e6..70f4d548 100644 --- a/src/java/org/apache/ivy/core/module/id/ModuleId.java +++ b/src/java/org/apache/ivy/core/module/id/ModuleId.java @@ -23,7 +23,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * + * Identifies a module, without revision information + * + * @see org.apache.ivy.core.module.id */ public class ModuleId implements Comparable { static final String ENCODE_SEPARATOR = ":#@#:"; diff --git a/src/java/org/apache/ivy/core/module/id/ModuleRevisionId.java b/src/java/org/apache/ivy/core/module/id/ModuleRevisionId.java index 7ed5b908..2e909526 100644 --- a/src/java/org/apache/ivy/core/module/id/ModuleRevisionId.java +++ b/src/java/org/apache/ivy/core/module/id/ModuleRevisionId.java @@ -30,7 +30,9 @@ import org.apache.ivy.core.IvyPatternHelper; import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; /** - * + * Identifies a module in a particular version + * + * @see org.apache.ivy.core.module.id */ public class ModuleRevisionId extends UnmodifiableExtendableItem { private static final String ENCODE_SEPARATOR = ModuleId.ENCODE_SEPARATOR; @@ -43,7 +45,6 @@ public class ModuleRevisionId extends UnmodifiableExtendableItem { private static final String REV_STRICT_CHARS_PATTERN = "[a-zA-Z0-9\\-/\\._+=,\\[\\]\\{\\}\\(\\):@]"; - private static final Map/**/ CACHE = new WeakHashMap(); /** diff --git a/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java b/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java index ea058591..a8694f2f 100644 --- a/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java +++ b/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java @@ -71,6 +71,10 @@ public class ArtifactDownloadReport { return artifact.getName(); } + /** + * + * @return the type of the downloaded artifact + */ public String getType() { return artifact.getType(); } diff --git a/src/java/org/apache/ivy/core/report/ConfigurationResolveReport.java b/src/java/org/apache/ivy/core/report/ConfigurationResolveReport.java index 32422098..077b2ae4 100644 --- a/src/java/org/apache/ivy/core/report/ConfigurationResolveReport.java +++ b/src/java/org/apache/ivy/core/report/ConfigurationResolveReport.java @@ -44,7 +44,7 @@ import org.apache.ivy.plugins.report.XmlReportParser; import org.apache.ivy.util.Message; /** - * + * Represents a whole resolution report for a module but for a specific configuration */ public class ConfigurationResolveReport { @@ -177,6 +177,15 @@ public class ConfigurationResolveReport { return (IvyNode[]) evicted.toArray(new IvyNode[evicted.size()]); } + private Set/**/ getEvictedMrids() { + Set/**/ evicted = new HashSet(); + IvyNode[] evictedNodes = getEvictedNodes(); + for (int i = 0; i < evictedNodes.length; i++) { + evicted.add(evictedNodes[i].getId()); + } + return evicted; + } + public IvyNode[] getDownloadedNodes() { List downloaded = new ArrayList(); for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { @@ -255,41 +264,67 @@ public class ConfigurationResolveReport { return total; } + /** + * Get every report on the download requests. + * + * @return the list of reports, never null + */ public ArtifactDownloadReport[] getAllArtifactsReports() { - List result = new ArrayList(); - for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { - Collection reports = (Collection) iter.next(); - result.addAll(reports); - } - return (ArtifactDownloadReport[]) result.toArray(new ArtifactDownloadReport[result.size()]); + return getArtifactsReports(null, true); } + /** + * Get the report on the download requests. The list of download report can be restricted to a + * specific download status, and also remove the download report for the evicted modules. + * + * @param downloadStatus + * the status of download to retreive. Set it to null for no + * restriction on the download status + * @param withEvicted + * set it to true if the report for the evicted modules have to be + * retrieved. + * @return the list of reports, never null + * @see ArtifactDownloadReport + */ + public ArtifactDownloadReport[] getArtifactsReports( + DownloadStatus downloadStatus, boolean withEvicted) { + Collection all = new HashSet(); + Collection evictedMrids = null; + if (!withEvicted) { + evictedMrids = getEvictedMrids(); + } + for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { + Collection reports = (Collection) iter.next(); + for (Iterator itReport = reports.iterator(); itReport.hasNext();) { + ArtifactDownloadReport report = (ArtifactDownloadReport) itReport.next(); + if (downloadStatus != null && report.getDownloadStatus() != downloadStatus) { + continue; + } + if (withEvicted + || !evictedMrids.contains(report.getArtifact().getModuleRevisionId())) { + all.add(report); + } + } + } + return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]); + } + + /** + * Get the report on the sucessfull download requests with the evicted modules + * + * @return the list of reports, never null + */ public ArtifactDownloadReport[] getDownloadedArtifactsReports() { - List result = new ArrayList(); - for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { - Collection reports = (Collection) iter.next(); - for (Iterator iterator = reports.iterator(); iterator.hasNext();) { - ArtifactDownloadReport adr = (ArtifactDownloadReport) iterator.next(); - if (adr.getDownloadStatus() == DownloadStatus.SUCCESSFUL) { - result.add(adr); - } - } - } - return (ArtifactDownloadReport[]) result.toArray(new ArtifactDownloadReport[result.size()]); + return getArtifactsReports(DownloadStatus.SUCCESSFUL, true); } + /** + * Get the report on the failed download requests with the evicted modules + * + * @return the list of reports, never null + */ public ArtifactDownloadReport[] getFailedArtifactsReports() { - List result = new ArrayList(); - for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { - Collection reports = (Collection) iter.next(); - for (Iterator iterator = reports.iterator(); iterator.hasNext();) { - ArtifactDownloadReport adr = (ArtifactDownloadReport) iterator.next(); - if (adr.getDownloadStatus() == DownloadStatus.FAILED) { - result.add(adr); - } - } - } - return (ArtifactDownloadReport[]) result.toArray(new ArtifactDownloadReport[result.size()]); + return getArtifactsReports(DownloadStatus.FAILED, true); } public boolean hasError() { diff --git a/src/java/org/apache/ivy/core/report/ResolveReport.java b/src/java/org/apache/ivy/core/report/ResolveReport.java index bf5c8a24..ecb4c4dc 100644 --- a/src/java/org/apache/ivy/core/report/ResolveReport.java +++ b/src/java/org/apache/ivy/core/report/ResolveReport.java @@ -42,12 +42,15 @@ import org.apache.ivy.util.filter.Filter; public class ResolveReport { private ModuleDescriptor md; + /** String conf -> ConfigurationResolveReport report */ private Map confReports = new LinkedHashMap(); private List problemMessages = new ArrayList(); - private List dependencies = new ArrayList(); - // the list of all dependencies resolved, ordered from the more dependent to the less dependent + /** + * the list of all dependencies resolved, ordered from the more dependent to the less dependent + */ + private List dependencies = new ArrayList(); private List artifacts = new ArrayList(); @@ -89,7 +92,7 @@ public class ResolveReport { return hasError; } - public void output(ReportOutputter[] outputters, ResolutionCacheManager cacheMgr) + public void output(ReportOutputter[] outputters, ResolutionCacheManager cacheMgr) throws IOException { for (int i = 0; i < outputters.length; i++) { outputters[i].output(this, cacheMgr); @@ -118,20 +121,46 @@ public class ResolveReport { return (IvyNode[]) all.toArray(new IvyNode[all.size()]); } + /** + * Get every report on the download requests. + * + * @return the list of reports, never null + */ public ArtifactDownloadReport[] getFailedArtifactsReports() { - Collection all = new HashSet(); - for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { - ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); - all.addAll(Arrays.asList(report.getFailedArtifactsReports())); - } - return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]); + return getArtifactsReports(DownloadStatus.FAILED, true); } + /** + * Get every report on the download requests. + * + * @return the list of reports, never null + */ public ArtifactDownloadReport[] getAllArtifactsReports() { + return getArtifactsReports(null, true); + } + + /** + * Get the report on the download requests. The list of download report can be restricted to a + * specific download status, and also remove the download report for the evicted modules. + * + * @param downloadStatus + * the status of download to retreive. Set it to null for no + * restriction on the download status + * @param withEvicted + * set it to true if the report for the evicted modules have to be + * retrieved, false to exclude reports from modules evicted in all + * configurations. + * @return the list of reports, never null + * @see ConfigurationResolveReport#getArtifactsReports(DownloadStatus, boolean) + */ + public ArtifactDownloadReport[] getArtifactsReports( + DownloadStatus downloadStatus, boolean withEvicted) { Collection all = new HashSet(); for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); - all.addAll(Arrays.asList(report.getAllArtifactsReports())); + ArtifactDownloadReport[] reports = + report.getArtifactsReports(downloadStatus, withEvicted); + all.addAll(Arrays.asList(reports)); } return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]); } @@ -209,7 +238,7 @@ public class ResolveReport { * Returns the list of all dependencies concerned by this report as a List of IvyNode ordered * from the more dependent to the least one * - * @return The list of all dependencies. + * @return The list of all dependencies. */ public List getDependencies() { return dependencies; @@ -219,7 +248,7 @@ public class ResolveReport { * Returns the list of all artifacts which should be downloaded per this resolve To know if the * artifact have actually been downloaded use information found in ConfigurationResolveReport. * - * @return The list of all artifacts. + * @return The list of all artifacts. */ public List getArtifacts() { return artifacts; @@ -262,7 +291,7 @@ public class ResolveReport { public void setDownloadSize(long size) { this.downloadSize = size; } - + /** * The total size of downloaded artifacts, in bytes. *