Search in sources :

Example 66 with Ivy

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

the class SearchTest method testListModulesWithExtraAttributes.

@Test
public void testListModulesWithExtraAttributes() throws ParseException, IOException {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/IVY-1128/ivysettings.xml"));
    IvySettings settings = ivy.getSettings();
    Map<String, String> extendedAttributes = new HashMap<>();
    extendedAttributes.put("e:att1", "extraatt");
    extendedAttributes.put("e:att2", "extraatt2");
    ModuleRevisionId criteria = ModuleRevisionId.newInstance("test", "a", "*", extendedAttributes);
    ModuleRevisionId[] mrids = ivy.listModules(criteria, settings.getMatcher(PatternMatcher.REGEXP));
    assertEquals(2, mrids.length);
    ModuleRevisionId mrid = mrids[0];
    assertEquals("extraatt", mrid.getExtraAttribute("att1"));
    Map<String, String> extraAttributes = mrid.getExtraAttributes();
    assertEquals(2, extraAttributes.size());
    assertTrue(extraAttributes.toString(), extraAttributes.keySet().contains("att1"));
    assertTrue(extraAttributes.toString(), extraAttributes.keySet().contains("att2"));
    Map<String, String> qualifiedExtraAttributes = mrid.getQualifiedExtraAttributes();
    assertEquals(2, qualifiedExtraAttributes.size());
    assertTrue(qualifiedExtraAttributes.toString(), qualifiedExtraAttributes.keySet().contains("e:att1"));
    assertTrue(qualifiedExtraAttributes.toString(), qualifiedExtraAttributes.keySet().contains("e:att2"));
}
Also used : HashMap(java.util.HashMap) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Ivy(org.apache.ivy.Ivy) File(java.io.File) Test(org.junit.Test)

Example 67 with Ivy

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

the class SearchTest method testListInMavenRepo.

@Test
public void testListInMavenRepo() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/m2/ivysettings.xml").toURI().toURL());
    Map<String, Object> otherTokenValues = new HashMap<>();
    otherTokenValues.put(IvyPatternHelper.ORGANISATION_KEY, "org.apache");
    otherTokenValues.put(IvyPatternHelper.MODULE_KEY, "test-metadata");
    String[] revs = ivy.listTokenValues(IvyPatternHelper.REVISION_KEY, otherTokenValues);
    assertEquals(new HashSet<>(Arrays.asList("1.0", "1.1")), new HashSet<>(Arrays.asList(revs)));
}
Also used : HashMap(java.util.HashMap) Ivy(org.apache.ivy.Ivy) File(java.io.File) Test(org.junit.Test)

Example 68 with Ivy

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

the class IvySettingsTest method testVariables.

@Test
public void testVariables() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configureDefault();
    IvySettings settings = ivy.getSettings();
    // test set
    assertNull(settings.getVariable("foo"));
    settings.setVariable("foo", "bar", false, null, null);
    assertEquals("bar", settings.getVariable("foo"));
    // test no override
    settings.setVariable("foo", "wrong", false, null, null);
    assertEquals("bar", settings.getVariable("foo"));
    // test override
    settings.setVariable("foo", "right", true, null, null);
    assertEquals("right", settings.getVariable("foo"));
    // test ifset no exist
    assertNull(settings.getVariable("bar"));
    settings.setVariable("bar", "foo", true, "noexist", null);
    assertNull(settings.getVariable("bar"));
    // test ifset exist
    settings.setVariable("bar", "foo", true, "foo", null);
    assertEquals("foo", settings.getVariable("bar"));
    // test unlessset exist
    assertNull(settings.getVariable("thing"));
    settings.setVariable("thing", "foo", true, null, "foo");
    assertNull(settings.getVariable("thing"));
    // test unlessset noexist
    settings.setVariable("thing", "foo", true, null, "noexist");
    assertEquals("foo", settings.getVariable("thing"));
    // test ifset no exist and unlessset exist
    assertNull(settings.getVariable("ivy"));
    settings.setVariable("ivy", "rocks", true, "noexist", "foo");
    assertNull(settings.getVariable("ivy"));
    // test ifset no exist and unlessset no exist
    settings.setVariable("ivy", "rocks", true, "noexist", "noexist");
    assertNull(settings.getVariable("ivy"));
    // test ifset exist and unlessset exist
    settings.setVariable("ivy", "rocks", true, "foo", "foo");
    assertNull(settings.getVariable("ivy"));
    // test ifset exist and unlessset no exist
    settings.setVariable("ivy", "rocks", true, "foo", "noexist");
    assertEquals("rocks", settings.getVariable("ivy"));
}
Also used : Ivy(org.apache.ivy.Ivy) Test(org.junit.Test)

Example 69 with Ivy

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

the class ResolveTest method testVersionRange2.

@Test
public void testVersionRange2() throws Exception {
    // mod 1.4 depends on mod1.2 [1.5,2.0[
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/ivysettings.xml"));
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml"), getResolveOptions(new String[] { "default" }));
    assertTrue(report.hasError());
}
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 70 with Ivy

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

the class ResolveTest method testDynamicFromCacheWithMDAfterOneTTLExpiration.

@Test
public void testDynamicFromCacheWithMDAfterOneTTLExpiration() throws Exception {
    // same as above, but this time we make a second resolve after ttl expiration before trying
    // to use the cached resolved information
    // mod1.4;1.0.2 depends on mod1.2;[1.0,2.0[
    Ivy ivy = ivyTestCache();
    ivy.getSettings().setVariable("ivy.cache.ttl.default", "500ms", true);
    // set up repository
    FileUtil.forceDelete(new File("build/testCache2"));
    FileUtil.copy(ResolveTest.class.getResourceAsStream("ivy-mod1.2-1.5.xml"), new File("build/testCache2/ivy-mod1.2-1.5.xml"), null);
    FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), new File("build/testCache2/mod1.2-1.5.jar"), null);
    // we first do a simple resolve so that module is in cache
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"), getResolveOptions(new String[] { "*" }));
    assertFalse(report.hasError());
    assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.5")), report.getConfigurationReport("default").getModuleRevisionIds());
    // now we wait for ttl expiration
    Thread.sleep(700);
    // we resolve again, it should work fine
    report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"), getResolveOptions(new String[] { "*" }));
    assertFalse(report.hasError());
    assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.5")), report.getConfigurationReport("default").getModuleRevisionIds());
    // now we clean the repository to simulate repo not available (network pb for instance)
    FileUtil.forceDelete(new File("build/testCache2"));
    // now do a new resolve: it should use cached data
    report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"), getResolveOptions(new String[] { "*" }));
    assertFalse(report.hasError());
    assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.5")), report.getConfigurationReport("default").getModuleRevisionIds());
}
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)

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