use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class BasicResolver method getDefaultRMDParser.
protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) {
return new ResourceMDParser() {
public MDResolvedResource parse(Resource resource, String rev) {
DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(new ModuleRevisionId(mid, rev));
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
madr.setDownloadStatus(DownloadStatus.NO);
madr.setSearched(true);
return new MDResolvedResource(resource, rev, new ResolvedModuleRevision(BasicResolver.this, BasicResolver.this, md, madr, isForce()));
}
};
}
use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class BasicResolver method getArtifactRef.
protected ResolvedResource getArtifactRef(Artifact artifact, Date date) {
IvyContext.getContext().set(getName() + ".artifact", artifact);
try {
ResolvedResource ret = findArtifactRef(artifact, date);
if (ret == null && artifact.getUrl() != null) {
URL url = artifact.getUrl();
Message.verbose("\tusing url for " + artifact + ": " + url);
logArtifactAttempt(artifact, url.toExternalForm());
Resource resource;
if ("file".equals(url.getProtocol())) {
File f;
try {
f = new File(new URI(url.toExternalForm()));
} catch (URISyntaxException e) {
// unexpected, try to get the best of it
f = new File(url.getPath());
}
resource = new FileResource(new FileRepository(), f);
} else {
resource = new URLResource(url, this.getTimeoutConstraint());
}
ret = new ResolvedResource(resource, artifact.getModuleRevisionId().getRevision());
}
return ret;
} finally {
IvyContext.getContext().set(getName() + ".artifact", null);
}
}
use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class IBiblioResolver method listResources.
@Override
protected ResolvedResource[] listResources(Repository repository, ModuleRevisionId mrid, String pattern, Artifact artifact) {
if (shouldUseMavenMetadata(pattern)) {
List<String> revs = listRevisionsWithMavenMetadata(repository, mrid.getModuleId().getAttributes());
if (revs != null) {
Message.debug("\tfound revs: " + revs);
List<ResolvedResource> rres = new ArrayList<>();
for (String rev : revs) {
ModuleRevisionId historicalMrid = ModuleRevisionId.newInstance(mrid, rev);
String patternForRev = pattern;
if (rev.endsWith("SNAPSHOT")) {
String snapshotVersion = findTimestampedSnapshotVersion(historicalMrid);
if (snapshotVersion != null) {
patternForRev = pattern.replaceFirst("\\-\\[revision\\]", "-" + snapshotVersion);
}
}
String resolvedPattern = IvyPatternHelper.substitute(patternForRev, historicalMrid, artifact);
try {
Resource res = repository.getResource(resolvedPattern);
if (res != null) {
// we do not test if the resource actually exist here, it would cause
// a lot of checks which are not always necessary depending on the usage
// which is done of the returned ResolvedResource array
rres.add(new ResolvedResource(res, rev));
}
} catch (IOException e) {
Message.warn("impossible to get resource from name listed by maven-metadata.xml:" + rres, e);
}
}
return rres.toArray(new ResolvedResource[rres.size()]);
} else {
// use default listing capability
return super.listResources(repository, mrid, pattern, artifact);
}
} else {
return super.listResources(repository, mrid, pattern, artifact);
}
}
use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class JarResolver method setSettings.
@Override
public void setSettings(ResolverSettings settings) {
super.setSettings(settings);
if (url == null) {
return;
}
// let's resolve the url
ArtifactDownloadReport report;
EventManager eventManager = getEventManager();
try {
if (eventManager != null) {
getRepository().addTransferListener(eventManager);
}
Resource jarResource = new URLResource(url, this.getTimeoutConstraint());
CacheResourceOptions options = new CacheResourceOptions();
report = getRepositoryCacheManager().downloadRepositoryResource(jarResource, "jarrepository", "jar", "jar", options, new URLRepository());
} finally {
if (eventManager != null) {
getRepository().removeTransferListener(eventManager);
}
}
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
throw new RuntimeException("The jar file " + url.toExternalForm() + " could not be downloaded (" + report.getDownloadDetails() + ")");
}
setJarFile(report.getLocalFile());
}
use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class URLRepository method getResource.
public Resource getResource(String source) throws IOException {
Resource res = resourcesCache.get(source);
if (res == null) {
res = new URLResource(new URL(source), this.getTimeoutConstraint());
resourcesCache.put(source, res);
}
return res;
}
Aggregations