Search in sources :

Example 41 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class XmlSettingsParserTest method testIncludeAbsoluteFile.

@Test
public void testIncludeAbsoluteFile() throws Exception {
    // WARNING : this test will only work if the test are launched from the project root
    // directory
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-include-absolute-file.xml"));
    DependencyResolver inc = settings.getResolver("includeworks");
    assertNotNull(inc);
    assertTrue(inc instanceof ChainResolver);
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 42 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class XmlSettingsParserTest method testMacroAndRef.

/**
 * Test case for IVY-319.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-319">IVY-319</a>
 */
@Test
public void testMacroAndRef() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro+ref.xml"));
    DependencyResolver shared = settings.getResolver("shared");
    assertNotNull(shared);
    assertTrue(shared instanceof FileSystemResolver);
    DependencyResolver mychain = settings.getResolver("mychain");
    assertNotNull(mychain);
    assertTrue(mychain instanceof ChainResolver);
    ChainResolver chain = (ChainResolver) mychain;
    List<DependencyResolver> subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(1, subresolvers.size());
    shared = subresolvers.get(0);
    assertEquals("shared", shared.getName());
    assertTrue(shared instanceof FileSystemResolver);
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 43 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class XmlSettingsParserTest method testMacro.

@Test
public void testMacro() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro.xml"));
    DependencyResolver def = settings.getResolver("default");
    assertNotNull(def);
    assertTrue(def instanceof ChainResolver);
    ChainResolver chain = (ChainResolver) def;
    List<DependencyResolver> subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(2, subresolvers.size());
    FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0);
    assertEquals("default-fs1", fsInt1.getName());
    List<String> ivyPatterns = fsInt1.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("path/to/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", ivyPatterns.get(0));
    FileSystemResolver fsInt2 = (FileSystemResolver) subresolvers.get(1);
    assertEquals("default-fs2", fsInt2.getName());
    ivyPatterns = fsInt2.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("path/to/secondrep/[organisation]/[module]/[type]s/ivy-[revision].xml", ivyPatterns.get(0));
    DependencyResolver other = settings.getResolver("other");
    assertNotNull(other);
    assertTrue(other instanceof ChainResolver);
    chain = (ChainResolver) other;
    subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(2, subresolvers.size());
    fsInt2 = (FileSystemResolver) subresolvers.get(1);
    assertEquals("other-fs2", fsInt2.getName());
    ivyPatterns = fsInt2.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("path/to/secondrep/[module]/[type]s/ivy-[revision].xml", ivyPatterns.get(0));
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 44 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class XmlSettingsParserTest method testFileAttribute.

@Test
public void testFileAttribute() throws Exception {
    IvySettings settings = new IvySettings();
    File basedir = new File("test").getAbsoluteFile();
    settings.setBaseDir(basedir);
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-packager.xml"));
    DependencyResolver r = settings.getResolver("packager");
    assertNotNull(r);
    assertTrue(r instanceof PackagerResolver);
    PackagerResolver packager = (PackagerResolver) r;
    assertEquals(new File(basedir, "packager/build"), packager.getBuildRoot());
    assertEquals(new File(basedir, "packager/cache"), packager.getResourceCache());
}
Also used : PackagerResolver(org.apache.ivy.plugins.resolver.packager.PackagerResolver) File(java.io.File) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 45 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver 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

DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)50 Test (org.junit.Test)23 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)11 ChainResolver (org.apache.ivy.plugins.resolver.ChainResolver)11 File (java.io.File)10 Ivy (org.apache.ivy.Ivy)9 HashMap (java.util.HashMap)8 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)8 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LinkedHashSet (java.util.LinkedHashSet)6 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 FileSystemResolver (org.apache.ivy.plugins.resolver.FileSystemResolver)6 ParseException (java.text.ParseException)5 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)5 IvyRepResolver (org.apache.ivy.plugins.resolver.IvyRepResolver)5 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)4