org.apache.ivy.core.module.descriptor.Configuration Java Examples

The following examples show how to use org.apache.ivy.core.module.descriptor.Configuration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * 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\""));
}
 
Example #2
Source File: AbstractModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private void addExtendingConfigurations(String conf, DefaultDependencyDescriptor dd,
        boolean useDefaultMappingToGuessRightOperand) {
    Set<String> configsToAdd = new HashSet<>();
    for (Configuration config : md.getConfigurations()) {
        for (String ext : config.getExtends()) {
            if (conf.equals(ext)) {
                String configName = config.getName();
                configsToAdd.add(configName);
                addExtendingConfigurations(configName, dd,
                        useDefaultMappingToGuessRightOperand);
            }
        }
    }

    parseDepsConfs(configsToAdd.toArray(new String[configsToAdd.size()]),
            dd, useDefaultMappingToGuessRightOperand);
}
 
Example #3
Source File: XmlModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected static void printConfiguration(Configuration conf, PrintWriter out) {
    out.print("<conf");
    out.print(" name=\"" + XMLHelper.escape(conf.getName()) + "\"");
    out.print(" visibility=\"" + XMLHelper.escape(conf.getVisibility().toString()) + "\"");
    if (conf.getDescription() != null) {
        out.print(" description=\"" + XMLHelper.escape(conf.getDescription()) + "\"");
    }
    String[] exts = conf.getExtends();
    if (exts.length > 0) {
        out.print(listToPrefixedString(exts, " extends=\""));
    }
    if (!conf.isTransitive()) {
        out.print(" transitive=\"false\"");
    }
    if (conf.getDeprecated() != null) {
        out.print(" deprecated=\"" + XMLHelper.escape(conf.getDeprecated()) + "\"");
    }
    printExtraAttributes(conf, out, " ");
    out.println("/>");
}
 
Example #4
Source File: OSGiManifestParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() throws Exception {
    ModuleDescriptor md = OSGiManifestParser.getInstance().parseDescriptor(settings,
        getClass().getResource("MANIFEST_classpath.MF"), true);
    assertNotNull(md);
    assertEquals("bundle", md.getModuleRevisionId().getOrganisation());
    assertEquals("org.apache.ivy.test", md.getModuleRevisionId().getName());
    assertEquals("1.0.0", md.getModuleRevisionId().getRevision());

    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(new Configuration("default"),
            new Configuration("optional"), new Configuration("transitive-optional")),
        Arrays.asList(md.getConfigurations()));

    assertEquals(0, md.getAllArtifacts().length);

    assertNotNull(md.getDependencies());
    assertEquals(0, md.getDependencies().length);
}
 
Example #5
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #6
Source File: XmlModuleDescriptorWriterTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * 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="));
}
 
Example #7
Source File: XmlModuleDescriptorWriterTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Test that the transitive attribute is written for non-transitive configurations.
 *
 * <code>&lt;conf ... transitive="false" ... /&gt;</code>
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1207">IVY-1207</a>
 */
@Test
public void testTransitiveAttributeForNonTransitiveConfs() throws Exception {
    // Given a ModuleDescriptor with a non-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, false, null);
    md.addConfiguration(conf);

    // When the ModuleDescriptor is written
    XmlModuleDescriptorWriter.write(md, LICENSE, dest);

    // Then the transitive attribute must be set to false
    String output = FileUtil.readEntirely(dest);
    String writtenConf = output.substring(output.indexOf("<configurations>") + 16,
        output.indexOf("</configurations>")).trim();
    assertTrue("Transitive attribute not set to false: " + writtenConf,
            writtenConf.contains("transitive=\"false\""));
}
 
Example #8
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoPublication() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-nopublication.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals("myrev", md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    assertEquals(pubdate, md.getPublicationDate());

    assertNotNull(md.getConfigurations());
    assertEquals(Collections.singletonList(new Configuration("default")),
        Arrays.asList(md.getConfigurations()));

    assertNotNull(md.getArtifacts("default"));
    assertEquals(1, md.getArtifacts("default").length);

    assertNotNull(md.getDependencies());
    assertEquals(1, md.getDependencies().length);
}
 
Example #9
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-simple.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals(Ivy.getWorkingRevision(), 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);
}
 
Example #10
Source File: IvyNode.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Deprecated
public void discardConf(String rootModuleConf, String conf) {
    Set<String> depConfs = usage.addAndGetConfigurations(rootModuleConf);
    if (md == null) {
        depConfs.remove(conf);
    } else {
        // remove all given dependency configurations to the set + extended ones
        Configuration c = md.getConfiguration(conf);
        if (conf == null) {
            Message.warn("unknown configuration in " + getId() + ": " + conf);
        } else {
            // recursive remove of extended configurations
            for (String ext : c.getExtends()) {
                discardConf(rootModuleConf, ext);
            }
            depConfs.remove(c.getName());
        }
    }
}
 
Example #11
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #12
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testImportConfigurationsWithExtendOtherConfigs() throws Exception {
    // import configurations and default mapping
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-configextendsothers2.xml"), true);
    assertNotNull(md);

    // has an 'all-public' configuration
    Configuration allPublic = md.getConfiguration("all-public");
    assertNotNull(allPublic);

    // 'all-public' extends all other public configurations
    String[] allPublicExt = allPublic.getExtends();
    assertEquals(Arrays.asList("default", "test", "extra"),
        Arrays.asList(allPublicExt));
}
 
Example #13
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug60() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-bug60.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals("myrev", md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    assertEquals(pubdate, md.getPublicationDate());

    assertEquals(Collections.singletonList(new Configuration("default")),
        Arrays.asList(md.getConfigurations()));

    assertArtifacts(md.getArtifacts("default"), new String[] {"myartifact1", "myartifact2"});
}
 
Example #14
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoArtifact() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-noartifact.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals(Ivy.getWorkingRevision(), 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(0, md.getArtifacts("default").length);

    assertNotNull(md.getDependencies());
    assertEquals(0, md.getDependencies().length);
}
 
Example #15
Source File: AbstractModuleDescriptorParserTester.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected void assertConf(ModuleDescriptor md, String name, String desc, Visibility visibility,
        String[] exts) {
    Configuration conf = md.getConfiguration(name);
    assertNotNull("configuration not found: " + name, conf);
    assertEquals(name, conf.getName());
    assertEquals(desc, conf.getDescription());
    assertEquals(visibility, conf.getVisibility());
    assertEquals(Arrays.asList(exts), Arrays.asList(conf.getExtends()));
}
 
Example #16
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportConfigurations1() throws Exception {
    // import configurations
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-configurations-import1.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")));
}
 
Example #17
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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")));
}
 
Example #18
Source File: IvyNodeCallers.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void addConfiguration(String callerConf, String[] dependencyConfs) {
    updateConfs(callerConf, dependencyConfs);
    Configuration conf = md.getConfiguration(callerConf);
    if (conf != null) {
        String[] confExtends = conf.getExtends();
        if (confExtends != null) {
            for (String confExtend : confExtends) {
                addConfiguration(confExtend, dependencyConfs);
            }
        }
    }
}
 
Example #19
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportConfigurations2() throws Exception {
    // import configurations and add another one
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-configurations-import2.xml"), true);
    assertNotNull(md);

    // should have imported configurations and added the one defined in the file itself
    assertNotNull(md.getConfigurations());
    assertEquals(
        Arrays.asList(new Configuration("conf1", PUBLIC, "", new String[0], true, null),
                new Configuration("conf2", PRIVATE, "", new String[0], true, null),
                new Configuration("conf3", PUBLIC, "", 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: conf2,conf3->*
    dd = getDependency(dependencies, "mymodule2");
    assertEquals(new HashSet<>(Arrays.asList("conf2", "conf3")),
            new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
    assertEquals(Collections.singletonList("*"),
        Arrays.asList(dd.getDependencyConfigurations("conf2")));
    assertEquals(Collections.singletonList("*"),
        Arrays.asList(dd.getDependencyConfigurations("conf3")));
}
 
Example #20
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportConfigurations3() throws Exception {
    // import configurations and default mapping
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-configurations-import3.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 defined in imported file: *->@
    DependencyDescriptor dd = getDependency(dependencies, "mymodule1");
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("conf1"),
        Arrays.asList(dd.getDependencyConfigurations("conf1")));
    assertEquals(Collections.singletonList("conf2"),
        Arrays.asList(dd.getDependencyConfigurations("conf2")));

    // confs def: conf1->*
    dd = getDependency(dependencies, "mymodule2");
    assertEquals(Collections.singletonList("conf1"),
        Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("*"),
        Arrays.asList(dd.getDependencyConfigurations("conf1")));
}
 
Example #21
Source File: AbstractModuleDescriptorBackedMetaData.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DefaultConfigurationMetaData populateConfigurationFromDescriptor(String name) {
    Configuration descriptorConfiguration = moduleDescriptor.getConfiguration(name);
    if (descriptorConfiguration == null) {
        return null;
    }
    Set<String> hierarchy = new LinkedHashSet<String>();
    hierarchy.add(name);
    for (String parent : descriptorConfiguration.getExtends()) {
        hierarchy.addAll(getConfiguration(parent).hierarchy);
    }
    DefaultConfigurationMetaData configuration = new DefaultConfigurationMetaData(name, descriptorConfiguration, hierarchy);
    configurations.put(name, configuration);
    return configuration;
}
 
Example #22
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtendOtherConfigs() throws Exception {
    // import configurations and default mapping
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-configextendsothers1.xml"), true);
    assertNotNull(md);

    // has an 'all-public' configuration
    Configuration allPublic = md.getConfiguration("all-public");
    assertNotNull(allPublic);

    // 'all-public' extends all other public configurations
    String[] allPublicExt = allPublic.getExtends();
    assertEquals(Arrays.asList("default", "test"), Arrays.asList(allPublicExt));
}
 
Example #23
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #24
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtendsDescription() throws Exception {
    // descriptor specifies that only parent description should be included
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-extends-description.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 merged.
    assertEquals("Parent module description.", md.getDescription());

    // verify that the parent configurations were ignored.
    final Configuration[] expectedConfs = {new Configuration("default")};
    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(Collections.singletonList("default"),
        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());
}
 
Example #25
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtendsDescriptionWithOverride() throws Exception {
    // descriptor specifies that only parent description should be included
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-extends-description-override.xml"), true);
    assertNotNull(md);

    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());

    // child description should always be preferred, even if extendType="description"
    assertEquals("Child description overrides parent.", md.getDescription());

    // verify that the parent configurations were ignored.
    final Configuration[] expectedConfs = {new Configuration("default")};
    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(Collections.singletonList("default"),
        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());
}
 
Example #26
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that when the <code>location</code> attribute of the <code>extends</code> element of
 * a module descriptor file, includes an {@link File#isAbsolute() absolute path} with
 * characters that {@link java.net.URI} considers as encoded characters (for example,
 * <code>%2F</code>) then the module descriptor and the location of the parent descriptor
 * are resolved and parsed correctly.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1562">IVY-1562</a>
 */
@Test
public void testExtendsAbsoluteLocation() throws Exception {
    final URL ivyXML = this.getClass().getResource("foo%2Fbar/hello/test-ivy-extends-absolute.xml");
    assertNotNull("Ivy xml file is missing", ivyXML);
    final URL parentIvyXML = this.getClass().getResource("foo%2Fbar/parent-ivy.xml");
    assertNotNull("Parent Ivy xml file is missing", parentIvyXML);
    // the ivy xml references a parent ivy xml via extends "location" and expects the parent
    // ivy to be present at a location under java.io.tmpdir, so we copy over the parent ivy
    // file over there
    final Path targetDir = Paths.get(System.getProperty("java.io.tmpdir"), "foo%2Fbar");
    Files.createDirectories(targetDir);
    final Path parentIvyXMLPath = Paths.get(targetDir.toString(), "parent-ivy.xml");
    try (final InputStream is = parentIvyXML.openStream()) {
        Files.copy(is, parentIvyXMLPath, StandardCopyOption.REPLACE_EXISTING);
    }
    assertTrue("Parent ivy xml file wasn't copied", Files.isRegularFile(parentIvyXMLPath));
    try {
        // now start parsing the Ivy xml
        final ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyXML, true);
        assertNotNull("Parsed module descriptor is null", md);
        assertEquals("Unexpected org for the parsed module descriptor", "myorg", md.getModuleRevisionId().getOrganisation());
        assertEquals("Unexpected module name for the parsed module descriptor", "mymodule", md.getModuleRevisionId().getName());
        assertEquals("Unexpected revision for the parsed module descriptor", "1.0.0", md.getModuleRevisionId().getRevision());

        final Configuration[] confs = md.getConfigurations();
        assertNotNull("No configurations found in module descriptor", confs);
        assertEquals("Unexpected number of configurations found in module descriptor", 3, confs.length);

        final Set<String> expectedConfs = new HashSet<>(Arrays.asList("parent-conf1", "parent-conf2", "conf2"));
        for (final Configuration conf : confs) {
            assertNotNull("One of the configurations was null in module descriptor", conf);
            assertTrue("Unexpected configuration " + conf.getName() + " found in parsed module descriptor", expectedConfs.remove(conf.getName()));
        }
        assertTrue("Missing configurations " + expectedConfs + " from the parsed module descriptor", expectedConfs.isEmpty());
    } finally {
        // clean up the copied over file
        Files.delete(parentIvyXMLPath);
    }
}
 
Example #27
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example #28
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * 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->@()\""));
}
 
Example #29
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * 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\""));
}
 
Example #30
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * 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/"));
}