Search in sources :

Example 1 with FileSystemResolver

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

the class TestHelper method newTestRepository.

/**
 * A file system resolver which can be used with the
 * {@link #fillRepository(DependencyResolver, Collection)} method to create a test case of
 * module descriptor.
 * <p>
 * When finished you should call {@link #cleanTestRepository()}
 * </p>
 *
 * @return FileSystemResolver
 */
public static FileSystemResolver newTestRepository() {
    FileSystemResolver testRepository = new FileSystemResolver();
    testRepository.setName("test");
    String testRepoDir = new File("build/test/test-repo").getAbsolutePath();
    testRepository.addIvyPattern(testRepoDir + "/[organisation]/[module]/[revision]/[artifact].[ext]");
    testRepository.addArtifactPattern(testRepoDir + "/[organisation]/[module]/[revision]/[artifact].[ext]");
    return testRepository;
}
Also used : File(java.io.File) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver)

Example 2 with FileSystemResolver

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

the class ResolveTest method ivyTestCache.

/**
 * Configures an Ivy instance using a resolver locating modules on file system, in a
 * build/testCache2 location which is created for the test and removed after, and can thus
 * easily simulate a repository availability problem
 *
 * @return the configured ivy instance
 */
private Ivy ivyTestCache() {
    Ivy ivy = Ivy.newInstance();
    DualResolver resolver = new DualResolver();
    resolver.setName("dual");
    FileSystemResolver r = new FileSystemResolver();
    r.setName("1");
    r.addIvyPattern(ivy.getSettings().getBaseDir().getPath() + "/build/testCache2/ivy-[module]-[revision].xml");
    resolver.add(r);
    r = new FileSystemResolver();
    r.setName("2");
    r.addArtifactPattern(ivy.getSettings().getBaseDir().getPath() + "/build/testCache2/[artifact]-[revision].[ext]");
    resolver.add(r);
    ivy.getSettings().addResolver(resolver);
    ivy.getSettings().setDefaultResolver("dual");
    return ivy;
}
Also used : DualResolver(org.apache.ivy.plugins.resolver.DualResolver) Ivy(org.apache.ivy.Ivy) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver)

Example 3 with FileSystemResolver

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

the class ResolveTest method testExtraAttributes.

@Test
public void testExtraAttributes() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/extra-attributes/ivysettings.xml"));
    ivy.getSettings().setDefaultCache(cache);
    FileSystemResolver fResolver = (FileSystemResolver) ivy.getSettings().getDefaultResolver();
    // important for testing IVY-929
    fResolver.setCheckconsistency(false);
    ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-extra-att.xml"), getResolveOptions(ivy.getSettings(), new String[] { "*" }).setValidate(false));
    assertFalse(report.hasError());
    assertTrue(new File(cache, "apache/mymodule/task1/1854/ivy.xml").exists());
    assertTrue(new File(cache, "apache/mymodule/task1/1854/mymodule-windows.jar").exists());
    assertTrue(new File(cache, "apache/mymodule/task1/1854/mymodule-linux.jar").exists());
    Set<ModuleRevisionId> moduleRevisions = report.getConfigurationReport("default").getModuleRevisionIds();
    assertEquals(1, moduleRevisions.size());
    ModuleRevisionId resolveModRevId = moduleRevisions.iterator().next();
    assertEquals("apache", resolveModRevId.getOrganisation());
    assertEquals("mymodule", resolveModRevId.getName());
    assertEquals("1854", resolveModRevId.getRevision());
    assertEquals("task1", resolveModRevId.getExtraAttribute("eatt"));
    assertEquals("another", resolveModRevId.getExtraAttribute("eatt2"));
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) 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)

Example 4 with FileSystemResolver

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

the class XmlModuleDescriptorParserTest method testExtendsCached.

@Test
public void testExtendsCached() throws Exception {
    // configure a resolver to serve the parent descriptor, so that parse succeeds.
    File resolveRoot = new File("build/tmp/xmlModuleDescriptorTest");
    assertTrue(resolveRoot.exists() || resolveRoot.mkdirs());
    FileUtil.copy(getClass().getResource("test-extends-parent.xml"), new File(resolveRoot, "myorg/myparent/ivy.xml"), null, null);
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setSettings(settings);
    resolver.setName("testExtendsCached");
    resolver.addIvyPattern(resolveRoot.getAbsolutePath() + "/[organisation]/[module]/[artifact].[ext]");
    settings.addResolver(resolver);
    settings.setDefaultResolver("testExtendsCached");
    // descriptor extends a module without a location="..." attribute, so resolver lookup
    // must be performed.
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-extends-cached.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals("myrev", md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());
    // verify that the parent description was merged.
    assertEquals("Parent module description.", md.getDescription());
    // verify that the parent and child configurations were merged together.
    final Configuration[] expectedConfs = { new Configuration("default"), new Configuration("conf1"), new Configuration("conf2") };
    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(expectedConfs), Arrays.asList(md.getConfigurations()));
    // verify parent and child dependencies were merged together.
    DependencyDescriptor[] deps = md.getDependencies();
    assertNotNull(deps);
    assertEquals(2, deps.length);
    assertEquals(Collections.singletonList("default"), Arrays.asList(deps[0].getModuleConfigurations()));
    ModuleRevisionId dep = deps[0].getDependencyRevisionId();
    assertEquals("myorg", dep.getModuleId().getOrganisation());
    assertEquals("mymodule1", dep.getModuleId().getName());
    assertEquals("1.0", dep.getRevision());
    assertEquals(Arrays.asList("conf1", "conf2"), Arrays.asList(deps[1].getModuleConfigurations()));
    dep = deps[1].getDependencyRevisionId();
    assertEquals("myorg", dep.getModuleId().getOrganisation());
    assertEquals("mymodule2", dep.getModuleId().getName());
    assertEquals("2.0", dep.getRevision());
    // verify only child publications are present
    Artifact[] artifacts = md.getAllArtifacts();
    assertNotNull(artifacts);
    assertEquals(1, artifacts.length);
    assertEquals("mymodule", artifacts[0].getName());
    assertEquals("jar", artifacts[0].getType());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test)

Example 5 with FileSystemResolver

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

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