Search in sources :

Example 11 with ArtifactDownloadReport

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

the class IvyCacheFileset method doExecute.

public void doExecute() throws BuildException {
    prepareAndCheck();
    if (setid == null) {
        throw new BuildException("setid is required in ivy cachefileset");
    }
    try {
        final List<ArtifactDownloadReport> artifactDownloadReports = getArtifactReports();
        if (artifactDownloadReports.isEmpty()) {
            // generate an empty fileset
            final FileSet emptyFileSet = new EmptyFileSet();
            emptyFileSet.setProject(getProject());
            getProject().addReference(setid, emptyFileSet);
            return;
        }
        // find a common base dir of the resolved artifacts
        final File baseDir = this.requireCommonBaseDir(artifactDownloadReports);
        final FileSet fileset = new FileSet();
        fileset.setDir(baseDir);
        fileset.setProject(getProject());
        // enroll each of the artifact files into the fileset
        for (final ArtifactDownloadReport artifactDownloadReport : artifactDownloadReports) {
            if (artifactDownloadReport.getLocalFile() == null) {
                continue;
            }
            final NameEntry ne = fileset.createInclude();
            ne.setName(getPath(baseDir, artifactDownloadReport.getLocalFile()));
        }
        getProject().addReference(setid, fileset);
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy cache fileset: " + ex, ex);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) BuildException(org.apache.tools.ant.BuildException) NameEntry(org.apache.tools.ant.types.PatternSet.NameEntry) File(java.io.File) BuildException(org.apache.tools.ant.BuildException) NoSuchElementException(java.util.NoSuchElementException)

Example 12 with ArtifactDownloadReport

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

the class IvyCachePath method doExecute.

public void doExecute() throws BuildException {
    prepareAndCheck();
    if (pathid == null) {
        if (id == null) {
            throw new BuildException("pathid is required in ivy classpath");
        }
        pathid = id;
        log("ID IS DEPRECATED, PLEASE USE PATHID INSTEAD", Project.MSG_WARN);
    }
    try {
        Path path = new Path(getProject());
        getProject().addReference(pathid, path);
        for (ArtifactDownloadReport adr : getArtifactReports()) {
            File f = adr.getLocalFile();
            if (adr.getUnpackedLocalFile() != null) {
                f = adr.getUnpackedLocalFile();
            }
            addToPath(path, f);
        }
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy path: " + ex, ex);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

Example 13 with ArtifactDownloadReport

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

the class UpdateSiteLoader method loadFromSite.

private UpdateSiteDescriptor loadFromSite(UpdateSite site) throws IOException, SAXException {
    UpdateSiteDescriptor repoDescriptor = new UpdateSiteDescriptor(site.getUri(), ExecutionEnvironmentProfileProvider.getInstance());
    for (EclipseFeature feature : site.getFeatures()) {
        URL url = site.getUri().resolve(feature.getUrl()).toURL();
        final URLResource res = new URLResource(url, this.timeoutConstraint);
        ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, feature.getId(), "feature", "jar", options, urlRepository);
        if (report.getDownloadStatus() == DownloadStatus.FAILED) {
            return null;
        }
        try (InputStream in = new FileInputStream(report.getLocalFile())) {
            ZipInputStream zipped = findEntry(in, "feature.xml");
            if (zipped == null) {
                return null;
            }
            EclipseFeature f = FeatureParser.parse(zipped);
            f.setURL(feature.getUrl());
            repoDescriptor.addFeature(f);
        }
    }
    return repoDescriptor;
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) EclipseFeature(org.apache.ivy.osgi.updatesite.xml.EclipseFeature) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 14 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport 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 15 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport 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)

Aggregations

ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)64 File (java.io.File)33 Artifact (org.apache.ivy.core.module.descriptor.Artifact)29 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)26 Test (org.junit.Test)25 DownloadReport (org.apache.ivy.core.report.DownloadReport)23 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)18 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)17 ResolveReport (org.apache.ivy.core.report.ResolveReport)15 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)11 IOException (java.io.IOException)10 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)10 URL (java.net.URL)8 JarFile (java.util.jar.JarFile)8 Date (java.util.Date)7 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)7 URLResource (org.apache.ivy.plugins.repository.url.URLResource)7 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)6 MalformedURLException (java.net.MalformedURLException)5