Search in sources :

Example 1 with ConfigurationResolveReport

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

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

the class ResolveEngine method findModule.

public ResolvedModuleRevision findModule(ModuleRevisionId id, ResolveOptions options) {
    DependencyResolver r = settings.getResolver(id);
    if (r == null) {
        throw new IllegalStateException("no resolver found for " + id.getModuleId());
    }
    DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(id, new String[] { "*" }, false, false);
    if (options.getResolveId() == null) {
        options.setResolveId(ResolveOptions.getDefaultResolveId(md));
    }
    try {
        return r.getDependency(new DefaultDependencyDescriptor(id, true), new ResolveData(this, options, new ConfigurationResolveReport(this, md, "default", null, options)));
    } catch (ParseException e) {
        throw new RuntimeException("problem while parsing repository module descriptor for " + id + ": " + e, e);
    }
}
Also used : DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ParseException(java.text.ParseException) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 3 with ConfigurationResolveReport

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

the class ResolveEngine method getDependencies.

/**
 * Resolve the dependencies of a module without downloading corresponding artifacts. The module
 * to resolve is given by its module descriptor. This method requires appropriate configuration
 * of the ivy instance, especially resolvers.
 * <p>
 * The <code>IvyNode</code>s are ordered from the most dependent to the less dependent, so that
 * an IvyNode is always found in the list after all IvyNode depending directly on it.
 *
 * @param md
 *            the descriptor of the module for which we want to get dependencies - must not be
 *            null
 * @param options
 *            the resolve options to use to resolve the dependencies
 * @param report
 *            a resolve report to fill during resolution - may be null
 * @return an array of the resolved Dependencies
 */
public IvyNode[] getDependencies(ModuleDescriptor md, ResolveOptions options, ResolveReport report) {
    // check parameters
    if (md == null) {
        throw new NullPointerException("module descriptor must not be null");
    }
    String[] confs = options.getConfs(md);
    Collection<String> missingConfs = new ArrayList<>();
    for (String conf : confs) {
        if (conf == null) {
            throw new NullPointerException("null conf not allowed: confs where: " + Arrays.asList(confs));
        }
        if (md.getConfiguration(conf) == null) {
            missingConfs.add(" '" + conf + "' ");
        }
    }
    if (!missingConfs.isEmpty()) {
        throw new IllegalArgumentException("requested configuration" + (missingConfs.size() > 1 ? "s" : "") + " not found in " + md.getModuleRevisionId() + ": " + missingConfs);
    }
    IvyContext context = IvyContext.pushNewCopyContext();
    try {
        options.setConfs(confs);
        Date reportDate = new Date();
        ResolveData data = context.getResolveData();
        if (data == null) {
            data = new ResolveData(this, options);
            context.setResolveData(data);
        }
        IvyNode rootNode = new IvyNode(data, md);
        for (String conf : confs) {
            Message.verbose("resolving dependencies for configuration '" + conf + "'");
            // for each configuration we clear the cache of what's been fetched
            fetchedSet.clear();
            ConfigurationResolveReport confReport = null;
            if (report != null) {
                confReport = report.getConfigurationReport(conf);
                if (confReport == null) {
                    confReport = new ConfigurationResolveReport(this, md, conf, reportDate, options);
                    report.addReport(conf, confReport);
                }
            }
            // we reuse the same resolve data with a new report for each conf
            data.setReport(confReport);
            // update the root module conf we are about to fetch
            VisitNode root = new VisitNode(data, rootNode, null, conf, null);
            root.setRequestedConf(conf);
            rootNode.updateConfsToFetch(Collections.singleton(conf));
            // go fetch !
            boolean fetched = false;
            while (!fetched) {
                try {
                    fetchDependencies(root, conf, false);
                    fetched = true;
                } catch (RestartResolveProcess restart) {
                    Message.verbose("====================================================");
                    Message.verbose("=           RESTARTING RESOLVE PROCESS");
                    Message.verbose("= " + restart.getMessage());
                    Message.verbose("====================================================");
                    fetchedSet.clear();
                }
            }
            // clean data
            for (IvyNode dep : data.getNodes()) {
                dep.clean();
            }
        }
        // prune and reverse sort fetched dependencies
        Collection<IvyNode> nodes = data.getNodes();
        // use a Set to avoid duplicates, linked to preserve order
        Collection<IvyNode> dependencies = new LinkedHashSet<>(nodes.size());
        for (IvyNode node : nodes) {
            if (node != null && !node.isRoot() && !node.isCompletelyBlacklisted()) {
                dependencies.add(node);
            }
        }
        List<IvyNode> sortedDependencies = sortEngine.sortNodes(dependencies, SortOptions.SILENT);
        Collections.reverse(sortedDependencies);
        handleTransitiveEviction(md, confs, data, sortedDependencies);
        return dependencies.toArray(new IvyNode[dependencies.size()]);
    } finally {
        IvyContext.popContext();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Date(java.util.Date) IvyContext(org.apache.ivy.core.IvyContext) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport)

Example 4 with ConfigurationResolveReport

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

the class ResolveTest method testResolveConflict.

@Test
public void testResolveConflict() throws Exception {
    // mod4.1 v 4.1 depends on
    // - mod1.1 v 1.0 which depends on mod1.2 v 2.0
    // - mod3.1 v 1.1 which depends on mod1.2 v 2.1
    ResolveReport report = ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.1.xml"), getResolveOptions(new String[] { "*" }));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.1");
    assertEquals(mrid, md.getModuleRevisionId());
    assertTrue(getResolvedIvyFileInCache(mrid).exists());
    // dependencies
    ConfigurationResolveReport crr = report.getConfigurationReport("default");
    assertNotNull(crr);
    assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).length);
    assertEquals(1, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).length);
    File r = getConfigurationResolveReportInCache(ResolveOptions.getDefaultResolveId(md), "default");
    assertTrue(r.exists());
    final boolean[] found = new boolean[] { false };
    SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
    saxParser.parse(r, new DefaultHandler() {

        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes) {
            if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) {
                found[0] = true;
            }
        }
    });
    // the report should contain the evicted revision
    assertTrue(found[0]);
    assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
    assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
    assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists());
    assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists());
    assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
    assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
    assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) Attributes(org.xml.sax.Attributes) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) SAXParser(javax.xml.parsers.SAXParser) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) JarFile(java.util.jar.JarFile) File(java.io.File) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Test(org.junit.Test)

Example 5 with ConfigurationResolveReport

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

the class ResolveTest method testResolveSeveralDefaultWithArtifactsAndConfs2.

/**
 * Second test case for IVY-283.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-283">IVY-283</a>
 */
@Test
public void testResolveSeveralDefaultWithArtifactsAndConfs2() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/IVY-283/ivysettings.xml"));
    ResolveReport report = ivy.resolve(new File("test/repositories/IVY-283/ivy-d.xml"), getResolveOptions(new String[] { "*" }));
    assertFalse(report.hasError());
    // dependencies
    ConfigurationResolveReport crr = report.getConfigurationReport("build");
    assertNotNull(crr);
    assertEquals(9, crr.getDownloadReports(ModuleRevisionId.newInstance("medicel", "module_a", "local")).length);
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_a", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_b", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_c", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_d", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_e", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_f", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_g", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_h", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_i", "jar", "jar").exists());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Aggregations

ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)45 ResolveReport (org.apache.ivy.core.report.ResolveReport)43 File (java.io.File)40 Test (org.junit.Test)40 JarFile (java.util.jar.JarFile)34 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)27 Ivy (org.apache.ivy.Ivy)16 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)12 SAXParser (javax.xml.parsers.SAXParser)4 Attributes (org.xml.sax.Attributes)4 DefaultHandler (org.xml.sax.helpers.DefaultHandler)4 HashMap (java.util.HashMap)3 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 IvyContext (org.apache.ivy.core.IvyContext)1 ResolutionCacheManager (org.apache.ivy.core.cache.ResolutionCacheManager)1 EndResolveEvent (org.apache.ivy.core.event.resolve.EndResolveEvent)1