diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 989dbdf004c..a7f2c15f9d6 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -371,7 +371,7 @@ public class Server extends HandlerWrapper implements Attributes String gitHash = Jetty.GIT_HASH; String timestamp = Jetty.BUILD_TIMESTAMP; - LOG.info("jetty-{}; built: {}; git: {}; jvm {}", getVersion(), timestamp, gitHash, JavaVersion.VERSION); + LOG.info("jetty-{}; built: {}; git: {}; jvm {}", getVersion(), timestamp, gitHash, System.getProperty("java.runtime.version",System.getProperty("java.version"))); if (!Jetty.STABLE) { LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!"); 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 235b0358626..00301abfe8f 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 @@ -1265,12 +1265,11 @@ public class StartArgs try { JavaVersion ver = JavaVersion.parse(value); - properties.setProperty("java.version",ver.getVersion(),source); + properties.setProperty("java.version",System.getProperty("java.version"),source); properties.setProperty("java.version.platform",Integer.toString(ver.getPlatform()),source); properties.setProperty("java.version.major",Integer.toString(ver.getMajor()),source); properties.setProperty("java.version.minor",Integer.toString(ver.getMinor()),source); properties.setProperty("java.version.micro",Integer.toString(ver.getMicro()),source); - properties.setProperty("java.version.update",Integer.toString(ver.getUpdate()),source); } catch (Throwable x) { diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/JavaVersion.java b/jetty-util/src/main/java/org/eclipse/jetty/util/JavaVersion.java index 69117e6ddae..f1cbd74b718 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/JavaVersion.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/JavaVersion.java @@ -32,35 +32,34 @@ public class JavaVersion * Acceptable values should correspond to those returned by JavaVersion.getPlatform(). */ public static final String JAVA_TARGET_PLATFORM = "org.eclipse.jetty.javaTargetPlatform"; - - /** Regex for Java version numbers */ - private static final String VSTR_FORMAT = "(?[1-9][0-9]*(?:(?:\\.0)*\\.[0-9]+)*).*"; - - static final Pattern VSTR_PATTERN = Pattern.compile(VSTR_FORMAT); - - public static final JavaVersion VERSION = parse(System.getProperty("java.runtime.version",System.getProperty("java.version","1.8"))); + + public static final JavaVersion VERSION = parse(System.getProperty("java.version")); public static JavaVersion parse(String v) - { - Matcher m = VSTR_PATTERN.matcher(v); - if (!m.matches() || m.group("VNUM")==null) - { - System.err.println("ERROR: Invalid version string: '" + v + "'"); - return new JavaVersion(v+"-UNKNOWN",8,1,8,0); - } - + { // $VNUM is a dot-separated list of integers of arbitrary length - String[] split = m.group("VNUM").split("\\."); - int[] version = new int[split.length]; - for (int i = 0; i < split.length; i++) - version[i] = Integer.parseInt(split[i]); + String[] split = v.split("[^0-9]"); + int len = Math.min(split.length,3); + int[] version = new int[len]; + for (int i = 0; i < len; i++) + { + try + { + version[i] = Integer.parseInt(split[i]); + } + catch(Throwable e) + { + len = i-1; + break; + } + } return new JavaVersion( v, - (version[0]>=9 || version.length==1)?version[0]:version[1], + (version[0]>=9 || len==1)?version[0]:version[1], version[0], - version.length>1?version[1]:0, - version.length>2?version[2]:0); + len>1?version[1]:0, + len>2?version[2]:0); } private final String version; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/JavaVersionTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/JavaVersionTest.java index bf1640c812e..b02896c454d 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/JavaVersionTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/JavaVersionTest.java @@ -28,6 +28,17 @@ import org.junit.Test; */ public class JavaVersionTest { + @Test + public void testAndroid() + { + JavaVersion version = JavaVersion.parse("0.9"); + assertThat(version.toString(),is("0.9")); + assertThat(version.getPlatform(),is(9)); + assertThat(version.getMajor(),is(0)); + assertThat(version.getMinor(),is(9)); + assertThat(version.getMicro(),is(0)); + } + @Test public void test9() {