Search in sources :

Example 16 with Configuration

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

the class XmlModuleDescriptorParserTest method testEmptyDependencies.

@Test
public void testEmptyDependencies() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-empty-dependencies.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals("myrev", md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());
    assertNotNull(md.getConfigurations());
    assertEquals(Collections.singletonList(new Configuration("default")), Arrays.asList(md.getConfigurations()));
    assertNotNull(md.getArtifacts("default"));
    assertEquals(1, md.getArtifacts("default").length);
    assertEquals("mymodule", md.getArtifacts("default")[0].getName());
    assertEquals("jar", md.getArtifacts("default")[0].getType());
    assertNotNull(md.getDependencies());
    assertEquals(0, md.getDependencies().length);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) Test(org.junit.Test)

Example 17 with Configuration

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

the class XmlModuleDescriptorParserTest method testImportConfigurations5.

@Test
public void testImportConfigurations5() throws Exception {
    // import configurations
    settings.setVariable("base.dir", new File(".").getAbsolutePath());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-configurations-import5.xml"), true);
    assertNotNull(md);
    // should have imported configurations
    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(new Configuration("conf1", PUBLIC, "", new String[0], true, null), new Configuration("conf2", PRIVATE, "", new String[0], true, null)), Arrays.asList(md.getConfigurations()));
    DependencyDescriptor[] dependencies = md.getDependencies();
    assertNotNull(dependencies);
    assertEquals(2, dependencies.length);
    // no conf def => defaults to defaultConf: *->*
    DependencyDescriptor dd = getDependency(dependencies, "mymodule1");
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getDependencyConfigurations("conf1")));
    // confs def: conf1->*
    dd = getDependency(dependencies, "mymodule2");
    assertEquals(Collections.singletonList("conf1"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getDependencyConfigurations("conf1")));
}
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) File(java.io.File) Test(org.junit.Test)

Example 18 with Configuration

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

the class XmlModuleDescriptorParserTest method testExtendsAll.

@Test
public void testExtendsAll() throws Exception {
    Message.setDefaultLogger(new DefaultMessageLogger(99));
    // default extends type is 'all' when no extendsType attribute is specified.
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-extends-all.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) DefaultMessageLogger(org.apache.ivy.util.DefaultMessageLogger) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 19 with Configuration

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

the class XmlModuleDescriptorParserTest method testExtendsConfigurations.

@Test
public void testExtendsConfigurations() throws Exception {
    // descriptor specifies that only parent configurations should be included
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-extends-configurations.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());
    // verify that the parent description was ignored.
    assertEquals("", 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 dependencies were ignored.
    DependencyDescriptor[] deps = md.getDependencies();
    assertNotNull(deps);
    assertEquals(1, deps.length);
    assertEquals(Arrays.asList("conf1", "conf2"), Arrays.asList(deps[0].getModuleConfigurations()));
    ModuleRevisionId dep = deps[0].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) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 20 with Configuration

use of org.apache.ivy.core.module.descriptor.Configuration 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)

Aggregations

Configuration (org.apache.ivy.core.module.descriptor.Configuration)45 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)30 Test (org.junit.Test)29 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)17 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)16 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)15 Artifact (org.apache.ivy.core.module.descriptor.Artifact)10 Date (java.util.Date)9 URL (java.net.URL)7 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 BasicResource (org.apache.ivy.plugins.repository.BasicResource)6 File (java.io.File)5 Map (java.util.Map)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)4 GregorianCalendar (java.util.GregorianCalendar)3 License (org.apache.ivy.core.module.descriptor.License)3 IOException (java.io.IOException)2