Skip to content

Commit

Permalink
Issue #6153 Swap order of jetty maven plugin jvmArgs for EXTERNAL (#6155
Browse files Browse the repository at this point in the history
)

* Issue #6153 Swap order of jetty maven plugin jvmArgs for EXTERNAL

Signed-off-by: Jan Bartel <janb@webtide.com>
  • Loading branch information
janbartel committed Apr 29, 2021
1 parent 973dfcf commit f05fc25
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
Expand Up @@ -189,7 +189,7 @@ Optional.
Map of key/value pairs to pass as environment to the forked JVM.
jvmArgs::
Optional.
A string representing arbitrary arguments to pass to the forked JVM.
A space separated string representing arbitrary arguments to pass to the forked JVM.
forkWebXml::
Optional.
Defaults to `target/fork-web.xml`.
Expand Down Expand Up @@ -218,9 +218,13 @@ jettyHome::
Optional.
The location of an existing unpacked jetty distribution.
If one does not exist, a fresh jetty distribution will be downloaded from maven and installed to the `target` directory.
jettyOptions::
Optional.
A space separated string representing extra arguments to the synthesized jetty command line.
Values for these arguments can be found in the section titled "Options" in the output of `java -jar $jetty.home/start.jar --help`.
jvmArgs::
Optional.
A string representing arguments that should be passed to the jvm of the child process running the distro.
A space separated string representing arguments that should be passed to the jvm of the child process running the distro.
modules::
Optional.
An array of names of additional jetty modules that the jetty child process will activate.
Expand Down
Expand Up @@ -103,6 +103,7 @@
<jetty.http.port>0</jetty.http.port>
</jettyProperties>
<modules>jsp,jstl,testmod</modules>
<jettyOptions>--debug</jettyOptions>
</configuration>
</execution>
</executions>
Expand Down
Expand Up @@ -290,7 +290,6 @@ public enum DeploymentMode
@Parameter
protected int stopPort;


/**
* Key to provide when stopping jetty on executing java -DSTOP.KEY=&lt;stopKey&gt;
* -DSTOP.PORT=&lt;stopPort&gt; -jar start.jar --stop
Expand Down Expand Up @@ -319,6 +318,13 @@ public enum DeploymentMode
*/
@Parameter
protected String[] modules;

/**
* Extra options that can be passed to the jetty command line
*/
@Parameter (property = "jetty.options")
protected String jettyOptions;

//End of EXTERNAL only parameters

//Start of parameters only valid for FORK
Expand Down Expand Up @@ -511,6 +517,7 @@ protected JettyHomeForker newJettyHomeForker()
jetty.setStopPort(stopPort);
jetty.setEnv(env);
jetty.setJvmArgs(jvmArgs);
jetty.setJettyOptions(jettyOptions);
jetty.setJettyXmlFiles(jettyXmls);
jetty.setJettyProperties(jettyProperties);
jetty.setModules(modules);
Expand Down
Expand Up @@ -25,10 +25,10 @@
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -74,6 +74,11 @@ public class JettyHomeForker extends AbstractForker
*/
protected String[] modules;

/*
* Optional jetty commands
*/
protected String jettyOptions;

protected List<File> libExtJarFiles;
protected Path modulesPath;
protected Path etcPath;
Expand All @@ -82,6 +87,16 @@ public class JettyHomeForker extends AbstractForker
protected Path mavenLibPath;
protected String version;

public void setJettyOptions(String jettyOptions)
{
this.jettyOptions = jettyOptions;
}

public String getJettyOptions()
{
return jettyOptions;
}

public List<File> getLibExtJarFiles()
{
return libExtJarFiles;
Expand Down Expand Up @@ -167,24 +182,16 @@ protected ProcessBuilder createCommand()
{
List<String> cmd = new ArrayList<>();
cmd.add("java");
cmd.add("-jar");
cmd.add(new File(jettyHome, "start.jar").getAbsolutePath());

cmd.add("-DSTOP.PORT=" + stopPort);
if (stopKey != null)
cmd.add("-DSTOP.KEY=" + stopKey);

//add any args to the jvm
if (jvmArgs != null)
if (StringUtil.isNotBlank(jvmArgs))
{
String[] args = jvmArgs.split(" ");
for (String a : args)
{
if (!StringUtil.isBlank(a))
cmd.add(a.trim());
}
Arrays.stream(jvmArgs.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim()));
}

cmd.add("-jar");
cmd.add(new File(jettyHome, "start.jar").getAbsolutePath());

if (systemProperties != null)
{
for (Map.Entry<String, String> e : systemProperties.entrySet())
Expand All @@ -193,6 +200,10 @@ protected ProcessBuilder createCommand()
}
}

cmd.add("-DSTOP.PORT=" + stopPort);
if (stopKey != null)
cmd.add("-DSTOP.KEY=" + stopKey);

//set up enabled jetty modules
StringBuilder tmp = new StringBuilder();
tmp.append("--module=");
Expand All @@ -210,6 +221,12 @@ protected ProcessBuilder createCommand()
tmp.append(",ext");
tmp.append(",maven");
cmd.add(tmp.toString());

//put any other jetty options onto the command line
if (StringUtil.isNotBlank(jettyOptions))
{
Arrays.stream(jettyOptions.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim()));
}

//put any jetty properties onto the command line
if (jettyProperties != null)
Expand Down

0 comments on commit f05fc25

Please sign in to comment.