From 14f6764fb7830ad6e108cb18f2a36b4506fa0d65 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 10 Jan 2025 16:52:36 +0100 Subject: [PATCH] SCANCLI-168 Update Scanner Java Library dependency to 3.2 --- pom.xml | 2 +- .../java/org/sonarsource/scanner/cli/Main.java | 18 ++++++++++++------ .../org/sonarsource/scanner/cli/MainTest.java | 6 +++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1d8ee3b1..2b243fea 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ org.sonarsource.scanner.lib sonar-scanner-java-library - 3.1.1.261 + 3.2.0.370 org.slf4j diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index fe53f1c5..7d548b73 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -71,14 +71,20 @@ void analyze() { checkSkip(p); configureLogging(p); init(p); - try (var engine = scannerEngineBootstrapper.bootstrap()) { - var success = engine.analyze((Map) p); - if (success) { - displayExecutionResult(stats, "SUCCESS"); - status = Exit.SUCCESS; + try (var result = scannerEngineBootstrapper.bootstrap()) { + if (result.isSuccessful()) { + var engine = result.getEngineFacade(); + var success = engine.analyze((Map) p); + if (success) { + displayExecutionResult(stats, "SUCCESS"); + status = Exit.SUCCESS; + } else { + displayExecutionResult(stats, "FAILURE"); + status = Exit.SCANNER_ENGINE_ERROR; + } } else { displayExecutionResult(stats, "FAILURE"); - status = Exit.SCANNER_ENGINE_ERROR; + status = Exit.INTERNAL_ERROR; } } } catch (Throwable e) { diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java index 746f5c98..93421381 100644 --- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java +++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java @@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory; import org.slf4j.event.Level; import org.sonar.api.utils.MessageException; +import org.sonarsource.scanner.lib.ScannerEngineBootstrapResult; import org.sonarsource.scanner.lib.ScannerEngineBootstrapper; import org.sonarsource.scanner.lib.ScannerEngineFacade; import org.sonarsource.scanner.lib.ScannerProperties; @@ -60,7 +61,10 @@ class MainTest { @BeforeEach void setUp() { when(scannerEngineBootstrapperFactory.create(any(Properties.class), any(String.class))).thenReturn(bootstrapper); - when(bootstrapper.bootstrap()).thenReturn(engine); + var result = mock(ScannerEngineBootstrapResult.class); + when(result.isSuccessful()).thenReturn(true); + when(result.getEngineFacade()).thenReturn(engine); + when(bootstrapper.bootstrap()).thenReturn(result); when(engine.analyze(any())).thenReturn(true); when(conf.properties()).thenReturn(properties); }