Search in sources :

Example 31 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class ResolveTest method testResolveForceWithDynamicRevisionsAndCyclicDependencies.

/**
 * Test case for IVY-182.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-182">IVY-182</a>
 */
@Test
public void testResolveForceWithDynamicRevisionsAndCyclicDependencies() throws Exception {
    // * has no revision
    // * declares conf compile, test extends compile,
    // * depends on
    // - mod1.2 v 1+ and forces it in conf compile
    // - mod3.1 v 1+ in conf test->runtime excluding mod4.1 (to avoid cyclic dep failure)
    // which defines confs compile, runtime extends compile
    // which depends on mod1.2 v 2+ in conf compile->default
    // which depends on mod4.1 v 4+ in conf compile->compile
    ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-182.xml"), getResolveOptions(new String[] { "*" }));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);
    ModuleId mid = new ModuleId("test", "IVY-182");
    assertEquals(mid, md.getModuleRevisionId().getModuleId());
    // dependencies
    assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org3", "mod3.1", "1.4")).exists());
    assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.4", "mod3.1", "jar", "jar").exists());
    assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists());
    assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists());
    assertFalse(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists());
    assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ModuleId(org.apache.ivy.core.module.id.ModuleId) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) Test(org.junit.Test)

Example 32 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class DefaultRepositoryCacheManagerTest method createArtifact.

private static DefaultArtifact createArtifact(String org, String module, String rev, String name, String type, String ext) {
    ModuleId mid = new ModuleId(org, module);
    ModuleRevisionId mrid = new ModuleRevisionId(mid, rev);
    return new DefaultArtifact(mrid, new Date(), name, type, ext);
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date)

Example 33 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyBuildList method filterModulesFromLeaf.

/**
 * Returns a collection of ModuleDescriptors that are contained in the input collection of
 * ModuleDescriptors which depends on the leaf module
 *
 * @param mds
 *            input collection of ModuleDescriptors
 * @param leafmds
 *            leaf module
 * @return filtered list of modules
 */
private Collection<ModuleDescriptor> filterModulesFromLeaf(Collection<ModuleDescriptor> mds, List<ModuleDescriptor> leafmds) {
    Map<ModuleId, ModuleDescriptor> moduleIdMap = new HashMap<>();
    for (ModuleDescriptor md : mds) {
        moduleIdMap.put(md.getModuleRevisionId().getModuleId(), md);
    }
    // recursively process the nodes
    Set<ModuleDescriptor> toKeep = new LinkedHashSet<>();
    for (ModuleDescriptor leafmd : leafmds) {
        // With the excludeleaf attribute set to true, take the rootmd out of the toKeep set.
        if (excludeLeaf) {
            Message.verbose("Excluded module " + leafmd.getModuleRevisionId().getModuleId().getName());
        } else {
            toKeep.add(leafmd);
        }
        processFilterNodeFromLeaf(leafmd, toKeep, moduleIdMap);
    }
    // just for logging
    for (ModuleDescriptor md : toKeep) {
        Message.verbose("Kept module " + md.getModuleRevisionId().getModuleId().getName());
    }
    return toKeep;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) HashMap(java.util.HashMap)

Example 34 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyBuildList method processFilterNodeFromRoot.

/**
 * Adds the current node to the toKeep collection and then processes the each of the direct
 * dependencies of this node that appear in the moduleIdMap (indicating that the dependency is
 * part of this BuildList)
 *
 * @param node
 *            the node to be processed
 * @param toKeep
 *            the set of ModuleDescriptors that should be kept
 * @param moduleIdMap
 *            reference mapping of moduleId to ModuleDescriptor that are part of the BuildList
 */
private void processFilterNodeFromRoot(ModuleDescriptor node, Set<ModuleDescriptor> toKeep, Map<ModuleId, ModuleDescriptor> moduleIdMap) {
    // toKeep.add(node);
    for (DependencyDescriptor dep : node.getDependencies()) {
        ModuleId id = dep.getDependencyId();
        ModuleDescriptor md = moduleIdMap.get(id);
        // toKeep Set, in which there's probably a circular dependency
        if (md != null && !toKeep.contains(md)) {
            toKeep.add(md);
            if (!getOnlydirectdep()) {
                processFilterNodeFromRoot(md, toKeep, moduleIdMap);
            }
        }
    }
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor)

Example 35 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyBuildNumber method doExecute.

public void doExecute() throws BuildException {
    if (organisation == null) {
        throw new BuildException("no organisation provided for ivy buildnumber task");
    }
    if (module == null) {
        throw new BuildException("no module name provided for ivy buildnumber task");
    }
    if (prefix == null) {
        throw new BuildException("null prefix not allowed");
    }
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    if (branch == null) {
        branch = settings.getDefaultBranch(new ModuleId(organisation, module));
    }
    if (isNullOrEmpty(revision)) {
        revision = "latest.integration";
    } else if (!revision.endsWith("+")) {
        revision += "+";
    }
    if (!prefix.endsWith(".") && !prefix.isEmpty()) {
        prefix += ".";
    }
    SearchEngine searcher = new SearchEngine(settings);
    PatternMatcher patternMatcher = new PatternMatcher() {

        private PatternMatcher exact = new ExactPatternMatcher();

        private PatternMatcher regexp = new ExactOrRegexpPatternMatcher();

        public Matcher getMatcher(String expression) {
            if (expression.equals(organisation) || expression.equals(module) || expression.equals(branch)) {
                return exact.getMatcher(expression);
            } else {
                return regexp.getMatcher(expression);
            }
        }

        public String getName() {
            return "buildnumber-matcher";
        }
    };
    String revisionPattern = ".*";
    if (revision.endsWith("+")) {
        revisionPattern = Pattern.quote(revision.substring(0, revision.length() - 1)) + ".*";
    }
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(organisation, module, branch, revisionPattern);
    ModuleRevisionId[] revisions;
    if (resolver == null) {
        revisions = searcher.listModules(mrid, patternMatcher);
    } else {
        DependencyResolver depResolver = settings.getResolver(resolver);
        if (depResolver == null) {
            throw new BuildException("Unknown resolver: " + resolver);
        }
        revisions = searcher.listModules(depResolver, mrid, patternMatcher);
    }
    List<ArtifactInfo> infos = new ArrayList<>(revisions.length);
    for (ModuleRevisionId rev : revisions) {
        infos.add(new ResolvedModuleRevisionArtifactInfo(rev));
    }
    VersionMatcher matcher = settings.getVersionMatcher();
    LatestStrategy latestStrategy = settings.getLatestStrategy("latest-revision");
    List<ArtifactInfo> sorted = latestStrategy.sort(infos.toArray(new ArtifactInfo[revisions.length]));
    ModuleRevisionId askedMrid = ModuleRevisionId.newInstance(organisation, module, branch, revision);
    String foundRevision = null;
    ListIterator<ArtifactInfo> iter = sorted.listIterator(sorted.size());
    while (iter.hasPrevious()) {
        ResolvedModuleRevisionArtifactInfo info = (ResolvedModuleRevisionArtifactInfo) iter.previous();
        if (!matcher.accept(askedMrid, info.rmr)) {
            continue;
        }
        if (matcher.needModuleDescriptor(askedMrid, info.rmr)) {
            ResolvedModuleRevision rmr = ivy.findModule(info.rmr);
            if (matcher.accept(askedMrid, rmr.getDescriptor())) {
                foundRevision = info.rmr.getRevision();
            }
        } else {
            foundRevision = info.rmr.getRevision();
        }
        if (foundRevision != null) {
            break;
        }
    }
    NewRevision newRevision = computeNewRevision(foundRevision);
    setProperty("revision", newRevision.getRevision());
    setProperty("new.revision", newRevision.getNewRevision());
    setProperty("build.number", newRevision.getBuildNumber());
    setProperty("new.build.number", newRevision.getNewBuildNumber());
}
Also used : ExactPatternMatcher(org.apache.ivy.plugins.matcher.ExactPatternMatcher) ArrayList(java.util.ArrayList) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) Ivy(org.apache.ivy.Ivy) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) ModuleId(org.apache.ivy.core.module.id.ModuleId) ExactOrRegexpPatternMatcher(org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher) SearchEngine(org.apache.ivy.core.search.SearchEngine) ArtifactInfo(org.apache.ivy.plugins.latest.ArtifactInfo) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) BuildException(org.apache.tools.ant.BuildException) ExactPatternMatcher(org.apache.ivy.plugins.matcher.ExactPatternMatcher) ExactOrRegexpPatternMatcher(org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher)

Aggregations

ModuleId (org.apache.ivy.core.module.id.ModuleId)49 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)19 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)13 File (java.io.File)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Date (java.util.Date)6 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)6 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)6 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)6 BuildException (org.apache.tools.ant.BuildException)6 Ivy (org.apache.ivy.Ivy)5 ArtifactId (org.apache.ivy.core.module.id.ArtifactId)5 ResolveReport (org.apache.ivy.core.report.ResolveReport)5 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)5 IvySettings (org.apache.ivy.core.settings.IvySettings)5 IOException (java.io.IOException)4 Map (java.util.Map)4 Configuration (org.apache.ivy.core.module.descriptor.Configuration)4