From ef96f7b0518343fa48a1d74d2763cd3ed479ba70 Mon Sep 17 00:00:00 2001 From: Dimitris Kavvathas Date: Fri, 5 Jan 2024 15:35:33 +0100 Subject: [PATCH] SONAR-21195 Convert exception to a warning when no language plugins are installed. --- .../fs/NoLanguagesPluginsMediumIT.java | 23 ++++++++++++++----- .../scan/SpringProjectScanContainer.java | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumIT.java index d575c39d0e5..db2d45e5904 100644 --- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumIT.java +++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumIT.java @@ -22,12 +22,15 @@ package org.sonar.scanner.mediumtest.fs; import java.io.File; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.slf4j.event.Level; +import org.sonar.api.testfixtures.log.LogTester; import org.sonar.scanner.mediumtest.ScannerMediumTester; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.assertThat; public class NoLanguagesPluginsMediumIT { @Rule @@ -36,15 +39,23 @@ public class NoLanguagesPluginsMediumIT { @Rule public ScannerMediumTester tester = new ScannerMediumTester(); + @Rule + public LogTester logger = new LogTester(); + + @Before + public void before() { + logger.clear(); + } + @Test public void testNoLanguagePluginsInstalled() throws Exception { File projectDir = copyProject("test-resources/mediumtest/xoo/sample"); - assertThatThrownBy(() -> tester - .newAnalysis(new File(projectDir, "sonar-project.properties")) - .execute()) - .isInstanceOf(IllegalStateException.class) - .hasMessage("No language plugins are installed."); + tester. + newAnalysis(new File(projectDir, "sonar-project.properties")) + .execute(); + + assertThat(logger.logs(Level.WARN)).contains("No language plugins are installed."); } private File copyProject(String path) throws Exception { 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 3382d6f25de..bef9b1fb632 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 @@ -149,7 +149,7 @@ public class SpringProjectScanContainer extends SpringComponentContainer { ScanProperties properties = getComponentByType(ScanProperties.class); if (getComponentByType(Languages.class).all().length == 0) { - throw new IllegalStateException("No language plugins are installed."); + LOG.warn("No language plugins are installed."); } // Log detected languages and their profiles after FS is indexed and languages detected -- 2.39.5