-<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>
<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>
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);
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;
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);
}
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 {
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;
}
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);
}
inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
inOrder.verify(scannerEngineBootstrapperFactory, times(1)).create(p, "");
- inOrder.verify(exit, times(1)).exit(Exit.SUCCESS);
}
@Test
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