Search in sources :

Example 16 with ArtifactDownloadReport

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

the class IBiblioMavenSnapshotsResolutionTest method testSnapshotResolution.

/**
 * Tests that an Ivy module that depends on regular and timestamped snapshots of Maven
 * artifacts, when resolved using a {@link IBiblioResolver} and with
 * {@link MavenTimedSnapshotVersionMatcher} configured in {@link IvySettings}, is resolved
 * correctly for such snapshot dependencies.
 *
 * @throws Exception
 *             if something goes wrong
 */
@Test
public void testSnapshotResolution() throws Exception {
    final IvySettings settings = this.ivy.getSettings();
    assertNotNull("Maven timestamped snapshot revision version matcher is absent", settings.getVersionMatcher(new MavenTimedSnapshotVersionMatcher().getName()));
    final ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setConfs(new String[] { "default" });
    final ResolveReport report = ivy.resolve(new File("test/repositories/2/maven-snapshot-deps-test/ivy-with-maven-snapshot-deps.xml"), resolveOptions);
    assertNotNull("Resolution report was null", report);
    assertFalse("Resolution report has error(s)", report.hasError());
    final ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull("Module descriptor in resolution report was null", md);
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ivy", "maven-snapshot-deps-test", "1.2.3");
    assertEquals("Unexpected module resolved", mrid, md.getModuleRevisionId());
    final ConfigurationResolveReport crr = report.getConfigurationReport("default");
    final ModuleRevisionId exactRevision = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "exact-revision", "2.3.4");
    final ArtifactDownloadReport[] dr1 = crr.getDownloadReports(exactRevision);
    assertNotNull("Artifact download report missing for dependency " + exactRevision, dr1);
    assertEquals("Unexpected number of artifact download report for dependency " + exactRevision, dr1.length, 1);
    final ArtifactDownloadReport exactRevDownloadReport = dr1[0];
    assertEquals("Unexpected download status for dependency " + exactRevision, exactRevDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
    final ModuleRevisionId regularSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "regular-snapshot", "1.2.3-SNAPSHOT");
    final ArtifactDownloadReport[] dr2 = crr.getDownloadReports(regularSnapshot);
    assertNotNull("Artifact download report missing for dependency " + regularSnapshot, dr2);
    assertEquals("Unexpected number of artifact download report for dependency " + regularSnapshot, dr2.length, 1);
    final ArtifactDownloadReport regularSnapshotDownloadReport = dr2[0];
    assertEquals("Unexpected download status for dependency " + regularSnapshot, regularSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
    final ModuleRevisionId timestampedSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "timestamped-snapshot", "5.6.7-20170911.130943-1");
    final ArtifactDownloadReport[] dr3 = crr.getDownloadReports(timestampedSnapshot);
    assertNotNull("Artifact download report missing for dependency " + timestampedSnapshot, dr3);
    assertEquals("Unexpected number of artifact download report for dependency " + timestampedSnapshot, dr3.length, 1);
    final ArtifactDownloadReport timestampedSnapshotDownloadReport = dr3[0];
    assertEquals("Unexpected download status for dependency " + timestampedSnapshot, timestampedSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) MavenTimedSnapshotVersionMatcher(org.apache.ivy.plugins.version.MavenTimedSnapshotVersionMatcher) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) Test(org.junit.Test)

Example 17 with ArtifactDownloadReport

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

the class BintrayResolverTest method testBintrayArtifacts.

@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());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) 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) DefaultIncludeRule(org.apache.ivy.core.module.descriptor.DefaultIncludeRule) 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 18 with ArtifactDownloadReport

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

the class URLResolverTest method testFile.

@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());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) 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) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) Date(java.util.Date) 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 19 with ArtifactDownloadReport

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

the class RetrieveEngine method determineArtifactsToCopy.

public Map<ArtifactDownloadReport, Set<String>> determineArtifactsToCopy(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options) throws ParseException, IOException {
    ModuleId moduleId = mrid.getModuleId();
    if (options.getResolveId() == null) {
        options.setResolveId(ResolveOptions.getDefaultResolveId(moduleId));
    }
    ResolutionCacheManager cacheManager = getCache();
    String[] confs = getConfs(mrid, options);
    String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(), settings.getVariables());
    // find what we must retrieve where
    // ArtifactDownloadReport source -> Set (String copyDestAbsolutePath)
    final Map<ArtifactDownloadReport, Set<String>> artifactsToCopy = new HashMap<>();
    // String copyDestAbsolutePath -> Set (ArtifactRevisionId source)
    final Map<String, Set<ArtifactRevisionId>> conflictsMap = new HashMap<>();
    // String copyDestAbsolutePath -> Set (ArtifactDownloadReport source)
    final Map<String, Set<ArtifactDownloadReport>> conflictsReportsMap = new HashMap<>();
    // String copyDestAbsolutePath -> Set (String conf)
    final Map<String, Set<String>> conflictsConfMap = new HashMap<>();
    XmlReportParser parser = new XmlReportParser();
    for (final String conf : confs) {
        File report = cacheManager.getConfigurationResolveReportInCache(options.getResolveId(), conf);
        parser.parse(report);
        Collection<ArtifactDownloadReport> artifacts = new ArrayList<>(Arrays.asList(parser.getArtifactReports()));
        if (destIvyPattern != null) {
            for (ModuleRevisionId rmrid : parser.getRealDependencyRevisionIds()) {
                artifacts.add(parser.getMetadataArtifactReport(rmrid));
            }
        }
        final PackagingManager packagingManager = new PackagingManager();
        packagingManager.setSettings(IvyContext.getContext().getSettings());
        for (final ArtifactDownloadReport adr : artifacts) {
            final Artifact artifact = adr.getArtifact();
            final String ext;
            if (adr.getUnpackedLocalFile() == null) {
                ext = artifact.getExt();
            } else {
                final Artifact unpackedArtifact;
                // check if the download report is aware of the unpacked artifact
                if (adr.getUnpackedArtifact() != null) {
                    unpackedArtifact = adr.getUnpackedArtifact();
                } else {
                    // use the packaging manager to get hold of the unpacked artifact
                    unpackedArtifact = packagingManager.getUnpackedArtifact(artifact);
                }
                if (unpackedArtifact == null) {
                    throw new RuntimeException("Could not determine unpacked artifact for " + artifact + " while determining artifacts to copy for module " + mrid);
                }
                ext = unpackedArtifact.getExt();
            }
            String destPattern = "ivy".equals(adr.getType()) ? destIvyPattern : destFilePattern;
            if (!"ivy".equals(adr.getType()) && !options.getArtifactFilter().accept(adr.getArtifact())) {
                // skip this artifact, the filter didn't accept it!
                continue;
            }
            ModuleRevisionId aMrid = artifact.getModuleRevisionId();
            String destFileName = IvyPatternHelper.substitute(destPattern, aMrid.getOrganisation(), aMrid.getName(), aMrid.getBranch(), aMrid.getRevision(), artifact.getName(), artifact.getType(), ext, conf, adr.getArtifactOrigin(), aMrid.getQualifiedExtraAttributes(), artifact.getQualifiedExtraAttributes());
            Set<String> dest = artifactsToCopy.get(adr);
            if (dest == null) {
                dest = new HashSet<>();
                artifactsToCopy.put(adr, dest);
            }
            String copyDest = settings.resolveFile(destFileName).getAbsolutePath();
            String[] destinations = new String[] { copyDest };
            if (options.getMapper() != null) {
                destinations = options.getMapper().mapFileName(copyDest);
            }
            for (String destination : destinations) {
                dest.add(destination);
                Set<ArtifactRevisionId> conflicts = conflictsMap.get(destination);
                Set<ArtifactDownloadReport> conflictsReports = conflictsReportsMap.get(destination);
                Set<String> conflictsConf = conflictsConfMap.get(destination);
                if (conflicts == null) {
                    conflicts = new HashSet<>();
                    conflictsMap.put(destination, conflicts);
                }
                if (conflictsReports == null) {
                    conflictsReports = new HashSet<>();
                    conflictsReportsMap.put(destination, conflictsReports);
                }
                if (conflictsConf == null) {
                    conflictsConf = new HashSet<>();
                    conflictsConfMap.put(destination, conflictsConf);
                }
                if (conflicts.add(artifact.getId())) {
                    conflictsReports.add(adr);
                    conflictsConf.add(conf);
                }
            }
        }
    }
    // resolve conflicts if any
    for (Map.Entry<String, Set<ArtifactRevisionId>> entry : conflictsMap.entrySet()) {
        String copyDest = entry.getKey();
        Set<ArtifactRevisionId> artifacts = entry.getValue();
        Set<String> conflictsConfs = conflictsConfMap.get(copyDest);
        if (artifacts.size() > 1) {
            List<ArtifactDownloadReport> artifactsList = new ArrayList<>(conflictsReportsMap.get(copyDest));
            // conflicts battle is resolved by a sort using a conflict resolving policy
            // comparator which consider as greater a winning artifact
            Collections.sort(artifactsList, getConflictResolvingPolicy());
            // after the sort, the winning artifact is the greatest one, i.e. the last one
            // we fail if different artifacts of the same module are mapped to the same file
            ArtifactDownloadReport winner = artifactsList.get(artifactsList.size() - 1);
            ModuleRevisionId winnerMD = winner.getArtifact().getModuleRevisionId();
            for (int i = artifactsList.size() - 2; i >= 0; i--) {
                ArtifactDownloadReport current = artifactsList.get(i);
                if (winnerMD.equals(current.getArtifact().getModuleRevisionId())) {
                    throw new RuntimeException("Multiple artifacts of the module " + winnerMD + " are retrieved to the same file! Update the retrieve pattern " + " to fix this error.");
                }
            }
            Message.info("\tconflict on " + copyDest + " in " + conflictsConfs + ": " + winnerMD.getRevision() + " won");
            // and going backward to the least artifact
            for (int i = artifactsList.size() - 2; i >= 0; i--) {
                ArtifactDownloadReport looser = artifactsList.get(i);
                Message.verbose("\t\tremoving conflict looser artifact: " + looser.getArtifact());
                // for each loser, we remove the pair (loser - copyDest) in the artifactsToCopy
                // map
                Set<String> dest = artifactsToCopy.get(looser);
                dest.remove(copyDest);
                if (dest.isEmpty()) {
                    artifactsToCopy.remove(looser);
                }
            }
        }
    }
    return artifactsToCopy;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ArrayList(java.util.ArrayList) ModuleId(org.apache.ivy.core.module.id.ModuleId) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Artifact(org.apache.ivy.core.module.descriptor.Artifact) XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) PackagingManager(org.apache.ivy.core.pack.PackagingManager) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) ArtifactRevisionId(org.apache.ivy.core.module.id.ArtifactRevisionId)

Example 20 with ArtifactDownloadReport

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

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