Issue #2090 Java Version JEP223
This commit is contained in:
parent
1cad36969f
commit
a107e543e6
|
@ -32,6 +32,7 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||||
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
||||||
import org.eclipse.jetty.util.Attributes;
|
import org.eclipse.jetty.util.Attributes;
|
||||||
import org.eclipse.jetty.util.AttributesMap;
|
import org.eclipse.jetty.util.AttributesMap;
|
||||||
|
import org.eclipse.jetty.util.JavaVersion;
|
||||||
import org.eclipse.jetty.util.Jetty;
|
import org.eclipse.jetty.util.Jetty;
|
||||||
import org.eclipse.jetty.util.MultiException;
|
import org.eclipse.jetty.util.MultiException;
|
||||||
import org.eclipse.jetty.util.URIUtil;
|
import org.eclipse.jetty.util.URIUtil;
|
||||||
|
@ -370,7 +371,7 @@ public class Server extends HandlerWrapper implements Attributes
|
||||||
String gitHash = Jetty.GIT_HASH;
|
String gitHash = Jetty.GIT_HASH;
|
||||||
String timestamp = Jetty.BUILD_TIMESTAMP;
|
String timestamp = Jetty.BUILD_TIMESTAMP;
|
||||||
|
|
||||||
LOG.info("jetty-{}, build timestamp: {}, git hash: {}", getVersion(), timestamp, gitHash);
|
LOG.info("jetty-{}; build timestamp: {}; git hash: {}; on {}", getVersion(), timestamp, gitHash, JavaVersion.VERSION);
|
||||||
if (!Jetty.STABLE)
|
if (!Jetty.STABLE)
|
||||||
{
|
{
|
||||||
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
|
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
|
||||||
|
|
|
@ -27,55 +27,103 @@ import java.util.regex.Pattern;
|
||||||
*/
|
*/
|
||||||
public class JavaVersion
|
public class JavaVersion
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context attribute that can be set to target a different version of the jvm than the current runtime.
|
* Context attribute that can be set to target a different version of the jvm than the current runtime.
|
||||||
* Acceptable values should correspond to those returned by JavaVersion.getPlatform().
|
* Acceptable values should correspond to those returned by JavaVersion.getPlatform().
|
||||||
*/
|
*/
|
||||||
public static final String JAVA_TARGET_PLATFORM = "org.eclipse.jetty.javaTargetPlatform";
|
public static final String JAVA_TARGET_PLATFORM = "org.eclipse.jetty.javaTargetPlatform";
|
||||||
|
|
||||||
// Copy of version in jetty-start
|
/** Regex for Java version numbers */
|
||||||
|
private static final String VNUM = "(?<VNUM>[1-9][0-9]*(?:(?:\\.0)*\\.[0-9]+)*)";
|
||||||
|
private static final String UPDATE = "(?:(?<UNDERSCORE>_)(?<UPDATE>[0-9]+))?";
|
||||||
|
private static final String PRE = "(?:-(?<PRE>[a-zA-Z0-9]+))?";
|
||||||
|
private static final String BUILD = "(?:(?<PLUS>\\+)(?<BUILD>[0-9]+))?";
|
||||||
|
private static final String OPT = "(?:-(?<OPT>[-a-zA-Z0-9.]+))?";
|
||||||
|
|
||||||
private static final Pattern PRE_JDK9 = Pattern.compile("1\\.(\\d)(\\.(\\d+)(_(\\d+))?)?(-.+)?");
|
private static final String VSTR_FORMAT = VNUM + UPDATE + PRE + BUILD + OPT;
|
||||||
// Regexp from JEP 223 (http://openjdk.java.net/jeps/223).
|
|
||||||
private static final Pattern JDK9 = Pattern.compile("(\\d+)(\\.(\\d+))?(\\.(\\d+))?((-.+)?(\\+(\\d+)?(-.+)?)?)");
|
|
||||||
|
|
||||||
public static final JavaVersion VERSION = parse(System.getProperty("java.version"));
|
static final Pattern VSTR_PATTERN = Pattern.compile(VSTR_FORMAT);
|
||||||
|
|
||||||
public static JavaVersion parse(String version)
|
public static final JavaVersion VERSION = parse(System.getProperty("java.runtime.version",System.getProperty("java.version")));
|
||||||
|
|
||||||
|
public static JavaVersion parse(String v)
|
||||||
{
|
{
|
||||||
if (version.startsWith("1."))
|
Matcher m = VSTR_PATTERN.matcher(v);
|
||||||
return parsePreJDK9(version);
|
if (!m.matches())
|
||||||
return parseJDK9(version);
|
throw new IllegalArgumentException("Invalid version string: '" + v + "'");
|
||||||
|
|
||||||
|
// $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]);
|
||||||
|
|
||||||
|
if (m.group("UNDERSCORE")!=null)
|
||||||
|
{
|
||||||
|
return new JavaVersion(
|
||||||
|
v,
|
||||||
|
(version[0]>=9 || version.length==1)?version[0]:version[1],
|
||||||
|
version[0],
|
||||||
|
version.length>1?version[1]:0,
|
||||||
|
version.length>2?version[2]:0,
|
||||||
|
Integer.parseInt(m.group("UPDATE")),
|
||||||
|
suffix(version,m.group("PRE"),m.group("OPT"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m.group("PLUS")!=null)
|
||||||
|
{
|
||||||
|
return new JavaVersion(
|
||||||
|
v,
|
||||||
|
(version[0]>=9 || version.length==1)?version[0]:version[1],
|
||||||
|
version[0],
|
||||||
|
version.length>1?version[1]:0,
|
||||||
|
version.length>2?version[2]:0,
|
||||||
|
Integer.parseInt(m.group("BUILD")),
|
||||||
|
suffix(version,m.group("PRE"),m.group("OPT"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JavaVersion(
|
||||||
|
v,
|
||||||
|
(version[0]>=9 || version.length==1)?version[0]:version[1],
|
||||||
|
version[0],
|
||||||
|
version.length>1?version[1]:0,
|
||||||
|
version.length>2?version[2]:0,
|
||||||
|
0,
|
||||||
|
suffix(version,m.group("PRE"),m.group("OPT"))
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JavaVersion parsePreJDK9(String version)
|
private static String suffix(int[] version, String pre, String opt)
|
||||||
{
|
{
|
||||||
Matcher matcher = PRE_JDK9.matcher(version);
|
StringBuilder buf = new StringBuilder();
|
||||||
if (!matcher.matches())
|
for (int i=3;i<version.length;i++)
|
||||||
throw new IllegalArgumentException("Invalid Java version " + version);
|
{
|
||||||
int major = 1;
|
if (i>3)
|
||||||
int minor = Integer.parseInt(matcher.group(1));
|
buf.append(".");
|
||||||
String microGroup = matcher.group(3);
|
buf.append(version[i]);
|
||||||
int micro = microGroup == null || microGroup.isEmpty() ? 0 : Integer.parseInt(microGroup);
|
}
|
||||||
String updateGroup = matcher.group(5);
|
|
||||||
int update = updateGroup == null || updateGroup.isEmpty() ? 0 : Integer.parseInt(updateGroup);
|
|
||||||
String suffix = matcher.group(6);
|
|
||||||
return new JavaVersion(version, minor, major, minor, micro, update, suffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static JavaVersion parseJDK9(String version)
|
if (pre!=null)
|
||||||
{
|
{
|
||||||
Matcher matcher = JDK9.matcher(version);
|
if (buf.length()>0)
|
||||||
if (!matcher.matches())
|
buf.append('-');
|
||||||
throw new IllegalArgumentException("Invalid Java version " + version);
|
buf.append(pre);
|
||||||
int major = Integer.parseInt(matcher.group(1));
|
}
|
||||||
String minorGroup = matcher.group(3);
|
|
||||||
int minor = minorGroup == null || minorGroup.isEmpty() ? 0 : Integer.parseInt(minorGroup);
|
if (opt!=null)
|
||||||
String microGroup = matcher.group(5);
|
{
|
||||||
int micro = microGroup == null || microGroup.isEmpty() ? 0 : Integer.parseInt(microGroup);
|
if (buf.length()>0)
|
||||||
String suffix = matcher.group(6);
|
buf.append('-');
|
||||||
return new JavaVersion(version, major, major, minor, micro, 0, suffix);
|
buf.append(opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf.length()==0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String version;
|
private final String version;
|
||||||
|
@ -136,7 +184,7 @@ public class JavaVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Returns the micro number version, such as {@code 0} for JDK 1.8.0_92 and {@code 4} for JDK 9.2.4.</p>
|
* <p>Returns the micro number version (aka security number), such as {@code 0} for JDK 1.8.0_92 and {@code 4} for JDK 9.2.4.</p>
|
||||||
*
|
*
|
||||||
* @return the micro number version
|
* @return the micro number version
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -56,7 +56,10 @@ public class Jetty
|
||||||
LOG.ignore( e );
|
LOG.ignore( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
GIT_HASH = __buildProperties.getProperty( "buildNumber", "unknown" );
|
String git_hash = __buildProperties.getProperty( "buildNumber", "unknown" );
|
||||||
|
if (git_hash.startsWith("${"))
|
||||||
|
git_hash = "unknown";
|
||||||
|
GIT_HASH = git_hash;
|
||||||
System.setProperty( "jetty.git.hash" , GIT_HASH );
|
System.setProperty( "jetty.git.hash" , GIT_HASH );
|
||||||
BUILD_TIMESTAMP = formatTimestamp( __buildProperties.getProperty( "timestamp", "unknown" ));
|
BUILD_TIMESTAMP = formatTimestamp( __buildProperties.getProperty( "timestamp", "unknown" ));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue