aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-main
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-06-21 14:03:02 -0500
committersonartech <sonartech@sonarsource.com>2019-06-28 08:45:48 +0200
commit753dcaa9e056c9f582145167db63f66e482bbbd0 (patch)
tree3a4f938c618cf4d29405dd6a403c808b82b5abb9 /server/sonar-main
parent490653d0c92fb4fb453802adaa9e181f74bca8ac (diff)
downloadsonarqube-753dcaa9e056c9f582145167db63f66e482bbbd0.tar.gz
sonarqube-753dcaa9e056c9f582145167db63f66e482bbbd0.zip
SONAR-12002 Fail startup if JRE < 11
Diffstat (limited to 'server/sonar-main')
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/command/CeJvmOptions.java13
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java8
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/command/WebJvmOptions.java21
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/command/CeJvmOptionsTest.java16
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java9
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/command/WebJvmOptionsTest.java18
6 files changed, 58 insertions, 27 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/CeJvmOptions.java b/server/sonar-main/src/main/java/org/sonar/application/command/CeJvmOptions.java
index 57e6e95b052..44a58d1d52d 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/command/CeJvmOptions.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/command/CeJvmOptions.java
@@ -25,19 +25,20 @@ import java.util.Map;
public class CeJvmOptions extends JvmOptions<CeJvmOptions> {
- public CeJvmOptions(File tmpDir) {
- super(mandatoryOptions(tmpDir));
+ public CeJvmOptions(File tmpDir, JavaVersion javaVersion) {
+ super(mandatoryOptions(tmpDir, javaVersion));
}
- private static Map<String, String> mandatoryOptions(File tmpDir) {
+ private static Map<String, String> mandatoryOptions(File tmpDir, JavaVersion javaVersion) {
Map<String, String> res = new LinkedHashMap<>(3);
res.put("-Djava.awt.headless=", "true");
res.put("-Dfile.encoding=", "UTF-8");
res.put("-Djava.io.tmpdir=", tmpDir.getAbsolutePath());
- // avoid illegal reflective access operations done by MyBatis
- res.put("--add-opens=java.base/java.util=ALL-UNNAMED", "");
-
+ if (javaVersion.isAtLeastJava11()) {
+ // avoid illegal reflective access operations done by MyBatis
+ res.put("--add-opens=java.base/java.util=ALL-UNNAMED", "");
+ }
return res;
}
}
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
index f254c255e20..6e4a0aaea73 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
@@ -72,11 +72,13 @@ public class CommandFactoryImpl implements CommandFactory {
private final Props props;
private final File tempDir;
private final System2 system2;
+ private final JavaVersion javaVersion;
- public CommandFactoryImpl(Props props, File tempDir, System2 system2) {
+ public CommandFactoryImpl(Props props, File tempDir, System2 system2, JavaVersion javaVersion) {
this.props = props;
this.tempDir = tempDir;
this.system2 = system2;
+ this.javaVersion = javaVersion;
String javaToolOptions = system2.getenv(ENV_VAR_JAVA_TOOL_OPTIONS);
if (javaToolOptions != null && !javaToolOptions.trim().isEmpty()) {
LoggerFactory.getLogger(CommandFactoryImpl.class)
@@ -151,7 +153,7 @@ public class CommandFactoryImpl implements CommandFactory {
public JavaCommand createWebCommand(boolean leader) {
File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey());
- WebJvmOptions jvmOptions = new WebJvmOptions(tempDir)
+ WebJvmOptions jvmOptions = new WebJvmOptions(tempDir, javaVersion)
.addFromMandatoryProperty(props, WEB_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, WEB_JAVA_ADDITIONAL_OPTS.getKey());
addProxyJvmOptions(jvmOptions);
@@ -178,7 +180,7 @@ public class CommandFactoryImpl implements CommandFactory {
public JavaCommand createCeCommand() {
File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey());
- CeJvmOptions jvmOptions = new CeJvmOptions(tempDir)
+ CeJvmOptions jvmOptions = new CeJvmOptions(tempDir, javaVersion)
.addFromMandatoryProperty(props, CE_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, CE_JAVA_ADDITIONAL_OPTS.getKey());
addProxyJvmOptions(jvmOptions);
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/WebJvmOptions.java b/server/sonar-main/src/main/java/org/sonar/application/command/WebJvmOptions.java
index 9b13df769de..8e55debe854 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/command/WebJvmOptions.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/command/WebJvmOptions.java
@@ -24,24 +24,25 @@ import java.util.LinkedHashMap;
import java.util.Map;
public class WebJvmOptions extends JvmOptions<WebJvmOptions> {
- public WebJvmOptions(File tmpDir) {
- super(mandatoryOptions(tmpDir));
+ public WebJvmOptions(File tmpDir, JavaVersion javaVersion) {
+ super(mandatoryOptions(tmpDir, javaVersion));
}
- private static Map<String, String> mandatoryOptions(File tmpDir) {
+ private static Map<String, String> mandatoryOptions(File tmpDir, JavaVersion javaVersion) {
Map<String, String> res = new LinkedHashMap<>(3);
res.put("-Djava.awt.headless=", "true");
res.put("-Dfile.encoding=", "UTF-8");
res.put("-Djava.io.tmpdir=", tmpDir.getAbsolutePath());
- // avoid illegal reflective access operations done by MyBatis
- res.put("--add-opens=java.base/java.util=ALL-UNNAMED", "");
-
- // avoid illegal reflective access operations done by Tomcat
- res.put("--add-opens=java.base/java.lang=ALL-UNNAMED", "");
- res.put("--add-opens=java.base/java.io=ALL-UNNAMED", "");
- res.put("--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED", "");
+ if (javaVersion.isAtLeastJava11()) {
+ // avoid illegal reflective access operations done by MyBatis
+ res.put("--add-opens=java.base/java.util=ALL-UNNAMED", "");
+ // avoid illegal reflective access operations done by Tomcat
+ res.put("--add-opens=java.base/java.lang=ALL-UNNAMED", "");
+ res.put("--add-opens=java.base/java.io=ALL-UNNAMED", "");
+ res.put("--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED", "");
+ }
return res;
}
}
diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/CeJvmOptionsTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/CeJvmOptionsTest.java
index 89ee9972281..863ee763340 100644
--- a/server/sonar-main/src/test/java/org/sonar/application/command/CeJvmOptionsTest.java
+++ b/server/sonar-main/src/test/java/org/sonar/application/command/CeJvmOptionsTest.java
@@ -27,22 +27,34 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class CeJvmOptionsTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private File tmpDir;
+ private JavaVersion javaVersion = mock(JavaVersion.class);
private CeJvmOptions underTest;
@Before
public void setUp() throws IOException {
tmpDir = temporaryFolder.newFolder();
- underTest = new CeJvmOptions(tmpDir);
}
@Test
- public void constructor_sets_mandatory_JVM_options() {
+ public void constructor_sets_mandatory_JVM_options_before_java11() {
+ when(javaVersion.isAtLeastJava11()).thenReturn(false);
+ underTest = new CeJvmOptions(tmpDir, javaVersion);
+ assertThat(underTest.getAll()).containsExactly(
+ "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath());
+ }
+
+ @Test
+ public void constructor_sets_mandatory_JVM_options_for_java11() {
+ when(javaVersion.isAtLeastJava11()).thenReturn(true);
+ underTest = new CeJvmOptions(tmpDir, javaVersion);
assertThat(underTest.getAll()).containsExactly(
"-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
"--add-opens=java.base/java.util=ALL-UNNAMED");
diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
index ff20bebcd0b..babc1e2204b 100644
--- a/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
+++ b/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
@@ -53,6 +53,7 @@ public class CommandFactoryImplTest {
public TemporaryFolder temp = new TemporaryFolder();
private System2 system2 = Mockito.mock(System2.class);
+ private JavaVersion javaVersion = Mockito.mock(JavaVersion.class);
private File homeDir;
private File tempDir;
private File logsDir;
@@ -76,7 +77,7 @@ public class CommandFactoryImplTest {
public void constructor_logs_no_warning_if_env_variable_JAVA_TOOL_OPTIONS_is_not_set() {
attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class);
- new CommandFactoryImpl(new Props(new Properties()), tempDir, system2);
+ new CommandFactoryImpl(new Props(new Properties()), tempDir, system2, javaVersion);
assertThat(listAppender.getLogs()).isEmpty();
}
@@ -86,7 +87,7 @@ public class CommandFactoryImplTest {
when(system2.getenv("JAVA_TOOL_OPTIONS")).thenReturn("sds");
attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class);
- new CommandFactoryImpl(new Props(new Properties()), tempDir, system2);
+ new CommandFactoryImpl(new Props(new Properties()), tempDir, system2, javaVersion);
assertThat(listAppender.getLogs())
.extracting(ILoggingEvent::getMessage)
@@ -100,7 +101,7 @@ public class CommandFactoryImplTest {
when(system2.getenv("ES_JAVA_OPTS")).thenReturn("xyz");
attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class);
- new CommandFactoryImpl(new Props(new Properties()), tempDir, system2);
+ new CommandFactoryImpl(new Props(new Properties()), tempDir, system2, javaVersion);
assertThat(listAppender.getLogs())
.extracting(ILoggingEvent::getMessage)
@@ -325,7 +326,7 @@ public class CommandFactoryImplTest {
ServiceLoaderWrapper serviceLoaderWrapper = mock(ServiceLoaderWrapper.class);
when(serviceLoaderWrapper.load()).thenReturn(ImmutableSet.of());
new ProcessProperties(serviceLoaderWrapper).completeDefaults(props);
- return new CommandFactoryImpl(props, tempDir, system2);
+ return new CommandFactoryImpl(props, tempDir, system2, javaVersion);
}
private <T> void attachMemoryAppenderToLoggerOf(Class<T> loggerClass) {
diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/WebJvmOptionsTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/WebJvmOptionsTest.java
index 2d647b6dc8d..5ab518cbb16 100644
--- a/server/sonar-main/src/test/java/org/sonar/application/command/WebJvmOptionsTest.java
+++ b/server/sonar-main/src/test/java/org/sonar/application/command/WebJvmOptionsTest.java
@@ -27,22 +27,35 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class WebJvmOptionsTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private File tmpDir;
+ private JavaVersion javaVersion = mock(JavaVersion.class);
private WebJvmOptions underTest;
@Before
public void setUp() throws IOException {
tmpDir = temporaryFolder.newFolder();
- underTest = new WebJvmOptions(tmpDir);
}
@Test
- public void constructor_sets_mandatory_JVM_options() {
+ public void constructor_sets_mandatory_JVM_options_before_java11() {
+ when(javaVersion.isAtLeastJava11()).thenReturn(false);
+ underTest = new WebJvmOptions(tmpDir, javaVersion);
+ assertThat(underTest.getAll()).containsExactly(
+ "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath());
+ }
+
+ @Test
+ public void constructor_sets_mandatory_JVM_options_for_java11() throws IOException {
+ when(javaVersion.isAtLeastJava11()).thenReturn(true);
+ underTest = new WebJvmOptions(tmpDir, javaVersion);
+
assertThat(underTest.getAll()).containsExactly(
"-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
"--add-opens=java.base/java.util=ALL-UNNAMED",
@@ -50,4 +63,5 @@ public class WebJvmOptionsTest {
"--add-opens=java.base/java.io=ALL-UNNAMED",
"--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED");
}
+
}