This is an automated email from the ASF dual-hosted git repository.
jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant-ivy.git
The following commit(s) were added to refs/heads/master by this push:
new 400cb51 IVY-1586 IVY-1610 Make sure that empty value of "classifier"
in pom.xml is considered the same as classifier not being specified
400cb51 is described below
commit 400cb51d07f867ff26bc8d367dbce22d883645e4
Author: Jaikiran Pai <[email protected]>
AuthorDate: Fri Oct 11 10:20:34 2019 +0530
IVY-1586 IVY-1610 Make sure that empty value of "classifier" in pom.xml is
considered the same as classifier not being specified
---
.../apache/ivy/plugins/parser/m2/PomReader.java | 22 +++++++++++++++++++---
.../1580-foo-impl/1.2.3/1580-foo-impl-1.2.3.pom | 4 ++++
2 files changed, 23 insertions(+), 3 deletions(-)
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 @@ public class PomReader {
@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>