Search in sources :

Example 1 with ConflictManager

use of org.apache.ivy.plugins.conflict.ConflictManager in project ant-ivy by apache.

the class BasicResolver method findResource.

/**
 * When the resolver has many choices, this function helps choosing one
 *
 * @param rress
 *            the list of resolved resource which the resolver found to fit the requirement
 * @param rmdparser
 *            the parser of module descriptor
 * @param mrid
 *            the module being resolved
 * @param date
 *            the current date
 * @return the selected resource
 */
public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser, ModuleRevisionId mrid, Date date) {
    String name = getName();
    VersionMatcher versionMatcher = getSettings().getVersionMatcher();
    ResolvedResource found = null;
    List<ArtifactInfo> sorted = getLatestStrategy().sort(rress);
    List<String> rejected = new ArrayList<>();
    List<ModuleRevisionId> foundBlacklisted = new ArrayList<>();
    IvyContext context = IvyContext.getContext();
    ListIterator<ArtifactInfo> iter = sorted.listIterator(sorted.size());
    while (iter.hasPrevious()) {
        ResolvedResource rres = (ResolvedResource) iter.previous();
        // name, blacklisting and first level version matching
        if (filterNames(new ArrayList<>(Collections.singleton(rres.getRevision()))).isEmpty()) {
            Message.debug("\t" + name + ": filtered by name: " + rres);
            continue;
        }
        ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision());
        ResolveData data = context.getResolveData();
        if (data != null && data.getReport() != null && data.isBlacklisted(data.getReport().getConfiguration(), foundMrid)) {
            Message.debug("\t" + name + ": blacklisted: " + rres);
            rejected.add(rres.getRevision() + " (blacklisted)");
            foundBlacklisted.add(foundMrid);
            continue;
        }
        if (!versionMatcher.accept(mrid, foundMrid)) {
            Message.debug("\t" + name + ": rejected by version matcher: " + rres);
            rejected.add(rres.getRevision());
            continue;
        }
        if (rres.getResource() != null && !rres.getResource().exists()) {
            Message.debug("\t" + name + ": unreachable: " + rres + "; res=" + rres.getResource());
            rejected.add(rres.getRevision() + " (unreachable)");
            continue;
        }
        if (date != null && rres.getLastModified() > date.getTime()) {
            Message.verbose("\t" + name + ": too young: " + rres);
            rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")");
            continue;
        }
        if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) {
            ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision());
            if (r == null) {
                Message.debug("\t" + name + ": impossible to get module descriptor resource: " + rres);
                rejected.add(rres.getRevision() + " (no or bad MD)");
                continue;
            }
            ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision().getDescriptor();
            if (md.isDefault()) {
                Message.debug("\t" + name + ": default md rejected by version matcher" + "requiring module descriptor: " + rres);
                rejected.add(rres.getRevision() + " (MD)");
                continue;
            }
            if (!versionMatcher.accept(mrid, md)) {
                Message.debug("\t" + name + ": md rejected by version matcher: " + rres);
                rejected.add(rres.getRevision() + " (MD)");
                continue;
            }
            found = r;
        } else {
            found = rres;
        }
        if (found != null) {
            break;
        }
    }
    if (found == null && !rejected.isEmpty()) {
        logAttempt(rejected.toString());
    }
    if (found == null && !foundBlacklisted.isEmpty()) {
        // all acceptable versions have been blacklisted, this means that an unsolvable conflict
        // has been found
        DependencyDescriptor dd = context.getDependencyDescriptor();
        IvyNode parentNode = context.getResolveData().getNode(dd.getParentRevisionId());
        ConflictManager cm = parentNode.getConflictManager(mrid.getModuleId());
        cm.handleAllBlacklistedRevisions(dd, foundBlacklisted);
    }
    return found;
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ArrayList(java.util.ArrayList) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) ArtifactInfo(org.apache.ivy.plugins.latest.ArtifactInfo) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) IvyContext(org.apache.ivy.core.IvyContext) ConflictManager(org.apache.ivy.plugins.conflict.ConflictManager) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 2 with ConflictManager

use of org.apache.ivy.plugins.conflict.ConflictManager in project ant-ivy by apache.

the class XmlSettingsParser method endDocument.

@Override
public void endDocument() throws SAXException {
    if (defaultResolver != null) {
        ivy.setDefaultResolver(ivy.substitute(defaultResolver));
    }
    if (defaultCM != null) {
        ConflictManager conflictManager = ivy.getConflictManager(ivy.substitute(defaultCM));
        if (conflictManager == null) {
            throw new IllegalArgumentException("unknown conflict manager " + ivy.substitute(defaultCM));
        }
        ivy.setDefaultConflictManager(conflictManager);
    }
    if (defaultLatest != null) {
        LatestStrategy latestStrategy = ivy.getLatestStrategy(ivy.substitute(defaultLatest));
        if (latestStrategy == null) {
            throw new IllegalArgumentException("unknown latest strategy " + ivy.substitute(defaultLatest));
        }
        ivy.setDefaultLatestStrategy(latestStrategy);
    }
    if (defaultCacheManager != null) {
        RepositoryCacheManager cache = ivy.getRepositoryCacheManager(ivy.substitute(defaultCacheManager));
        if (cache == null) {
            throw new IllegalArgumentException("unknown cache manager " + ivy.substitute(defaultCacheManager));
        }
        ivy.setDefaultRepositoryCacheManager(cache);
    }
    if (defaultCircular != null) {
        CircularDependencyStrategy strategy = ivy.getCircularDependencyStrategy(ivy.substitute(defaultCircular));
        if (strategy == null) {
            throw new IllegalArgumentException("unknown circular dependency strategy " + ivy.substitute(defaultCircular));
        }
        ivy.setCircularDependencyStrategy(strategy);
    }
    if (defaultLock != null) {
        LockStrategy strategy = ivy.getLockStrategy(ivy.substitute(defaultLock));
        if (strategy == null) {
            throw new IllegalArgumentException("unknown lock strategy " + ivy.substitute(defaultLock));
        }
        ivy.setDefaultLockStrategy(strategy);
    }
}
Also used : CircularDependencyStrategy(org.apache.ivy.plugins.circular.CircularDependencyStrategy) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) ConflictManager(org.apache.ivy.plugins.conflict.ConflictManager) LockStrategy(org.apache.ivy.plugins.lock.LockStrategy)

Example 3 with ConflictManager

use of org.apache.ivy.plugins.conflict.ConflictManager in project ant-ivy by apache.

the class ResolveEngine method resolveConflict.

/**
 * Resolves conflict for the given node in the given ancestor. This method do conflict
 * resolution in ancestor parents recursively, unless not necessary.
 *
 * @param node
 *            the node for which conflict resolution should be done
 * @param ancestor
 *            the ancestor in which the conflict resolution should be done
 * @param conf String
 * @param toevict
 *            a collection of IvyNode to evict (as computed by conflict resolution in
 *            descendants of ancestor)
 * @return true if conflict resolution has been done, false it can't be done yet
 */
private boolean resolveConflict(VisitNode node, VisitNode ancestor, String conf, Collection<IvyNode> toevict) {
    if (ancestor == null || node == ancestor) {
        return true;
    }
    // check if job is not already done
    if (checkConflictSolvedEvicted(node, ancestor)) {
        // job is done and node is evicted, nothing to do
        return true;
    }
    boolean debugConflictResolution = settings.debugConflictResolution();
    if (checkConflictSolvedSelected(node, ancestor)) {
        // before
        if (resolveConflict(node, ancestor.getParent(), conf, toevict)) {
            // now that conflict resolution is ok in ancestors
            // we just have to check if the node wasn't previously evicted in root ancestor
            EvictionData evictionData = node.getEvictionDataInRoot(node.getRootModuleConf(), ancestor);
            if (evictionData != null) {
                // node has been previously evicted in an ancestor: we mark it as evicted
                if (debugConflictResolution) {
                    Message.debug(node + " was previously evicted in root module conf " + node.getRootModuleConf());
                }
                node.markEvicted(evictionData);
                if (debugConflictResolution) {
                    Message.debug("evicting " + node + " by " + evictionData);
                }
            }
            return true;
        } else {
            return false;
        }
    }
    // compute conflicts
    Set<IvyNode> resolvedNodes = ancestor.getNode().getResolvedNodes(node.getModuleId(), node.getRootModuleConf());
    resolvedNodes.addAll(ancestor.getNode().getPendingConflicts(node.getRootModuleConf(), node.getModuleId()));
    Collection<IvyNode> conflicts = computeConflicts(node, ancestor, conf, toevict, resolvedNodes);
    ConflictManager conflictManager = null;
    for (VisitNode current : ancestor.getPath()) {
        ModuleDescriptor descriptor = current.getNode().getDescriptor();
        if (descriptor == null) {
            throw new IllegalStateException("impossible to get conflict manager when data has not been loaded. IvyNode = " + current.getNode());
        }
        conflictManager = descriptor.getConflictManager(node.getModuleId());
        if (conflictManager != null) {
            break;
        }
    }
    if (conflictManager == null) {
        conflictManager = settings.getConflictManager(node.getModuleId());
    }
    Collection<IvyNode> resolved = resolveConflicts(node, ancestor, conflicts, conflictManager);
    if (resolved == null) {
        if (debugConflictResolution) {
            Message.debug("impossible to resolve conflicts for " + node + " in " + ancestor + " yet");
            Message.debug("setting all nodes as pending conflicts for later conflict" + " resolution: " + conflicts);
        }
        ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), conflicts);
        return false;
    }
    if (debugConflictResolution) {
        Message.debug("selected revisions for " + node + " in " + ancestor + ": " + resolved);
    }
    if (resolved.contains(node.getNode())) {
        // node has been selected for the current parent
        // handle previously selected nodes that are now evicted by this new node
        toevict = resolvedNodes;
        toevict.removeAll(resolved);
        for (IvyNode te : toevict) {
            te.markEvicted(node.getRootModuleConf(), ancestor.getNode(), conflictManager, resolved);
            if (debugConflictResolution) {
                Message.debug("evicting " + te + " by " + te.getEvictedData(node.getRootModuleConf()));
            }
        }
        // it's very important to update resolved and evicted nodes BEFORE recompute parent call
        // to allow it to recompute its resolved collection with correct data
        // if necessary
        ancestor.getNode().setResolvedNodes(node.getModuleId(), node.getRootModuleConf(), resolved);
        Collection<IvyNode> evicted = new HashSet<>(ancestor.getNode().getEvictedNodes(node.getModuleId(), node.getRootModuleConf()));
        evicted.removeAll(resolved);
        evicted.addAll(toevict);
        ancestor.getNode().setEvictedNodes(node.getModuleId(), node.getRootModuleConf(), evicted);
        ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), Collections.<IvyNode>emptySet());
        return resolveConflict(node, ancestor.getParent(), conf, toevict);
    } else {
        // node has been evicted for the current parent
        if (resolved.isEmpty()) {
            if (debugConflictResolution) {
                Message.verbose("conflict manager '" + conflictManager + "' evicted all revisions among " + conflicts);
            }
        }
        // it's time to update parent resolved and evicted with what was found
        Collection<IvyNode> evicted = new HashSet<>(ancestor.getNode().getEvictedNodes(node.getModuleId(), node.getRootModuleConf()));
        toevict.removeAll(resolved);
        evicted.removeAll(resolved);
        evicted.addAll(toevict);
        evicted.add(node.getNode());
        ancestor.getNode().setEvictedNodes(node.getModuleId(), node.getRootModuleConf(), evicted);
        ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), Collections.<IvyNode>emptySet());
        node.markEvicted(ancestor, conflictManager, resolved);
        if (debugConflictResolution) {
            Message.debug("evicting " + node + " by " + node.getEvictedData());
        }
        // if resolved changed we have to go up in the graph
        Collection<IvyNode> prevResolved = ancestor.getNode().getResolvedNodes(node.getModuleId(), node.getRootModuleConf());
        boolean solved = true;
        if (!prevResolved.equals(resolved)) {
            ancestor.getNode().setResolvedNodes(node.getModuleId(), node.getRootModuleConf(), resolved);
            for (IvyNode sel : resolved) {
                if (!prevResolved.contains(sel)) {
                    solved &= resolveConflict(node.gotoNode(sel), ancestor.getParent(), conf, toevict);
                }
            }
        }
        return solved;
    }
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) EvictionData(org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData) ConflictManager(org.apache.ivy.plugins.conflict.ConflictManager) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with ConflictManager

use of org.apache.ivy.plugins.conflict.ConflictManager in project ant-ivy by apache.

the class IvyConflict method addConflict.

void addConflict(DefaultModuleDescriptor md, IvySettings settings) {
    String matcherName = (matcher == null) ? PatternMatcher.EXACT : matcher;
    String orgPattern = (org == null) ? PatternMatcher.ANY_EXPRESSION : org;
    String modulePattern = (module == null) ? PatternMatcher.ANY_EXPRESSION : module;
    ConflictManager cm = null;
    if (rev != null) {
        cm = new FixedConflictManager(splitToArray(rev));
    } else if (manager != null) {
        cm = settings.getConflictManager(manager);
    }
    md.addConflictManager(new ModuleId(orgPattern, modulePattern), settings.getMatcher(matcherName), cm);
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ConflictManager(org.apache.ivy.plugins.conflict.ConflictManager) FixedConflictManager(org.apache.ivy.plugins.conflict.FixedConflictManager) FixedConflictManager(org.apache.ivy.plugins.conflict.FixedConflictManager)

Example 5 with ConflictManager

use of org.apache.ivy.plugins.conflict.ConflictManager in project ant-ivy by apache.

the class XmlModuleDescriptorParserTest method testFull.

@Test
public void testFull() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals("myrev", md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    assertEquals(pubdate, md.getPublicationDate());
    License[] licenses = md.getLicenses();
    assertEquals(1, licenses.length);
    assertEquals("MyLicense", licenses[0].getName());
    assertEquals("http://www.my.org/mymodule/mylicense.html", licenses[0].getUrl());
    assertEquals("http://www.my.org/mymodule/", md.getHomePage());
    assertEquals("This module is <b>great</b> !<br/>\n\t" + "You can use it especially with myconf1 and myconf2, " + "and myconf4 is not too bad too.", md.getDescription().replaceAll("\r\n", "\n").replace('\r', '\n'));
    assertEquals(1, md.getExtraInfos().size());
    ExtraInfoHolder someExtraElement = md.getExtraInfos().get(0);
    assertEquals("e:someExtra", someExtraElement.getName());
    assertEquals("56576", someExtraElement.getContent());
    assertEquals(0, someExtraElement.getAttributes().size());
    Configuration[] confs = md.getConfigurations();
    assertNotNull(confs);
    assertEquals(5, confs.length);
    assertConf(md, "myconf1", "desc 1", PUBLIC, new String[0]);
    assertConf(md, "myconf2", "desc 2", PUBLIC, new String[0]);
    assertConf(md, "myconf3", "desc 3", PRIVATE, new String[0]);
    assertConf(md, "myconf4", "desc 4", PUBLIC, new String[] { "myconf1", "myconf2" });
    assertConf(md, "myoldconf", "my old desc", PUBLIC, new String[0]);
    assertArtifacts(md.getArtifacts("myconf1"), new String[] { "myartifact1", "myartifact2", "myartifact3", "myartifact4" });
    assertArtifacts(md.getArtifacts("myconf2"), new String[] { "myartifact1", "myartifact3" });
    assertArtifacts(md.getArtifacts("myconf3"), new String[] { "myartifact1", "myartifact3", "myartifact4" });
    assertArtifacts(md.getArtifacts("myconf4"), new String[] { "myartifact1" });
    DependencyDescriptor[] dependencies = md.getDependencies();
    assertNotNull(dependencies);
    assertEquals(13, dependencies.length);
    // no conf def => equivalent to *->*
    DependencyDescriptor dd = getDependency(dependencies, "mymodule2");
    assertNotNull(dd);
    assertEquals("myorg", dd.getDependencyId().getOrganisation());
    assertEquals("2.0", dd.getDependencyRevisionId().getRevision());
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf2", "myconf3", "myconf4" })));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
    assertFalse(dd.isChanging());
    assertTrue(dd.isTransitive());
    // changing = true
    dd = getDependency(dependencies, "mymodule3");
    assertNotNull(dd);
    assertTrue(dd.isChanging());
    assertFalse(dd.isTransitive());
    // conf="myconf1" => equivalent to myconf1->myconf1
    dd = getDependency(dependencies, "yourmodule1");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("trunk", dd.getDependencyRevisionId().getBranch());
    assertEquals("1.1", dd.getDependencyRevisionId().getRevision());
    assertEquals("branch1", dd.getDynamicConstraintDependencyRevisionId().getBranch());
    assertEquals("1+", dd.getDynamicConstraintDependencyRevisionId().getRevision());
    assertEquals("yourorg#yourmodule1#branch1;1+", dd.getDynamicConstraintDependencyRevisionId().toString());
    assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf2", "myconf3", "myconf4" })));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
    // conf="myconf1->yourconf1"
    dd = getDependency(dependencies, "yourmodule2");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("2+", dd.getDependencyRevisionId().getRevision());
    assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("yourconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf2", "myconf3", "myconf4" })));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
    // conf="myconf1->yourconf1, yourconf2"
    dd = getDependency(dependencies, "yourmodule3");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("3.1", dd.getDependencyRevisionId().getRevision());
    assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf2", "myconf3", "myconf4" })));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
    // conf="myconf1, myconf2->yourconf1, yourconf2"
    dd = getDependency(dependencies, "yourmodule4");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("4.1", dd.getDependencyRevisionId().getRevision());
    assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
    assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf3", "myconf4" })));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
    // conf="myconf1->yourconf1;myconf2->yourconf1, yourconf2"
    dd = getDependency(dependencies, "yourmodule5");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("5.1", dd.getDependencyRevisionId().getRevision());
    assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertEquals(Collections.singletonList("yourconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
    assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf3", "myconf4" })));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
    // conf="*->@"
    dd = getDependency(dependencies, "yourmodule11");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("11.1", dd.getDependencyRevisionId().getRevision());
    assertEquals(Collections.singleton("*"), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Collections.singletonList("myconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
    assertEquals(Collections.singletonList("myconf3"), Arrays.asList(dd.getDependencyConfigurations("myconf3")));
    assertEquals(Collections.singletonList("myconf4"), Arrays.asList(dd.getDependencyConfigurations("myconf4")));
    dd = getDependency(dependencies, "yourmodule6");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("latest.integration", dd.getDependencyRevisionId().getRevision());
    assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertEquals(Collections.singletonList("yourconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
    assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf3", "myconf4" })));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
    dd = getDependency(dependencies, "yourmodule7");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("7.1", dd.getDependencyRevisionId().getRevision());
    assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertEquals(Collections.singletonList("yourconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
    assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
    assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf3", "myconf4" })));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
    dd = getDependency(dependencies, "yourmodule8");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("8.1", dd.getDependencyRevisionId().getRevision());
    assertEquals(new HashSet<>(Collections.singletonList("*")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertDependencyArtifacts(dd, new String[] { "myconf1" }, new String[] { "yourartifact8-1", "yourartifact8-2" });
    assertDependencyArtifacts(dd, new String[] { "myconf2" }, new String[] { "yourartifact8-1", "yourartifact8-2" });
    assertDependencyArtifacts(dd, new String[] { "myconf3" }, new String[] { "yourartifact8-1", "yourartifact8-2" });
    assertDependencyArtifacts(dd, new String[] { "myconf4" }, new String[] { "yourartifact8-1", "yourartifact8-2" });
    dd = getDependency(dependencies, "yourmodule9");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("9.1", dd.getDependencyRevisionId().getRevision());
    assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2", "myconf3")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertDependencyArtifacts(dd, new String[] { "myconf1" }, new String[] { "yourartifact9-1" });
    assertDependencyArtifacts(dd, new String[] { "myconf2" }, new String[] { "yourartifact9-1", "yourartifact9-2" });
    assertDependencyArtifacts(dd, new String[] { "myconf3" }, new String[] { "yourartifact9-2" });
    assertDependencyArtifacts(dd, new String[] { "myconf4" }, new String[] {});
    assertDependencyArtifactExcludeRules(dd, new String[] { "myconf1" }, new String[] {});
    assertDependencyArtifactExcludeRules(dd, new String[] { "myconf2" }, new String[] {});
    assertDependencyArtifactExcludeRules(dd, new String[] { "myconf3" }, new String[] {});
    assertDependencyArtifactExcludeRules(dd, new String[] { "myconf4" }, new String[] {});
    dd = getDependency(dependencies, "yourmodule10");
    assertNotNull(dd);
    assertEquals("yourorg", dd.getDependencyId().getOrganisation());
    assertEquals("10.1", dd.getDependencyRevisionId().getRevision());
    assertEquals(Collections.singleton("*"), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1" }, new String[] { "your.*", PatternMatcher.ANY_EXPRESSION });
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf2" }, new String[] { "your.*", PatternMatcher.ANY_EXPRESSION });
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf3" }, new String[] { "your.*", PatternMatcher.ANY_EXPRESSION });
    assertDependencyArtifactIncludeRules(dd, new String[] { "myconf4" }, new String[] { "your.*", PatternMatcher.ANY_EXPRESSION });
    assertDependencyArtifactExcludeRules(dd, new String[] { "myconf1" }, new String[] { "toexclude" });
    assertDependencyArtifactExcludeRules(dd, new String[] { "myconf2" }, new String[] { "toexclude" });
    assertDependencyArtifactExcludeRules(dd, new String[] { "myconf3" }, new String[] { "toexclude" });
    assertDependencyArtifactExcludeRules(dd, new String[] { "myconf4" }, new String[] { "toexclude" });
    ConflictManager cm = md.getConflictManager(new ModuleId("yourorg", "yourmodule1"));
    assertNotNull(cm);
    assertTrue(cm instanceof NoConflictManager);
    cm = md.getConflictManager(new ModuleId("yourorg", "yourmodule2"));
    assertNotNull(cm);
    assertTrue(cm instanceof NoConflictManager);
    cm = md.getConflictManager(new ModuleId("theirorg", "theirmodule1"));
    assertNotNull(cm);
    assertTrue(cm instanceof FixedConflictManager);
    FixedConflictManager fcm = (FixedConflictManager) cm;
    assertEquals(2, fcm.getRevs().size());
    assertTrue(fcm.getRevs().contains("1.0"));
    assertTrue(fcm.getRevs().contains("1.1"));
    cm = md.getConflictManager(new ModuleId("theirorg", "theirmodule2"));
    assertNull(cm);
    assertEquals(ModuleRevisionId.parse("yourorg#yourmodule1#BRANCH;1.0"), md.mediate(new DefaultDependencyDescriptor(ModuleRevisionId.parse("yourorg#yourmodule1;2.0"), false)).getDependencyRevisionId());
    ExcludeRule[] rules = md.getAllExcludeRules();
    assertNotNull(rules);
    assertEquals(2, rules.length);
    assertEquals(GlobPatternMatcher.INSTANCE, rules[0].getMatcher());
    assertEquals(ExactPatternMatcher.INSTANCE, rules[1].getMatcher());
    assertEquals(Collections.singletonList("myconf1"), Arrays.asList(rules[0].getConfigurations()));
    assertEquals(Arrays.asList("myconf1", "myconf2", "myconf3", "myconf4", "myoldconf"), Arrays.asList(rules[1].getConfigurations()));
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) ExtraInfoHolder(org.apache.ivy.core.module.descriptor.ExtraInfoHolder) GregorianCalendar(java.util.GregorianCalendar) License(org.apache.ivy.core.module.descriptor.License) FixedConflictManager(org.apache.ivy.plugins.conflict.FixedConflictManager) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) Date(java.util.Date) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ModuleId(org.apache.ivy.core.module.id.ModuleId) NoConflictManager(org.apache.ivy.plugins.conflict.NoConflictManager) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) NoConflictManager(org.apache.ivy.plugins.conflict.NoConflictManager) FixedConflictManager(org.apache.ivy.plugins.conflict.FixedConflictManager) ConflictManager(org.apache.ivy.plugins.conflict.ConflictManager) Test(org.junit.Test)

Aggregations

ConflictManager (org.apache.ivy.plugins.conflict.ConflictManager)5 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)3 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)2 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)2 ModuleId (org.apache.ivy.core.module.id.ModuleId)2 FixedConflictManager (org.apache.ivy.plugins.conflict.FixedConflictManager)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 IvyContext (org.apache.ivy.core.IvyContext)1 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)1 Configuration (org.apache.ivy.core.module.descriptor.Configuration)1 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)1 ExcludeRule (org.apache.ivy.core.module.descriptor.ExcludeRule)1 ExtraInfoHolder (org.apache.ivy.core.module.descriptor.ExtraInfoHolder)1 License (org.apache.ivy.core.module.descriptor.License)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 IvyNode (org.apache.ivy.core.resolve.IvyNode)1