Skip to content

Commit f5a378e

Browse files
committed
release-version.sh: avoid mvn ANSI colors
Firstly, the mvn echo logic needs to pass -B. But even then, it seems that at least some versions of mvn (3.8.7 is an offender on my system) still prepend an <ESC>[0m even in batch mode. So we also work around this bug by forcibly stripping ANSI color codes. Thanks to ChatGPT for the regex -- saved me a few minutes of time!
1 parent e3cd694 commit f5a378e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

release-version.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ Options include:
119119
debug "Extracting project details"
120120

121121
echoArg='${project.version}:${license.licenseName}:${project.parent.groupId}:${project.parent.artifactId}:${project.parent.version}'
122-
projectDetails=$(mvn -N -Dexec.executable=echo -Dexec.args="$echoArg" exec:exec -q)
123-
test $? -eq 0 || projectDetails=$(mvn -U -N -Dexec.executable=echo -Dexec.args="$echoArg" exec:exec -q)
122+
projectDetails=$(mvn -B -N -Dexec.executable=echo -Dexec.args="$echoArg" exec:exec -q)
123+
test $? -eq 0 || projectDetails=$(mvn -B -U -N -Dexec.executable=echo -Dexec.args="$echoArg" exec:exec -q)
124124
test $? -eq 0 || die "Could not extract version from pom.xml. Error follows:\n$projectDetails"
125-
echo "$projectDetails" | grep -Fqv '[ERROR]' ||
125+
printf '%s' "$projectDetails\n" | grep -Fqv '[ERROR]' ||
126126
die "Error extracting version from pom.xml. Error follows:\n$projectDetails"
127+
# HACK: Even with -B, some versions of mvn taint the output with the <ESC>[0m
128+
# color reset sequence. So we forcibly remove such sequences, just to be safe.
129+
projectDetails=$(printf '%s' "$projectDetails" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g")
130+
# And also remove extraneous newlines, particularly any trailing ones.
131+
projectDetails=$(printf '%s' "$projectDetails" | tr -d '\n')
127132
currentVersion=${projectDetails%%:*}
128133
projectDetails=${projectDetails#*:}
129134
licenseName=${projectDetails%%:*}
@@ -185,7 +190,7 @@ test "$SKIP_VERSION_CHECK" -o "$parentGAV" != "${parentGAV#$}" || {
185190
latestParentVersion=$(sh -$- "$MAVEN_HELPER" latest-version "$parentGAV")
186191
currentParentVersion=${parentGAV##*:}
187192
test "$currentParentVersion" = "$latestParentVersion" ||
188-
die "Newer version of parent '${parentGAV%:*}' is available: $latestParentVersion.
193+
die "Newer version of parent '$parentGAV' is available: $latestParentVersion.
189194
I recommend you update it before releasing.
190195
Or if you know better, try again with --skip-version-check flag."
191196
}

0 commit comments

Comments
 (0)