Search in sources :

Example 16 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class ResolveTest method testBranches6.

/**
 * Test case for IVY-717.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-717">IVY-717</a>
 */
@Test
public void testBranches6() throws Exception {
    // bar1;4 -> foo#foo1#${ivy.branch};5
    // foo#foo1#branch1;5 -> foo#foo2#${ivy.branch};1
    // foo#foo1#trunk;5 -> {}
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/branches/ivysettings.xml"));
    ivy.setVariable("ivy.branch", "branch1");
    ResolveReport report = ivy.resolve(new File("test/repositories/branches/bar/bar1/trunk/4/ivy.xml"), getResolveOptions(new String[] { "*" }).setValidate(false));
    assertFalse(report.hasError());
    assertTrue(getArchiveFileInCache(ivy, "foo#foo1#branch1;5", "foo1", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "foo#foo2#branch1;1", "foo2", "jar", "jar").exists());
    ivy.setVariable("ivy.branch", "trunk");
    report = ivy.resolve(new File("test/repositories/branches/bar/bar1/trunk/4/ivy.xml"), getResolveOptions(new String[] { "*" }).setValidate(false));
    assertFalse(report.hasError());
    assertEquals(1, report.getConfigurationReport("default").getNodesNumber());
    assertTrue(getArchiveFileInCache(ivy, "foo#foo1#trunk;5", "foo1", "jar", "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) Test(org.junit.Test)

Example 17 with Ivy

use of org.apache.ivy.Ivy 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 18 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class ResolveTest method testResolveSeveralDefaultWithArtifactsAndConfs2.

/**
 * Second test case for IVY-283.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-283">IVY-283</a>
 */
@Test
public void testResolveSeveralDefaultWithArtifactsAndConfs2() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/IVY-283/ivysettings.xml"));
    ResolveReport report = ivy.resolve(new File("test/repositories/IVY-283/ivy-d.xml"), getResolveOptions(new String[] { "*" }));
    assertFalse(report.hasError());
    // dependencies
    ConfigurationResolveReport crr = report.getConfigurationReport("build");
    assertNotNull(crr);
    assertEquals(9, crr.getDownloadReports(ModuleRevisionId.newInstance("medicel", "module_a", "local")).length);
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_a", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_b", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_c", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_d", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_e", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_f", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_g", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_h", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a", "local", "lib_a_i", "jar", "jar").exists());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 19 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class ResolveTest method testIVY1236.

/**
 * Test case for IVY-1236.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1236">IVY-1236</a>
 */
@Test
public void testIVY1236() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/IVY-1236/ivysettings.xml"));
    ResolveReport report = ivy.resolve(new File("test/repositories/IVY-1236/ivy.xml"), getResolveOptions(new String[] { "*" }));
    assertNotNull(report);
    assertNotNull(report.getUnresolvedDependencies());
    assertEquals("Number of unresolved dependencies not correct", 0, report.getUnresolvedDependencies().length);
    // dependencies
    assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("myorg", "modB", "1.0")).exists());
    assertTrue(getArchiveFileInCache("myorg", "modB", "1.0", "modB", "jar", "jar").exists());
    assertTrue(getArchiveFileInCache("myorg", "modB", "1.0", "modB-A", "jar", "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) Test(org.junit.Test)

Example 20 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class ResolveTest method testMultipleCache.

@Test
public void testMultipleCache() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/ivysettings-multicache.xml"));
    // mod2.1 depends on mod1.1 which depends on mod1.2
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml"), getResolveOptions(new String[] { "*" }));
    assertNotNull(report);
    assertFalse(report.hasError());
    // dependencies
    DefaultArtifact depArtifact = TestHelper.newArtifact("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar");
    ModuleRevisionId depMrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    DefaultRepositoryCacheManager cacheMgr1 = (DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager();
    DefaultRepositoryCacheManager cacheMgr2 = (DefaultRepositoryCacheManager) ivy.getSettings().getRepositoryCacheManager("cache2");
    // ivy file should be cached in default cache, and artifact in cache2
    assertTrue(cacheMgr1.getIvyFileInCache(depMrid).exists());
    assertFalse(cacheMgr1.getArchiveFileInCache(depArtifact).exists());
    assertEquals(new File(cache, "repo1/mod1.1/ivy-1.0.xml").getCanonicalFile(), cacheMgr1.getIvyFileInCache(depMrid).getCanonicalFile());
    assertFalse(cacheMgr2.getIvyFileInCache(depMrid).exists());
    assertTrue(cacheMgr2.getArchiveFileInCache(depArtifact).exists());
    assertEquals(new File(cache, "repo2/mod1.1-1.0/mod1.1.jar").getCanonicalFile(), cacheMgr2.getArchiveFileInCache(depArtifact).getCanonicalFile());
}
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) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

Ivy (org.apache.ivy.Ivy)169 File (java.io.File)147 Test (org.junit.Test)137 ResolveReport (org.apache.ivy.core.report.ResolveReport)102 JarFile (java.util.jar.JarFile)100 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)97 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)40 IvySettings (org.apache.ivy.core.settings.IvySettings)26 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)23 BuildException (org.apache.tools.ant.BuildException)17 Before (org.junit.Before)12 HashMap (java.util.HashMap)9 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)8 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)6 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)6 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)5 ModuleId (org.apache.ivy.core.module.id.ModuleId)5 IOException (java.io.IOException)4 ParseException (java.text.ParseException)4 Date (java.util.Date)4