use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class ResolveTest method testUseOrigin.
@Test
public void testUseOrigin() throws Exception {
((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).setUseOrigin(true);
ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "default" }));
assertNotNull(report);
ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct.", 1, dReports.length);
assertEquals("download status not correct: should not download the artifact in useOrigin mode.", DownloadStatus.NO, dReports[0].getDownloadStatus());
Artifact artifact = dReports[0].getArtifact();
assertNotNull(artifact);
String expectedLocation = new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath();
ArtifactOrigin origin = getSavedArtifactOrigin(artifact);
File artInCache = new File(cache, getArchivePathInCache(artifact, origin));
assertFalse("should not download artifact in useOrigin mode.", artInCache.exists());
assertEquals("location for artifact not correct.", expectedLocation, getArchiveFileInCache(artifact).getAbsolutePath());
}
use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class AggregatedOSGiResolverTest method genericTestResolveDownload.
private void genericTestResolveDownload(DependencyResolver resolver, ModuleRevisionId mrid) throws ParseException {
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
DownloadReport report = resolver.download(new Artifact[] { artifact }, new DownloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
// test to ask to download again, should use cache
report = resolver.download(new Artifact[] { artifact }, new DownloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class OBRResolver method init.
@Override
protected void init() {
if (repoXmlFile != null && repoXmlURL != null) {
throw new RuntimeException("The OBR repository resolver " + getName() + " couldn't be configured: repoXmlFile and repoXmlUrl cannot be set both");
}
if (repoXmlFile != null) {
File f = new File(repoXmlFile);
loadRepoFromFile(f.getParentFile().toURI(), f, repoXmlFile);
} else if (repoXmlURL != null) {
final URL url;
try {
url = new URL(repoXmlURL);
} catch (MalformedURLException e) {
throw new RuntimeException("The OBR repository resolver " + getName() + " couldn't be configured: repoXmlURL '" + repoXmlURL + "' is not an URL");
}
ArtifactDownloadReport report;
EventManager eventManager = getEventManager();
try {
if (eventManager != null) {
getRepository().addTransferListener(eventManager);
}
final Resource obrResource = new URLResource(url, this.getTimeoutConstraint());
CacheResourceOptions options = new CacheResourceOptions();
if (metadataTtl != null) {
options.setTtl(metadataTtl);
}
if (forceMetadataUpdate != null) {
options.setForce(forceMetadataUpdate);
}
report = getRepositoryCacheManager().downloadRepositoryResource(obrResource, "obr", "obr", "xml", options, getRepository());
} finally {
if (eventManager != null) {
getRepository().removeTransferListener(eventManager);
}
}
URI baseURI;
try {
baseURI = new URI(repoXmlURL);
} catch (URISyntaxException e) {
throw new RuntimeException("illegal uri");
}
loadRepoFromFile(baseURI, report.getLocalFile(), repoXmlURL);
} else {
throw new RuntimeException("The OBR repository resolver " + getName() + " couldn't be configured: repoXmlFile or repoXmlUrl is missing");
}
}
use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class UpdateSiteLoader method loadSite.
private UpdateSite loadSite(URI repoUri) throws IOException, SAXException {
URI siteUri = normalizeSiteUri(repoUri, null);
URL u = siteUri.resolve("site.xml").toURL();
final URLResource res = new URLResource(u, this.timeoutConstraint);
ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, "site", "updatesite", "xml", options, urlRepository);
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
return null;
}
try (InputStream in = new FileInputStream(report.getLocalFile())) {
UpdateSite site = EclipseUpdateSiteParser.parse(in);
site.setUri(normalizeSiteUri(site.getUri(), siteUri));
return site;
}
}
use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class UpdateSiteLoader method loadFromDigest.
private UpdateSiteDescriptor loadFromDigest(UpdateSite site) throws IOException, SAXException {
URI digestBaseUri = site.getDigestUri();
if (digestBaseUri == null) {
digestBaseUri = site.getUri();
} else if (!digestBaseUri.isAbsolute()) {
digestBaseUri = site.getUri().resolve(digestBaseUri);
}
URL digest = digestBaseUri.resolve("digest.zip").toURL();
Message.verbose("\tReading " + digest);
final URLResource res = new URLResource(digest, this.timeoutConstraint);
ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, "digest", "digest", "zip", options, urlRepository);
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
return null;
}
try (InputStream in = new FileInputStream(report.getLocalFile())) {
ZipInputStream zipped = findEntry(in, "digest.xml");
if (zipped == null) {
return null;
}
return UpdateSiteDigestParser.parse(zipped, site);
}
}
Aggregations