]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14550 Show analysis warning when scanner uses Java < 11 8.8.0.42792
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 24 Mar 2021 21:45:07 +0000 (16:45 -0500)
committersonartech <sonartech@sonarsource.com>
Fri, 26 Mar 2021 20:03:35 +0000 (20:03 +0000)
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java

index 886afd69033418b8529a84546745a0a6332a1e4c..74f450538d8555a62c3e5afad60b1523eae7bd19 100644 (file)
@@ -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,
index 300d15568d94c1fc86021ca68697259557756899..d6c494f76fbec9332628e50b1c6b0046f1b5425b 100644 (file)
@@ -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,