-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix special characters in .mvn/jvm.config (fix #11363, #11485 and #11486) #11365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gnodet
merged 17 commits into
apache:master
from
gnodet:fix/mng-11363-pipe-symbols-jvm-config
Dec 10, 2025
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d1dc6f1
[gh-11363] Fix pipe symbol parsing in .mvn/jvm.config
gnodet a3b9936
[gh-11363] Initialize JVM_CONFIG_MAVEN_OPTS and add debug output
gnodet 1c5a9c9
[gh-11363] Add debug output to file for IT verification
gnodet 92667bb
[gh-11363] Use random temp directory for Java parser compilation
gnodet 199b457
[gh-11363] Remove debug output, ready for merge
gnodet 178c6fa
Revert "[gh-11363] Remove debug output, ready for merge"
gnodet 937fcf2
[MNG-11363] Fix pipe symbols and special characters in .mvn/jvm.config
gnodet 3abc5ce
Fix possible issue
gnodet f9a4c67
Improve JvmConfigParser error handling and output flushing
gnodet f0d92e5
Use Java source-launch mode and add comprehensive error logging
gnodet ee17825
Fix description
gnodet c0f1a94
Merge remote-tracking branch 'origin/master' into fix/mng-11363-pipe-…
gnodet 36f56b6
Add debug info to windows batch file
gnodet 838608b
Improve IT debugging: capture shell script output and fix log file co…
gnodet 343b518
Fix Windows temp file locking issue in mvn.cmd jvm.config parsing
gnodet 7685323
Fix Windows jvm.config parsing and add debug logging to scripts
gnodet 9de4237
Fix Windows jvm.config parsing and add debug logging to scripts
gnodet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
apache-maven/src/assembly/maven/bin/JvmConfigParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Stream; | ||
|
|
||
| /** | ||
| * Parses .mvn/jvm.config file for Windows batch scripts. | ||
| * This avoids the complexity of parsing special characters (pipes, quotes, etc.) in batch scripts. | ||
| * | ||
| * Usage: java JvmConfigParser.java <jvm.config-path> <maven-project-basedir> | ||
| * | ||
| * Outputs: Single line with space-separated quoted arguments (safe for batch scripts) | ||
| */ | ||
| public class JvmConfigParser { | ||
| public static void main(String[] args) { | ||
| if (args.length != 2) { | ||
| System.err.println("Usage: java JvmConfigParser.java <jvm.config-path> <maven-project-basedir>"); | ||
| System.exit(1); | ||
| } | ||
|
|
||
| Path jvmConfigPath = Paths.get(args[0]); | ||
| String mavenProjectBasedir = args[1]; | ||
|
|
||
| if (!Files.exists(jvmConfigPath)) { | ||
| // No jvm.config file - output nothing | ||
| return; | ||
| } | ||
|
|
||
| try (Stream<String> lines = Files.lines(jvmConfigPath, StandardCharsets.UTF_8)) { | ||
| StringBuilder result = new StringBuilder(); | ||
|
|
||
| lines.forEach(line -> { | ||
| // Remove comments | ||
| int commentIndex = line.indexOf('#'); | ||
| if (commentIndex >= 0) { | ||
| line = line.substring(0, commentIndex); | ||
| } | ||
|
|
||
| // Trim whitespace | ||
| line = line.trim(); | ||
|
|
||
| // Skip empty lines | ||
| if (line.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| // Replace MAVEN_PROJECTBASEDIR placeholders | ||
| line = line.replace("${MAVEN_PROJECTBASEDIR}", mavenProjectBasedir); | ||
| line = line.replace("$MAVEN_PROJECTBASEDIR", mavenProjectBasedir); | ||
|
|
||
| // Parse line into individual arguments (split on spaces, respecting quotes) | ||
| List<String> parsed = parseArguments(line); | ||
|
|
||
| // Append each argument quoted | ||
| for (String arg : parsed) { | ||
| if (result.length() > 0) { | ||
| result.append(' '); | ||
| } | ||
| result.append('"').append(arg).append('"'); | ||
| } | ||
| }); | ||
|
|
||
| System.out.print(result.toString()); | ||
| System.out.flush(); // Ensure output is flushed before exit (important on Windows) | ||
bmarwell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (IOException e) { | ||
| System.err.println("Error reading jvm.config: " + e.getMessage()); | ||
| System.exit(1); | ||
bmarwell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Parse a line into individual arguments, respecting quoted strings. | ||
| * Quotes are stripped from the arguments. | ||
| */ | ||
| private static List<String> parseArguments(String line) { | ||
| List<String> args = new ArrayList<>(); | ||
| StringBuilder current = new StringBuilder(); | ||
| boolean inQuotes = false; | ||
| boolean inSingleQuotes = false; | ||
|
|
||
| for (int i = 0; i < line.length(); i++) { | ||
| char c = line.charAt(i); | ||
|
|
||
| if (c == '"' && !inSingleQuotes) { | ||
| inQuotes = !inQuotes; | ||
| // Don't include the quote character itself | ||
| } else if (c == '\'' && !inQuotes) { | ||
| inSingleQuotes = !inSingleQuotes; | ||
| // Don't include the quote character itself | ||
| } else if (c == ' ' && !inQuotes && !inSingleQuotes) { | ||
| // Space outside quotes - end of argument | ||
| if (current.length() > 0) { | ||
| args.add(current.toString()); | ||
| current.setLength(0); | ||
| } | ||
| } else { | ||
| current.append(c); | ||
| } | ||
| } | ||
|
|
||
| // Add last argument | ||
| if (current.length() > 0) { | ||
| args.add(current.toString()); | ||
| } | ||
|
|
||
| return args; | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,38 +177,25 @@ cd /d "%EXEC_DIR%" | |
|
|
||
| :endDetectBaseDir | ||
|
|
||
| rem Initialize JVM_CONFIG_MAVEN_OPTS to empty to avoid inheriting from environment | ||
| set JVM_CONFIG_MAVEN_OPTS= | ||
|
|
||
| if not exist "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadJvmConfig | ||
|
|
||
| @setlocal EnableExtensions EnableDelayedExpansion | ||
| set JVM_CONFIG_MAVEN_OPTS= | ||
| for /F "usebackq tokens=* delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do ( | ||
| set "line=%%a" | ||
|
|
||
| rem Skip empty lines and full-line comments | ||
| echo !line! | findstr /b /r /c:"[ ]*#" >nul | ||
| if errorlevel 1 ( | ||
| rem Handle end-of-line comments by taking everything before # | ||
| for /f "tokens=1* delims=#" %%i in ("!line!") do set "line=%%i" | ||
|
|
||
| rem Trim leading/trailing spaces while preserving spaces in quotes | ||
| set "trimmed=!line!" | ||
| for /f "tokens=* delims= " %%i in ("!trimmed!") do set "trimmed=%%i" | ||
| for /l %%i in (1,1,100) do if "!trimmed:~-1!"==" " set "trimmed=!trimmed:~0,-1!" | ||
|
|
||
| rem Replace MAVEN_PROJECTBASEDIR placeholders | ||
| set "trimmed=!trimmed:${MAVEN_PROJECTBASEDIR}=%MAVEN_PROJECTBASEDIR%!" | ||
| set "trimmed=!trimmed:$MAVEN_PROJECTBASEDIR=%MAVEN_PROJECTBASEDIR%!" | ||
|
|
||
| if not "!trimmed!"=="" ( | ||
| if "!JVM_CONFIG_MAVEN_OPTS!"=="" ( | ||
| set "JVM_CONFIG_MAVEN_OPTS=!trimmed!" | ||
| ) else ( | ||
| set "JVM_CONFIG_MAVEN_OPTS=!JVM_CONFIG_MAVEN_OPTS! !trimmed!" | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| @endlocal & set JVM_CONFIG_MAVEN_OPTS=%JVM_CONFIG_MAVEN_OPTS% | ||
| rem Use Java to parse jvm.config to avoid batch script parsing issues with special characters | ||
| rem This handles pipes, quotes, @, and other special characters correctly | ||
| rem Use random temp directory to avoid conflicts between different Maven invocations | ||
| set "JVM_CONFIG_PARSER_DIR=%TEMP%\mvn-jvm-parser-%RANDOM%-%RANDOM%" | ||
| mkdir "%JVM_CONFIG_PARSER_DIR%" | ||
| set "JVM_CONFIG_TEMP=%TEMP%\mvn-jvm-config-%RANDOM%.txt" | ||
| "%JAVACMD:java.exe=javac.exe%" -d "%JVM_CONFIG_PARSER_DIR%" "%MAVEN_HOME%\bin\JvmConfigParser.java" >nul 2>&1 | ||
|
||
| "%JAVACMD%" -cp "%JVM_CONFIG_PARSER_DIR%" JvmConfigParser "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" "%MAVEN_PROJECTBASEDIR%" > "%JVM_CONFIG_TEMP%" 2>nul | ||
| rem Read the single line from temp file | ||
| set /p JVM_CONFIG_MAVEN_OPTS=<"%JVM_CONFIG_TEMP%" | ||
|
|
||
| rem Cleanup temp files and directory | ||
| del "%JVM_CONFIG_TEMP%" 2>nul | ||
| rmdir /s /q "%JVM_CONFIG_PARSER_DIR%" 2>nul | ||
|
|
||
| :endReadJvmConfig | ||
|
|
||
|
|
@@ -286,4 +273,4 @@ if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" | |
| @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' | ||
| if "%MAVEN_BATCH_PAUSE%"=="on" pause | ||
|
|
||
| exit /b %ERROR_CODE% | ||
| exit /b %ERROR_CODE% | ||
53 changes: 53 additions & 0 deletions
53
...-it-suite/src/test/java/org/apache/maven/it/MavenITgh11363PipeSymbolsInJvmConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.it; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.Properties; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| /** | ||
| * This is a test set for <a href="https://github.com/apache/maven/issues/11363">gh-11363</a>: | ||
| * Verify that pipe symbols in .mvn/jvm.config are properly handled and don't cause shell command parsing errors. | ||
| */ | ||
| public class MavenITgh11363PipeSymbolsInJvmConfigTest extends AbstractMavenIntegrationTestCase { | ||
|
|
||
| /** | ||
| * Verify that pipe symbols in .mvn/jvm.config are properly handled | ||
| */ | ||
| @Test | ||
| void testPipeSymbolsInJvmConfig() throws Exception { | ||
| Path basedir = extractResources("/gh-11363-pipe-symbols-jvm-config") | ||
| .getAbsoluteFile() | ||
| .toPath(); | ||
|
|
||
| Verifier verifier = newVerifier(basedir.toString()); | ||
| verifier.setForkJvm(true); // Use forked JVM to test .mvn/jvm.config processing | ||
| verifier.addCliArguments("validate"); | ||
| verifier.execute(); | ||
| verifier.verifyErrorFreeLog(); | ||
|
|
||
| Properties props = verifier.loadProperties("target/pom.properties"); | ||
| assertEquals("de|*.de|my.company.mirror.de", props.getProperty("project.properties.pom.prop.nonProxyHosts")); | ||
| assertEquals("value|with|pipes", props.getProperty("project.properties.pom.prop.with.pipes")); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.