org.apache.ivy.core.resolve.DownloadOptions Java Examples

The following examples show how to use org.apache.ivy.core.resolve.DownloadOptions. 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: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Override
public ArtifactDownloadReport download(final ArtifactOrigin origin, DownloadOptions options) {
    Checks.checkNotNull(origin, "origin");
    return getRepositoryCacheManager().download(origin.getArtifact(),
        new ArtifactResourceResolver() {
            public ResolvedResource resolve(Artifact artifact) {
                try {
                    Resource resource = getResource(origin.getLocation());
                    if (resource != null) {
                        String revision = origin.getArtifact().getModuleRevisionId().getRevision();
                        return new ResolvedResource(resource, revision);
                    }
                } catch (IOException e) {
                    Message.debug(e);
                }
                return null;
            }
        }, downloader, getCacheDownloadOptions(options));
}
 
Example #2
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: CacheResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
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 #5
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 #6
Source File: DualResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    if (artifact.getArtifact().isMetadata()) {
        return ivyResolver.download(artifact, options);
    } else {
        return artifactResolver.download(artifact, options);
    }
}
 
Example #7
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    EventManager eventManager = getEventManager();
    try {
        if (eventManager != null) {
            repository.addTransferListener(eventManager);
        }
        return super.download(artifacts, options);
    } finally {
        if (eventManager != null) {
            repository.removeTransferListener(eventManager);
        }
    }
}
 
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
Source File: ChainResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDownloadWithDual() {
    ChainResolver chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);
    chain.setDual(true);

    // first resolver has only an artifact pattern which don't lead to anything: it won't find
    // the module
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("1");
    resolver.setSettings(settings);
    resolver.addArtifactPattern(settings.getBaseDir()
            + "/test/repositories/nowhere/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");

    chain.add(resolver);

    resolver = new FileSystemResolver();
    resolver.setName("2");
    resolver.setSettings(settings);

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

    settings.addResolver(chain);

    MockMessageLogger mockLogger = new MockMessageLogger();
    IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockLogger);
    DownloadReport report = chain.download(
        new Artifact[] {new DefaultArtifact(ModuleRevisionId.parse("org1#mod1.1;1.0"),
                new Date(), "mod1.1", "jar", "jar")}, new DownloadOptions());
    assertNotNull(report);
    assertEquals(1, report.getArtifactsReports().length);
    assertEquals(DownloadStatus.SUCCESSFUL, report.getArtifactsReports()[0].getDownloadStatus());
    mockLogger.assertLogDoesntContain("[FAILED     ] org1#mod1.1;1.0!mod1.1.jar");
}
 
Example #14
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 #15
Source File: MockResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        dr.addArtifactReport(new ArtifactDownloadReport(artifact));
    }
    return dr;
}
 
Example #16
Source File: AbstractMavenResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    throw new UnsupportedOperationException("A Maven deployer cannot be used to resolve dependencies. It can only be used to publish artifacts.");
}
 
Example #17
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 #18
Source File: AbstractDependencyResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
protected DownloadOptions downloadOptions() {
    return new DownloadOptions();
}
 
Example #19
Source File: IBiblioResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    ensureConfigured(getSettings());
    return super.download(artifacts, options);
}
 
Example #20
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private DownloadOptions getDownloadOptions() {
    return new DownloadOptions();
}
 
Example #21
Source File: AbstractResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
protected DownloadOptions getDownloadOptions(ResolveOptions options) {
    return (DownloadOptions) new DownloadOptions().setLog(options.getLog());
}
 
Example #22
Source File: LoopbackDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: AbstractMavenResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    throw new UnsupportedOperationException("A Maven deployer cannot be used to resolve dependencies. It can only be used to publish artifacts.");
}
 
Example #24
Source File: LoopbackDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    throw new UnsupportedOperationException();
}
 
Example #25
Source File: LoopbackDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    throw new UnsupportedOperationException();
}
 
Example #26
Source File: LegacyDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    // This is never used
    throw new UnsupportedOperationException();
}
 
Example #27
Source File: LegacyDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin origin, DownloadOptions options) {
    // This is never used
    throw new UnsupportedOperationException();
}
 
Example #28
Source File: AbstractMavenResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    throw new UnsupportedOperationException("A Maven deployer cannot be used to resolve dependencies. It can only be used to publish artifacts.");
}
 
Example #29
Source File: AbstractMavenResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    throw new UnsupportedOperationException("A Maven deployer cannot be used to resolve dependencies. It can only be used to publish artifacts.");
}
 
Example #30
Source File: LoopbackDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    throw new UnsupportedOperationException();
}