Search in sources :

Example 1 with DownloadReport

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

the class CacheResolver method download.

@Override
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    ensureConfigured();
    clearArtifactAttempts();
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
        dr.addArtifactReport(adr);
        ResolvedResource artifactRef = getArtifactRef(artifact, null);
        if (artifactRef != null) {
            Message.verbose("\t[NOT REQUIRED] " + artifact);
            ArtifactOrigin origin = new ArtifactOrigin(artifact, true, artifactRef.getResource().getName());
            File archiveFile = ((FileResource) artifactRef.getResource()).getFile();
            adr.setDownloadStatus(DownloadStatus.NO);
            adr.setSize(archiveFile.length());
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(archiveFile);
        } else {
            adr.setDownloadStatus(DownloadStatus.FAILED);
        }
    }
    return dr;
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact)

Example 2 with DownloadReport

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

the class ChainResolver method download.

public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    List<Artifact> artifactsToDownload = new ArrayList<>(Arrays.asList(artifacts));
    DownloadReport report = new DownloadReport();
    for (DependencyResolver resolver : chain) {
        if (artifactsToDownload.isEmpty()) {
            break;
        }
        DownloadReport r = resolver.download(artifactsToDownload.toArray(new Artifact[artifactsToDownload.size()]), options);
        for (ArtifactDownloadReport adr : r.getArtifactsReports()) {
            if (adr.getDownloadStatus() != DownloadStatus.FAILED) {
                artifactsToDownload.remove(adr.getArtifact());
                report.addArtifactReport(adr);
            }
        }
    }
    for (Artifact art : artifactsToDownload) {
        ArtifactDownloadReport adr = new ArtifactDownloadReport(art);
        adr.setDownloadStatus(DownloadStatus.FAILED);
        report.addArtifactReport(adr);
    }
    return report;
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArrayList(java.util.ArrayList) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Artifact(org.apache.ivy.core.module.descriptor.Artifact)

Example 3 with DownloadReport

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

the class FileSystemResolverTest method testSHA256Checksum.

/**
 * Tests that <code>SHA-256</code> algorithm can be used for checksums on resolvers
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testSHA256Checksum() throws Exception {
    final FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("sha256-checksum-resolver");
    resolver.setSettings(settings);
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.setChecksums("SHA-256");
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("test", "allright", "2.0");
    final ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull("Resolved module revision was null for " + mrid, rmr);
    final DownloadReport dr = resolver.download(rmr.getDescriptor().getAllArtifacts(), getDownloadOptions());
    final ArtifactDownloadReport[] successfulDownloadReports = dr.getArtifactsReports(DownloadStatus.SUCCESSFUL);
    assertNotNull("No artifacts were downloaded successfully", successfulDownloadReports);
    assertEquals("Unexpected number of successfully downloaded artifacts", 1, successfulDownloadReports.length);
    final ArtifactDownloadReport successfulDownloadReport = successfulDownloadReports[0];
    final Artifact downloadedArtifact = successfulDownloadReport.getArtifact();
    assertEquals("Unexpected organization of downloaded artifact", "test", downloadedArtifact.getModuleRevisionId().getOrganisation());
    assertEquals("Unexpected module of downloaded artifact", "allright", downloadedArtifact.getModuleRevisionId().getModuleId().getName());
    assertEquals("Unexpected revision of downloaded artifact", "2.0", downloadedArtifact.getModuleRevisionId().getRevision());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) 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) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 4 with DownloadReport

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

the class FileSystemResolverTest method testSHA512Checksum.

/**
 * Tests that <code>SHA-512</code> algorithm can be used for checksums on resolvers
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testSHA512Checksum() throws Exception {
    final FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("sha256-checksum-resolver");
    resolver.setSettings(settings);
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.setChecksums("SHA-512");
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("test", "allright", "3.0");
    final ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull("Resolved module revision was null for " + mrid, rmr);
    final DownloadReport dr = resolver.download(rmr.getDescriptor().getAllArtifacts(), getDownloadOptions());
    final ArtifactDownloadReport[] successfulDownloadReports = dr.getArtifactsReports(DownloadStatus.SUCCESSFUL);
    assertNotNull("No artifacts were downloaded successfully", successfulDownloadReports);
    assertEquals("Unexpected number of successfully downloaded artifacts", 1, successfulDownloadReports.length);
    final ArtifactDownloadReport successfulDownloadReport = successfulDownloadReports[0];
    final Artifact downloadedArtifact = successfulDownloadReport.getArtifact();
    assertEquals("Unexpected organization of downloaded artifact", "test", downloadedArtifact.getModuleRevisionId().getOrganisation());
    assertEquals("Unexpected module of downloaded artifact", "allright", downloadedArtifact.getModuleRevisionId().getModuleId().getName());
    assertEquals("Unexpected revision of downloaded artifact", "3.0", downloadedArtifact.getModuleRevisionId().getRevision());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) 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) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 5 with DownloadReport

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

the class BintrayResolverTest method testBintrayArtifacts.

@Test
public void testBintrayArtifacts() throws Exception {
    BintrayResolver resolver = new BintrayResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ant", "ant-antunit", "1.2");
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false);
    dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "javadoc", "jar"), ExactPatternMatcher.INSTANCE, null));
    dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "sources", "jar"), ExactPatternMatcher.INSTANCE, null));
    ResolvedModuleRevision rmr = resolver.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "javadoc", "jar");
    DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "sources", "jar");
    DownloadReport report = resolver.download(new Artifact[] { profiler, trace }, downloadOptions());
    assertNotNull(report);
    assertEquals(2, report.getArtifactsReports().length);
    ArtifactDownloadReport ar = report.getArtifactReport(profiler);
    assertNotNull(ar);
    assertEquals(profiler, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    ar = report.getArtifactReport(trace);
    assertNotNull(ar);
    assertEquals(trace, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    // test to ask to download again, should use cache
    report = resolver.download(new Artifact[] { profiler, trace }, downloadOptions());
    assertNotNull(report);
    assertEquals(2, report.getArtifactsReports().length);
    ar = report.getArtifactReport(profiler);
    assertNotNull(ar);
    assertEquals(profiler, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
    ar = report.getArtifactReport(trace);
    assertNotNull(ar);
    assertEquals(trace, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) 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) DefaultIncludeRule(org.apache.ivy.core.module.descriptor.DefaultIncludeRule) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

DownloadReport (org.apache.ivy.core.report.DownloadReport)25 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)24 Artifact (org.apache.ivy.core.module.descriptor.Artifact)20 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)18 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 Test (org.junit.Test)16 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)15 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)12 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)10 Date (java.util.Date)6 File (java.io.File)5 GregorianCalendar (java.util.GregorianCalendar)5 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)2 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)2 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)2 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)1 CacheDownloadOptions (org.apache.ivy.core.cache.CacheDownloadOptions)1 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)1