Search in sources :

Example 71 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testParentDependencyMgt.

@Test
public void testParentDependencyMgt() 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-dependencyMgt.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-parentDependencyMgt.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-collection", "commons-collection", "1.0.5"), dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), 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());
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ParseException(java.text.ParseException) IOException(java.io.IOException) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 72 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testOverrideParentProperties.

@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());
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ParseException(java.text.ParseException) IOException(java.io.IOException) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 73 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testWithoutVersion.

@Test
public void testWithoutVersion() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-without-version.pom"), false);
    assertNotNull(md);
    assertEquals(new ModuleId("org.apache", "test"), md.getModuleRevisionId().getModuleId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), dds[0].getDependencyRevisionId());
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ModuleId(org.apache.ivy.core.module.id.ModuleId) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 74 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testDependencyManagement.

@Test
public void testDependencyManagement() throws ParseException, IOException {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-dependencyMgt.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-depMgt", "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);
    assertEquals(4, md.getExtraInfos().size());
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 75 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testSystemPropertyAndEnvReferences.

/**
 * 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()), Charset.forName("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, Charset.forName("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");
    }
}
Also used : Path(java.nio.file.Path) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ArrayList(java.util.ArrayList) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) URL(java.net.URL) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) HashSet(java.util.HashSet) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Aggregations

DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)101 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)80 Test (org.junit.Test)75 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)35 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)33 File (java.io.File)26 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)26 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)25 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 IvySettings (org.apache.ivy.core.settings.IvySettings)17 Configuration (org.apache.ivy.core.module.descriptor.Configuration)15 Artifact (org.apache.ivy.core.module.descriptor.Artifact)13 ParseException (java.text.ParseException)12 IOException (java.io.IOException)11 ResolveData (org.apache.ivy.core.resolve.ResolveData)11 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)9 JarFile (java.util.jar.JarFile)7 GregorianCalendar (java.util.GregorianCalendar)6 ModuleId (org.apache.ivy.core.module.id.ModuleId)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6