use of org.apache.ivy.core.report.DownloadReport in project ant-ivy by apache.
the class ResolveEngine method download.
/**
* Download an artifact to the cache. Not used internally, useful especially for IDE plugins
* needing to download artifact one by one (for source or javadoc artifact, for instance).
* <p>
* Downloaded 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 artifact
* the artifact to download
* @param options DownloadOptions
* @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);
}
use of org.apache.ivy.core.report.DownloadReport in project ant-ivy by apache.
the class ResolveEngine method downloadArtifacts.
public void downloadArtifacts(ResolveReport report, Filter<Artifact> artifactFilter, DownloadOptions options) {
long start = System.currentTimeMillis();
eventManager.fireIvyEvent(new PrepareDownloadEvent(report.getArtifacts().toArray(new Artifact[report.getArtifacts().size()])));
long totalSize = 0;
for (IvyNode dependency : report.getDependencies()) {
checkInterrupted();
// download artifacts required in all asked configurations
if (!dependency.isCompletelyEvicted() && !dependency.hasProblem() && dependency.getModuleRevision() != null) {
DependencyResolver resolver = dependency.getModuleRevision().getArtifactResolver();
Artifact[] selectedArtifacts = dependency.getSelectedArtifacts(artifactFilter);
DownloadReport dReport = resolver.download(selectedArtifacts, options);
for (ArtifactDownloadReport adr : dReport.getArtifactsReports()) {
if (adr.getDownloadStatus() == DownloadStatus.FAILED) {
if (adr.getArtifact().getExtraAttribute("ivy:merged") != null) {
Message.warn("\tmerged artifact not found: " + adr.getArtifact() + ". It was required in " + adr.getArtifact().getExtraAttribute("ivy:merged"));
} else {
Message.warn("\t" + adr);
resolver.reportFailure(adr.getArtifact());
}
} else if (adr.getDownloadStatus() == DownloadStatus.SUCCESSFUL) {
totalSize += adr.getSize();
}
}
// update concerned reports
for (String dconf : dependency.getRootModuleConfigurations()) {
// (as described by the Dependency object)
if (dependency.isEvicted(dconf) || dependency.isBlacklisted(dconf)) {
report.getConfigurationReport(dconf).addDependency(dependency);
} else {
report.getConfigurationReport(dconf).addDependency(dependency, dReport);
}
}
}
}
report.setDownloadTime(System.currentTimeMillis() - start);
report.setDownloadSize(totalSize);
}
use of org.apache.ivy.core.report.DownloadReport in project ant-ivy by apache.
the class OBRResolverTest 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.DownloadReport in project ant-ivy by apache.
the class P2DescriptorTest method testResolveZipped.
@Test
public void testResolveZipped() throws Exception {
settings.setDefaultResolver("p2-zipped");
ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.apache.ant", "1.8.3.v20120321-1730");
ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);
DownloadOptions options = new DownloadOptions();
DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(), options);
assertNotNull(report);
assertEquals(2, report.getArtifactsReports().length);
for (int i = 0; i < 2; i++) {
Artifact artifact = rmr.getDescriptor().getAllArtifacts()[i];
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
// only the binary get unpacked
if (ar.getArtifact().getType().equals("source")) {
assertNull(ar.getUnpackedLocalFile());
} else {
assertNotNull(ar.getUnpackedLocalFile());
}
}
}
use of org.apache.ivy.core.report.DownloadReport in project ant-ivy by apache.
the class UpdateSiteResolverTest 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());
}
Aggregations