Skip to content

Commit 8ba35f7

Browse files
committed
Fixes
1 parent d34a509 commit 8ba35f7

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
lines changed

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

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,29 @@ concat_lines() {
181181
line=$(echo "$line" | sed \
182182
-e "s@\${MAVEN_PROJECTBASEDIR}@$MAVEN_PROJECTBASEDIR@g" \
183183
-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+
184203
if [ -z "$_result" ]; then
185-
_result="$line"
204+
_result="$processed_line"
186205
else
187-
_result="$_result $line"
206+
_result="$_result $processed_line"
188207
fi
189208
fi
190209
done < "$_temp_file"
@@ -198,7 +217,15 @@ concat_lines() {
198217
}
199218

200219
MAVEN_PROJECTBASEDIR="`find_maven_basedir "$@"`"
201-
MAVEN_OPTS="$MAVEN_OPTS `concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"`"
220+
# Read JVM config and append to MAVEN_OPTS, preserving special characters
221+
_jvm_config="`concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"`"
222+
if [ -n "$_jvm_config" ]; then
223+
if [ -n "$MAVEN_OPTS" ]; then
224+
MAVEN_OPTS="$MAVEN_OPTS $_jvm_config"
225+
else
226+
MAVEN_OPTS="$_jvm_config"
227+
fi
228+
fi
202229
LAUNCHER_JAR=`echo "$MAVEN_HOME"/boot/plexus-classworlds-*.jar`
203230
LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher
204231

@@ -245,28 +272,43 @@ handle_args() {
245272
done
246273
}
247274

275+
276+
248277
handle_args "$@"
249278
MAVEN_MAIN_CLASS=${MAVEN_MAIN_CLASS:=org.apache.maven.cling.MavenCling}
250279

251-
cmd="\"$JAVACMD\" \
252-
$MAVEN_OPTS \
253-
$MAVEN_DEBUG_OPTS \
254-
--enable-native-access=ALL-UNNAMED \
255-
-classpath \"$LAUNCHER_JAR\" \
256-
\"-Dclassworlds.conf=$CLASSWORLDS_CONF\" \
257-
\"-Dmaven.home=$MAVEN_HOME\" \
258-
\"-Dmaven.mainClass=$MAVEN_MAIN_CLASS\" \
259-
\"-Dlibrary.jline.path=${MAVEN_HOME}/lib/jline-native\" \
260-
\"-Dmaven.multiModuleProjectDirectory=$MAVEN_PROJECTBASEDIR\" \
261-
$LAUNCHER_CLASS \
262-
$MAVEN_ARGS"
263-
# Add remaining arguments with proper quoting
280+
# Build the command with proper quoting for pipe symbols
281+
cmd="exec \"$JAVACMD\""
282+
283+
# Add MAVEN_OPTS if present
284+
if [ -n "$MAVEN_OPTS" ]; then
285+
cmd="$cmd $MAVEN_OPTS"
286+
fi
287+
288+
# Add MAVEN_DEBUG_OPTS if present
289+
if [ -n "$MAVEN_DEBUG_OPTS" ]; then
290+
cmd="$cmd $MAVEN_DEBUG_OPTS"
291+
fi
292+
293+
# Add fixed arguments
294+
cmd="$cmd --enable-native-access=ALL-UNNAMED"
295+
cmd="$cmd -classpath \"$LAUNCHER_JAR\""
296+
cmd="$cmd \"-Dclassworlds.conf=$CLASSWORLDS_CONF\""
297+
cmd="$cmd \"-Dmaven.home=$MAVEN_HOME\""
298+
cmd="$cmd \"-Dmaven.mainClass=$MAVEN_MAIN_CLASS\""
299+
cmd="$cmd \"-Dlibrary.jline.path=${MAVEN_HOME}/lib/jline-native\""
300+
cmd="$cmd \"-Dmaven.multiModuleProjectDirectory=$MAVEN_PROJECTBASEDIR\""
301+
cmd="$cmd $LAUNCHER_CLASS"
302+
303+
# Add MAVEN_ARGS if present
304+
if [ -n "$MAVEN_ARGS" ]; then
305+
cmd="$cmd $MAVEN_ARGS"
306+
fi
307+
308+
# Add remaining command line arguments
264309
for arg in "$@"; do
265-
cmd="$cmd \"$arg\""
310+
cmd="$cmd \"$arg\""
266311
done
267312

268-
# Debug: print the command that will be executed
269-
#echo "About to execute:"
270-
#echo "$cmd"
271-
272-
eval exec "$cmd"
313+
# Execute the command using eval to properly handle quoted arguments
314+
eval "$cmd"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
import static org.junit.jupiter.api.Assertions.assertEquals;
2727

2828
/**
29-
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-11363">MNG-11363</a>:
29+
* This is a test set for <a href="https://github.com/apache/maven/issues/11363">gh-11363</a>:
3030
* Verify that pipe symbols in .mvn/jvm.config are properly handled and don't cause shell command parsing errors.
3131
*/
32-
public class MavenITmng11363PipeSymbolsInJvmConfigTest extends AbstractMavenIntegrationTestCase {
32+
public class MavenITgh11363PipeSymbolsInJvmConfigTest extends AbstractMavenIntegrationTestCase {
3333

3434
/**
3535
* Verify that pipe symbols in .mvn/jvm.config are properly handled
3636
*/
3737
@Test
3838
void testPipeSymbolsInJvmConfig() throws Exception {
39-
Path basedir = extractResources("/mng-11363-pipe-symbols-jvm-config")
39+
Path basedir = extractResources("/gh-11363-pipe-symbols-jvm-config")
4040
.getAbsoluteFile()
4141
.toPath();
4242

0 commit comments

Comments
 (0)