Search in sources :

Example 1 with PrepareDownloadEvent

use of org.apache.ivy.core.event.download.PrepareDownloadEvent 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);
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Artifact(org.apache.ivy.core.module.descriptor.Artifact) PrepareDownloadEvent(org.apache.ivy.core.event.download.PrepareDownloadEvent) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Aggregations

PrepareDownloadEvent (org.apache.ivy.core.event.download.PrepareDownloadEvent)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)1 DownloadReport (org.apache.ivy.core.report.DownloadReport)1 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)1