mirror of https://github.com/apache/ant-ivy
IMPROVEMENT: in Ivy API, let users first locate an Artifact, then download it in a second step. This will be used to fix IVYDE-117, and could also be useful to allow a report only resolve, which does not download any artifact but only locate them (a kind of dry run).
git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@689862 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6247b11e3a
commit
12e916f9cc
|
|
@ -222,7 +222,7 @@ public class IvyArtifactReport extends IvyPostResolveTask {
|
|||
ArtifactDownloadReport artifact)
|
||||
throws IOException, SAXException {
|
||||
ArtifactOrigin origin = artifact.getArtifactOrigin();
|
||||
if (origin != ArtifactOrigin.UNKNOWN && origin != null) {
|
||||
if (!ArtifactOrigin.isUnknown(origin)) {
|
||||
String originName = origin.getLocation();
|
||||
boolean isOriginLocal = origin.isLocal();
|
||||
|
||||
|
|
|
|||
|
|
@ -438,14 +438,14 @@ public final class IvyPatternHelper {
|
|||
|
||||
origin = cacheManager.getSavedArtifactOrigin(artifact);
|
||||
|
||||
if (origin == ArtifactOrigin.UNKNOWN) {
|
||||
if (ArtifactOrigin.isUnknown(origin)) {
|
||||
Message.debug("no artifact origin found for " + artifact + " in "
|
||||
+ cacheManager);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (origin == ArtifactOrigin.UNKNOWN) {
|
||||
if (ArtifactOrigin.isUnknown(origin)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@
|
|||
*/
|
||||
package org.apache.ivy.core.cache;
|
||||
|
||||
import org.apache.ivy.core.module.descriptor.Artifact;
|
||||
import org.apache.ivy.util.Checks;
|
||||
|
||||
/**
|
||||
* This class contains information about the origin of an artifact.
|
||||
*
|
||||
|
|
@ -24,10 +27,22 @@ package org.apache.ivy.core.cache;
|
|||
* @see org.apache.ivy.plugins.resolver.util.ResolvedResource
|
||||
*/
|
||||
public class ArtifactOrigin {
|
||||
private static final String UNKNOWN = "UNKNOWN";
|
||||
|
||||
/**
|
||||
* ArtifactOrigin instance used when the origin is unknown.
|
||||
*/
|
||||
public static final ArtifactOrigin UNKNOWN = new ArtifactOrigin(false, "UNKNOWN");
|
||||
public static final ArtifactOrigin unkwnown(Artifact artifact) {
|
||||
return new ArtifactOrigin(artifact, false, UNKNOWN);
|
||||
}
|
||||
|
||||
public static final boolean isUnknown(ArtifactOrigin artifact) {
|
||||
return artifact == null || UNKNOWN.equals(artifact.getLocation());
|
||||
}
|
||||
|
||||
public static final boolean isUnknown(String location) {
|
||||
return location == null || UNKNOWN.equals(location);
|
||||
}
|
||||
|
||||
private static final int MAGIC_HASH_VALUE = 31;
|
||||
|
||||
|
|
@ -35,16 +50,23 @@ public class ArtifactOrigin {
|
|||
|
||||
private String location;
|
||||
|
||||
private Artifact artifact;
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
* @param artifact
|
||||
* the artifact pointed by this location. Must not be <code>null</code>.
|
||||
* @param isLocal
|
||||
* <code>boolean</code> value indicating if the resource is local (on the
|
||||
* filesystem).
|
||||
* @param location
|
||||
* the location of the resource (normally a url)
|
||||
* the location of the resource (normally a url). Must not be <code>null</code>.
|
||||
*/
|
||||
public ArtifactOrigin(boolean isLocal, String location) {
|
||||
public ArtifactOrigin(Artifact artifact, boolean isLocal, String location) {
|
||||
Checks.checkNotNull(artifact, "artifact");
|
||||
Checks.checkNotNull(location, "location");
|
||||
this.artifact = artifact;
|
||||
this.isLocal = isLocal;
|
||||
this.location = location;
|
||||
}
|
||||
|
|
@ -66,6 +88,15 @@ public class ArtifactOrigin {
|
|||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the artifact that this location is pointing at.
|
||||
*
|
||||
* @return the artifact that this location is pointing at.
|
||||
*/
|
||||
public Artifact getArtifact() {
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ArtifactOrigin { isLocal=" + isLocal + ", location=" + location + "}";
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
|
|||
public File getArchiveFileInCache(Artifact artifact, ArtifactOrigin origin) {
|
||||
File archive = new File(getRepositoryCacheRoot(), getArchivePathInCache(artifact, origin));
|
||||
if (!archive.exists()
|
||||
&& origin != null && origin != ArtifactOrigin.UNKNOWN && origin.isLocal()) {
|
||||
&& !ArtifactOrigin.isUnknown(origin) && origin.isLocal()) {
|
||||
File original = new File(origin.getLocation());
|
||||
if (original.exists()) {
|
||||
return original;
|
||||
|
|
@ -359,7 +359,7 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
|
|||
*/
|
||||
private File getArchiveFileInCache(
|
||||
Artifact artifact, ArtifactOrigin origin, boolean useOrigin) {
|
||||
if (useOrigin && origin != null && origin != ArtifactOrigin.UNKNOWN && origin.isLocal()) {
|
||||
if (useOrigin && !ArtifactOrigin.isUnknown(origin) && origin.isLocal()) {
|
||||
return new File(origin.getLocation());
|
||||
} else {
|
||||
return new File(getRepositoryCacheRoot(), getArchivePathInCache(artifact, origin));
|
||||
|
|
@ -452,7 +452,7 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
|
|||
ModuleRevisionId mrid = artifact.getModuleRevisionId();
|
||||
if (!lockMetadataArtifact(mrid)) {
|
||||
Message.error("impossible to acquire lock for " + mrid);
|
||||
return ArtifactOrigin.UNKNOWN;
|
||||
return ArtifactOrigin.unkwnown(artifact);
|
||||
}
|
||||
try {
|
||||
PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
|
||||
|
|
@ -462,10 +462,10 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
|
|||
|
||||
if (location == null) {
|
||||
// origin has not been specified, return null
|
||||
return ArtifactOrigin.UNKNOWN;
|
||||
return ArtifactOrigin.unkwnown(artifact);
|
||||
}
|
||||
|
||||
return new ArtifactOrigin(isLocal, location);
|
||||
return new ArtifactOrigin(artifact, isLocal, location);
|
||||
} finally {
|
||||
unlockMetadataArtifact(mrid);
|
||||
}
|
||||
|
|
@ -772,20 +772,20 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
|
|||
try {
|
||||
ResolvedResource artifactRef = resourceResolver.resolve(artifact);
|
||||
if (artifactRef != null) {
|
||||
origin = new ArtifactOrigin(artifactRef.getResource().isLocal(),
|
||||
origin = new ArtifactOrigin(
|
||||
artifact,
|
||||
artifactRef.getResource().isLocal(),
|
||||
artifactRef.getResource().getName());
|
||||
if (useOrigin && artifactRef.getResource().isLocal()) {
|
||||
saveArtifactOrigin(artifact, origin);
|
||||
archiveFile = getArchiveFileInCache(artifact,
|
||||
origin);
|
||||
archiveFile = getArchiveFileInCache(artifact, origin);
|
||||
adr.setDownloadStatus(DownloadStatus.NO);
|
||||
adr.setSize(archiveFile.length());
|
||||
adr.setArtifactOrigin(origin);
|
||||
adr.setLocalFile(archiveFile);
|
||||
} else {
|
||||
// refresh archive file now that we better now its origin
|
||||
archiveFile = getArchiveFileInCache(artifact,
|
||||
origin, useOrigin);
|
||||
archiveFile = getArchiveFileInCache(artifact, origin, useOrigin);
|
||||
if (ResourceHelper.equals(artifactRef.getResource(), archiveFile)) {
|
||||
throw new IllegalStateException("invalid settings for '"
|
||||
+ resourceResolver
|
||||
|
|
@ -1026,7 +1026,8 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
|
|||
private ArtifactOrigin getDefaultMetadataArtifactOrigin(ModuleRevisionId mrid) {
|
||||
// it's important to say the origin is not local to make sure it won't ever be used for
|
||||
// anything else than original token
|
||||
return new ArtifactOrigin(false, getIvyFileInCache(mrid).getPath());
|
||||
return new ArtifactOrigin(
|
||||
DefaultArtifact.newIvyArtifact(mrid, null), false, getIvyFileInCache(mrid).getPath());
|
||||
}
|
||||
|
||||
private Artifact getDefaultMetadataArtifact(ModuleRevisionId mrid) {
|
||||
|
|
|
|||
|
|
@ -54,8 +54,10 @@ public interface RepositoryCacheManager {
|
|||
ModuleDescriptor descriptor, String metadataResolverName, String artifactResolverName);
|
||||
|
||||
/**
|
||||
* Returns the artifact origin of the given artifact as saved in this cache, or
|
||||
* {@link ArtifactOrigin#UNKNOWN} if the origin is unknown.
|
||||
* Returns the artifact origin of the given artifact as saved in this cache.
|
||||
* <p>
|
||||
* If the origin is unknown, the returned ArtifactOrigin instance will return true when
|
||||
* {@link ArtifactOrigin#isUnknown(ArtifactOrigin)} is called.
|
||||
*
|
||||
* @param artifact
|
||||
* the artifact for which the saved artifact origin should be returned.
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class EndArtifactDownloadEvent extends DownloadEvent {
|
|||
addAttribute("file", dest.getAbsolutePath());
|
||||
addAttribute("duration", String.valueOf(this.report.getDownloadTimeMillis()));
|
||||
ArtifactOrigin origin = report.getArtifactOrigin();
|
||||
if (origin != null && origin != ArtifactOrigin.UNKNOWN) {
|
||||
if (!ArtifactOrigin.isUnknown(origin)) {
|
||||
addAttribute("origin", origin.getLocation());
|
||||
addAttribute("local", String.valueOf(origin.isLocal()));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import java.util.Set;
|
|||
import org.apache.ivy.Ivy;
|
||||
import org.apache.ivy.core.IvyContext;
|
||||
import org.apache.ivy.core.LogOptions;
|
||||
import org.apache.ivy.core.cache.ArtifactOrigin;
|
||||
import org.apache.ivy.core.cache.ResolutionCacheManager;
|
||||
import org.apache.ivy.core.event.EventManager;
|
||||
import org.apache.ivy.core.event.download.PrepareDownloadEvent;
|
||||
|
|
@ -394,12 +395,56 @@ public class ResolveEngine {
|
|||
* @param artifact
|
||||
* the artifact to download
|
||||
* @return a report concerning the download
|
||||
* @see #download(ArtifactOrigin, DownloadOptions)
|
||||
*/
|
||||
public ArtifactDownloadReport download(Artifact artifact, DownloadOptions options) {
|
||||
DependencyResolver resolver = settings.getResolver(artifact.getModuleRevisionId());
|
||||
DownloadReport r = resolver.download(new Artifact[] {artifact}, options);
|
||||
return r.getArtifactReport(artifact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates an artifact in dependency resolvers, and return its location if it can be located and
|
||||
* actually exists, or an unknown {@link ArtifactOrigin} in other cases.
|
||||
*
|
||||
* @param artifact
|
||||
* the artifact to locate.
|
||||
* @return the artifact location, should be tested with
|
||||
* {@link ArtifactOrigin#isUnknown(ArtifactOrigin)} to check if the artifact has
|
||||
* actually been located.
|
||||
*/
|
||||
public ArtifactOrigin locate(Artifact artifact) {
|
||||
DependencyResolver resolver = settings.getResolver(artifact.getModuleRevisionId());
|
||||
return resolver.locate(artifact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Materialize an artifact already located.
|
||||
* <p>
|
||||
* Not used internally, useful especially for IDE plugins needing to download artifact one by
|
||||
* one (for source or javadoc artifact, for instance).
|
||||
* </p>
|
||||
* <p>
|
||||
* Materialized artifact file can be accessed using
|
||||
* {@link ArtifactDownloadReport#getLocalFile()}.
|
||||
* </p>
|
||||
* <p>
|
||||
* It is possible to track the progression of the download using classical ivy progress
|
||||
* monitoring feature (see addTransferListener).
|
||||
* </p>
|
||||
*
|
||||
* @param origin
|
||||
* the artifact origin to materialize
|
||||
* @return a report concerning the download
|
||||
* @see #download(Artifact, DownloadOptions)
|
||||
* @see #locate(Artifact)
|
||||
*/
|
||||
public ArtifactDownloadReport download(ArtifactOrigin origin, DownloadOptions options) {
|
||||
DependencyResolver resolver = settings.getResolver(
|
||||
origin.getArtifact().getModuleRevisionId());
|
||||
return resolver.download(origin, options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the dependencies of a module without downloading corresponding artifacts. The module
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.ivy.core.IvyContext;
|
||||
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;
|
||||
|
|
@ -263,21 +264,27 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
|
|||
Message.debug("no resolver found for " + mrid
|
||||
+ ": no source or javadoc artifact lookup");
|
||||
} else {
|
||||
String mainArtifact = resolver.locate(mdBuilder.getMainArtifact());
|
||||
ArtifactOrigin mainArtifact = resolver.locate(mdBuilder.getMainArtifact());
|
||||
|
||||
String sourceArtifact = resolver.locate(mdBuilder.getSourceArtifact());
|
||||
if (sourceArtifact != null && !sourceArtifact.equals(mainArtifact)) {
|
||||
Message.debug("source artifact found for " + mrid);
|
||||
mdBuilder.addSourceArtifact();
|
||||
} else {
|
||||
Message.debug("no source artifact found for " + mrid);
|
||||
}
|
||||
String javadocArtifact = resolver.locate(mdBuilder.getJavadocArtifact());
|
||||
if (javadocArtifact != null && !javadocArtifact.equals(mainArtifact)) {
|
||||
Message.debug("javadoc artifact found for " + mrid);
|
||||
mdBuilder.addJavadocArtifact();
|
||||
} else {
|
||||
Message.debug("no javadoc artifact found for " + mrid);
|
||||
if (!ArtifactOrigin.isUnknown(mainArtifact)) {
|
||||
String mainArtifactLocation = mainArtifact.getLocation();
|
||||
|
||||
ArtifactOrigin sourceArtifact = resolver.locate(mdBuilder.getSourceArtifact());
|
||||
if (!ArtifactOrigin.isUnknown(sourceArtifact)
|
||||
&& !sourceArtifact.getLocation().equals(mainArtifactLocation)) {
|
||||
Message.debug("source artifact found for " + mrid);
|
||||
mdBuilder.addSourceArtifact();
|
||||
} else {
|
||||
Message.debug("no source artifact found for " + mrid);
|
||||
}
|
||||
ArtifactOrigin javadocArtifact = resolver.locate(mdBuilder.getJavadocArtifact());
|
||||
if (!ArtifactOrigin.isUnknown(javadocArtifact)
|
||||
&& !javadocArtifact.getLocation().equals(mainArtifactLocation)) {
|
||||
Message.debug("javadoc artifact found for " + mrid);
|
||||
mdBuilder.addJavadocArtifact();
|
||||
} else {
|
||||
Message.debug("no javadoc artifact found for " + mrid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,12 +133,12 @@ public class XmlReportParser {
|
|||
new File(attributes.getValue("original-local-location")));
|
||||
}
|
||||
if (attributes.getValue("origin-location") != null) {
|
||||
if (ArtifactOrigin.UNKNOWN.getLocation().equals(
|
||||
attributes.getValue("origin-location"))) {
|
||||
madr.setArtifactOrigin(ArtifactOrigin.UNKNOWN);
|
||||
if (ArtifactOrigin.isUnknown(attributes.getValue("origin-location"))) {
|
||||
madr.setArtifactOrigin(ArtifactOrigin.unkwnown(madr.getArtifact()));
|
||||
} else {
|
||||
madr.setArtifactOrigin(
|
||||
new ArtifactOrigin(
|
||||
madr.getArtifact(),
|
||||
parseBoolean(attributes.getValue("origin-is-local")),
|
||||
attributes.getValue("origin-location")));
|
||||
}
|
||||
|
|
@ -171,12 +171,12 @@ public class XmlReportParser {
|
|||
ArtifactDownloadReport aReport = (ArtifactDownloadReport)
|
||||
revisionArtifacts.get(revisionArtifacts.size() - 1);
|
||||
|
||||
if (ArtifactOrigin.UNKNOWN.getLocation().equals(
|
||||
attributes.getValue("location"))) {
|
||||
aReport.setArtifactOrigin(ArtifactOrigin.UNKNOWN);
|
||||
if (ArtifactOrigin.isUnknown(attributes.getValue("location"))) {
|
||||
aReport.setArtifactOrigin(ArtifactOrigin.unkwnown(aReport.getArtifact()));
|
||||
} else {
|
||||
aReport.setArtifactOrigin(
|
||||
new ArtifactOrigin(
|
||||
aReport.getArtifact(),
|
||||
parseBoolean(attributes.getValue("is-local")),
|
||||
attributes.getValue("location")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,6 +190,14 @@ public abstract class AbstractResolver
|
|||
public String getTypeName() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation downloads the artifact without taking advantage of its location
|
||||
*/
|
||||
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
|
||||
DownloadReport r = download(new Artifact[] {artifact.getArtifact()}, options);
|
||||
return r.getArtifactReport(artifact.getArtifact());
|
||||
}
|
||||
|
||||
public boolean exists(Artifact artifact) {
|
||||
return locate(artifact) != null;
|
||||
|
|
@ -199,7 +207,7 @@ public abstract class AbstractResolver
|
|||
* Default implementation actually download the artifact Subclasses should overwrite this to
|
||||
* avoid the download
|
||||
*/
|
||||
public String locate(Artifact artifact) {
|
||||
public ArtifactOrigin locate(Artifact artifact) {
|
||||
DownloadReport dr = download(new Artifact[] {artifact}, new DownloadOptions());
|
||||
if (dr == null) {
|
||||
/*
|
||||
|
|
@ -211,8 +219,7 @@ public abstract class AbstractResolver
|
|||
+ " when trying to download " + artifact);
|
||||
}
|
||||
ArtifactDownloadReport adr = dr.getArtifactReport(artifact);
|
||||
return adr.getDownloadStatus() == DownloadStatus.FAILED || adr.getArtifactOrigin() == null
|
||||
? null : adr.getArtifactOrigin().getLocation();
|
||||
return adr.getDownloadStatus() == DownloadStatus.FAILED ? null : adr.getArtifactOrigin();
|
||||
}
|
||||
|
||||
public LatestStrategy getLatestStrategy() {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import java.util.Map.Entry;
|
|||
import org.apache.ivy.core.IvyContext;
|
||||
import org.apache.ivy.core.IvyPatternHelper;
|
||||
import org.apache.ivy.core.LogOptions;
|
||||
import org.apache.ivy.core.cache.ArtifactOrigin;
|
||||
import org.apache.ivy.core.cache.ModuleDescriptorWriter;
|
||||
import org.apache.ivy.core.cache.RepositoryCacheManager;
|
||||
import org.apache.ivy.core.module.descriptor.Artifact;
|
||||
|
|
@ -68,6 +69,7 @@ import org.apache.ivy.plugins.repository.url.URLResource;
|
|||
import org.apache.ivy.plugins.resolver.util.MDResolvedResource;
|
||||
import org.apache.ivy.plugins.resolver.util.ResolvedResource;
|
||||
import org.apache.ivy.plugins.resolver.util.ResourceMDParser;
|
||||
import org.apache.ivy.util.Checks;
|
||||
import org.apache.ivy.util.ChecksumHelper;
|
||||
import org.apache.ivy.util.HostUtil;
|
||||
import org.apache.ivy.util.Message;
|
||||
|
|
@ -731,6 +733,30 @@ public abstract class BasicResolver extends AbstractResolver {
|
|||
protected void clearArtifactAttempts() {
|
||||
artattempts.clear();
|
||||
}
|
||||
|
||||
public ArtifactDownloadReport download(final ArtifactOrigin origin, DownloadOptions options) {
|
||||
Checks.checkNotNull(origin, "origin");
|
||||
return getRepositoryCacheManager().download(
|
||||
origin.getArtifact(),
|
||||
new ArtifactResourceResolver() {
|
||||
public ResolvedResource resolve(Artifact artifact) {
|
||||
try {
|
||||
Resource resource = getResource(origin.getLocation());
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
String revision = origin.getArtifact().getModuleRevisionId().getRevision();
|
||||
return new ResolvedResource(resource, revision);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
downloader,
|
||||
getCacheDownloadOptions(options));
|
||||
}
|
||||
|
||||
protected abstract Resource getResource(String source) throws IOException;
|
||||
|
||||
public boolean exists(Artifact artifact) {
|
||||
ResolvedResource artifactRef = getArtifactRef(artifact, null);
|
||||
|
|
@ -740,10 +766,17 @@ public abstract class BasicResolver extends AbstractResolver {
|
|||
return false;
|
||||
}
|
||||
|
||||
public String locate(Artifact artifact) {
|
||||
public ArtifactOrigin locate(Artifact artifact) {
|
||||
ArtifactOrigin origin = getRepositoryCacheManager().getSavedArtifactOrigin(artifact);
|
||||
if (!ArtifactOrigin.isUnknown(origin)) {
|
||||
return origin;
|
||||
}
|
||||
ResolvedResource artifactRef = getArtifactRef(artifact, null);
|
||||
if (artifactRef != null && artifactRef.getResource().exists()) {
|
||||
return artifactRef.getResource().getName();
|
||||
return new ArtifactOrigin(
|
||||
artifact,
|
||||
artifactRef.getResource().isLocal(),
|
||||
artifactRef.getResource().getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public class CacheResolver extends FileSystemResolver {
|
|||
if (artifactRef != null) {
|
||||
Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
|
||||
ArtifactOrigin origin = new ArtifactOrigin(
|
||||
true, artifactRef.getResource().getName());
|
||||
artifacts[i], true, artifactRef.getResource().getName());
|
||||
File archiveFile = ((FileResource) artifactRef.getResource()).getFile();
|
||||
adr.setDownloadStatus(DownloadStatus.NO);
|
||||
adr.setSize(archiveFile.length());
|
||||
|
|
@ -130,7 +130,7 @@ public class CacheResolver extends FileSystemResolver {
|
|||
return super.exists(artifact);
|
||||
}
|
||||
|
||||
public String locate(Artifact artifact) {
|
||||
public ArtifactOrigin locate(Artifact artifact) {
|
||||
ensureConfigured();
|
||||
return super.locate(artifact);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import java.util.Arrays;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ivy.core.cache.ArtifactOrigin;
|
||||
import org.apache.ivy.core.module.descriptor.Artifact;
|
||||
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
|
||||
import org.apache.ivy.core.module.id.ModuleRevisionId;
|
||||
|
|
@ -302,6 +303,30 @@ public class ChainResolver extends AbstractResolver {
|
|||
return false;
|
||||
}
|
||||
|
||||
public ArtifactOrigin locate(Artifact artifact) {
|
||||
for (Iterator iter = chain.iterator(); iter.hasNext();) {
|
||||
DependencyResolver resolver = (DependencyResolver) iter.next();
|
||||
ArtifactOrigin origin = resolver.locate(artifact);
|
||||
if (!ArtifactOrigin.isUnknown(origin)) {
|
||||
return origin;
|
||||
}
|
||||
}
|
||||
return ArtifactOrigin.unkwnown(artifact);
|
||||
}
|
||||
|
||||
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
|
||||
for (Iterator iter = chain.iterator(); iter.hasNext();) {
|
||||
DependencyResolver resolver = (DependencyResolver) iter.next();
|
||||
ArtifactDownloadReport adr = resolver.download(artifact, options);
|
||||
if (adr.getDownloadStatus() != DownloadStatus.FAILED) {
|
||||
return adr;
|
||||
}
|
||||
}
|
||||
ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact.getArtifact());
|
||||
adr.setDownloadStatus(DownloadStatus.FAILED);
|
||||
return adr;
|
||||
}
|
||||
|
||||
private static void setLatest(DependencyResolver resolver, LatestStrategy latest) {
|
||||
if (resolver instanceof HasLatestStrategy) {
|
||||
HasLatestStrategy r = (HasLatestStrategy) resolver;
|
||||
|
|
|
|||
|
|
@ -22,10 +22,12 @@ import java.io.IOException;
|
|||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ivy.core.cache.ArtifactOrigin;
|
||||
import org.apache.ivy.core.cache.RepositoryCacheManager;
|
||||
import org.apache.ivy.core.module.descriptor.Artifact;
|
||||
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
|
||||
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;
|
||||
|
|
@ -84,12 +86,29 @@ public interface DependencyResolver {
|
|||
* </p>
|
||||
*
|
||||
* @param artifacts
|
||||
* an array of artifacts to download
|
||||
* an array of artifacts to download. Must not be <code>null</code>.
|
||||
* @param options
|
||||
* options to apply for this download
|
||||
* options to apply for this download. Must not be <code>null</code>.
|
||||
* @return a DownloadReport with details about each Artifact download.
|
||||
*/
|
||||
DownloadReport download(Artifact[] artifacts, DownloadOptions options);
|
||||
|
||||
/**
|
||||
* Download an artifact according to the given DownloadOptions.
|
||||
* <p>
|
||||
* This methods is an alternative to {@link #download(Artifact[], DownloadOptions)}, which
|
||||
* locates and downloads a set of artifacts. This method uses an {@link ArtifactOrigin}, and as
|
||||
* such is only used to materialize an already located Artifact.
|
||||
* </p>
|
||||
*
|
||||
* @param artifact
|
||||
* the location of the artifact to download. Must not be <code>null</code>.
|
||||
* @param options
|
||||
* options to apply for this download. Must not be <code>null</code>.
|
||||
* @return a report detailing how the download has gone, is never <code>null</code>.
|
||||
*/
|
||||
ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options);
|
||||
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the given artifact can be located by this resolver and
|
||||
|
|
@ -103,15 +122,15 @@ public interface DependencyResolver {
|
|||
boolean exists(Artifact artifact);
|
||||
|
||||
/**
|
||||
* Locates the given artifact and returns a String identifying its location if it can be located
|
||||
* by this resolver and if it actually exists, or <code>null</code> in other cases.
|
||||
* Locates the given artifact and returns its location if it can be located by this resolver and
|
||||
* if it actually exists, or <code>null</code> in other cases.
|
||||
*
|
||||
* @param artifact
|
||||
* the artifact which should be located
|
||||
* @return a String identifying the artifact location, or <code>null</code> if it can't be
|
||||
* located or doesn't exist.
|
||||
* @return the artifact location, or <code>null</code> if it can't be located by this resolver
|
||||
* or doesn't exist.
|
||||
*/
|
||||
String locate(Artifact artifact);
|
||||
ArtifactOrigin locate(Artifact artifact);
|
||||
|
||||
void publish(Artifact artifact, File src, boolean overwrite) throws IOException;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,11 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.apache.ivy.core.cache.ArtifactOrigin;
|
||||
import org.apache.ivy.core.module.descriptor.Artifact;
|
||||
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
|
||||
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;
|
||||
|
|
@ -158,11 +160,27 @@ public class DualResolver extends AbstractResolver {
|
|||
}
|
||||
|
||||
public boolean exists(Artifact artifact) {
|
||||
return artifactResolver.exists(artifact);
|
||||
if (artifact.isMetadata()) {
|
||||
return ivyResolver.exists(artifact);
|
||||
} else {
|
||||
return artifactResolver.exists(artifact);
|
||||
}
|
||||
}
|
||||
|
||||
public String locate(Artifact artifact) {
|
||||
return artifactResolver.locate(artifact);
|
||||
public ArtifactOrigin locate(Artifact artifact) {
|
||||
if (artifact.isMetadata()) {
|
||||
return ivyResolver.locate(artifact);
|
||||
} else {
|
||||
return artifactResolver.locate(artifact);
|
||||
}
|
||||
}
|
||||
|
||||
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
|
||||
if (artifact.getArtifact().isMetadata()) {
|
||||
return ivyResolver.download(artifact, options);
|
||||
} else {
|
||||
return artifactResolver.download(artifact, options);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAllownomd() {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import java.util.Map;
|
|||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.ivy.core.IvyPatternHelper;
|
||||
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.DependencyDescriptor;
|
||||
|
|
@ -508,7 +509,7 @@ public class IBiblioResolver extends URLResolver {
|
|||
return super.exists(artifact);
|
||||
}
|
||||
|
||||
public String locate(Artifact artifact) {
|
||||
public ArtifactOrigin locate(Artifact artifact) {
|
||||
ensureConfigured(getSettings());
|
||||
return super.locate(artifact);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.ivy.core.IvyPatternHelper;
|
||||
import org.apache.ivy.core.cache.ArtifactOrigin;
|
||||
import org.apache.ivy.core.module.descriptor.Artifact;
|
||||
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
|
||||
import org.apache.ivy.core.report.DownloadReport;
|
||||
|
|
@ -291,7 +292,7 @@ public class IvyRepResolver extends URLResolver {
|
|||
return super.exists(artifact);
|
||||
}
|
||||
|
||||
public String locate(Artifact artifact) {
|
||||
public ArtifactOrigin locate(Artifact artifact) {
|
||||
ensureArtifactConfigured(getSettings());
|
||||
return super.locate(artifact);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,6 +152,10 @@ public class RepositoryResolver extends AbstractPatternsBasedResolver {
|
|||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
protected Resource getResource(String source) throws IOException {
|
||||
return repository.getResource(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all revisions as resolved resources for the given artifact in the given repository using
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class DefaultRepositoryCacheManagerTest extends TestCase {
|
|||
cacheManager.setBasedir(f);
|
||||
|
||||
artifact = createArtifact("org", "module", "rev", "name", "type", "ext");
|
||||
origin = new ArtifactOrigin(true, "/some/where");
|
||||
origin = new ArtifactOrigin(artifact, true, "/some/where");
|
||||
cacheManager.saveArtifactOrigin(artifact, origin);
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ public class DefaultRepositoryCacheManagerTest extends TestCase {
|
|||
|
||||
artifact = createArtifact("org", "module", "rev", "name", "type2", "ext");
|
||||
found = cacheManager.getSavedArtifactOrigin(artifact);
|
||||
assertEquals(ArtifactOrigin.UNKNOWN, found);
|
||||
assertTrue(ArtifactOrigin.isUnknown(found));
|
||||
}
|
||||
|
||||
public void testUniqueness() {
|
||||
|
|
@ -77,27 +77,27 @@ public class DefaultRepositoryCacheManagerTest extends TestCase {
|
|||
|
||||
artifact = createArtifact("org1", "module", "rev", "name", "type", "ext");
|
||||
ArtifactOrigin found = cacheManager.getSavedArtifactOrigin(artifact);
|
||||
assertEquals(ArtifactOrigin.UNKNOWN, found);
|
||||
assertTrue(ArtifactOrigin.isUnknown(found));
|
||||
|
||||
artifact = createArtifact("org", "module1", "rev", "name", "type", "ext");
|
||||
found = cacheManager.getSavedArtifactOrigin(artifact);
|
||||
assertEquals(ArtifactOrigin.UNKNOWN, found);
|
||||
assertTrue(ArtifactOrigin.isUnknown(found));
|
||||
|
||||
artifact = createArtifact("org", "module", "rev1", "name", "type", "ext");
|
||||
found = cacheManager.getSavedArtifactOrigin(artifact);
|
||||
assertEquals(ArtifactOrigin.UNKNOWN, found);
|
||||
assertTrue(ArtifactOrigin.isUnknown(found));
|
||||
|
||||
artifact = createArtifact("org", "module", "rev", "name1", "type", "ext");
|
||||
found = cacheManager.getSavedArtifactOrigin(artifact);
|
||||
assertEquals(ArtifactOrigin.UNKNOWN, found);
|
||||
assertTrue(ArtifactOrigin.isUnknown(found));
|
||||
|
||||
artifact = createArtifact("org", "module", "rev", "name", "type1", "ext");
|
||||
found = cacheManager.getSavedArtifactOrigin(artifact);
|
||||
assertEquals(ArtifactOrigin.UNKNOWN, found);
|
||||
assertTrue(ArtifactOrigin.isUnknown(found));
|
||||
|
||||
artifact = createArtifact("org", "module", "rev", "name", "type", "ext1");
|
||||
found = cacheManager.getSavedArtifactOrigin(artifact);
|
||||
assertEquals(ArtifactOrigin.UNKNOWN, found);
|
||||
assertTrue(ArtifactOrigin.isUnknown(found));
|
||||
}
|
||||
|
||||
protected Artifact createArtifact(String org, String module, String rev, String name,
|
||||
|
|
|
|||
|
|
@ -18,11 +18,17 @@
|
|||
package org.apache.ivy.core.resolve;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.ivy.Ivy;
|
||||
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.id.ModuleRevisionId;
|
||||
import org.apache.ivy.core.report.ArtifactDownloadReport;
|
||||
import org.apache.ivy.core.report.DownloadStatus;
|
||||
import org.apache.ivy.core.report.ResolveReport;
|
||||
import org.apache.ivy.util.CacheCleaner;
|
||||
|
||||
|
|
@ -58,6 +64,35 @@ public class ResolveEngineTest extends TestCase {
|
|||
assertNotNull("The ResolveReport may never be null", report);
|
||||
assertTrue(report.hasError());
|
||||
}
|
||||
|
||||
public void testLocateThenDownload() throws Exception {
|
||||
ResolveEngine engine = new ResolveEngine(ivy.getSettings(),
|
||||
ivy.getEventManager(), ivy.getSortEngine());
|
||||
|
||||
testLocateThenDownload(
|
||||
engine,
|
||||
DefaultArtifact.newIvyArtifact(ModuleRevisionId.parse("org1#mod1.1;1.0"), new Date()),
|
||||
new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"));
|
||||
testLocateThenDownload(
|
||||
engine,
|
||||
new DefaultArtifact(ModuleRevisionId.parse("org1#mod1.1;1.0"), new Date(), "mod1.1", "jar", "jar"),
|
||||
new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"));
|
||||
}
|
||||
|
||||
private void testLocateThenDownload(ResolveEngine engine, Artifact artifact, File artifactFile) {
|
||||
ArtifactOrigin origin = engine.locate(artifact);
|
||||
assertNotNull(origin);
|
||||
assertTrue(origin.isLocal());
|
||||
assertEquals(
|
||||
artifactFile.getAbsolutePath(),
|
||||
new File(origin.getLocation()).getAbsolutePath());
|
||||
|
||||
ArtifactDownloadReport r = engine.download(origin, new DownloadOptions());
|
||||
assertNotNull(r);
|
||||
assertEquals(DownloadStatus.SUCCESSFUL, r.getDownloadStatus());
|
||||
assertNotNull(r.getLocalFile());
|
||||
assertTrue(r.getLocalFile().exists());
|
||||
}
|
||||
|
||||
private void createCache() {
|
||||
cache.mkdirs();
|
||||
|
|
|
|||
Loading…
Reference in New Issue