Search in sources :

Example 1 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin 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 ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class ResolveTest method testArtifactOrigin.

@Test
public void testArtifactOrigin() throws Exception {
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "default" }));
    assertNotNull(report);
    ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
    assertNotNull(dReports);
    assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
    Artifact artifact = dReports[0].getArtifact();
    assertNotNull(artifact);
    String expectedLocation = new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath();
    // verify the origin in the report
    ArtifactOrigin reportOrigin = dReports[0].getArtifactOrigin();
    assertNotNull(reportOrigin);
    assertTrue("isLocal for artifact not correct", reportOrigin.isLocal());
    assertEquals("location for artifact not correct", expectedLocation, reportOrigin.getLocation());
    // verify the saved origin on disk
    ArtifactOrigin ivyOrigin = getSavedArtifactOrigin(artifact);
    assertNotNull(ivyOrigin);
    assertTrue("isLocal for artifact not correct", ivyOrigin.isLocal());
    assertEquals("location for artifact not correct", expectedLocation, ivyOrigin.getLocation());
    // now resolve the same artifact again and verify the origin of the (not-downloaded)
    // artifact
    report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "default" }));
    assertNotNull(report);
    dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
    assertNotNull(dReports);
    assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
    assertEquals("download status not correct", DownloadStatus.NO, dReports[0].getDownloadStatus());
    reportOrigin = dReports[0].getArtifactOrigin();
    assertNotNull(reportOrigin);
    assertTrue("isLocal for artifact not correct", reportOrigin.isLocal());
    assertEquals("location for artifact not correct", expectedLocation, reportOrigin.getLocation());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 3 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class ResolveEngineTest method testLocateThenDownload.

private void testLocateThenDownload(ResolveEngine engine, Artifact artifact, File artifactFile) {
    ArtifactOrigin origin = engine.locate(artifact);
    assertNotNull(origin);
    assertTrue(origin.isLocal());
    assertEquals(artifactFile.getAbsolutePath(), new File(origin.getLocation()).getAbsolutePath());
    ArtifactDownloadReport r = engine.download(origin, new DownloadOptions());
    assertNotNull(r);
    assertEquals(DownloadStatus.SUCCESSFUL, r.getDownloadStatus());
    assertNotNull(r.getLocalFile());
    assertTrue(r.getLocalFile().exists());
}
Also used : ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) File(java.io.File)

Example 4 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class ResolveTest method testUseOrigin.

@Test
public void testUseOrigin() throws Exception {
    ((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).setUseOrigin(true);
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "default" }));
    assertNotNull(report);
    ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
    assertNotNull(dReports);
    assertEquals("number of downloaded artifacts not correct.", 1, dReports.length);
    assertEquals("download status not correct: should not download the artifact in useOrigin mode.", DownloadStatus.NO, dReports[0].getDownloadStatus());
    Artifact artifact = dReports[0].getArtifact();
    assertNotNull(artifact);
    String expectedLocation = new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath();
    ArtifactOrigin origin = getSavedArtifactOrigin(artifact);
    File artInCache = new File(cache, getArchivePathInCache(artifact, origin));
    assertFalse("should not download artifact in useOrigin mode.", artInCache.exists());
    assertEquals("location for artifact not correct.", expectedLocation, getArchiveFileInCache(artifact).getAbsolutePath());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 5 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class UpdateSiteResolver method init.

protected void init() {
    if (url == null) {
        throw new RuntimeException("Missing url");
    }
    CacheResourceOptions options = new CacheResourceOptions();
    if (metadataTtl != null) {
        options.setTtl(metadataTtl);
    }
    if (forceMetadataUpdate != null) {
        options.setForce(forceMetadataUpdate);
    }
    final int log;
    if (logLevel != null) {
        if ("debug".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_DEBUG;
        } else if ("verbose".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_VERBOSE;
        } else if ("info".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_INFO;
        } else if ("warn".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_WARN;
        } else if ("error".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_ERR;
        } else {
            throw new RuntimeException("Unknown log level: " + logLevel);
        }
    } else {
        log = Message.MSG_INFO;
    }
    options.setListener(new DownloadListener() {

        public void startArtifactDownload(RepositoryCacheManager cache, ResolvedResource rres, Artifact artifact, ArtifactOrigin origin) {
            if (log <= Message.MSG_INFO) {
                Message.info("\tdownloading " + rres.getResource().getName());
            }
        }

        public void needArtifact(RepositoryCacheManager cache, Artifact artifact) {
            if (log <= Message.MSG_VERBOSE) {
                Message.verbose("\ttrying to download " + artifact);
            }
        }

        public void endArtifactDownload(RepositoryCacheManager cache, Artifact artifact, ArtifactDownloadReport adr, File archiveFile) {
            if (log <= Message.MSG_VERBOSE) {
                if (adr.isDownloaded()) {
                    Message.verbose("\tdownloaded to " + archiveFile.getAbsolutePath());
                } else {
                    Message.verbose("\tnothing to download");
                }
            }
        }
    });
    final UpdateSiteLoader loader = new UpdateSiteLoader(getRepositoryCacheManager(), getEventManager(), options, this.getTimeoutConstraint());
    loader.setLogLevel(log);
    RepoDescriptor repoDescriptor;
    try {
        repoDescriptor = loader.load(new URI(url));
    } catch (IOException e) {
        throw new RuntimeException("IO issue while trying to read the update site (" + e.getMessage() + ")");
    } catch (ParseException e) {
        throw new RuntimeException("Failed to parse the updatesite (" + e.getMessage() + ")", e);
    } catch (SAXException e) {
        throw new RuntimeException("Ill-formed updatesite (" + e.getMessage() + ")", e);
    } catch (URISyntaxException e) {
        throw new RuntimeException("Ill-formed url (" + e.getMessage() + ")", e);
    }
    if (repoDescriptor == null) {
        setRepoDescriptor(FAILING_REPO_DESCRIPTOR);
        throw new RuntimeException("No update site was found at the location: " + url);
    }
    setRepoDescriptor(repoDescriptor);
}
Also used : RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) URI(java.net.URI) Artifact(org.apache.ivy.core.module.descriptor.Artifact) SAXException(org.xml.sax.SAXException) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) DownloadListener(org.apache.ivy.core.cache.DownloadListener) RepoDescriptor(org.apache.ivy.osgi.repo.RepoDescriptor) CacheResourceOptions(org.apache.ivy.core.cache.CacheResourceOptions) ParseException(java.text.ParseException) File(java.io.File)

Aggregations

ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)11 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)6 File (java.io.File)5 Artifact (org.apache.ivy.core.module.descriptor.Artifact)4 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)3 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)3 JarFile (java.util.jar.JarFile)2 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)2 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)2 ResolveReport (org.apache.ivy.core.report.ResolveReport)2 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 CacheResourceOptions (org.apache.ivy.core.cache.CacheResourceOptions)1 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)1 DownloadListener (org.apache.ivy.core.cache.DownloadListener)1