From 41d73907d9cf4b08c7483a6a07d5ad4efaf13f84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 12 May 2020 13:52:39 +0200 Subject: [PATCH] SONAR-14951 Scanners require Java 11 --- build.gradle | 74 +++++++++++++++++-- plugins/sonar-xoo-plugin/build.gradle | 2 + .../ce/container/CePluginRepository.java | 4 +- .../application/command/CeJvmOptions.java | 13 ++-- .../command/CommandFactoryImpl.java | 8 +- .../application/command/JavaVersion.java | 33 --------- .../application/command/WebJvmOptions.java | 20 +++-- .../application/command/CeJvmOptionsTest.java | 16 +--- .../command/CommandFactoryImplTest.java | 9 +-- .../command/WebJvmOptionsTest.java | 16 +--- .../email/EmailNotificationChannel.java | 2 +- .../org/sonar/server/rule/RegisterRules.java | 2 +- .../main/java/org/sonar/application/App.java | 20 +---- sonar-check-api/build.gradle | 2 + sonar-core/build.gradle | 2 + sonar-markdown/build.gradle | 2 + sonar-plugin-api-impl/build.gradle | 2 + sonar-plugin-api/build.gradle | 2 + .../java/org/sonar/scanner/ProjectInfo.java | 2 +- .../scanner/bootstrap/GlobalContainer.java | 14 ---- sonar-scanner-protocol/build.gradle | 2 + sonar-testing-harness/build.gradle | 2 + sonar-ws/build.gradle | 2 + 23 files changed, 116 insertions(+), 135 deletions(-) delete mode 100644 server/sonar-main/src/main/java/org/sonar/application/command/JavaVersion.java diff --git a/build.gradle b/build.gradle index 874b93c60c4..9a738e93b22 100644 --- a/build.gradle +++ b/build.gradle @@ -164,9 +164,6 @@ subprojects { apply plugin: 'idea' apply plugin: 'signing' - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - // do not deploy to Artifactory by default artifactoryPublish.skip = true @@ -177,8 +174,74 @@ subprojects { ext { protobufVersion = '3.11.4' + + // define a method which can be called by project to change Java version to compile to + configureCompileJavaToVersion = { javaVersion -> + if ( javaVersion != 11 & javaVersion != 8) { + throw new InvalidUserDataException("Only Java 8 and 11 are supported") + } + if ( javaVersion == 8 ) { + println "Configuring project ${project.name} to compile to Java ${javaVersion}" + + if (!project.hasProperty('skipJava8Checks')) { + task ensureDependenciesRunOnJava8(dependsOn: [configurations.compileClasspath]) { + ext.readJavaMajorVersion = { classFile -> + classFile.withDataInputStream({ d -> + if (d.skip(7) == 7) { + // read the version of the class file + d.read() + } else { + throw new GradleException("Could not read major version from $classFile") + } + }) + } + + doLast { + [configurations.compileClasspath].each { config -> + config.resolvedConfiguration.files + .findAll({ f -> f.name.endsWith("jar") }) + .each { jarFile -> + def onlyJava8 = true + zipTree(jarFile) + .matching({ + include "**/*.class" + // multi-release jar files were introduced with Java 9 => contains only classes targeting Java 9+ + exclude "META-INF/versions/**" + // ignore module-info existing in some archives for Java 9 forward compatibility + exclude "module-info.class" + }) + .files + .each { classFile -> + int javaMajorVersion = readJavaMajorVersion(classFile) + if (javaMajorVersion > 52) { + println "$classFile has been compiled to a more recent version of Java than 8 (java8=52, java11=55, actual=$javaMajorVersion)" + onlyJava8 = false + } + } + if (!onlyJava8) { + throw new GradleException("Dependency ${jarFile} in configuration ${config.name} contains class file(s) compiled to a Java version > Java 8 (see logs for details)") + } + } + } + } + } + + compileJava.dependsOn ensureDependenciesRunOnJava8 + } + } + + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + + tasks.withType(JavaCompile) { + options.compilerArgs.addAll(['--release', javaVersion + '']) + options.encoding = 'UTF-8' + } + } } + configureCompileJavaToVersion 11 + sonarqube { properties { property 'sonar.moduleKey', project.group + ':' + project.name @@ -367,11 +430,6 @@ subprojects { exclude group: 'javax.mail', module: 'mail' } - tasks.withType(JavaCompile) { - options.compilerArgs.addAll(['--release', '8']) - options.encoding = 'UTF-8' - } - tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') options.encoding = 'UTF-8' diff --git a/plugins/sonar-xoo-plugin/build.gradle b/plugins/sonar-xoo-plugin/build.gradle index df25e2a4593..b4bb30a3c11 100644 --- a/plugins/sonar-xoo-plugin/build.gradle +++ b/plugins/sonar-xoo-plugin/build.gradle @@ -2,6 +2,8 @@ configurations { testCompile.extendsFrom(compileOnly) } +configureCompileJavaToVersion 8 + dependencies { compile 'com.google.guava:guava' compile 'commons-io:commons-io' diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java index ae22d5ddb3e..38da7d20514 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java @@ -19,12 +19,12 @@ */ package org.sonar.ce.container; -import com.google.common.collect.ImmutableList; import java.io.File; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; @@ -100,7 +100,7 @@ public class CePluginRepository implements PluginRepository, Startable { @Override public Collection getPluginInfos() { checkState(started.get(), NOT_STARTED_YET); - return ImmutableList.copyOf(pluginInfosByKeys.values()); + return Set.copyOf(pluginInfosByKeys.values()); } @Override 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 { - public CeJvmOptions(File tmpDir, JavaVersion javaVersion) { - super(mandatoryOptions(tmpDir, javaVersion)); + public CeJvmOptions(File tmpDir) { + super(mandatoryOptions(tmpDir)); } - private static Map mandatoryOptions(File tmpDir, JavaVersion javaVersion) { + private static Map mandatoryOptions(File tmpDir) { Map 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 { - public WebJvmOptions(File tmpDir, JavaVersion javaVersion) { - super(mandatoryOptions(tmpDir, javaVersion)); + public WebJvmOptions(File tmpDir) { + super(mandatoryOptions(tmpDir)); } - private static Map mandatoryOptions(File tmpDir, JavaVersion javaVersion) { + private static Map mandatoryOptions(File tmpDir) { Map 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 void attachMemoryAppenderToLoggerOf(Class 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", diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java index e7813b984bd..39eee326b0c 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java @@ -176,7 +176,7 @@ public class EmailNotificationChannel extends NotificationChannel { } return (int) deliveries.stream() - .filter(t -> !t.getRecipientEmail().trim().isEmpty()) + .filter(t -> !t.getRecipientEmail().isBlank()) .map(t -> { EmailMessage emailMessage = format(t.getNotification()); if (emailMessage != null) { diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java index 86b5c3148c5..ce0fc6e48e0 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java @@ -225,7 +225,7 @@ public class RegisterRules implements Startable { .filter(Objects::nonNull) .findFirst(); // may occur in case of plugin downgrade - if (!res.isPresent()) { + if (res.isEmpty()) { return Optional.ofNullable(dbRulesByDbDeprecatedKey.get(ruleKey)); } return res; 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 aaea1090f12..bd4b19204e3 100644 --- a/sonar-application/src/main/java/org/sonar/application/App.java +++ b/sonar-application/src/main/java/org/sonar/application/App.java @@ -19,12 +19,9 @@ */ package org.sonar.application; -import org.sonar.api.SonarEdition; -import org.sonar.api.internal.MetadataLoader; import org.sonar.api.utils.log.Loggers; import org.sonar.application.command.CommandFactory; import org.sonar.application.command.CommandFactoryImpl; -import org.sonar.application.command.JavaVersion; import org.sonar.application.config.AppSettings; import org.sonar.application.config.AppSettingsLoader; import org.sonar.application.config.AppSettingsLoaderImpl; @@ -32,19 +29,14 @@ import org.sonar.core.extension.ServiceLoaderWrapper; import org.sonar.process.System2; import org.sonar.process.SystemExit; -import static com.google.common.base.Preconditions.checkState; import static org.sonar.application.config.SonarQubeVersionHelper.getSonarqubeVersion; import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME; public class App { private final SystemExit systemExit = new SystemExit(); - private final JavaVersion javaVersion; private StopRequestWatcher stopRequestWatcher = null; private StopRequestWatcher hardStopRequestWatcher = null; - public App(JavaVersion javaVersion) { - this.javaVersion = javaVersion; - } public void start(String[] cliArguments) { AppSettingsLoader settingsLoader = new AppSettingsLoaderImpl(System2.INSTANCE, cliArguments, new ServiceLoaderWrapper()); @@ -53,14 +45,13 @@ public class App { AppLogging logging = new AppLogging(settings); logging.configure(); AppFileSystem fileSystem = new AppFileSystem(settings); - checkJavaVersion(); try (AppState appState = new AppStateFactory(settings).create()) { appState.registerSonarQubeVersion(getSonarqubeVersion()); appState.registerClusterName(settings.getProps().nonNullValue(CLUSTER_NAME.getKey())); AppReloader appReloader = new AppReloaderImpl(settingsLoader, fileSystem, appState, logging); fileSystem.reset(); - CommandFactory commandFactory = new CommandFactoryImpl(settings.getProps(), fileSystem.getTempDir(), System2.INSTANCE, JavaVersion.INSTANCE); + CommandFactory commandFactory = new CommandFactoryImpl(settings.getProps(), fileSystem.getTempDir(), System2.INSTANCE); try (ProcessLauncher processLauncher = new ProcessLauncherImpl(fileSystem.getTempDir())) { Scheduler scheduler = new SchedulerImpl(settings, appReloader, commandFactory, processLauncher, appState); @@ -86,15 +77,8 @@ public class App { systemExit.exit(0); } - private void checkJavaVersion() { - if (MetadataLoader.loadEdition(org.sonar.api.utils.System2.INSTANCE) == SonarEdition.SONARCLOUD) { - return; - } - checkState(javaVersion.isAtLeastJava11(), "SonarQube requires Java 11 to run"); - } - public static void main(String[] args) throws Exception { - new App(JavaVersion.INSTANCE).start(args); + new App().start(args); } private class ShutdownHook extends Thread { diff --git a/sonar-check-api/build.gradle b/sonar-check-api/build.gradle index f76bc07f842..bf0f33e4f29 100644 --- a/sonar-check-api/build.gradle +++ b/sonar-check-api/build.gradle @@ -4,6 +4,8 @@ sonarqube { } } +configureCompileJavaToVersion 8 + dependencies { compileOnly 'com.google.code.findbugs:jsr305' } diff --git a/sonar-core/build.gradle b/sonar-core/build.gradle index 7a44963f1c3..3b658b278c9 100644 --- a/sonar-core/build.gradle +++ b/sonar-core/build.gradle @@ -4,6 +4,8 @@ sonarqube { } } +configureCompileJavaToVersion 8 + dependencies { // please keep list ordered diff --git a/sonar-markdown/build.gradle b/sonar-markdown/build.gradle index 16e8e834cdc..f75aae381bf 100644 --- a/sonar-markdown/build.gradle +++ b/sonar-markdown/build.gradle @@ -4,6 +4,8 @@ sonarqube { } } +configureCompileJavaToVersion 8 + dependencies { // please keep list ordered diff --git a/sonar-plugin-api-impl/build.gradle b/sonar-plugin-api-impl/build.gradle index ee9930a295d..303fa2f1549 100644 --- a/sonar-plugin-api-impl/build.gradle +++ b/sonar-plugin-api-impl/build.gradle @@ -4,6 +4,8 @@ sonarqube { } } +configureCompileJavaToVersion 8 + dependencies { // please keep the list grouped by configuration and ordered by name diff --git a/sonar-plugin-api/build.gradle b/sonar-plugin-api/build.gradle index 04612e58427..8cdf7778f70 100644 --- a/sonar-plugin-api/build.gradle +++ b/sonar-plugin-api/build.gradle @@ -4,6 +4,8 @@ sonarqube { } } +configureCompileJavaToVersion 8 + apply plugin: 'com.github.johnrengelman.shadow' dependencies { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java index bd1028670f9..dea7bdfc6e1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java @@ -66,7 +66,7 @@ public class ProjectInfo implements Startable { private Date loadAnalysisDate() { Optional value = settings.get(CoreProperties.PROJECT_DATE_PROPERTY); - if (!value.isPresent()) { + if (value.isEmpty()) { return Date.from(clock.instant()); } try { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java index e8aee0067b9..dfc5047dd19 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java @@ -31,7 +31,6 @@ import org.sonar.api.SonarQubeVersion; import org.sonar.api.SonarRuntime; import org.sonar.api.internal.MetadataLoader; import org.sonar.api.internal.SonarRuntimeImpl; -import org.sonar.api.notifications.AnalysisWarnings; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.System2; import org.sonar.api.utils.UriReader; @@ -83,23 +82,10 @@ public class GlobalContainer extends ComponentContainer { addBootstrapComponents(); } - private static void checkJavaVersion(AnalysisWarnings analysisWarnings) { - try { - String.class.getMethod("isBlank"); - } catch (NoSuchMethodException e) { - LOG.warn("SonarScanner will require Java 11 to run, starting in SonarQube 9.x"); - analysisWarnings.addUnique("SonarScanner will require Java 11 to run, starting in SonarQube 9.x. Please upgrade the version of Java that executes the scanner and " + - "refer to the documentation if needed."); - } - } - private void addBootstrapComponents() { Version apiVersion = MetadataLoader.loadVersion(System2.INSTANCE); SonarEdition edition = MetadataLoader.loadEdition(System2.INSTANCE); DefaultAnalysisWarnings analysisWarnings = new DefaultAnalysisWarnings(System2.INSTANCE); - if (edition != SonarEdition.SONARCLOUD) { - checkJavaVersion(analysisWarnings); - } LOG.debug("{} {}", edition.getLabel(), apiVersion); add( // plugins diff --git a/sonar-scanner-protocol/build.gradle b/sonar-scanner-protocol/build.gradle index 805cedb6d12..f89669bd222 100644 --- a/sonar-scanner-protocol/build.gradle +++ b/sonar-scanner-protocol/build.gradle @@ -5,6 +5,8 @@ sonarqube { } } +configureCompileJavaToVersion 8 + dependencies { // please keep the list ordered compile 'com.google.code.gson:gson' diff --git a/sonar-testing-harness/build.gradle b/sonar-testing-harness/build.gradle index 2138f193b85..80da028df67 100644 --- a/sonar-testing-harness/build.gradle +++ b/sonar-testing-harness/build.gradle @@ -4,6 +4,8 @@ sonarqube { } } +configureCompileJavaToVersion 8 + dependencies { // please keep list ordered diff --git a/sonar-ws/build.gradle b/sonar-ws/build.gradle index a1640ab28b0..bfb707e01e7 100644 --- a/sonar-ws/build.gradle +++ b/sonar-ws/build.gradle @@ -5,6 +5,8 @@ sonarqube { } } +configureCompileJavaToVersion 8 + configurations { testCompile.extendsFrom(compileOnly) } -- 2.39.5