Skip to content

Commit 130c86d

Browse files
committed
Improve method
1 parent 8ba35f7 commit 130c86d

File tree

1 file changed

+28
-47
lines changed
  • apache-maven/src/assembly/maven/bin

1 file changed

+28
-47
lines changed

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

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -167,53 +167,34 @@ find_file_argument_basedir() {
167167

168168
# concatenates all lines of a file and replaces variables
169169
concat_lines() {
170-
if [ -f "$1" ]; then
171-
# Use a temporary file to avoid subshell issues with variable substitution
172-
# First, clean the file: convert CR to LF, remove empty lines and comments
173-
_temp_file=$(mktemp)
174-
tr '\r' '\n' < "$1" | sed -e '/^$/d' -e 's/#.*$//' > "$_temp_file"
175-
176-
# Read each line and perform variable substitution, then concatenate with spaces
177-
_result=""
178-
while IFS= read -r line || [ -n "$line" ]; do
179-
if [ -n "$line" ]; then
180-
# Replace variables
181-
line=$(echo "$line" | sed \
182-
-e "s@\${MAVEN_PROJECTBASEDIR}@$MAVEN_PROJECTBASEDIR@g" \
183-
-e "s@\$MAVEN_PROJECTBASEDIR@$MAVEN_PROJECTBASEDIR@g")
184-
# Escape pipe symbols that are not within quotes to prevent shell interpretation
185-
processed_line=$(printf '%s' "$line" | awk '
186-
{
187-
result = ""
188-
in_quotes = 0
189-
for (i = 1; i <= length($0); i++) {
190-
char = substr($0, i, 1)
191-
if (char == "\"") {
192-
in_quotes = !in_quotes
193-
result = result char
194-
} else if (char == "|" && !in_quotes) {
195-
result = result "\\|"
196-
} else {
197-
result = result char
198-
}
199-
}
200-
print result
201-
}')
202-
203-
if [ -z "$_result" ]; then
204-
_result="$processed_line"
205-
else
206-
_result="$_result $processed_line"
207-
fi
208-
fi
209-
done < "$_temp_file"
210-
211-
# Clean up temporary file
212-
rm -f "$_temp_file"
213-
214-
# Output the result
215-
echo "$_result"
216-
fi
170+
[ -f "$1" ] || return
171+
172+
tr '\r' '\n' < "$1" | sed -e '/^$/d' -e 's/#.*$//' | awk \
173+
-v maven_dir="${MAVEN_PROJECTBASEDIR//\\/\\\\}" '
174+
{
175+
# Replace variables
176+
gsub(/\$\{MAVEN_PROJECTBASEDIR\}/, maven_dir)
177+
gsub(/\$MAVEN_PROJECTBASEDIR/, maven_dir)
178+
179+
# Escape unquoted pipe symbols
180+
result = ""
181+
in_quotes = 0
182+
for (i = 1; i <= length($0); i++) {
183+
char = substr($0, i, 1)
184+
if (char == "\"") {
185+
in_quotes = !in_quotes
186+
} else if (char == "|" && !in_quotes) {
187+
char = "\\|"
188+
}
189+
result = result char
190+
}
191+
192+
# Accumulate lines with space separator
193+
if (NR > 1) printf " "
194+
printf "%s", result
195+
}
196+
END { print "" }
197+
'
217198
}
218199

219200
MAVEN_PROJECTBASEDIR="`find_maven_basedir "$@"`"

0 commit comments

Comments
 (0)