Skip to content
Permalink
Browse files
IVY-1531: Translation of POM to Ivy XML with * exclusion is removing …
…main artifact

This closes #10
  • Loading branch information
hibnico committed May 16, 2017
2 parents 6973dcb + d19212c commit 6b5b674cdc4458794d37284de602379f6e0001c7
Showing 3 changed files with 56 additions and 14 deletions.
@@ -289,9 +289,18 @@ public void addDependency(Resource res, PomDependencyData dep) {
if ((mRevId != null) && mRevId.getModuleId().equals(moduleRevId.getModuleId())) {
return;
}

// experimentation shows the following, excluded modules are
// inherited from parent POMs if either of the following is true:
// the <exclusions> element is missing or the <exclusions> element
// is present, but empty.
List<ModuleId> excluded = dep.getExcludedModules();
if (excluded.isEmpty()) {
excluded = getDependencyMgtExclusions(ivyModuleDescriptor, dep.getGroupId(),
dep.getArtifactId());
}
final boolean excludeAllTransitiveDeps = shouldExcludeAllTransitiveDeps(excluded);
DefaultDependencyDescriptor dd = new PomDependencyDescriptor(dep, ivyModuleDescriptor,
moduleRevId);
moduleRevId, !excludeAllTransitiveDeps);
scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
mapping.addMappingConfs(dd, dep.isOptional());
@@ -326,16 +335,12 @@ public void addDependency(Resource res, PomDependencyData dep) {
dd.addDependencyArtifact(optionalizedScope, depArtifact);
}

// experimentation shows the following, excluded modules are
// inherited from parent POMs if either of the following is true:
// the <exclusions> element is missing or the <exclusions> element
// is present, but empty.
List<ModuleId> excluded = dep.getExcludedModules();
if (excluded.isEmpty()) {
excluded = getDependencyMgtExclusions(ivyModuleDescriptor, dep.getGroupId(),
dep.getArtifactId());
}
for (ModuleId excludedModule : excluded) {
// This represents exclude all transitive dependencies, which we have already taken
// in account while defining the DefaultDependencyDescriptor itself
if ("*".equals(excludedModule.getOrganisation()) && "*".equals(excludedModule.getName())) {
continue;
}
String[] confs = dd.getModuleConfigurations();
for (int k = 0; k < confs.length; k++) {
dd.addExcludeRule(confs[k], new DefaultExcludeRule(new ArtifactId(excludedModule,
@@ -347,6 +352,21 @@ public void addDependency(Resource res, PomDependencyData dep) {
ivyModuleDescriptor.addDependency(dd);
}

private static boolean shouldExcludeAllTransitiveDeps(final List<ModuleId> exclusions) {
if (exclusions == null || exclusions.isEmpty()) {
return false;
}
for (final ModuleId exclusion : exclusions) {
if (exclusion == null) {
continue;
}
if ("*".equals(exclusion.getOrganisation()) && "*".equals(exclusion.getName())) {
return true;
}
}
return false;
}

public void addDependency(DependencyDescriptor descriptor) {
// Some POMs depend on themselves through their parent pom, don't add this dependency
// since Ivy doesn't allow this!
@@ -689,8 +709,8 @@ public static class PomDependencyDescriptor extends DefaultDependencyDescriptor
private final PomDependencyData pomDependencyData;

private PomDependencyDescriptor(PomDependencyData pomDependencyData,
ModuleDescriptor moduleDescriptor, ModuleRevisionId revisionId) {
super(moduleDescriptor, revisionId, true, false, true);
ModuleDescriptor moduleDescriptor, ModuleRevisionId revisionId, final boolean transitive) {
super(moduleDescriptor, revisionId, true, false, transitive);
this.pomDependencyData = pomDependencyData;
}

@@ -536,7 +536,7 @@ public void testExclusion() throws Exception {

DependencyDescriptor[] dds = md.getDependencies();
assertNotNull(dds);
assertEquals(3, dds.length);
assertEquals(4, dds.length);
assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
dds[0].getDependencyRevisionId());
assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet(
@@ -569,6 +569,17 @@ public void testExclusion() throws Exception {
assertEquals(new HashSet(Arrays.asList(new String[] {"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(new String[] {"compile", "runtime"})), new HashSet(Arrays.asList(excludeAllTransitiveDepsDescriptor.getModuleConfigurations())));
assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})),
new HashSet(Arrays.asList(excludeAllTransitiveDepsDescriptor.getDependencyConfigurations("compile"))));
assertEquals(new HashSet(Arrays.asList(new String[] {"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());
}

public void testWithPlugins() throws Exception {
@@ -57,5 +57,16 @@
<exclusion />
</exclusions>
</dependency>
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

0 comments on commit 6b5b674

Please sign in to comment.