aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2024-05-07 17:39:21 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2024-05-13 09:37:44 +0200
commit9e72835bb09a703c7bb91ba387fef09f881d5418 (patch)
tree5c2bd132588cdfc824bd550a052c297e7569ed09
parentf2df80dbd277ffa97d2d43f8e44368944d3e1e4b (diff)
downloadsonar-scanner-cli-9e72835bb09a703c7bb91ba387fef09f881d5418.tar.gz
sonar-scanner-cli-9e72835bb09a703c7bb91ba387fef09f881d5418.zip
Log improvements
-rw-r--r--pom.xml11
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Exit.java1
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Main.java20
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Stats.java6
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/MainTest.java2
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/StatsTest.java3
6 files changed, 23 insertions, 20 deletions
diff --git a/pom.xml b/pom.xml
index 226c511..451b4f5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonarsource.parent</groupId>
@@ -66,7 +68,12 @@
<dependency>
<groupId>org.sonarsource.scanner.lib</groupId>
<artifactId>sonar-scanner-java-library</artifactId>
- <version>3.0.0.141</version>
+ <version>3.0.0.146</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>2.0.13</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
diff --git a/src/main/java/org/sonarsource/scanner/cli/Exit.java b/src/main/java/org/sonarsource/scanner/cli/Exit.java
index 703d081..d265bed 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Exit.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Exit.java
@@ -23,6 +23,7 @@ class Exit {
static final int SUCCESS = 0;
static final int INTERNAL_ERROR = 1;
static final int USER_ERROR = 2;
+ static final int SCANNER_ENGINE_ERROR = 3;
void exit(int status) {
System.exit(status);
diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java
index 7ec139d..df60585 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Main.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Main.java
@@ -43,7 +43,6 @@ import org.sonarsource.scanner.lib.ScannerProperties;
public class Main {
private static final Logger LOG = LoggerFactory.getLogger(Main.class);
- private static final String SEPARATOR = "------------------------------------------------------------------------";
private final Exit exit;
private final Cli cli;
private final Conf conf;
@@ -75,13 +74,18 @@ public class Main {
init(p);
try (var engine = scannerEngineBootstrapper.bootstrap()) {
logServerType(engine);
- engine.analyze((Map) p);
- displayExecutionResult(stats, "SUCCESS");
- status = Exit.SUCCESS;
+ var success = engine.analyze((Map) p);
+ if (success) {
+ displayExecutionResult(stats, "SUCCESS");
+ status = Exit.SUCCESS;
+ } else {
+ displayExecutionResult(stats, "FAILURE");
+ status = Exit.SCANNER_ENGINE_ERROR;
+ }
}
} catch (Throwable e) {
displayExecutionResult(stats, "FAILURE");
- showError("Error during SonarScanner CLI execution", e, cli.isDebugEnabled());
+ showError(e, cli.isDebugEnabled());
status = isUserError(e) ? Exit.USER_ERROR : Exit.INTERNAL_ERROR;
} finally {
exit.exit(status);
@@ -123,14 +127,12 @@ public class Main {
}
private static void displayExecutionResult(Stats stats, String resultMsg) {
- LOG.info(SEPARATOR);
LOG.info("EXECUTION {}", resultMsg);
- LOG.info(SEPARATOR);
stats.stop();
- LOG.info(SEPARATOR);
}
- private void showError(String message, Throwable e, boolean debug) {
+ private void showError(Throwable e, boolean debug) {
+ var message = "Error during SonarScanner CLI execution";
if (debug || !isUserError(e)) {
LOG.error(message, e);
} else {
diff --git a/src/main/java/org/sonarsource/scanner/cli/Stats.java b/src/main/java/org/sonarsource/scanner/cli/Stats.java
index 0d9913a..28cb88d 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Stats.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Stats.java
@@ -34,12 +34,6 @@ class Stats {
Stats stop() {
long stopTime = System.currentTimeMillis() - startTime;
LOG.atInfo().addArgument(() -> formatTime(stopTime)).log("Total time: {}");
-
- System.gc();
- Runtime r = Runtime.getRuntime();
- long mb = 1024L * 1024;
- LOG.atInfo().addArgument((r.totalMemory() - r.freeMemory()) / mb + "M/" + r.totalMemory() / mb + "M").log("Final Memory: {}");
-
return this;
}
diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
index 7b6ccfd..48b2ed3 100644
--- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
@@ -61,6 +61,7 @@ class MainTest {
void setUp() {
when(scannerEngineBootstrapperFactory.create(any(Properties.class), any(String.class))).thenReturn(bootstrapper);
when(bootstrapper.bootstrap()).thenReturn(engine);
+ when(engine.analyze(any())).thenReturn(true);
when(conf.properties()).thenReturn(properties);
}
@@ -223,7 +224,6 @@ class MainTest {
inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
inOrder.verify(scannerEngineBootstrapperFactory, times(1)).create(p, "");
- inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
}
@Test
diff --git a/src/test/java/org/sonarsource/scanner/cli/StatsTest.java b/src/test/java/org/sonarsource/scanner/cli/StatsTest.java
index 4895640..174acbc 100644
--- a/src/test/java/org/sonarsource/scanner/cli/StatsTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/StatsTest.java
@@ -34,9 +34,8 @@ class StatsTest {
void shouldPrintStats() {
new Stats().start().stop();
- assertThat(logTester.logs(Level.INFO)).hasSize(2);
+ assertThat(logTester.logs(Level.INFO)).hasSize(1);
assertThat(logTester.logs(Level.INFO).get(0)).startsWith("Total time: ");
- assertThat(logTester.logs(Level.INFO).get(1)).startsWith("Final Memory: ");
}
@Test