diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2020-05-12 13:52:39 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-06-09 20:03:05 +0000 |
commit | 41d73907d9cf4b08c7483a6a07d5ad4efaf13f84 (patch) | |
tree | e20a82cf47a80f063c967562e8a3389d6891f787 /server/sonar-main/src | |
parent | ef7557b75dec680b0bed940f87e52023720b8a53 (diff) | |
download | sonarqube-41d73907d9cf4b08c7483a6a07d5ad4efaf13f84.tar.gz sonarqube-41d73907d9cf4b08c7483a6a07d5ad4efaf13f84.zip |
SONAR-14951 Scanners require Java 11
Diffstat (limited to 'server/sonar-main/src')
7 files changed, 25 insertions, 90 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 3490d66e033..9896319fe15 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,21 +25,18 @@ import java.util.Map; public class CeJvmOptions extends JvmOptions<CeJvmOptions> { - public CeJvmOptions(File tmpDir, JavaVersion javaVersion) { - super(mandatoryOptions(tmpDir, javaVersion)); + public CeJvmOptions(File tmpDir) { + super(mandatoryOptions(tmpDir)); } - private static Map<String, String> mandatoryOptions(File tmpDir, JavaVersion javaVersion) { + private static Map<String, String> mandatoryOptions(File tmpDir) { 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()); res.put("-XX:-OmitStackTraceInFastThrow", ""); - - 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 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 9bd07d512e6..b51d2a69e6f 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 @@ -75,13 +75,11 @@ 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, JavaVersion javaVersion) { + public CommandFactoryImpl(Props props, File tempDir, System2 system2) { 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) @@ -155,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, javaVersion) + WebJvmOptions jvmOptions = new WebJvmOptions(tempDir) .addFromMandatoryProperty(props, WEB_JAVA_OPTS.getKey()) .addFromMandatoryProperty(props, WEB_JAVA_ADDITIONAL_OPTS.getKey()); addProxyJvmOptions(jvmOptions); @@ -182,7 +180,7 @@ public class CommandFactoryImpl implements CommandFactory { public JavaCommand createCeCommand() { File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); - CeJvmOptions jvmOptions = new CeJvmOptions(tempDir, javaVersion) + CeJvmOptions jvmOptions = new CeJvmOptions(tempDir) .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/JavaVersion.java b/server/sonar-main/src/main/java/org/sonar/application/command/JavaVersion.java deleted file mode 100644 index b38df59de3a..00000000000 --- a/server/sonar-main/src/main/java/org/sonar/application/command/JavaVersion.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.application.command; - -public class JavaVersion { - public static final JavaVersion INSTANCE = new JavaVersion(); - - public boolean isAtLeastJava11() { - try { - String.class.getMethod("isBlank"); - return true; - } catch (NoSuchMethodException e) { - return false; - } - } -} 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 33ac1ef56ba..e5a7ea1afed 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,26 +24,24 @@ import java.util.LinkedHashMap; import java.util.Map; public class WebJvmOptions extends JvmOptions<WebJvmOptions> { - public WebJvmOptions(File tmpDir, JavaVersion javaVersion) { - super(mandatoryOptions(tmpDir, javaVersion)); + public WebJvmOptions(File tmpDir) { + super(mandatoryOptions(tmpDir)); } - private static Map<String, String> mandatoryOptions(File tmpDir, JavaVersion javaVersion) { + private static Map<String, String> mandatoryOptions(File tmpDir) { 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()); res.put("-XX:-OmitStackTraceInFastThrow", ""); - 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 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", ""); - } + // 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 853929f1f6c..db4bb86ef15 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,15 +27,12 @@ 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 @@ -44,17 +41,8 @@ public class CeJvmOptionsTest { } @Test - 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(), "-XX:-OmitStackTraceInFastThrow"); - } - - @Test - public void constructor_sets_mandatory_JVM_options_for_java11() { - when(javaVersion.isAtLeastJava11()).thenReturn(true); - underTest = new CeJvmOptions(tmpDir, javaVersion); + public void constructor_sets_mandatory_JVM_options() { + underTest = new CeJvmOptions(tmpDir); assertThat(underTest.getAll()).containsExactly( "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(), "-XX:-OmitStackTraceInFastThrow", "--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 f8d7029008a..ddcf1cad501 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,7 +53,6 @@ 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; @@ -77,7 +76,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, javaVersion); + new CommandFactoryImpl(new Props(new Properties()), tempDir, system2); assertThat(listAppender.getLogs()).isEmpty(); } @@ -87,7 +86,7 @@ public class CommandFactoryImplTest { when(system2.getenv("JAVA_TOOL_OPTIONS")).thenReturn("sds"); attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class); - new CommandFactoryImpl(new Props(new Properties()), tempDir, system2, javaVersion); + new CommandFactoryImpl(new Props(new Properties()), tempDir, system2); assertThat(listAppender.getLogs()) .extracting(ILoggingEvent::getMessage) @@ -101,7 +100,7 @@ public class CommandFactoryImplTest { when(system2.getenv("ES_JAVA_OPTS")).thenReturn("xyz"); attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class); - new CommandFactoryImpl(new Props(new Properties()), tempDir, system2, javaVersion); + new CommandFactoryImpl(new Props(new Properties()), tempDir, system2); assertThat(listAppender.getLogs()) .extracting(ILoggingEvent::getMessage) @@ -321,7 +320,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, javaVersion); + return new CommandFactoryImpl(props, tempDir, system2); } 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 4d966f7641e..e4f9da4b96f 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,15 +27,12 @@ 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 @@ -44,17 +41,8 @@ public class WebJvmOptionsTest { } @Test - 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(), "-XX:-OmitStackTraceInFastThrow"); - } - - @Test - public void constructor_sets_mandatory_JVM_options_for_java11() { - when(javaVersion.isAtLeastJava11()).thenReturn(true); - underTest = new WebJvmOptions(tmpDir, javaVersion); + public void constructor_sets_mandatory_JVM_options() { + underTest = new WebJvmOptions(tmpDir); assertThat(underTest.getAll()).containsExactly( "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(), "-XX:-OmitStackTraceInFastThrow", |