@Test public void testParseNew() throws Exception { 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)); } }
@Override public void configure(Binder binder) { binder.disableCircularProxies(); binder.bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer()); configBinder(binder).bindConfig(JmxConfig.class); newExporter(binder).export(StackTraceMBean.class).withGeneratedName(); binder.bind(StackTraceMBean.class).in(Scopes.SINGLETON); discoveryBinder(binder).bindServiceAnnouncement(JmxAnnouncementProvider.class); if (JavaVersion.current().getMajor() < 9) { binder.bind(JmxAgent8.class).in(Scopes.SINGLETON); binder.bind(JmxAgent.class).to(JmxAgent8.class); } else { binder.bind(JmxAgent9.class).in(Scopes.SINGLETON); binder.bind(JmxAgent.class).to(JmxAgent9.class); } }
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)); }
@Override public void configure(Binder binder) { binder.disableCircularProxies(); binder.bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer()); configBinder(binder).bindConfig(JmxConfig.class); newExporter(binder).export(StackTraceMBean.class).withGeneratedName(); binder.bind(StackTraceMBean.class).in(Scopes.SINGLETON); discoveryBinder(binder).bindServiceAnnouncement(JmxAnnouncementProvider.class); if (JavaVersion.current().getMajor() < 9) { binder.bind(JmxAgent8.class).in(Scopes.SINGLETON); binder.bind(JmxAgent.class).to(JmxAgent8.class); } else { binder.bind(JmxAgent9.class).in(Scopes.SINGLETON); binder.bind(JmxAgent.class).to(JmxAgent9.class); } }
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() throws Exception { 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)); } }
@Override public void configure(Binder binder) { binder.disableCircularProxies(); binder.bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer()); configBinder(binder).bindConfig(JmxConfig.class); newExporter(binder).export(StackTraceMBean.class).withGeneratedName(); binder.bind(StackTraceMBean.class).in(Scopes.SINGLETON); discoveryBinder(binder).bindServiceAnnouncement(JmxAnnouncementProvider.class); if (JavaVersion.current().getMajor() < 9) { binder.bind(JmxAgent8.class).in(Scopes.SINGLETON); binder.bind(JmxAgent.class).to(JmxAgent8.class); } else { binder.bind(JmxAgent9.class).in(Scopes.SINGLETON); binder.bind(JmxAgent.class).to(JmxAgent9.class); } }
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() throws Exception { 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_131-foo-bar-baz-qux"), new JavaVersion(8, 0, OptionalInt.of(131))); }
@Test public void testParseLegacy() throws Exception { 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_131-foo-bar-baz-qux"), new JavaVersion(8, 0, OptionalInt.of(131))); }