Search in sources :

Example 1 with ChainResolver

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

the class IvySettings method addResolver.

public synchronized void addResolver(DependencyResolver resolver) {
    if (resolver == null) {
        throw new NullPointerException("null resolver");
    }
    init(resolver);
    resolversMap.put(resolver.getName(), resolver);
    if (resolver instanceof ChainResolver) {
        List<DependencyResolver> subresolvers = ((ChainResolver) resolver).getResolvers();
        for (DependencyResolver dr : subresolvers) {
            addResolver(dr);
        }
    } else if (resolver instanceof DualResolver) {
        DependencyResolver ivyResolver = ((DualResolver) resolver).getIvyResolver();
        if (ivyResolver != null) {
            addResolver(ivyResolver);
        }
        DependencyResolver artifactResolver = ((DualResolver) resolver).getArtifactResolver();
        if (artifactResolver != null) {
            addResolver(artifactResolver);
        }
    }
}
Also used : WorkspaceChainResolver(org.apache.ivy.plugins.resolver.WorkspaceChainResolver) ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) DualResolver(org.apache.ivy.plugins.resolver.DualResolver) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 2 with ChainResolver

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

the class XmlSettingsParserTest method testTypedef.

@Test
public void testTypedef() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-typedef.xml"));
    DependencyResolver mock = settings.getResolver("mock3");
    assertNotNull(mock);
    assertTrue(mock instanceof MockResolver);
    DependencyResolver internal = settings.getResolver("internal");
    assertNotNull(internal);
    assertTrue(internal instanceof ChainResolver);
    ChainResolver chain = (ChainResolver) internal;
    List<DependencyResolver> subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(2, subresolvers.size());
    assertEquals("mock1", subresolvers.get(0).getName());
    assertEquals("mock2", subresolvers.get(1).getName());
    assertTrue(subresolvers.get(0) instanceof MockResolver);
    assertTrue(subresolvers.get(1) instanceof MockResolver);
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 3 with ChainResolver

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

the class XmlSettingsParserTest method testInclude.

@Test
public void testInclude() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-include.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));
    DependencyResolver inc = settings.getResolver("includeworks");
    assertNotNull(inc);
    assertTrue(inc instanceof ChainResolver);
    chain = (ChainResolver) inc;
    subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(2, subresolvers.size());
    fsInt1 = (FileSystemResolver) subresolvers.get(0);
    assertEquals("includeworks-fs1", fsInt1.getName());
    ivyPatterns = fsInt1.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("included/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", ivyPatterns.get(0));
    // properties defined in included file should be available to including file (IVY-780)
    assertEquals("myvalue", settings.getVariable("ivy.test.prop"));
}
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 4 with ChainResolver

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

the class XmlSettingsParserTest method test.

@Test
public void test() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-test.xml"));
    File defaultCache = settings.getDefaultCache();
    assertNotNull(defaultCache);
    assertEquals("mycache", defaultCache.getName());
    assertFalse(settings.isCheckUpToDate());
    assertFalse(settings.doValidate());
    assertEquals("[module]/ivys/ivy-[revision].xml", settings.getDefaultCacheIvyPattern());
    assertEquals("[module]/[type]s/[artifact]-[revision].[ext]", settings.getDefaultCacheArtifactPattern());
    LatestStrategy latest = settings.getLatestStrategy("mylatest-revision");
    assertNotNull(latest);
    assertTrue(latest instanceof LatestRevisionStrategy);
    LatestRevisionStrategy l = (LatestRevisionStrategy) latest;
    assertEquals(new Integer(-2), l.getSpecialMeanings().get("pre"));
    assertEquals(new Integer(4), l.getSpecialMeanings().get("qa"));
    DependencyResolver defaultResolver = settings.getDefaultResolver();
    assertNotNull(defaultResolver);
    assertEquals("libraries", defaultResolver.getName());
    assertTrue(defaultResolver instanceof FileSystemResolver);
    FileSystemResolver fsres = (FileSystemResolver) defaultResolver;
    List<String> ivyPatterns = fsres.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("lib/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns.get(0));
    LatestStrategy strategy = fsres.getLatestStrategy();
    assertNotNull(strategy);
    assertTrue(strategy instanceof LatestRevisionStrategy);
    DependencyResolver internal = settings.getResolver("internal");
    assertNotNull(internal);
    assertTrue(internal instanceof ChainResolver);
    ChainResolver chain = (ChainResolver) internal;
    List<DependencyResolver> subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(2, subresolvers.size());
    FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0);
    assertEquals("int1", fsInt1.getName());
    assertEquals(1, fsInt1.getIvyPatterns().size());
    assertLocationEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", fsInt1.getIvyPatterns().get(0));
    assertEquals("int2", subresolvers.get(1).getName());
    strategy = fsInt1.getLatestStrategy();
    assertNotNull(strategy);
    assertTrue(strategy instanceof LatestTimeStrategy);
    assertEquals("libraries", settings.getResolver(ModuleRevisionId.newInstance("unknown", "lib", "1.0")).getName());
    assertEquals("internal", settings.getResolver(ModuleRevisionId.newInstance("apache", "ant", "1.0")).getName());
    assertEquals("int2", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivy", "2.0")).getName());
    assertEquals("int1", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivy", "1.0")).getName());
    assertEquals("int1", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivyde", "1.0")).getName());
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) LatestRevisionStrategy(org.apache.ivy.plugins.latest.LatestRevisionStrategy) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) LatestTimeStrategy(org.apache.ivy.plugins.latest.LatestTimeStrategy) File(java.io.File) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 5 with ChainResolver

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

the class XmlSettingsParserTest method testMacroAndRef2.

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

Aggregations

ChainResolver (org.apache.ivy.plugins.resolver.ChainResolver)12 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)11 Test (org.junit.Test)10 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)9 FileSystemResolver (org.apache.ivy.plugins.resolver.FileSystemResolver)6 File (java.io.File)2 IBiblioResolver (org.apache.ivy.plugins.resolver.IBiblioResolver)2 URL (java.net.URL)1 Ivy (org.apache.ivy.Ivy)1 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)1 ResolveData (org.apache.ivy.core.resolve.ResolveData)1 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)1 IvySettings (org.apache.ivy.core.settings.IvySettings)1 LatestRevisionStrategy (org.apache.ivy.plugins.latest.LatestRevisionStrategy)1 LatestStrategy (org.apache.ivy.plugins.latest.LatestStrategy)1 LatestTimeStrategy (org.apache.ivy.plugins.latest.LatestTimeStrategy)1 DualResolver (org.apache.ivy.plugins.resolver.DualResolver)1 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)1 WorkspaceChainResolver (org.apache.ivy.plugins.resolver.WorkspaceChainResolver)1 Before (org.junit.Before)1