Search in sources :

Example 26 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class P2DescriptorTest method testResolvePacked.

@Test
public void testResolvePacked() throws Exception {
    settings.setDefaultResolver("p2-with-packed");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.junit", "4.10.0.v4_10_0_v20120426-0900");
    ResolvedModuleRevision rmr = p2WithPackedResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(1, rmr.getDescriptor().getAllArtifacts().length);
    DownloadOptions options = new DownloadOptions();
    DownloadReport report = p2WithPackedResolver.download(rmr.getDescriptor().getAllArtifacts(), options);
    assertNotNull(report);
    assertEquals(1, report.getArtifactsReports().length);
    Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);
    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    assertNotNull(ar.getUnpackedLocalFile());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 27 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class P2DescriptorTest method testResolveNotZipped.

@Test
public void testResolveNotZipped() throws Exception {
    settings.setDefaultResolver("p2-zipped");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.eclipse.e4.core.services", "1.0.0.v20120521-2346");
    ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(1, rmr.getDescriptor().getAllArtifacts().length);
    DownloadOptions options = new DownloadOptions();
    DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(), options);
    assertNotNull(report);
    assertEquals(1, report.getArtifactsReports().length);
    Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);
    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    assertNull(ar.getUnpackedLocalFile());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 28 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project Saturn by vipshop.

the class IvyGetArtifact method getCachePath.

private Set<URL> getCachePath(ModuleDescriptor md, String[] confs) throws ParseException, IOException {
    Set<URL> fs = new HashSet<URL>();
    StringBuffer buf = new StringBuffer();
    Collection<ArtifactDownloadReport> all = new LinkedHashSet<ArtifactDownloadReport>();
    ResolutionCacheManager cacheMgr = ivy.getResolutionCacheManager();
    XmlReportParser parser = new XmlReportParser();
    for (int i = 0; i < confs.length; i++) {
        String resolveId = ResolveOptions.getDefaultResolveId(md);
        File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]);
        parser.parse(report);
        all.addAll(Arrays.asList(parser.getArtifactReports()));
    }
    for (ArtifactDownloadReport artifact : all) {
        if (artifact.getLocalFile() != null) {
            buf.append(artifact.getLocalFile().getCanonicalPath());
            buf.append(File.pathSeparator);
        }
    }
    String[] fs_str = buf.toString().split(File.pathSeparator);
    for (String str : fs_str) {
        File file = new File(str);
        if (file.exists()) {
            fs.add(file.toURI().toURL());
        }
    }
    return fs;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) URL(java.net.URL) XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 29 with ArtifactDownloadReport

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

Example 30 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport 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

ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)64 File (java.io.File)33 Artifact (org.apache.ivy.core.module.descriptor.Artifact)29 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)26 Test (org.junit.Test)25 DownloadReport (org.apache.ivy.core.report.DownloadReport)23 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)18 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)17 ResolveReport (org.apache.ivy.core.report.ResolveReport)15 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)11 IOException (java.io.IOException)10 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)10 URL (java.net.URL)8 JarFile (java.util.jar.JarFile)8 Date (java.util.Date)7 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)7 URLResource (org.apache.ivy.plugins.repository.url.URLResource)7 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)6 MalformedURLException (java.net.MalformedURLException)5