Search in sources :

Example 41 with Configuration

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

the class XmlModuleDescriptorWriterTest method testTransitiveAttributeNotWrittenForTransitiveConfs.

/**
 * Test that the transitive attribute is not written when the configuration IS transitive.
 *
 * This is the default and writing it will only add noise and cause a deviation from the known
 * behavior (before fixing IVY-1207).
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1207">IVY-1207</a>
 */
@Test
public void testTransitiveAttributeNotWrittenForTransitiveConfs() throws Exception {
    // Given a ModuleDescriptor with a transitive configuration
    DefaultModuleDescriptor md = new DefaultModuleDescriptor(new ModuleRevisionId(new ModuleId("myorg", "myname"), "1.0"), "integration", new Date());
    Configuration conf = new Configuration("conf", PUBLIC, "desc", null, true, null);
    md.addConfiguration(conf);
    // When the ModuleDescriptor is written
    XmlModuleDescriptorWriter.write(md, LICENSE, dest);
    // Then the transitive attribute must NOT be written
    String output = FileUtil.readEntirely(dest);
    String writtenConf = output.substring(output.indexOf("<configurations>") + 16, output.indexOf("</configurations>")).trim();
    assertFalse("Transitive attribute set: " + writtenConf, writtenConf.contains("transitive="));
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Date(java.util.Date) Test(org.junit.Test) PomModuleDescriptorParserTest(org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParserTest)

Example 42 with Configuration

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

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations3.

@Test
public void testUpdateWithExcludeConfigurations3() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs3.xml").toURI().toURL();
    XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] { "myconf2", "conf2" }));
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    // test the number of configurations
    Configuration[] configs = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configs);
    assertEquals("Number of configurations incorrect", 4, configs.length);
    // test that the correct configuration has been removed
    assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2"));
    assertNull("conf2 hasn't been removed", updatedMd.getConfiguration("conf2"));
    // test that the other configurations aren't removed
    assertNotNull("conf1 has been removed", updatedMd.getConfiguration("conf1"));
    assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1"));
    assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3"));
    assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4"));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 43 with Configuration

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

the class XmlModuleUpdaterTest method testMergedUpdateWithExtendsAndDefaultConfMappings.

/**
 * Test case for IVY-1420.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1420">IVY-1420</a>
 */
@Test
public void testMergedUpdateWithExtendsAndDefaultConfMappings() throws Exception {
    URL url = XmlModuleUpdaterTest.class.getResource("test-extends-configurations-defaultconfmapping.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);
    Configuration[] configurations = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configurations);
    assertEquals("Number of configurations is incorrect", 3, configurations.length);
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains("configurations defaultconfmapping=\"conf1,default->@()\""));
    assertTrue(updatedXml.contains("dependencies defaultconfmapping=\"conf1,default->@()\""));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 44 with Configuration

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

the class XmlModuleUpdaterTest method testMergedUpdateWithIncludeAndExcludedConf.

/**
 * Test case for IVY-1419.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1419">IVY-1419</a>
 */
@Test
public void testMergedUpdateWithIncludeAndExcludedConf() throws Exception {
    URL url = XmlModuleUpdaterTest.class.getResource("test-update-excludedconfs6.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).setConfsToExclude(new String[] { "conf1" }));
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    Configuration[] configurations = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configurations);
    assertEquals("Number of configurations is incorrect", 5, configurations.length);
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains("dependencies/"));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 45 with Configuration

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

the class AbstractWorkspaceResolver method createWorkspaceMd.

protected WorkspaceModuleDescriptor createWorkspaceMd(ModuleDescriptor md) {
    DefaultWorkspaceModuleDescriptor newMd = new DefaultWorkspaceModuleDescriptor(md.getModuleRevisionId(), "release", null, true);
    newMd.addConfiguration(new Configuration(ModuleDescriptor.DEFAULT_CONFIGURATION));
    newMd.setLastModified(System.currentTimeMillis());
    newMd.setDescription(md.getDescription());
    newMd.setHomePage(md.getHomePage());
    newMd.setLastModified(md.getLastModified());
    newMd.setPublicationDate(md.getPublicationDate());
    newMd.setResolvedPublicationDate(md.getResolvedPublicationDate());
    newMd.setStatus(md.getStatus());
    Configuration[] allConfs = md.getConfigurations();
    for (Artifact af : createWorkspaceArtifacts(md)) {
        if (allConfs.length == 0) {
            newMd.addArtifact(ModuleDescriptor.DEFAULT_CONFIGURATION, af);
        } else {
            for (Configuration conf : allConfs) {
                newMd.addConfiguration(conf);
                newMd.addArtifact(conf.getName(), af);
            }
        }
    }
    for (DependencyDescriptor dependency : md.getDependencies()) {
        newMd.addDependency(dependency);
    }
    for (ExcludeRule excludeRule : md.getAllExcludeRules()) {
        newMd.addExcludeRule(excludeRule);
    }
    newMd.getExtraInfos().addAll(md.getExtraInfos());
    for (License license : md.getLicenses()) {
        newMd.addLicense(license);
    }
    return newMd;
}
Also used : DefaultWorkspaceModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultWorkspaceModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) License(org.apache.ivy.core.module.descriptor.License) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact)

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