private static void verifyJavaVersion() { String javaVersion = StandardSystemProperty.JAVA_VERSION.value(); if (javaVersion == null) { failRequirement("Java version not defined"); } JavaVersion version = JavaVersion.parse(javaVersion); if (version.getMajor() == 8 && version.getUpdate().isPresent() && version.getUpdate().getAsInt() >= 151) { return; } if (version.getMajor() >= 9) { return; } failRequirement("Presto requires Java 8u151+ (found %s)", javaVersion); }
@Test public void testParseNew() { assertEquals(JavaVersion.parse("9-ea+19"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9+100"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9.0.1+20"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9.1.1+20"), new JavaVersion(9, 1)); } }
public static JavaVersion current() { return parse(StandardSystemProperty.JAVA_VERSION.value()); }
public static JavaVersion parse(String version) { Matcher matcher = LEGACY_PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); String update = matcher.group("UPDATE"); if (update == null) { return new JavaVersion(major, minor); } return new JavaVersion(major, minor, OptionalInt.of(Integer.parseInt(update))); } matcher = PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); return new JavaVersion(major, minor); } throw new IllegalArgumentException(format("Cannot parse version %s", version)); }
@Test public void testParseNew() { assertEquals(JavaVersion.parse("9-ea+19"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9+100"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9.0.1+20"), new JavaVersion(9, 0)); assertEquals(JavaVersion.parse("9.1.1+20"), new JavaVersion(9, 1)); } }
public static JavaVersion current() { return parse(StandardSystemProperty.JAVA_VERSION.value()); }
public static JavaVersion parse(String version) { Matcher matcher = LEGACY_PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); String update = matcher.group("UPDATE"); if (update == null) { return new JavaVersion(major, minor); } return new JavaVersion(major, minor, OptionalInt.of(Integer.parseInt(update))); } matcher = PATTERN.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("MAJOR")); int minor = Optional.ofNullable(matcher.group("MINOR")) .map(Integer::parseInt) .orElse(0); return new JavaVersion(major, minor); } throw new IllegalArgumentException(format("Cannot parse version %s", version)); }
@Test public void testParseLegacy() { assertEquals(JavaVersion.parse("1.8"), new JavaVersion(8, 0)); assertEquals(JavaVersion.parse("1.8.0"), new JavaVersion(8, 0)); assertEquals(JavaVersion.parse("1.8.0_5"), new JavaVersion(8, 0, OptionalInt.of(5))); assertEquals(JavaVersion.parse("1.8.0_20"), new JavaVersion(8, 0, OptionalInt.of(20))); assertEquals(JavaVersion.parse("1.8.1_25"), new JavaVersion(8, 1, OptionalInt.of(25))); assertEquals(JavaVersion.parse("1.8.0_60-ea"), new JavaVersion(8, 0, OptionalInt.of(60))); assertEquals(JavaVersion.parse("1.8.0_111-internal"), new JavaVersion(8, 0, OptionalInt.of(111))); }
private static void verifyJavaVersion() { String javaVersion = StandardSystemProperty.JAVA_VERSION.value(); if (javaVersion == null) { failRequirement("Java version not defined"); } JavaVersion version = JavaVersion.parse(javaVersion); if (version.getMajor() == 8 && version.getUpdate().isPresent() && version.getUpdate().getAsInt() >= 151) { return; } if (version.getMajor() >= 9) { return; } failRequirement("Presto requires Java 8u151+ (found %s)", javaVersion); }
@Test public void testParseLegacy() { assertEquals(JavaVersion.parse("1.8"), new JavaVersion(8, 0)); assertEquals(JavaVersion.parse("1.8.0"), new JavaVersion(8, 0)); assertEquals(JavaVersion.parse("1.8.0_5"), new JavaVersion(8, 0, OptionalInt.of(5))); assertEquals(JavaVersion.parse("1.8.0_20"), new JavaVersion(8, 0, OptionalInt.of(20))); assertEquals(JavaVersion.parse("1.8.1_25"), new JavaVersion(8, 1, OptionalInt.of(25))); assertEquals(JavaVersion.parse("1.8.0_60-ea"), new JavaVersion(8, 0, OptionalInt.of(60))); assertEquals(JavaVersion.parse("1.8.0_111-internal"), new JavaVersion(8, 0, OptionalInt.of(111))); }