Java Code Examples for org.apache.ivy.core.module.descriptor.ModuleDescriptor#getDependencies()

The following examples show how to use org.apache.ivy.core.module.descriptor.ModuleDescriptor#getDependencies() . 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: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testDependencies() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-dependencies.pom"), false);
    assertNotNull(md);

    assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"),
        md.getModuleRevisionId());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[0].getDependencyRevisionId());
    assertEquals("There is no special artifact when there is no classifier", 0,
        dds[0].getAllDependencyArtifacts().length);
}
 
Example 2
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testDependencyManagementWithScope() throws ParseException, IOException {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-dependencyMgt-with-scope.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-depMgt", "1.1"),
        md.getModuleRevisionId());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[0].getDependencyRevisionId());
    assertEquals("There is no special artifact when there is no classifier", 0,
        dds[0].getAllDependencyArtifacts().length);
    assertEquals("The number of configurations is incorrect", 1,
        dds[0].getModuleConfigurations().length);
    assertEquals("The configuration must be test", "test", dds[0].getModuleConfigurations()[0]);
}
 
Example 3
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testEjbType() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-ejb-type.pom"), false);
    assertNotNull(md);

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test-ejb-type", "1.0");
    assertEquals(mrid, md.getModuleRevisionId());

    DependencyDescriptor[] deps = md.getDependencies();
    assertNotNull(deps);
    assertEquals(1, deps.length);

    DependencyArtifactDescriptor[] artifacts = deps[0].getAllDependencyArtifacts();
    assertNotNull(artifacts);
    assertEquals(1, artifacts.length);
    assertEquals("test", artifacts[0].getName());
    assertEquals("jar", artifacts[0].getExt());
    assertEquals("ejb", artifacts[0].getType());
}
 
Example 4
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateWithComments() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/"
            + "test-with-comments.xml").toURI().toURL();
    XmlModuleDescriptorUpdater.update(settingsUrl, new BufferedOutputStream(buffer, 1024),
        getUpdateOptions("release", "mynewrev"));

    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(),
        new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0,
                false), true);

    DependencyDescriptor[] dependencies = updatedMd.getDependencies();
    assertNotNull(dependencies);
    assertEquals(3, dependencies.length);
}
 
Example 5
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDependenciesWithClassifier() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-dependencies-with-classifier.pom"), true);
    assertNotNull(md);

    assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"),
        md.getModuleRevisionId());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[0].getDependencyRevisionId());
    Map<String, String> extraAtt = Collections.singletonMap("classifier", "asl");
    assertEquals(1, dds[0].getAllDependencyArtifacts().length);
    assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0].getExtraAttributes());

    // now we verify the conversion to an Ivy file
    PomModuleDescriptorParser.getInstance().toIvyFile(
        getClass().getResource("test-dependencies-with-classifier.pom").openStream(),
        new URLResource(getClass().getResource("test-dependencies-with-classifier.pom")), dest,
        md);

    assertTrue(dest.exists());

    // the converted Ivy file should be parsable with validate=true
    ModuleDescriptor md2 = XmlModuleDescriptorParser.getInstance().parseDescriptor(
        new IvySettings(), dest.toURI().toURL(), true);

    // and the parsed module descriptor should be similar to the original
    assertNotNull(md2);
    assertEquals(md.getModuleRevisionId(), md2.getModuleRevisionId());
    dds = md2.getDependencies();
    assertEquals(1, dds[0].getAllDependencyArtifacts().length);
    assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0].getExtraAttributes());
}
 
Example 6
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testReal() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("commons-lang-1.0.pom"), false);
    assertNotNull(md);

    assertEquals(ModuleRevisionId.newInstance("commons-lang", "commons-lang", "1.0"),
        md.getModuleRevisionId());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("junit", "junit", "3.7"),
        dds[0].getDependencyRevisionId());
}
 
Example 7
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testGrandparentBomImport() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {
        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
                throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
                        .parseDescriptor(settings,
                            getClass().getResource(
                                String.format("depmgt/%s.pom", dd.getDependencyId().getName())),
                            false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("depmgt/grandchild.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);

    assertEquals(
        ModuleRevisionId.newInstance("commons-collection", "commons-collection", "1.0.5"),
        dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[1].getDependencyRevisionId());
}
 
Example 8
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithVersionPropertyAndPropertiesTag() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-version.pom"), false);
    assertNotNull(md);

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-other", "1.0"),
        dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-yet-other", "5.76"),
        dds[1].getDependencyRevisionId());
}
 
Example 9
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testOverrideParentProperties() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {
        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
                throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
                        .parseDescriptor(settings, getClass().getResource("test-version.pom"),
                            false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-override-parent-properties.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);
    // 2 are inherited from parent. Only the first one is important for this test

    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-yet-other", "5.79"),
        dds[1].getDependencyRevisionId());
}
 
Example 10
Source File: IvyDeliverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithResolveIdInAnotherBuild() throws Exception {
    // create a new build
    Project other = TestHelper.newProject();
    other.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml");
    other.setProperty("build", "build/test/deliver");

    // do a resolve in the new build
    IvyResolve resolve = new IvyResolve();
    resolve.setProject(other);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
    resolve.setResolveId("withResolveId");
    resolve.execute();

    // resolve another ivy file
    resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
    resolve.execute();

    deliver.setResolveId("withResolveId");
    deliver.setPubrevision("1.2");
    deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
    deliver.execute();

    // should have done the ivy delivering
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(
        new IvySettings(), deliveredIvyFile.toURI().toURL(), true);
    assertEquals(ModuleRevisionId.newInstance("apache", "resolve-simple", "1.2"),
        md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),
        dds[0].getDependencyRevisionId());
}
 
Example 11
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testParentProperties() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {
        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
                throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
                        .parseDescriptor(settings, getClass().getResource("test-version.pom"),
                            false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });

    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-parent-properties.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(3, dds.length);
    // 2 are inherited from parent. Only the first one is important for this test

    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-version-other", "5.76"),
        dds[0].getDependencyRevisionId());
    // present in the pom using a property defined in the parent
}
 
Example 12
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 13
Source File: IvyDeliverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for IVY-415.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-415">IVY-415</a>
 */
@Test
public void testWithExtraAttributes() throws Exception {
    project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest-extra.xml");
    IvyResolve res = new IvyResolve();
    res.setValidate(false);
    res.setProject(project);
    res.execute();

    deliver.setPubrevision("1.2");
    deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
    deliver.setValidate(false);
    deliver.execute();

    // should have done the ivy delivering
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(
        new IvySettings(), deliveredIvyFile.toURI().toURL(), false);
    assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"),
        md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(1, dds.length);
    Map<String, String> extraAtt = new HashMap<>();
    extraAtt.put("myExtraAtt", "myValue");
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2", extraAtt),
        dds[0].getDependencyRevisionId());
}
 
Example 14
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testOverrideGrandparentProperties() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {
        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
                throws ParseException {
            String resource;
            if ("test".equals(dd.getDependencyId().getName())) {
                resource = "test-parent-properties.pom";
            } else {
                resource = "test-version.pom";
            }
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
                        .parseDescriptor(settings, getClass().getResource(resource), false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });

    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-override-grandparent-properties.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(3, dds.length);

    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-version-other", "5.79"),
        dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-yet-other", "5.79"),
        dds[2].getDependencyRevisionId());
}
 
Example 15
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportConfigurationsWithWildcardAndMappingOverride() throws Exception {
    // import configurations and default mapping
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-configextendsothers3.xml"), true);
    assertNotNull(md);

    // has 2 dependencies
    DependencyDescriptor[] dependencies = md.getDependencies();
    assertNotNull(dependencies);
    assertEquals(2, dependencies.length);

    // confs dep1: all-public->all-public (mappingoverride = true)
    DependencyDescriptor dd = getDependency(dependencies, "mymodule1");
    assertEquals(Collections.singletonList("all-public"),
        Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("all-public"),
        Arrays.asList(dd.getDependencyConfigurations("all-public")));

    // confs dep2: extra->extra;all-public->all-public (mappingoverride = true)
    dd = getDependency(dependencies, "mymodule2");
    assertEquals(Arrays.asList("extra", "all-public"),
        Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("extra"),
        Arrays.asList(dd.getDependencyConfigurations("extra")));
    assertEquals(Collections.singletonList("all-public"),
        Arrays.asList(dd.getDependencyConfigurations("all-public")));
}
 
Example 16
Source File: IvyBuildList.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Search in the moduleIdMap modules depending on node, add them to the toKeep set and process
 * them recursively.
 *
 * @param node
 *            the node to be processed
 * @param toKeep
 *            the set of ModuleDescriptors that should be kept
 * @param moduleIdMap
 *            reference mapping of moduleId to ModuleDescriptor that are part of the BuildList
 */
private void processFilterNodeFromLeaf(ModuleDescriptor node, Set<ModuleDescriptor> toKeep,
        Map<ModuleId, ModuleDescriptor> moduleIdMap) {
    for (ModuleDescriptor md : moduleIdMap.values()) {
        for (DependencyDescriptor dep : md.getDependencies()) {
            if (node.getModuleRevisionId().getModuleId().equals(dep.getDependencyId())
                    && !toKeep.contains(md)) {
                toKeep.add(md);
                if (!getOnlydirectdep()) {
                    processFilterNodeFromLeaf(md, toKeep, moduleIdMap);
                }
            }
        }
    }
}
 
Example 17
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Test
public void testExclusion() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-exclusion.pom"), false);
    assertNotNull(md);

    assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"),
        md.getModuleRevisionId());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(4, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[0].getDependencyRevisionId());
    assertEquals(new HashSet<>(Arrays.asList("compile", "runtime")),
        new HashSet<>(Arrays.asList(dds[0].getModuleConfigurations())));
    assertEquals(new HashSet<>(Arrays.asList("master(*)", "compile(*)")),
        new HashSet<>(Arrays.asList(dds[0].getDependencyConfigurations("compile"))));
    assertEquals(new HashSet<>(Collections.singletonList("runtime(*)")),
        new HashSet<>(Arrays.asList(dds[0].getDependencyConfigurations("runtime"))));
    assertEquals(0, dds[0].getAllExcludeRules().length);

    assertEquals(ModuleRevisionId.newInstance("dom4j", "dom4j", "1.6"),
        dds[1].getDependencyRevisionId());
    assertEquals(new HashSet<>(Arrays.asList("compile", "runtime")),
        new HashSet<>(Arrays.asList(dds[1].getModuleConfigurations())));
    assertEquals(new HashSet<>(Arrays.asList("master(*)", "compile(*)")),
        new HashSet<>(Arrays.asList(dds[1].getDependencyConfigurations("compile"))));
    assertEquals(new HashSet<>(Collections.singletonList("runtime(*)")),
        new HashSet<>(Arrays.asList(dds[1].getDependencyConfigurations("runtime"))));
    assertDependencyModulesExcludes(dds[1], new String[] {"compile"},
        new String[] {"jaxme-api", "jaxen"});
    assertDependencyModulesExcludes(dds[1], new String[] {"runtime"},
        new String[] {"jaxme-api", "jaxen"});

    assertEquals(ModuleRevisionId.newInstance("cglib", "cglib", "2.0.2"),
        dds[2].getDependencyRevisionId());
    assertEquals(new HashSet<>(Arrays.asList("compile", "runtime")),
        new HashSet<>(Arrays.asList(dds[2].getModuleConfigurations())));
    assertEquals(new HashSet<>(Arrays.asList("master(*)", "compile(*)")),
        new HashSet<>(Arrays.asList(dds[2].getDependencyConfigurations("compile"))));
    assertEquals(new HashSet<>(Collections.singletonList("runtime(*)")),
        new HashSet<>(Arrays.asList(dds[2].getDependencyConfigurations("runtime"))));
    assertEquals(0, dds[2].getAllExcludeRules().length);

    // test for IVY-1531 (where the pom.xml can have a exclusion for groupid=* and artifactid=*,
    // implying transitive=false, in Ivy land)
    final DependencyDescriptor excludeAllTransitiveDepsDescriptor = dds[3];
    assertEquals(ModuleRevisionId.newInstance("org.owasp.esapi", "esapi", "2.1.0"),
        excludeAllTransitiveDepsDescriptor.getDependencyRevisionId());
    assertEquals(new HashSet<>(Arrays.asList("compile", "runtime")),
        new HashSet<>(Arrays.asList(excludeAllTransitiveDepsDescriptor.getModuleConfigurations())));
    assertEquals(new HashSet<>(Arrays.asList("master(*)", "compile(*)")),
        new HashSet<>(Arrays.asList(excludeAllTransitiveDepsDescriptor.getDependencyConfigurations("compile"))));
    assertEquals(new HashSet<>(Collections.singletonList("runtime(*)")),
        new HashSet<>(Arrays.asList(excludeAllTransitiveDepsDescriptor.getDependencyConfigurations("runtime"))));
    assertEquals("No exclusion elements were expected to be present for " + excludeAllTransitiveDepsDescriptor,
        0, excludeAllTransitiveDepsDescriptor.getAllExcludeRules().length);
    assertFalse("Dependency  " + excludeAllTransitiveDepsDescriptor + " was expected to have transitive=false",
        excludeAllTransitiveDepsDescriptor.isTransitive());
}
 
Example 18
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for IVY-1561.
 * A pom.xml which has references to properties that are either set via environment variables
 * or system properties, must have its properties evaluated correctly.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1561">IVY-1561</a>
 */
@Test
public void testSystemPropertyAndEnvReferences() throws Exception {
    // The pom we are testing contains a reference to a string called
    // "env.THIS_WILL_BE_REPLACED_IN_TEST_BY_A_ENV_VAR". This piece of code replaces it with
    // "env.someenvname" where someenvname is a environment variable we choose in this test case
    // (after randomly picking it from the ones that are set).
    // Finally we save the updated pom content in a separate file and test against that file
    final String envName = chooseSomeEnvVar();
    final URL originalPomFile = this.getClass().getResource("test-system-properties.pom");
    assertNotNull("Pom file to test, is missing", originalPomFile);
    final List<String> pomContent = Files.readAllLines(Paths.get(originalPomFile.toURI()), StandardCharsets.UTF_8);
    final List<String> replacedContent = new ArrayList<>();
    for (final String line : pomContent) {
        replacedContent.add(line.replaceAll("THIS_WILL_BE_REPLACED_IN_TEST_BY_A_ENV_VAR", envName));
    }
    // write the new pom contents into a separate file
    final Path updatedPomFile = Paths.get(workDir.getRoot().toPath().toString(), "updated-test-system-properties.pom");
    Files.write(updatedPomFile, replacedContent, StandardCharsets.UTF_8);

    // now start testing - we do 2 rounds -
    // once with a system property (referenced in the pom) set and once unset
    boolean withSystemPropertiesSet = false;
    try {
        for (int i = 0; i < 2; i++) {
            if (i == 1) {
                System.setProperty("version.test.system.property.b", "1.2.3");
                withSystemPropertiesSet = true;
            }
            final ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, updatedPomFile.toUri().toURL(), false);
            assertNotNull("Module descriptor created from POM reader was null", md);
            assertEquals("Unexpected module descriptor created by POM reader",
                    ModuleRevisionId.newInstance("foo.bar", "hello-world", "2.0.2"),
                    md.getModuleRevisionId());

            final DependencyDescriptor[] dds = md.getDependencies();
            assertNotNull("No dependency descriptors found in module descriptor", dds);
            assertEquals("Unexpected number of dependencies in module descriptor", 4, dds.length);
            final Set<ModuleRevisionId> expectedDependencies = new HashSet<>();
            expectedDependencies.add(ModuleRevisionId.newInstance("aopalliance", "aopalliance", "1.0"));
            final String commonsLoggingDepVersion = envName == null ? "${env.THIS_WILL_BE_REPLACED_IN_TEST_BY_A_ENV_VAR}" : System.getenv(envName);
            expectedDependencies.add(ModuleRevisionId.newInstance("commons-logging", "commons-logging", commonsLoggingDepVersion));
            expectedDependencies.add(ModuleRevisionId.newInstance("foo.bar", "hello-world-api", "2.0.2"));
            expectedDependencies.add(ModuleRevisionId.newInstance("a", "b", withSystemPropertiesSet ? "1.2.3" : "2.3.4"));
            for (final DependencyDescriptor dd : dds) {
                assertNotNull("Dependency was null in the dependencies", dd);
                assertTrue("Unexpected dependency " + dd.getDependencyRevisionId() + " in module descriptor", expectedDependencies.remove(dd.getDependencyRevisionId()));
            }
            assertTrue("Following dependencies were missing from module descriptor " + expectedDependencies, expectedDependencies.isEmpty());
        }
    } finally {
        System.clearProperty("version.test.system.property.b");
    }
}
 
Example 19
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Test
public void testOverrideParentVersionPropertyDependencyMgt()
        throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {
        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
                throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
                        .parseDescriptor(settings,
                            getClass().getResource("test-versionPropertyDependencyMgt.pom"),
                            false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });

    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-overrideParentVersionPropertyDependencyMgt.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-parentdep", "1.0"),
        md.getModuleRevisionId());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);
    assertEquals(
        ModuleRevisionId.newInstance("commons-collections", "commons-collections", "3.2.1"),
        dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.1.1"),
        dds[1].getDependencyRevisionId());

    ExcludeRule[] excludes = dds[0].getAllExcludeRules();
    assertNotNull(excludes);
    assertEquals(2, excludes.length);
    assertEquals("javax.mail", excludes[0].getId().getModuleId().getOrganisation());
    assertEquals("mail", excludes[0].getId().getModuleId().getName());
    assertEquals("javax.jms", excludes[1].getId().getModuleId().getOrganisation());
    assertEquals("jms", excludes[1].getId().getModuleId().getName());
}
 
Example 20
Source File: IvyDeliverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for IVY-707.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-707">IVY-707</a>
 */
@Test
public void testWithDynEvicted2() throws Exception {
    // same as previous but dynamic dependency is placed after the one causing the conflict
    project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-dyn-evicted2.xml");
    IvyResolve res = new IvyResolve();
    res.setValidate(false);
    res.setProject(project);
    res.execute();

    deliver.setPubrevision("1.2");
    deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
    deliver.setValidate(false);
    deliver.execute();

    // should have done the ivy delivering
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(
        new IvySettings(), deliveredIvyFile.toURI().toURL(), false);
    assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"),
        md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"),
        dds[1].getDependencyRevisionId());

    IvyRetrieve ret = new IvyRetrieve();
    ret.setProject(project);
    ret.setPattern("build/test/retrieve/[artifact]-[revision].[ext]");
    ret.execute();

    File list = new File("build/test/retrieve");
    String[] files = list.list();
    HashSet<String> actualFileSet = new HashSet<>(Arrays.asList(files));
    HashSet<String> expectedFileSet = new HashSet<>();
    for (DependencyDescriptor dd : dds) {
        String name = dd.getDependencyId().getName();
        String rev = dd.getDependencyRevisionId().getRevision();
        String ext = "jar";
        String artifact = name + "-" + rev + "." + ext;
        expectedFileSet.add(artifact);
    }
    assertEquals("Delivered Ivy descriptor inconsistent with retrieved artifacts",
        expectedFileSet, actualFileSet);
    list.delete();
}