fix: read_pom fallback returned both artifactId and version
When xmllint is not in PATH, the grep fallback in read_pom() captured
both <artifactId> and <version> in a single multi-line string and
returned it for every call. Concatenating it with ':' produced an
invalid Docker tag like:
test-quarkus\n1.0.0-SNAPSHOT:test-quarkus\n1.0.0-SNAPSHOT
causing 'docker build' to fail with 'invalid reference format'.
Add a third 'tag' argument to read_pom() so the fallback extracts
only the requested element, and pass 'artifactId' / 'version' from
the call sites.
Also enrich pom.xml with <name> and <description> for Maven/IDE
metadata, without changing the image identity.
Tests cover the no-xmllint path explicitly (PATH stripped to
reproduce the vm-compilador environment) and the override path.
This commit is contained in:
@@ -102,14 +102,14 @@ EOF
|
||||
}
|
||||
|
||||
read_pom() {
|
||||
local xpath="$1" fallback="$2"
|
||||
local xpath="$1" fallback="$2" tag="${3:-}"
|
||||
local value=""
|
||||
if command -v xmllint >/dev/null 2>&1; then
|
||||
value=$(xmllint --xpath "string($xpath)" pom.xml 2>/dev/null || true)
|
||||
fi
|
||||
if [[ -z "$value" ]]; then
|
||||
value=$(grep -E "<artifactId>|<version>" pom.xml | head -2 \
|
||||
| sed -E 's:.*<(artifactId|version)>(.*)</\1>.*:\2:')
|
||||
if [[ -z "$value" && -n "$tag" ]]; then
|
||||
value=$(grep -E "<${tag}>" pom.xml | head -1 \
|
||||
| sed -E "s:.*<${tag}>(.*)</${tag}>.*:\1:")
|
||||
fi
|
||||
printf '%s' "${value:-$fallback}"
|
||||
}
|
||||
@@ -201,8 +201,8 @@ fi
|
||||
PROJECT_DIR="$(pwd)"
|
||||
|
||||
# ---------- defaults ----------
|
||||
[[ -z "$IMAGE_NAME" ]] && IMAGE_NAME=$(read_pom "/*[local-name()='project']/*[local-name()='artifactId']" "test-quarkus")
|
||||
[[ -z "$IMAGE_TAG" ]] && IMAGE_TAG=$(read_pom "/*[local-name()='project']/*[local-name()='version']" "1.0.0-SNAPSHOT")
|
||||
[[ -z "$IMAGE_NAME" ]] && IMAGE_NAME=$(read_pom "/*[local-name()='project']/*[local-name()='artifactId']" "test-quarkus" "artifactId")
|
||||
[[ -z "$IMAGE_TAG" ]] && IMAGE_TAG=$(read_pom "/*[local-name()='project']/*[local-name()='version']" "1.0.0-SNAPSHOT" "version")
|
||||
[[ -z "$REMOTE" ]] && die "Missing --remote USER@HOST[:PORT] (use --help)."
|
||||
|
||||
IMAGE_REF="${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
|
||||
Reference in New Issue
Block a user