mirror of https://github.com/sbt/sbt.git
[2.x] fix: Support inline comments in .jvmopts and .sbtopts files (#8758)
**Problem**
After PR #8730 (commit 921efce), inline comments in .jvmopts and .sbtopts files cause errors.
For example, `--add-opens=java.base/java.util=ALL-UNNAMED # comment` results in:
Error: Could not find or load main class #
The # and everything after it is now parsed as separate arguments instead of being stripped as a comment.
**Solution**
Update the sed command in outputConfigFileTokens() to strip inline comments (everything from # to end of line) before parsing tokens.
The new s/\s*\#.*// pattern matches optional whitespace + # + rest of line and removes it.
Generated-by: Claude Sonnet 4.5
This commit is contained in:
parent
44b9ca7c2d
commit
02d9d4c699
|
|
@ -309,4 +309,40 @@ object RunnerScriptTest extends verify.BasicTestSuite with ShellScriptUtil:
|
|||
s"Should not have shell expansion errors, but found: ${errorMessages.mkString(", ")}"
|
||||
)
|
||||
|
||||
// Test for issue #8755: Inline comments should be supported in .jvmopts
|
||||
testOutput(
|
||||
"sbt with inline comments in .jvmopts",
|
||||
jvmoptsFileContents =
|
||||
"--add-opens=java.base/java.util=ALL-UNNAMED # This is an inline comment\n-Dtest.key=value # Another comment",
|
||||
windowsSupport = false,
|
||||
)("-v"): (out: List[String]) =>
|
||||
// Verify that options are present (comments should be stripped)
|
||||
assert(
|
||||
out.contains[String]("--add-opens=java.base/java.util=ALL-UNNAMED"),
|
||||
"Option with inline comment should be parsed correctly"
|
||||
)
|
||||
assert(
|
||||
out.contains[String]("-Dtest.key=value"),
|
||||
"System property with inline comment should be parsed correctly"
|
||||
)
|
||||
// Verify comments themselves are NOT present as separate arguments
|
||||
assert(
|
||||
!out.exists(_.contains("This is an inline comment")),
|
||||
"Inline comment should not appear in command line"
|
||||
)
|
||||
assert(
|
||||
!out.exists(_.contains("Another comment")),
|
||||
"Inline comment should not appear in command line"
|
||||
)
|
||||
// Verify no "command not found" errors for '#' character
|
||||
val errorMessages = out.filter(line =>
|
||||
line.contains("Could not find or load main class #") ||
|
||||
line.contains("command not found") ||
|
||||
line.contains("was unexpected")
|
||||
)
|
||||
assert(
|
||||
errorMessages.isEmpty,
|
||||
s"Should not have errors from comment character, but found: ${errorMessages.mkString(", ")}"
|
||||
)
|
||||
|
||||
end RunnerScriptTest
|
||||
|
|
|
|||
2
sbt
2
sbt
|
|
@ -805,7 +805,7 @@ outputConfigFileTokens() {
|
|||
local file="$1"
|
||||
[[ ! -f "$file" ]] && return
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
line=$(printf '%s' "$line" | sed $'/^\#/d;s/\r$//')
|
||||
line=$(printf '%s' "$line" | sed $'/^\#/d;s/\s*\#.*//;s/\r$//')
|
||||
[[ -z "$line" ]] && continue
|
||||
if [[ "$line" == -J* ]]; then
|
||||
local rest="${line#-J}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue