Search in sources :

Example 21 with DownloadReport

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

the class BintrayResolverTest method testBintray.

@Test
public void testBintray() throws Exception {
    BintrayResolver resolver = new BintrayResolver();
    resolver.setSettings(settings);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ant", "ant-antunit", "1.2");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "jar", "jar");
    DownloadReport report = resolver.download(new Artifact[] { artifact }, 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 }, downloadOptions());
    assertNotNull(report);
    assertEquals(1, report.getArtifactsReports().length);
    ar = report.getArtifactReport(artifact);
    assertNotNull(ar);
    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
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) 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)

Example 22 with DownloadReport

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

the class PackagerResolverTest method testFile.

@Test
public void testFile() throws Exception {
    Locale oldLocale = Locale.getDefault();
    try {
        // set the locale to UK as workaround for SUN bug 6240963
        Locale.setDefault(Locale.UK);
        // Create and configure resolver
        PackagerResolver resolver = new PackagerResolver();
        resolver.setSettings(settings);
        String repoRoot = new File("test/repositories/packager/repo").toURI().toURL().toExternalForm();
        resolver.addIvyPattern(repoRoot + "[organisation]/[module]/[revision]/ivy.xml");
        resolver.setPackagerPattern(repoRoot + "[organisation]/[module]/[revision]/packager.xml");
        resolver.setBuildRoot(builddir);
        resolver.setResourceCache(cachedir);
        resolver.setPreserveBuildDirectories(true);
        resolver.setVerbose(true);
        resolver.setProperty("packager.website.url", new File("test/repositories/packager/website").toURI().toURL().toExternalForm());
        resolver.setName("packager");
        assertEquals("packager", resolver.getName());
        // Get module descriptor
        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", "mod", "1.0");
        ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
        assertNotNull(rmr);
        assertEquals(mrid, rmr.getId());
        Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
        assertEquals(pubdate, rmr.getPublicationDate());
        // Download artifact
        Artifact artifact = new DefaultArtifact(mrid, pubdate, "mod", "jar", "jar");
        DownloadReport report = resolver.download(new Artifact[] { artifact }, downloadOptions());
        assertNotNull(report);
        assertEquals(1, report.getArtifactsReports().length);
        ArtifactDownloadReport ar = report.getArtifactReport(artifact);
        System.out.println("download details: " + ar.getDownloadDetails());
        assertNotNull(ar);
        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
        // Verify resource cache now contains the distribution archive
        assertTrue(new File(cachedir, "mod-1.0.tar.gz").exists());
        // Download again, should use Ivy cache this time
        report = resolver.download(new Artifact[] { artifact }, downloadOptions());
        assertNotNull(report);
        assertEquals(1, report.getArtifactsReports().length);
        ar = report.getArtifactReport(artifact);
        assertNotNull(ar);
        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
        // Now download the maven2 artifact
        artifact = DefaultArtifact.cloneWithAnotherName(artifact, "foobar-janfu");
        report = resolver.download(new Artifact[] { artifact }, downloadOptions());
        assertNotNull(report);
        assertEquals(1, report.getArtifactsReports().length);
        ar = report.getArtifactReport(artifact);
        assertNotNull(ar);
        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    } finally {
        Locale.setDefault(oldLocale);
    }
}
Also used : Locale(java.util.Locale) GregorianCalendar(java.util.GregorianCalendar) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Date(java.util.Date) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) PackagerResolver(org.apache.ivy.plugins.resolver.packager.PackagerResolver) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 23 with DownloadReport

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

the class URLResolverTest method testDownloadWithUseOriginIsTrue.

@Test
public void testDownloadWithUseOriginIsTrue() throws Exception {
    URLResolver resolver = new URLResolver();
    resolver.setSettings(settings);
    String rootpath = new File("test/repositories/1").toURI().toURL().toExternalForm();
    resolver.addIvyPattern(rootpath + "/[organisation]/[module]/ivys/ivy-[revision].xml");
    resolver.addArtifactPattern(rootpath + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
    resolver.setName("test");
    ((DefaultRepositoryCacheManager) resolver.getRepositoryCacheManager()).setUseOrigin(true);
    assertEquals("test", resolver.getName());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());
    // test to ask to download
    DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar");
    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.NO, ar.getDownloadStatus());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) Date(java.util.Date) DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 24 with DownloadReport

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

the class BasicResolver method download.

public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    RepositoryCacheManager cacheManager = getRepositoryCacheManager();
    clearArtifactAttempts();
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        ArtifactDownloadReport adr = cacheManager.download(artifact, artifactResourceResolver, downloader, getCacheDownloadOptions(options));
        if (DownloadStatus.FAILED == adr.getDownloadStatus()) {
            if (!ArtifactDownloadReport.MISSING_ARTIFACT.equals(adr.getDownloadDetails())) {
                Message.warn("\t" + adr);
            }
        } else if (DownloadStatus.NO == adr.getDownloadStatus()) {
            Message.verbose("\t" + adr);
        } else if (LogOptions.LOG_QUIET.equals(options.getLog())) {
            Message.verbose("\t" + adr);
        } else {
            Message.info("\t" + adr);
        }
        dr.addArtifactReport(adr);
        checkInterrupted();
    }
    return dr;
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Artifact(org.apache.ivy.core.module.descriptor.Artifact)

Example 25 with DownloadReport

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

the class AbstractResolver method locate.

/**
 * Default implementation actually download the artifact Subclasses should overwrite this to
 * avoid the download
 *
 * @param artifact ArtifactOrigin
 * @return ArtifactOrigin
 */
public ArtifactOrigin locate(Artifact artifact) {
    DownloadReport dr = download(new Artifact[] { artifact }, new DownloadOptions());
    if (dr == null) {
        /*
             * according to IVY-831, it seems that this actually happen sometime, while the
             * contract of DependencyResolver says that it should never return null
             */
        throw new IllegalStateException("null download report returned by " + getName() + " (" + getClass().getName() + ")" + " when trying to download " + artifact);
    }
    ArtifactDownloadReport adr = dr.getArtifactReport(artifact);
    return adr.getDownloadStatus() == DownloadStatus.FAILED ? null : adr.getArtifactOrigin();
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) CacheDownloadOptions(org.apache.ivy.core.cache.CacheDownloadOptions) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport)

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