From af0fd0c86e23a75cc5258628e1860f3fe995f0de Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 25 Aug 2014 11:30:40 +0200 Subject: [PATCH] Minimum Viable Environment checks Java 1.6, 1.7 or 1.8 but not >= 1.6 --- .../main/java/org/sonar/process/MinimumViableSystem.java | 6 +++--- .../java/org/sonar/process/MinimumViableSystemTest.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java b/server/process/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java index 64526f56985..591be4198fd 100644 --- a/server/process/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java +++ b/server/process/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java @@ -70,14 +70,14 @@ public class MinimumViableSystem { } void checkJavaVersion() { - String javaVersion = System.getProperty("java.version"); + String javaVersion = System.getProperty("java.specification.version"); checkJavaVersion(javaVersion); } void checkJavaVersion(String javaVersion) { - if (javaVersion.startsWith("1.3") || javaVersion.startsWith("1.4") || javaVersion.startsWith("1.5")) { + if (!javaVersion.startsWith("1.6") && !javaVersion.startsWith("1.7") && !javaVersion.startsWith("1.8")) { // still better than "java.lang.UnsupportedClassVersionError: Unsupported major.minor version 49.0 - throw new MessageException(String.format("Minimal required Java version is 1.6. Got %s.", javaVersion)); + throw new MessageException(String.format("Supported versions of Java are 1.6, 1.7 and 1.8. Got %s.", javaVersion)); } } diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java index 11088902b14..a1bc83477bb 100644 --- a/server/process/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java +++ b/server/process/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java @@ -48,13 +48,13 @@ public class MinimumViableSystemTest { // yes, sources are compiled with a supported Java version! mve.checkJavaVersion(); + mve.checkJavaVersion("1.6"); - mve.checkJavaVersion("1.6.1_b2"); try { - mve.checkJavaVersion("1.5.2"); + mve.checkJavaVersion("1.9"); fail(); } catch (MessageException e) { - Assertions.assertThat(e).hasMessage("Minimal required Java version is 1.6. Got 1.5.2."); + Assertions.assertThat(e).hasMessage("Supported versions of Java are 1.6, 1.7 and 1.8. Got 1.9."); } } -- 2.39.5