From: Duarte Meneses Date: Wed, 24 Mar 2021 21:45:07 +0000 (-0500) Subject: SONAR-14550 Show analysis warning when scanner uses Java < 11 X-Git-Tag: 8.8.0.42792 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e6835da2fdcec099ea0613f278a3e2bb85d64adf;p=sonarqube.git SONAR-14550 Show analysis warning when scanner uses Java < 11 --- 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 886afd69033..74f450538d8 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,6 +31,7 @@ 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; @@ -40,13 +41,14 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.core.extension.CoreExtensionRepositoryImpl; import org.sonar.core.extension.CoreExtensionsLoader; import org.sonar.core.platform.ComponentContainer; +import org.sonar.core.platform.PluginClassLoader; import org.sonar.core.platform.PluginClassloaderFactory; import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.PluginClassLoader; import org.sonar.core.platform.PluginRepository; import org.sonar.core.util.DefaultHttpDownloader; import org.sonar.core.util.UuidFactoryImpl; import org.sonar.scanner.extension.ScannerCoreExtensionsInstaller; +import org.sonar.scanner.notifications.DefaultAnalysisWarnings; import org.sonar.scanner.platform.DefaultServer; import org.sonar.scanner.repository.DefaultMetricsRepositoryLoader; import org.sonar.scanner.repository.DefaultNewCodePeriodLoader; @@ -81,19 +83,21 @@ public class GlobalContainer extends ComponentContainer { addBootstrapComponents(); } - private static void checkJavaVersion() { + 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"); + 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."); } } 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(); + checkJavaVersion(analysisWarnings); } LOG.debug("{} {}", edition.getLabel(), apiVersion); add( @@ -110,6 +114,7 @@ public class GlobalContainer extends ComponentContainer { DefaultServer.class, new GlobalTempFolderProvider(), DefaultHttpDownloader.class, + analysisWarnings, UriReader.class, PluginFiles.class, System2.INSTANCE, diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java index 300d15568d9..d6c494f76fb 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java @@ -74,7 +74,6 @@ import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer; import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer; import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader; import org.sonar.scanner.mediumtest.AnalysisObservers; -import org.sonar.scanner.notifications.DefaultAnalysisWarnings; import org.sonar.scanner.postjob.DefaultPostJobContext; import org.sonar.scanner.postjob.PostJobOptimizer; import org.sonar.scanner.postjob.PostJobsExecutor; @@ -231,8 +230,6 @@ public class ProjectScanContainer extends ComponentContainer { ContextPropertiesCache.class, ContextPropertiesPublisher.class, - DefaultAnalysisWarnings.class, - SensorStrategy.class, MutableProjectSettings.class,