IVY-1586 IVY-1610 Make sure that empty value of "classifier" in pom.xml is considered the same as classifier not being specified
diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java b/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
index fb15e23..88c9d70 100644
--- a/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
+++ b/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
@@ -510,23 +510,39 @@
@Override
public String getScope() {
String val = getFirstChildText(depElement, SCOPE);
- return replaceProps(val);
+ return emptyIsNull(replaceProps(val));
}
public String getClassifier() {
String val = getFirstChildText(depElement, CLASSIFIER);
- return replaceProps(val);
+ return emptyIsNull(replaceProps(val));
}
public String getType() {
String val = getFirstChildText(depElement, TYPE);
- return replaceProps(val);
+ return emptyIsNull(replaceProps(val));
}
public boolean isOptional() {
return Boolean.parseBoolean(getFirstChildText(depElement, OPTIONAL));
}
+ /**
+ * We return null where certain elements within a pom don't have a value specified.
+ * For example, there are pom.xml out there which just use "<classifier/>" in the dependencies.
+ * (dependencies in org.seleniumhq.selenium:selenium-java:3.141.59 are one such example)
+ * We do this so that callers of such elements don't have to keep repeating checks for empty value.
+ * For us an empty value, for many of such elements, is really the same as that element not being specified
+ *
+ * @param val The value to check
+ * @return
+ */
+ private String emptyIsNull(final String val) {
+ if (val == null) {
+ return null;
+ }
+ return val.equals("") ? null : val;
+ }
}
public class PomProfileElement {
diff --git a/test/repositories/m2/org/apache/1580-foo-impl/1.2.3/1580-foo-impl-1.2.3.pom b/test/repositories/m2/org/apache/1580-foo-impl/1.2.3/1580-foo-impl-1.2.3.pom
index 9b2a7ea..4beff33 100644
--- a/test/repositories/m2/org/apache/1580-foo-impl/1.2.3/1580-foo-impl-1.2.3.pom
+++ b/test/repositories/m2/org/apache/1580-foo-impl/1.2.3/1580-foo-impl-1.2.3.pom
@@ -31,6 +31,10 @@
<groupId>org.apache</groupId>
<artifactId>1580-foo-api</artifactId>
<version>${project.version}</version>
+ <!-- Intentionally use a classifier without value.
+ This should behave same as not specifying any classifier.
+ See IVY-1586 for details -->
+ <classifier/>
</dependency>
<dependency>