[ivy-debian-helper] 01/04: Handle the download of renamed artifacts
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Tue Jan 26 09:13:48 UTC 2016
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to branch master
in repository ivy-debian-helper.
commit 80eb72fdd578b2877cc309f7e3d741b1ab7150a5
Author: Emmanuel Bourg <ebourg at apache.org>
Date: Tue Jan 26 09:57:33 2016 +0100
Handle the download of renamed artifacts
---
.../org/debian/ivy/DebianDependencyResolver.java | 80 +++++++++++++++++++++-
1 file changed, 77 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/debian/ivy/DebianDependencyResolver.java b/src/main/java/org/debian/ivy/DebianDependencyResolver.java
index 9c46ee8..608e078 100644
--- a/src/main/java/org/debian/ivy/DebianDependencyResolver.java
+++ b/src/main/java/org/debian/ivy/DebianDependencyResolver.java
@@ -18,13 +18,21 @@ package org.debian.ivy;
import java.lang.reflect.Field;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import org.apache.ivy.core.cache.ArtifactOrigin;
+import org.apache.ivy.core.module.descriptor.Artifact;
+import org.apache.ivy.core.module.descriptor.DefaultArtifact;
import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.ArtifactDownloadReport;
+import org.apache.ivy.core.report.DownloadReport;
+import org.apache.ivy.core.resolve.DownloadOptions;
import org.apache.ivy.core.resolve.ResolveData;
import org.apache.ivy.core.resolve.ResolvedModuleRevision;
import org.apache.ivy.plugins.resolver.IBiblioResolver;
@@ -37,7 +45,7 @@ import org.debian.maven.repo.DependencyRuleSetFiles;
/**
* Dependency resolver for Ivy using the Debian system repository under /usr/share/maven-repo.
- *
+ *
* @author Emmanuel Bourg
* @version $Revision$, $Date$
*/
@@ -61,7 +69,7 @@ public class DebianDependencyResolver extends IBiblioResolver {
@Override
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
-
+
ModuleDescriptor md = getModuleDescription(dd);
Dependency dependency = toDependency(dd);
@@ -77,7 +85,7 @@ public class DebianDependencyResolver extends IBiblioResolver {
} else {
Message.info("[ivy-debian-helper] Replacing " + format(dependency) + " -> " + format(resolved));
- Map attributes = new HashMap();
+ Map<String, String> attributes = new HashMap<String, String>();
if (resolved.getClassifier() != null && resolved.getClassifier().length() > 0) {
attributes.put("classifier", resolved.getClassifier());
}
@@ -136,6 +144,72 @@ public class DebianDependencyResolver extends IBiblioResolver {
}
/**
+ * Alters the download logic by ensuring the artifacts downloaded are those that were given
+ * by the substitution rules.
+ *
+ * Ivy allows to change the name of the artifact downloaded with a dependency like this one:
+ *
+ * <pre>
+ * <dependency org="org.eclipse.jetty.orbit" name="javax.servlet" rev="3.0">
+ * <artifact name="servlet" type="orbit" ext="jar"/>
+ * </dependency>
+ * </pre>
+ *
+ * In this case, if the following rule is applied:
+ *
+ * <pre> s/org.eclipse.jetty.orbit/javax.servlet/ s/javax.servlet/servlet-api/ * * * *</pre>
+ *
+ * Ivy will attempt to download:
+ *
+ * <pre> file:/usr/share/maven-repo/javax/servlet/servlet-api/3.0/servlet-3.0.jar</pre>
+ *
+ * instead of:
+ *
+ * <pre> file:/usr/share/maven-repo/javax/servlet/servlet-api/3.0/servlet-api-3.0.jar</pre>
+ *
+ * Thus this implementation ensures that the artifact name specified in the dependency is ignored.
+ */
+ @Override
+ public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
+ Map<Artifact, Artifact> replacedArtifacts = new HashMap<Artifact, Artifact>();
+
+ List<Artifact> resolvedArtifacts = new ArrayList<Artifact>();
+
+ if (artifacts != null) {
+ for (Artifact artifact : artifacts) {
+ Artifact artifact2 = DefaultArtifact.cloneWithAnotherName(artifact, artifact.getModuleRevisionId().getName());
+ resolvedArtifacts.add(artifact2);
+ replacedArtifacts.put(artifact2, artifact);
+ }
+ }
+
+ DownloadReport report = super.download(resolvedArtifacts.toArray(new Artifact[0]), options);
+
+ // rewrite the download report with the original artifacts
+ DownloadReport report2 = new DownloadReport();
+ for (ArtifactDownloadReport artifactDownloadReport : report.getArtifactsReports()) {
+ Artifact artifact = replacedArtifacts.get(artifactDownloadReport.getArtifact());
+
+ ArtifactDownloadReport artifactDownloadReport2 = new ArtifactDownloadReport(artifact);
+ String location = artifactDownloadReport.getArtifactOrigin().getLocation();
+
+ if (location != null) {
+ artifactDownloadReport2.setArtifactOrigin(new ArtifactOrigin(artifact, false, location));
+ artifactDownloadReport2.setLocalFile(artifactDownloadReport.getLocalFile());
+ artifactDownloadReport2.setSize(artifactDownloadReport.getSize());
+ }
+
+ artifactDownloadReport2.setDownloadStatus(artifactDownloadReport.getDownloadStatus());
+ artifactDownloadReport2.setDownloadDetails(artifactDownloadReport.getDownloadDetails());
+ artifactDownloadReport2.setDownloadTimeMillis(artifactDownloadReport.getDownloadTimeMillis());
+
+ report2.addArtifactReport(artifactDownloadReport2);
+ }
+
+ return report2;
+ }
+
+ /**
* Converts an Ivy dependency into a dependency object as handled by maven-repo-helper.
*/
private Dependency toDependency(DependencyDescriptor dd) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/ivy-debian-helper.git
More information about the pkg-java-commits
mailing list