diff options
author | Aurelien Poscia <aurelien.poscia@sonarsource.com> | 2022-10-03 11:24:02 +0200 |
---|---|---|
committer | Philippe Perrin <philippe.perrin@sonarsource.com> | 2022-10-07 12:13:56 +0200 |
commit | ce8ec9e82b7031005b038d2de3ac58519878f910 (patch) | |
tree | 85797b31e23ac35dca50d8865d19631d97c7d7c2 /sonar-scanner-engine | |
parent | 1a796086bedffa6c5f9fd7843a421eb1696b1c89 (diff) | |
download | sonarqube-ce8ec9e82b7031005b038d2de3ac58519878f910.tar.gz sonarqube-ce8ec9e82b7031005b038d2de3ac58519878f910.zip |
SONAR-17418 show deprecation warning in case scanner runs with 32 bits JRE
Diffstat (limited to 'sonar-scanner-engine')
5 files changed, 139 insertions, 11 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/JavaArchitectureInformationProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/JavaArchitectureInformationProvider.java new file mode 100644 index 00000000000..93f40b9446e --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/JavaArchitectureInformationProvider.java @@ -0,0 +1,30 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.scanner.report; + +import com.sun.jna.Platform; + +public class JavaArchitectureInformationProvider { + + public boolean is64bitJavaVersion() { + return Platform.is64Bit(); + } + +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java index 0fc66aa1c5f..6ae9fb233ac 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java @@ -19,6 +19,7 @@ */ package org.sonar.scanner.report; +import com.google.common.annotations.VisibleForTesting; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -34,6 +35,7 @@ import javax.annotation.Nullable; import okhttp3.HttpUrl; import org.apache.commons.io.FileUtils; import org.sonar.api.Startable; +import org.sonar.api.notifications.AnalysisWarnings; import org.sonar.api.platform.Server; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; @@ -68,6 +70,10 @@ public class ReportPublisher implements Startable { private static final String BRANCH = "branch"; private static final String ID = "id"; + @VisibleForTesting + static final String SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE = "You are using a 32 bits JRE. " + + "The support of 32 bits JRE is deprecated and a future version of the scanner will remove it completely."; + private final DefaultScannerWsClient wsClient; private final AnalysisContextReportPublisher contextPublisher; private final InputModuleHierarchy moduleHierarchy; @@ -82,10 +88,13 @@ public class ReportPublisher implements Startable { private final Path reportDir; private final ScannerReportWriter writer; private final ScannerReportReader reader; + private final AnalysisWarnings analysisWarnings; + private final JavaArchitectureInformationProvider javaArchitectureInformationProvider; public ReportPublisher(ScanProperties properties, DefaultScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher, InputModuleHierarchy moduleHierarchy, GlobalAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers, BranchConfiguration branchConfiguration, - CeTaskReportDataHolder ceTaskReportDataHolder) { + CeTaskReportDataHolder ceTaskReportDataHolder, AnalysisWarnings analysisWarnings, + JavaArchitectureInformationProvider javaArchitectureInformationProvider) { this.wsClient = wsClient; this.server = server; this.contextPublisher = contextPublisher; @@ -97,6 +106,8 @@ public class ReportPublisher implements Startable { this.properties = properties; this.ceTaskReportDataHolder = ceTaskReportDataHolder; this.reportDir = moduleHierarchy.root().getWorkDir().resolve("scanner-report"); + this.analysisWarnings = analysisWarnings; + this.javaArchitectureInformationProvider = javaArchitectureInformationProvider; this.writer = new ScannerReportWriter(reportDir.toFile()); this.reader = new ScannerReportReader(reportDir.toFile()); } @@ -133,6 +144,7 @@ public class ReportPublisher implements Startable { } public void execute() { + logDeprecationWarningIf32bitJava(); File report = generateReportFile(); if (properties.shouldKeepReport()) { LOG.info("Analysis report generated in " + reportDir); @@ -145,13 +157,10 @@ public class ReportPublisher implements Startable { logSuccess(); } - private void logSuccess() { - if (analysisMode.isMediumTest()) { - LOG.info("ANALYSIS SUCCESSFUL"); - } else if (!properties.shouldWaitForQualityGate()) { - LOG.info("ANALYSIS SUCCESSFUL, you can find the results at: {}", ceTaskReportDataHolder.getDashboardUrl()); - LOG.info("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report"); - LOG.info("More about the report processing at {}", ceTaskReportDataHolder.getCeTaskUrl()); + private void logDeprecationWarningIf32bitJava() { + if (!javaArchitectureInformationProvider.is64bitJavaVersion()) { + analysisWarnings.addUnique(SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE); + LOG.warn(SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE); } } @@ -175,6 +184,16 @@ public class ReportPublisher implements Startable { } } + private void logSuccess() { + if (analysisMode.isMediumTest()) { + LOG.info("ANALYSIS SUCCESSFUL"); + } else if (!properties.shouldWaitForQualityGate()) { + LOG.info("ANALYSIS SUCCESSFUL, you can find the results at: {}", ceTaskReportDataHolder.getDashboardUrl()); + LOG.info("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report"); + LOG.info("More about the report processing at {}", ceTaskReportDataHolder.getCeTaskUrl()); + } + } + /** * Uploads the report file to server and returns the generated task id */ diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java index 30aeaf63a9d..e3d2f50f631 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java @@ -88,6 +88,7 @@ import org.sonar.scanner.report.CeTaskReportDataHolder; import org.sonar.scanner.report.ChangedLinesPublisher; import org.sonar.scanner.report.ComponentsPublisher; import org.sonar.scanner.report.ContextPropertiesPublisher; +import org.sonar.scanner.report.JavaArchitectureInformationProvider; import org.sonar.scanner.report.MetadataPublisher; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.report.SourcePublisher; @@ -239,6 +240,7 @@ public class SpringProjectScanContainer extends SpringComponentContainer { // Report ReferenceBranchSupplier.class, ScannerMetrics.class, + JavaArchitectureInformationProvider.class, ReportPublisher.class, AnalysisContextReportPublisher.class, MetadataPublisher.class, diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/JavaArchitectureInformationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/JavaArchitectureInformationProviderTest.java new file mode 100644 index 00000000000..3af55c77461 --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/JavaArchitectureInformationProviderTest.java @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.scanner.report; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class JavaArchitectureInformationProviderTest { + + private JavaArchitectureInformationProvider javaArchitectureInformationProvider = new JavaArchitectureInformationProvider(); + + @Test + public void is64bitJavaVersion_returnsTrue_whenRunningWith64bitJava() { + assertThat(javaArchitectureInformationProvider.is64bitJavaVersion()).isTrue(); + } + +} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index 5be9155e320..5a9e6f465bb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -33,6 +33,7 @@ import org.mockito.Mockito; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.impl.utils.JUnitTempFolder; +import org.sonar.api.notifications.AnalysisWarnings; import org.sonar.api.platform.Server; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; @@ -57,7 +58,9 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static org.sonar.scanner.report.ReportPublisher.SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE; import static org.sonar.scanner.scan.branch.BranchType.BRANCH; import static org.sonar.scanner.scan.branch.BranchType.PULL_REQUEST; @@ -79,6 +82,8 @@ public class ReportPublisherTest { private BranchConfiguration branchConfiguration = mock(BranchConfiguration.class); private CeTaskReportDataHolder reportMetadataHolder = mock(CeTaskReportDataHolder.class); private ReportPublisher underTest; + private AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class); + private JavaArchitectureInformationProvider javaArchitectureInformationProvider = mock(JavaArchitectureInformationProvider.class); @Before public void setUp() { @@ -91,7 +96,7 @@ public class ReportPublisherTest { .resolve("folder") .resolve("report-task.txt")); underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, reportTempFolder, - new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder); + new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder, analysisWarnings, javaArchitectureInformationProvider); } @Test @@ -117,6 +122,20 @@ public class ReportPublisherTest { } @Test + public void should_not_log_success_when_should_wait_for_QG() { + when(properties.shouldWaitForQualityGate()).thenReturn(true); + + MockWsResponse submitMockResponse = new MockWsResponse(); + submitMockResponse.setContent(Ce.SubmitResponse.newBuilder().setTaskId("task-1234").build().toByteArray()); + when(wsClient.call(any())).thenReturn(submitMockResponse); + + underTest.start(); + underTest.execute(); + + assertThat(logTester.logs()).noneMatch(s -> s.contains("ANALYSIS SUCCESSFUL")); + } + + @Test public void dump_information_about_report_uploading() throws IOException { underTest.prepareAndDumpMetadata("TASK-123"); @@ -174,7 +193,7 @@ public class ReportPublisherTest { when(branchConfiguration.branchType()).thenReturn(BRANCH); when(branchConfiguration.branchName()).thenReturn("branch-6.7"); ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), - new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder); + new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder, analysisWarnings, javaArchitectureInformationProvider); underTest.prepareAndDumpMetadata("TASK-123"); @@ -195,7 +214,7 @@ public class ReportPublisherTest { when(branchConfiguration.pullRequestKey()).thenReturn("105"); ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), - new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder); + new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder, analysisWarnings, javaArchitectureInformationProvider); underTest.prepareAndDumpMetadata("TASK-123"); @@ -359,4 +378,27 @@ public class ReportPublisherTest { .containsExactlyInAnyOrder("pullRequest=" + pullRequestId); } + @Test + public void test_do_not_log_or_add_warning_if_using_64bit_jre() { + when(javaArchitectureInformationProvider.is64bitJavaVersion()).thenReturn(true); + when(mode.isMediumTest()).thenReturn(true); + underTest.start(); + underTest.execute(); + + assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty(); + + verifyNoInteractions(analysisWarnings); + } + + @Test + public void test_log_and_add_warning_if_using_non64bit_jre() { + when(javaArchitectureInformationProvider.is64bitJavaVersion()).thenReturn(false); + when(mode.isMediumTest()).thenReturn(true); + underTest.start(); + underTest.execute(); + + assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE); + verify(analysisWarnings).addUnique(SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE); + } + } |