Skip to content

Commit 32ee1b4

Browse files
committed
melting-pot: generalize pom value extraction
This lets us recursively extract values from POMs specified as GAVs.
1 parent 2cff749 commit 32ee1b4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

melting-pot.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,31 @@ xpath() {
293293
xmllint --xpath "$xpath" "$xmlFile" | sed -E 's/^[^>]*>(.*)<[^<]*$/\1/'
294294
}
295295

296+
# For the given GAV ($1), recursively gets the value of the
297+
# specified XPath expression of the form "//$2/$3/$4/...".
298+
pomValue() {
299+
local pomPath="$(pom "$1")"
300+
shift
301+
local value="$(xpath "$pomPath" $@)"
302+
if [ "$value" ]
303+
then
304+
echo "$value"
305+
else
306+
# Path not found in POM; look in the parent POM.
307+
local pg="$(xpath "$pomPath" project parent groupId)"
308+
if [ "$pg" ]
309+
then
310+
# There is a parent POM declaration in this POM.
311+
local pa="$(xpath "$pomPath" project parent artifactId)"
312+
local pv="$(xpath "$pomPath" project parent version)"
313+
pomValue "$pg:$pa:$pv" $@
314+
fi
315+
fi
316+
}
317+
296318
# Gets the SCM URL for the given GAV.
297319
scmURL() {
298-
xpath "$(pom "$1")" project scm connection | sed -E 's/.*>scm:git:(.*)<.*/\1/'
320+
pomValue "$1" project scm connection | sed -E 's/^scm:git://'
299321
}
300322

301323
# Gets the SCM tag for the given GAV.

0 commit comments

Comments
 (0)