Search in sources :

Example 6 with Configuration

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

the class XmlModuleDescriptorWriter method printConfigurations.

private static void printConfigurations(ModuleDescriptor md, PrintWriter out) {
    Configuration[] confs = md.getConfigurations();
    if (confs.length > 0) {
        out.println("\t<configurations>");
        for (Configuration conf : confs) {
            out.print("\t\t");
            printConfiguration(conf, out);
        }
        out.println("\t</configurations>");
    }
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration)

Example 7 with Configuration

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

the class XmlModuleUpdaterTest method testMergedUpdateWithExtendsAndConfigurationsInheritance.

/**
 * Test case for IVY-1437.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1437">IVY-1437</a>
 */
@Test
public void testMergedUpdateWithExtendsAndConfigurationsInheritance() throws Exception {
    URL url = XmlModuleUpdaterTest.class.getResource("test-extends-configurations-inherit.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", 2, configurations.length);
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains("configurations defaultconf=\"compile\" defaultconfmapping=\"*->default\""));
    assertTrue(updatedXml.contains("dependencies defaultconf=\"compile\" defaultconfmapping=\"*->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 8 with Configuration

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

the class XmlModuleUpdaterTest method testMergedUpdateWithInclude.

/**
 * Test case for IVY-1315.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1315">IVY-1315</a>
 */
@Test
public void testMergedUpdateWithInclude() 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));
    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", 6, configurations.length);
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains("dependencies defaultconf=\"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 9 with Configuration

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

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations1.

@Test
public void testUpdateWithExcludeConfigurations1() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs1.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);
    // test the number of configurations
    Configuration[] configs = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configs);
    assertEquals("Number of configurations incorrect", 3, configs.length);
    // test that the correct configuration has been removed
    assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2"));
    // test that the other configurations aren't removed
    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 10 with Configuration

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

the class ResolveReport method toFixedModuleDescriptor.

public ModuleDescriptor toFixedModuleDescriptor(IvySettings settings, List<ModuleId> midToKeep) {
    DefaultModuleDescriptor fixedmd = new DefaultModuleDescriptor(md.getModuleRevisionId(), md.getStatus(), new Date());
    // copy namespaces
    for (Map.Entry<String, String> ns : md.getExtraAttributesNamespaces().entrySet()) {
        fixedmd.addExtraAttributeNamespace(ns.getKey(), ns.getValue());
    }
    // copy info
    fixedmd.setDescription(md.getDescription());
    fixedmd.setHomePage(md.getHomePage());
    fixedmd.getExtraInfos().addAll(md.getExtraInfos());
    // copy configurations
    List<String> resolvedConfs = Arrays.asList(getConfigurations());
    for (String conf : resolvedConfs) {
        fixedmd.addConfiguration(new Configuration(conf));
    }
    // copy artifacts
    for (String conf : resolvedConfs) {
        for (Artifact a : md.getArtifacts(conf)) {
            fixedmd.addArtifact(conf, a);
        }
    }
    // add resolved dependencies
    for (IvyNode dep : dependencies) {
        ModuleRevisionId depMrid;
        boolean force;
        if (midToKeep != null && midToKeep.contains(dep.getModuleId())) {
            depMrid = dep.getId();
            force = false;
        } else {
            depMrid = dep.getResolvedId();
            force = true;
        }
        DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(fixedmd, depMrid, force, false, false);
        boolean evicted = true;
        for (String rootConf : dep.getRootModuleConfigurations()) {
            if (dep.isEvicted(rootConf)) {
                continue;
            }
            evicted = false;
            for (String targetConf : dep.getConfigurations(rootConf)) {
                dd.addDependencyConfiguration(rootConf, targetConf);
            }
        }
        if (!evicted) {
            fixedmd.addDependency(dd);
        }
    }
    return fixedmd;
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Date(java.util.Date) Artifact(org.apache.ivy.core.module.descriptor.Artifact) IvyNode(org.apache.ivy.core.resolve.IvyNode)

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