Search in sources :

Example 11 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class ChainResolverTest method testFixedWithDefault.

@Test
public void testFixedWithDefault() throws Exception {
    ChainResolver chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);
    chain.setLatestStrategy(new LatestRevisionStrategy());
    MockResolver[] resolvers = new MockResolver[] { MockResolver.buildMockResolver(settings, "1", false, null), MockResolver.buildMockResolver(settings, "2", true, ModuleRevisionId.newInstance("org", "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime(), true), // default
    MockResolver.buildMockResolver(settings, "3", false, null), MockResolver.buildMockResolver(settings, "4", true, ModuleRevisionId.newInstance("org", "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // not default -> should be the one kept
    MockResolver.buildMockResolver(settings, "5", false, null) };
    for (MockResolver resolver : resolvers) {
        chain.add(resolver);
    }
    assertResolversSizeAndNames(chain, resolvers.length);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org", "mod", "4"), false);
    ResolvedModuleRevision rmr = chain.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals("4", rmr.getResolver().getName());
    List<DependencyDescriptor> ddAsList = Collections.<DependencyDescriptor>singletonList(dd);
    for (int i = 0; i < 4; i++) {
        assertEquals("invalid asked dependencies for " + resolvers[i], ddAsList, resolvers[i].askedDeps);
    }
    for (int i = 4; i < resolvers.length; i++) {
        assertTrue("invalid asked dependencies for " + resolvers[i], resolvers[i].askedDeps.isEmpty());
    }
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) GregorianCalendar(java.util.GregorianCalendar) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) LatestRevisionStrategy(org.apache.ivy.plugins.latest.LatestRevisionStrategy) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Example 12 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations5.

@Test
public void testUpdateWithExcludeConfigurations5() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs5.xml").toURI().toURL();
    XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] { "myconf2" }));
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    DependencyDescriptor[] deps = updatedMd.getDependencies();
    assertNotNull("Dependencies shouldn't be null", deps);
    assertEquals("Number of dependencies is incorrect", 8, deps.length);
    // check that none of the dependencies contains myconf2
    for (DependencyDescriptor dep : deps) {
        String name = dep.getDependencyId().getName();
        assertFalse("Dependency " + name + " shouldn't have myconf2 as module configuration", Arrays.asList(dep.getModuleConfigurations()).contains("myconf2"));
        assertEquals("Dependency " + name + " shouldn't have a dependency artifact for configuration myconf2", 0, dep.getDependencyArtifacts("myconf2").length);
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 13 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class XmlModuleUpdaterTest method testMergedUpdateWithExtendsAndExcludes.

/**
 * Test case for IVY-1356.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1356">IVY-1356</a>
 */
@Test
public void testMergedUpdateWithExtendsAndExcludes() throws Exception {
    URL url = XmlModuleUpdaterTest.class.getResource("test-extends-dependencies-exclude.xml");
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev").setMerge(true).setMergedDescriptor(md));
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    DependencyDescriptor[] deps = updatedMd.getDependencies();
    assertNotNull("Dependencies shouldn't be null", deps);
    assertEquals("Number of dependencies is incorrect", 2, deps.length);
    // test indentation
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains(XmlModuleDescriptorUpdater.LINE_SEPARATOR + "\t\t<dependency org=\"myorg\" name=\"mymodule1\" rev=\"1.0\" conf=\"default->default\"/>" + XmlModuleDescriptorUpdater.LINE_SEPARATOR));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) URL(java.net.URL) Test(org.junit.Test)

Example 14 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class ChainResolverTest method testLatestRevisionResolve.

@Test
public void testLatestRevisionResolve() throws Exception {
    ChainResolver chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);
    chain.setLatestStrategy(new LatestRevisionStrategy());
    MockResolver[] resolvers = new MockResolver[] { MockResolver.buildMockResolver(settings, "1", true, ModuleRevisionId.newInstance("org", "mod", "1"), new GregorianCalendar(2005, 1, 20).getTime()), MockResolver.buildMockResolver(settings, "2", false, null), MockResolver.buildMockResolver(settings, "3", true, ModuleRevisionId.newInstance("org", "mod", "2"), new GregorianCalendar(2005, 1, 25).getTime()), MockResolver.buildMockResolver(settings, "4", false, null), MockResolver.buildMockResolver(settings, "5", true, ModuleRevisionId.newInstance("org", "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // latest -> should the one kept
    MockResolver.buildMockResolver(settings, "6", true, ModuleRevisionId.newInstance("org", "mod", "3"), new GregorianCalendar(2005, 1, 18).getTime()), MockResolver.buildMockResolver(settings, "7", false, null) };
    for (MockResolver resolver : resolvers) {
        chain.add(resolver);
    }
    assertResolversSizeAndNames(chain, resolvers.length);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org", "mod", "latest.integration"), false);
    ResolvedModuleRevision rmr = chain.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals("5", rmr.getResolver().getName());
    List<DependencyDescriptor> ddAsList = Collections.<DependencyDescriptor>singletonList(dd);
    for (MockResolver resolver : resolvers) {
        assertEquals(ddAsList, resolver.askedDeps);
    }
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) GregorianCalendar(java.util.GregorianCalendar) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) LatestRevisionStrategy(org.apache.ivy.plugins.latest.LatestRevisionStrategy) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Example 15 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class ChainResolverTest method testLatestTimeResolve.

@Test
public void testLatestTimeResolve() throws Exception {
    ChainResolver chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);
    settings.setDefaultLatestStrategy(new LatestTimeStrategy());
    MockResolver[] resolvers = new MockResolver[] { MockResolver.buildMockResolver(settings, "1", true, new GregorianCalendar(2005, 1, 20).getTime()), MockResolver.buildMockResolver(settings, "2", false, null), MockResolver.buildMockResolver(settings, "3", true, new GregorianCalendar(2005, 1, 25).getTime()), // younger -> should the one kept
    MockResolver.buildMockResolver(settings, "4", false, null), MockResolver.buildMockResolver(settings, "5", true, new GregorianCalendar(2005, 1, 22).getTime()), MockResolver.buildMockResolver(settings, "6", true, new GregorianCalendar(2005, 1, 18).getTime()), MockResolver.buildMockResolver(settings, "7", false, null) };
    for (MockResolver resolver : resolvers) {
        chain.add(resolver);
    }
    assertResolversSizeAndNames(chain, resolvers.length);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org", "mod", "latest.integration"), false);
    ResolvedModuleRevision rmr = chain.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals("3", rmr.getResolver().getName());
    List<DependencyDescriptor> ddAsList = Collections.<DependencyDescriptor>singletonList(dd);
    for (MockResolver resolver : resolvers) {
        assertEquals(ddAsList, resolver.askedDeps);
    }
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) GregorianCalendar(java.util.GregorianCalendar) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) LatestTimeStrategy(org.apache.ivy.plugins.latest.LatestTimeStrategy) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Aggregations

DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)101 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)80 Test (org.junit.Test)75 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)35 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)33 File (java.io.File)26 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)26 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)25 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 IvySettings (org.apache.ivy.core.settings.IvySettings)17 Configuration (org.apache.ivy.core.module.descriptor.Configuration)15 Artifact (org.apache.ivy.core.module.descriptor.Artifact)13 ParseException (java.text.ParseException)12 IOException (java.io.IOException)11 ResolveData (org.apache.ivy.core.resolve.ResolveData)11 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)9 JarFile (java.util.jar.JarFile)7 GregorianCalendar (java.util.GregorianCalendar)6 ModuleId (org.apache.ivy.core.module.id.ModuleId)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6