Java Code Examples for org.apache.ivy.core.report.DownloadReport#getArtifactReport()

The following examples show how to use org.apache.ivy.core.report.DownloadReport#getArtifactReport() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregatedOSGiResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 2
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDownloadWithUseOriginIsTrue() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    ((DefaultRepositoryCacheManager) resolver.getRepositoryCacheManager()).setUseOrigin(true);
    assertEquals("test", resolver.getName());

    resolver.addIvyPattern(IVY_PATTERN);
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/"
            + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");

    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}, getDownloadOptions());
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
 
Example 3
Source File: BintrayResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 4
Source File: URLResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 5
Source File: OBRResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 6
Source File: UpdateSiteResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 7
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 8
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
        }
    }
}
 
Example 9
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 10
Source File: AbstractResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 11
Source File: IvyRepResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Test
public void testIvyRepWithLocalURL() throws Exception {
    IvyRepResolver resolver = new IvyRepResolver();
    String rootpath = new File("test/repositories/1").getAbsolutePath();

    resolver.setName("testLocal");
    resolver.setIvyroot("file:" + rootpath);
    resolver.setIvypattern("[organisation]/[module]/ivys/ivy-[revision].xml");
    resolver.setArtroot("file:" + rootpath);
    resolver.setArtpattern("[organisation]/[module]/jars/[artifact]-[revision].[ext]");
    resolver.setSettings(settings);

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
            false), data);
    assertNotNull(rmr);

    DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "mod1.1",
            "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());
}
 
Example 12
Source File: URLResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Test
public void testFile() 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");
    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}, 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());
}
 
Example 13
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Test
public void testResolveSource() throws Exception {
    settings.setDefaultResolver("p2-sources");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE,
        "org.apache.ivy", "2.2.0.final_20100923230623");

    ResolvedModuleRevision rmr = p2SourceResolver.getDependency(
        new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);

    DownloadReport report = p2SourceResolver.download(rmr.getDescriptor().getAllArtifacts(),
        new DownloadOptions());
    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());

        // test to ask to download again, should use cache
        DownloadReport report2 = p2SourceResolver.download(new Artifact[] {artifact},
            new DownloadOptions());
        assertNotNull(report2);

        assertEquals(1, report2.getArtifactsReports().length);

        ar = report2.getArtifactReport(artifact);
        assertNotNull(ar);

        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
    }
}
 
Example 14
Source File: BintrayResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 15
Source File: PackagerResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@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);
    }
}
 
Example 16
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Test
public void testFixedRevision() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());

    resolver.addIvyPattern(IVY_PATTERN);
    resolver.addArtifactPattern(settings.getBaseDir()
            + "/test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");

    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}, getDownloadOptions());
    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}, getDownloadOptions());
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
 
Example 17
Source File: ResolveEngine.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: AbstractResolver.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * Default implementation downloads the artifact without taking advantage of its location
 *
 * @param artifact ArtifactOrigin
 * @param options DownloadOptions
 * @return ArtifactDownloadReport
 */
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    DownloadReport r = download(new Artifact[] {artifact.getArtifact()}, options);
    return r.getArtifactReport(artifact.getArtifact());
}