From 8500e806ecffb699546cf530725b30e4651f4d55 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 24 Oct 2018 19:02:31 +1000 Subject: [PATCH] align used algorithm to detect java bin to use (#3025) add javaPath for JettyRunDistro mojo to force a java executable to use Signed-off-by: olivier lamy --- .../development/maven/jetty-maven-plugin.adoc | 6 +++ .../jetty-simple-webapp/pom.xml | 1 + .../jetty/maven/plugin/JettyRunDistro.java | 15 ++++-- .../maven/plugin/JettyRunForkedMojo.java | 54 +++++-------------- .../jetty/maven/plugin/JettyRunMojo.java | 40 ++++++++++++++ 5 files changed, 71 insertions(+), 45 deletions(-) diff --git a/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc b/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc index 93e404d0258..a0fd6bacc42 100644 --- a/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc +++ b/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc @@ -624,6 +624,9 @@ Only relevant if `waitForChild` is `false`. forkWebXml:: Default is `target/fork-web.xml`. This is the name of the file into which jetty generates the effective web.xml for use by the child process. +javaPath:: +Default will be your `${java.home}/bin/java` +This the java executable used to start the child process The following `jetty:run` parameters are NOT applicable: @@ -715,6 +718,9 @@ maxChildCheckInterval:: Default value 100. This is the interval in milliseconds between checks to see if the child started correctly. Only applicable if `waitForChild` is `false`. +javaPath:: +Default will be your `${java.home}/bin/java` +This the java executable used to start the child process ____ [NOTE] diff --git a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml index a1d4c8c1ea1..5237db3ddcb 100644 --- a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml @@ -93,6 +93,7 @@ ${basedir}/src/base + ${java.home}/bin/java jetty.server.dumpAfterStart=true jetty.port.file=${jetty.port.file} diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java index 1a1fc463be4..d5a502e5f50 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java @@ -198,8 +198,10 @@ public class JettyRunDistro extends JettyRunMojo private Random random; private Path tokenFile; - - + + @Parameter(property = "jetty.javaPath") + private String javaPath; + /** * @see org.eclipse.jetty.maven.plugin.JettyRunMojo#execute() */ @@ -492,7 +494,14 @@ public class JettyRunDistro extends JettyRunMojo public ProcessBuilder configureCommand() { List cmd = new ArrayList<>(); - cmd.add("java"); + if(StringUtil.isNotBlank( javaPath )) + { + cmd.add( javaPath ); + } + else + { + cmd.add( getJavaBin() ); + } cmd.add("-jar"); cmd.add(new File(jettyHome, "start.jar").getAbsolutePath()); diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java index e0df458fdf9..5ff79475c8a 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java @@ -44,6 +44,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.eclipse.jetty.annotations.AnnotationConfiguration; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.thread.QueuedThreadPool; @@ -151,7 +152,9 @@ public class JettyRunForkedMojo extends JettyRunMojo * pom has an explicit dependency on it. */ private boolean hasSlf4jDeps; - + + @Parameter(property = "jetty.javaPath") + private String javaPath; /** * ShutdownThread @@ -271,7 +274,14 @@ public class JettyRunForkedMojo extends JettyRunMojo tpool.stop(); List cmd = new ArrayList<>(); - cmd.add(getJavaBin()); + if( StringUtil.isNotBlank( javaPath )) + { + cmd.add( javaPath ); + } + else + { + cmd.add( getJavaBin() ); + } if (jvmArgs != null) { @@ -307,7 +317,6 @@ public class JettyRunForkedMojo extends JettyRunMojo cmd.add("--props"); cmd.add(props.getAbsolutePath()); - String token = createToken(); Path tokenFile = target.toPath().resolve(createToken()+".txt"); cmd.add("--token"); cmd.add(tokenFile.toAbsolutePath().toString()); @@ -508,46 +517,7 @@ public class JettyRunForkedMojo extends JettyRunMojo return classPath.toString(); } - - - /** - * @return - */ - private String getJavaBin() - { - String javaexes[] = new String[] - { "java", "java.exe" }; - - File javaHomeDir = new File(System.getProperty("java.home")); - for (String javaexe : javaexes) - { - File javabin = new File(javaHomeDir,fileSeparators("bin/" + javaexe)); - if (javabin.exists() && javabin.isFile()) - { - return javabin.getAbsolutePath(); - } - } - - return "java"; - } - - public static String fileSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == '/') || (c == '\\')) - { - ret.append(File.separatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } public static String pathSeparators(String path) { diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java index a29d5beb2fb..038e3a83a82 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java @@ -738,4 +738,44 @@ public class JettyRunMojo extends AbstractJettyMojo return null; } + + + + /** + * @return + */ + protected String getJavaBin() + { + String javaexes[] = new String[] + { "java", "java.exe" }; + + File javaHomeDir = new File(System.getProperty("java.home")); + for (String javaexe : javaexes) + { + File javabin = new File(javaHomeDir,fileSeparators("bin/" + javaexe)); + if (javabin.exists() && javabin.isFile()) + { + return javabin.getAbsolutePath(); + } + } + + return "java"; + } + + public static String fileSeparators(String path) + { + StringBuilder ret = new StringBuilder(); + for (char c : path.toCharArray()) + { + if ((c == '/') || (c == '\\')) + { + ret.append(File.separatorChar); + } + else + { + ret.append(c); + } + } + return ret.toString(); + } }