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());
}
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());
}
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());
}
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());
}
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");
}
}
Aggregations