Skip to content

Commit e244f01

Browse files
committed
[gh-11363] Fix variable substitution in concat_lines for Linux compatibility
The previous implementation used AWK variables for substitution which didn't work correctly on Linux systems. This commit separates the concerns: 1. Use sed for variable substitution ( and $MAVEN_PROJECTBASEDIR) - this is more portable and reliable across different Unix-like systems 2. Use awk only for escaping unquoted pipe symbols This ensures that JVM config files work correctly on both macOS and Linux, with proper variable substitution and pipe symbol handling.
1 parent 130c86d commit e244f01

File tree

1 file changed

+11
-11
lines changed
  • apache-maven/src/assembly/maven/bin

1 file changed

+11
-11
lines changed

apache-maven/src/assembly/maven/bin/mvn

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,15 @@ find_file_argument_basedir() {
167167

168168
# concatenates all lines of a file and replaces variables
169169
concat_lines() {
170-
[ -f "$1" ] || return
171-
172-
tr '\r' '\n' < "$1" | sed -e '/^$/d' -e 's/#.*$//' | awk \
173-
-v maven_dir="${MAVEN_PROJECTBASEDIR//\\/\\\\}" '
170+
if [ -f "$1" ]; then
171+
# First pass: clean the file (convert CR to LF, remove empty lines and comments)
172+
# and perform variable substitution using sed
173+
tr '\r' '\n' < "$1" | sed -e '/^$/d' -e 's/#.*$//' | sed \
174+
-e "s@\${MAVEN_PROJECTBASEDIR}@$MAVEN_PROJECTBASEDIR@g" \
175+
-e "s@\$MAVEN_PROJECTBASEDIR@$MAVEN_PROJECTBASEDIR@g" | \
176+
# Second pass: escape unquoted pipe symbols using awk
177+
awk '
174178
{
175-
# Replace variables
176-
gsub(/\$\{MAVEN_PROJECTBASEDIR\}/, maven_dir)
177-
gsub(/\$MAVEN_PROJECTBASEDIR/, maven_dir)
178-
179-
# Escape unquoted pipe symbols
180179
result = ""
181180
in_quotes = 0
182181
for (i = 1; i <= length($0); i++) {
@@ -188,13 +187,14 @@ concat_lines() {
188187
}
189188
result = result char
190189
}
191-
190+
192191
# Accumulate lines with space separator
193192
if (NR > 1) printf " "
194193
printf "%s", result
195194
}
196195
END { print "" }
197-
'
196+
'
197+
fi
198198
}
199199

200200
MAVEN_PROJECTBASEDIR="`find_maven_basedir "$@"`"

0 commit comments

Comments
 (0)