diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index 09cf73b011d..4c641631d28 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -705,7 +705,7 @@ public class StartArgs } else { - cmd.addRawArg(x); + cmd.addRawArg(getProperties().expand(x)); } } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java index 0029aba2af2..e8fe18e9d38 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; @@ -169,6 +170,37 @@ public class MainTest ConfigurationAssert.assertConfiguration(baseHome, args, "assert-home-with-jvm.txt"); } + @Test + public void testJvmArgExpansion() throws Exception + { + List cmdLineArgs = new ArrayList<>(); + + Path homePath = MavenTestingUtils.getTestResourceDir("dist-home").toPath().toRealPath(); + cmdLineArgs.add("jetty.home=" + homePath.toString()); + cmdLineArgs.add("user.dir=" + homePath.toString()); + + // JVM args + cmdLineArgs.add("--exec"); + cmdLineArgs.add("-Xms1g"); + cmdLineArgs.add("-Xmx4g"); + cmdLineArgs.add("-Xloggc:${jetty.base}/logs/gc-${java.version}.log"); + + Main main = new Main(); + + StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()])); + BaseHome baseHome = main.getBaseHome(); + + assertThat("jetty.home", baseHome.getHome(), is(homePath.toString())); + assertThat("jetty.base", baseHome.getBase(), is(homePath.toString())); + + CommandLineBuilder commandLineBuilder = args.getMainArgs(true); + String commandLine = commandLineBuilder.toString("\n"); + String expectedExpansion = String.format("-Xloggc:%s/logs/gc-%s.log", + baseHome.getBase(), System.getProperty("java.version") + ); + assertThat(commandLine, containsString(expectedExpansion)); + } + @Test public void testWithModules() throws Exception {