Search in sources :

Example 66 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testWithPlugins.

/**
 * Test case for IVY-417.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-417">IVY-417</a>
 */
@Test
public void testWithPlugins() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("mule-1.3.3.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.mule", "mule", "1.3.3"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(0, dds.length);
}
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 67 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testDependenciesWithClassifier.

@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());
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) URLResource(org.apache.ivy.plugins.repository.url.URLResource) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 68 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testDependencies.

@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);
}
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 69 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testVariables.

/**
 * Test case for IVY-425.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-425">IVY-425</a>
 */
@Test
public void testVariables() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("spring-hibernate3-2.0.2.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.springframework", "spring-hibernate3", "2.0.2"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(11, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org.springframework", "spring-web", "2.0.2"), dds[10].getDependencyRevisionId());
}
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 70 with DependencyDescriptor

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

the class PomModuleDescriptorParserTest method testPropertiesDefinedInProfiles.

/**
 * Tests that the {@code properties} setup in the Maven {@code profiles} that are conditionally activated,
 * become available to the module being parsed and such properties can be used as references within the pom
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1577">IVY-1577</a> for more details
 */
@Test
public void testPropertiesDefinedInProfiles() throws Exception {
    final String[] packagingTypesToTest = new String[] { "bundle", "jar" };
    for (final String expectedPackagingType : packagingTypesToTest) {
        String sysPropToSet = null;
        switch(expectedPackagingType) {
            case "bundle":
                {
                    sysPropToSet = "PomModuleDescriptorParserTest.some-other-test-prop";
                    break;
                }
            case "jar":
                {
                    sysPropToSet = "PomModuleDescriptorParserTest.some-test-prop";
                    break;
                }
            default:
                {
                    fail("Unexpected packaging type");
                }
        }
        // activate the relevant profile, based on a system property
        System.setProperty(sysPropToSet, "foo");
        try {
            // now parse the pom
            final ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-properties-in-profile.pom"), false);
            assertNotNull("Parsed module descriptor was null", md);
            assertEquals("Unexpected module descriptor", ModuleRevisionId.newInstance("org.apache", "test", "5.0.1"), md.getModuleRevisionId());
            final Artifact[] artifacts = md.getAllArtifacts();
            assertNotNull("No artifacts found for module", artifacts);
            assertEquals("Unexpected number of artifacts for module", 1, artifacts.length);
            final Artifact mainArtifact = artifacts[0];
            // make sure that the main artifact which references a conditionally set property (via a Maven profile)
            // is indeed using the right value
            assertEquals("Unexpected artifact type", expectedPackagingType, mainArtifact.getType());
            // some other basic tests
            final DependencyDescriptor[] dds = md.getDependencies();
            assertNotNull(dds);
            assertEquals(1, dds.length);
            assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), dds[0].getDependencyRevisionId());
        } finally {
            if (sysPropToSet != null) {
                // reset the system prop that we had set
                System.clearProperty(sysPropToSet);
            }
        }
    }
}
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) Artifact(org.apache.ivy.core.module.descriptor.Artifact) 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