From 07d1bf1197d81da1c43b1214f3036c092d410d39 Mon Sep 17 00:00:00 2001 From: grperry Date: Mon, 19 Mar 2018 06:57:00 -0700 Subject: [PATCH] classifier fix --- .../parser/m2/PomModuleDescriptorBuilder.java | 35 +++++++++++++++++-- test/.gitignore | 1 + 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/.gitignore diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java index 40a007a9..4703579c 100644 --- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java +++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java @@ -40,6 +40,7 @@ import org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; import org.apache.ivy.core.module.descriptor.DefaultExcludeRule; import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; import org.apache.ivy.core.module.descriptor.DependencyDescriptor; import org.apache.ivy.core.module.descriptor.ExtraInfoHolder; import org.apache.ivy.core.module.descriptor.License; @@ -292,12 +293,38 @@ public class PomModuleDescriptorBuilder { return; } - DefaultDependencyDescriptor dd = new PomDependencyDescriptor(dep, ivyModuleDescriptor, - moduleRevId); + // Add "new" dependency, or add new artifact to "existing" dependency + // https://issues.apache.org/jira/browse/IVY-1576 + DefaultDependencyDescriptor dd = null; + DependencyDescriptor[] existingDeps = ivyModuleDescriptor.getDependencies(); + + for (int i = 0; i < existingDeps.length; ++i) { + DependencyDescriptor ddt = existingDeps[i]; + ModuleRevisionId existingModuleId = ddt.getDependencyRevisionId(); + + if (existingModuleId.equals(moduleRevId)) { + // dd = ivyModuleDescriptor.getDependency(mRevId); + dd = (DefaultDependencyDescriptor)ddt; + break; + } + } + + if (dd == null) { + // dependency not found create new one + dd = new PomDependencyDescriptor(dep, ivyModuleDescriptor, moduleRevId); + } + scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope; ConfMapper mapping = (ConfMapper) MAVEN2_CONF_MAPPING.get(scope); mapping.addMappingConfs(dd, dep.isOptional()); Map extraAtt = new HashMap(); + + // If classifier is not null, then potentially its another artifact associated with "this" dependency descriptior. + // The way this is processed however a "new" dependency descriptor comes up and therein lies the problem + // as 3 artifacts have the same dependency descriptor and the 'resolution' will only solve for 1 dependency - although there are + // 3 actual artifacts. So, we should check to see if the DefaultDependencyDescriptor already exists from the + // ivyModuleDescriptor. If it does we add the new artifact with the different classifier value .. + if ((dep.getClassifier() != null) || ((dep.getType() != null) && !"jar".equals(dep.getType()))) { String type = "jar"; @@ -306,6 +333,8 @@ public class PomModuleDescriptorBuilder { } String ext = type; + Message.info(" found classifier : " + dep.getClassifier()); + // if type is 'test-jar', the extension is 'jar' and the classifier is 'tests' // Cfr. http://maven.apache.org/guides/mini/guide-attached-tests.html if ("test-jar".equals(type)) { @@ -708,7 +737,7 @@ public class PomModuleDescriptorBuilder { /** * Get PomDependencyData. - * + * * @return PomDependencyData */ public PomDependencyData getPomDependencyData() { diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 00000000..9480c586 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +/repositories/