From a0b253f44108cbb210c1e92fe5bd47a2fc78d16c Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 26 May 2016 15:51:33 +0200 Subject: [PATCH] SONAR-7653 remove useless code JVM does not start if runtime version is not 1.8, so it's useless to check java version programmatically. --- .../main/java/org/sonar/ce/app/CeServer.java | 1 - .../org/sonar/process/MinimumViableSystem.java | 18 +----------------- .../sonar/process/MinimumViableSystemTest.java | 17 +---------------- .../java/org/sonar/search/SearchServer.java | 1 - .../java/org/sonar/server/app/WebServer.java | 1 - .../main/java/org/sonar/application/App.java | 2 -- 6 files changed, 2 insertions(+), 38 deletions(-) diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java index 1954b218eb0..34887667ca5 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java @@ -67,7 +67,6 @@ public class CeServer implements Monitored { this.webServerWatcher = webServerWatcher; this.computeEngine = computeEngine; mvs - .checkJavaVersion() .checkWritableTempDir() .checkRequiredJavaOptions(ImmutableMap.of("file.encoding", "UTF-8")); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java b/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java index 3b20d57c5dc..2d959c44613 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java +++ b/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java @@ -19,11 +19,10 @@ */ package org.sonar.process; -import org.apache.commons.lang.StringUtils; - import java.io.File; import java.io.IOException; import java.util.Map; +import org.apache.commons.lang.StringUtils; import static java.lang.String.format; import static org.sonar.process.FileUtils.deleteQuietly; @@ -58,19 +57,4 @@ public class MinimumViableSystem { } return this; } - - public MinimumViableSystem checkJavaVersion() { - String javaVersion = System.getProperty("java.specification.version"); - checkJavaVersion(javaVersion); - return this; - } - - // Visible for testing - void checkJavaVersion(String javaVersion) { - if (!javaVersion.startsWith("1.7") && !javaVersion.startsWith("1.8")) { - // still better than "java.lang.UnsupportedClassVersionError: Unsupported major.minor version 49.0 - throw new MessageException(format("Supported versions of Java are 1.7 and 1.8. Got %s.", javaVersion)); - } - } - } diff --git a/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java b/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java index 1f0b88730bf..0b10bd66c03 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java @@ -20,12 +20,11 @@ package org.sonar.process; import com.google.common.collect.ImmutableMap; +import java.io.File; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import java.io.File; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -36,20 +35,6 @@ public class MinimumViableSystemTest { MinimumViableSystem underTest = new MinimumViableSystem(); - @Test - public void checkJavaVersion() { - // yes, sources are compiled with a supported Java version! - underTest.checkJavaVersion(); - underTest.checkJavaVersion("1.7"); - - try { - underTest.checkJavaVersion("1.6"); - fail(); - } catch (MessageException e) { - assertThat(e).hasMessage("Supported versions of Java are 1.7 and 1.8. Got 1.6."); - } - } - @Test public void checkRequiredJavaOptions() { String key = "MinimumViableEnvironmentTest.test.prop"; diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java index eda960f22b3..899ab6891b8 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java +++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java @@ -36,7 +36,6 @@ public class SearchServer implements Monitored { public SearchServer(Props props) { this.settings = new EsSettings(props); new MinimumViableSystem() - .checkJavaVersion() .checkWritableTempDir(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java b/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java index 4dda540667c..7e6333899ba 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java @@ -32,7 +32,6 @@ public class WebServer implements Monitored { WebServer(Props props) { new MinimumViableSystem() - .checkJavaVersion() .checkWritableTempDir() .checkRequiredJavaOptions(ImmutableMap.of("file.encoding", "UTF-8")); this.tomcat = new EmbeddedTomcat(props); diff --git a/sonar-application/src/main/java/org/sonar/application/App.java b/sonar-application/src/main/java/org/sonar/application/App.java index de5db3c03e4..8c8d73529a8 100644 --- a/sonar-application/src/main/java/org/sonar/application/App.java +++ b/sonar-application/src/main/java/org/sonar/application/App.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Properties; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; -import org.sonar.process.MinimumViableSystem; import org.sonar.process.ProcessId; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; @@ -128,7 +127,6 @@ public class App implements Stoppable { } public static void main(String[] args) throws Exception { - new MinimumViableSystem().checkJavaVersion(); CommandLineParser cli = new CommandLineParser(); Properties rawProperties = cli.parseArguments(args); Props props = new PropsBuilder(rawProperties, new JdbcSettings()).build(); -- 2.39.5