Search in sources :

Example 6 with FileSystemResolver

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

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

the class XmlSettingsParserTest method testRef.

@Test
public void testRef() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-ref.xml"));
    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("fs", fsInt1.getName());
    List<String> ivyPatterns = fsInt1.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns.get(0));
    DependencyResolver external = settings.getResolver("external");
    assertNotNull(external);
    assertTrue(external instanceof ChainResolver);
    chain = (ChainResolver) external;
    subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(1, subresolvers.size());
    FileSystemResolver fsInt2 = (FileSystemResolver) subresolvers.get(0);
    assertEquals("fs", fsInt2.getName());
    ivyPatterns = fsInt2.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("sharedrep/[organisation]/[module]/ivys/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 8 with FileSystemResolver

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

the class XmlSettingsParserTest method testIncludeSpecialCharInName.

@Test
public void testIncludeSpecialCharInName() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-include-special.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 9 with FileSystemResolver

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

the class ResolveTest method testUseCacheOnly.

@Test
public void testUseCacheOnly() throws Exception {
    ResolveOptions option = getResolveOptions(new String[] { "*" }).setValidate(false);
    URL url = new File("test/repositories/1/usecacheonly/mod1/ivys/ivy-1.0.xml").toURI().toURL();
    // normal resolve, the file goes in the cache
    ResolveReport report = ivy.resolve(url, option);
    assertFalse(report.hasError());
    option.setUseCacheOnly(true);
    // use cache only, hit the cache
    report = ivy.resolve(url, option);
    assertFalse(report.hasError());
    CacheCleaner.deleteDir(cache);
    createCache();
    // no more in the cache, missed
    report = ivy.resolve(url, option);
    assertTrue(report.hasError());
    option.setUseCacheOnly(false);
    // try with use origin: should fail as the cache is empty
    ivy.getSettings().setDefaultUseOrigin(true);
    option.setUseCacheOnly(true);
    report = ivy.resolve(url, option);
    assertTrue(report.hasError());
    // populate the cache
    option.setUseCacheOnly(false);
    report = ivy.resolve(url, option);
    assertFalse(report.hasError());
    // use origin should now work
    option.setUseCacheOnly(true);
    report = ivy.resolve(url, option);
    assertFalse(report.hasError());
    // ensure that we hit only the cache and never try to hit in the repository
    FileSystemResolver resolver = (FileSystemResolver) ivy.getSettings().getResolver("1");
    resolver.setRepository(new AbstractRepository() {

        public List<String> list(String parent) {
            throw new UnsupportedOperationException();
        }

        public Resource getResource(String source) {
            throw new UnsupportedOperationException();
        }

        public void get(String source, File destination) {
            throw new UnsupportedOperationException();
        }
    });
    report = ivy.resolve(url, option);
    assertFalse(report.hasError());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) AbstractRepository(org.apache.ivy.plugins.repository.AbstractRepository) Resource(org.apache.ivy.plugins.repository.Resource) List(java.util.List) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test)

Example 10 with FileSystemResolver

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

the class ResolveTest method testExtraAttributes4.

/**
 * Second test case for IVY-745.ยจ
 * Now we disable consistency checking, everything must work fine.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-745">IVY-745</a>
 */
@Test
public void testExtraAttributes4() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/extra-attributes/ivysettings.xml"));
    ivy.getSettings().setDefaultCache(cache);
    ((FileSystemResolver) ivy.getSettings().getResolver("default")).setCheckconsistency(false);
    ivy.getSettings().validate();
    ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-extra-att3.xml"), getResolveOptions(ivy.getSettings(), new String[] { "*" }).setValidate(false));
    assertFalse(report.hasError());
    assertTrue(new File(cache, "apache/mymodule/task2/1749/ivy.xml").exists());
    assertTrue(new File(cache, "apache/mymodule/task2/1749/ivy.xml.original").exists());
    assertTrue(new File(cache, "apache/mymodule/task2/1749/mymodule-windows.jar").exists());
    assertTrue(new File(cache, "apache/mymodule/task2/1749/mymodule-linux.jar").exists());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test)

Aggregations

FileSystemResolver (org.apache.ivy.plugins.resolver.FileSystemResolver)18 Test (org.junit.Test)14 File (java.io.File)11 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)7 ChainResolver (org.apache.ivy.plugins.resolver.ChainResolver)6 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)6 Ivy (org.apache.ivy.Ivy)5 JarFile (java.util.jar.JarFile)4 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)4 ResolveReport (org.apache.ivy.core.report.ResolveReport)4 IvySettings (org.apache.ivy.core.settings.IvySettings)3 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 DualResolver (org.apache.ivy.plugins.resolver.DualResolver)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)1