diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2022-03-21 11:56:18 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2022-03-22 09:01:38 +0100 |
commit | 8c73aabed5dee00d5e184750984099b63aaf676a (patch) | |
tree | 01342122ea09c7eabb43eef00fe0cb8b80335ba6 /src/main/java/org/sonarsource/scanner/cli/Main.java | |
parent | 62768e25da3981a8ffd3778accfcd459d79ede24 (diff) | |
download | sonar-scanner-cli-8c73aabed5dee00d5e184750984099b63aaf676a.tar.gz sonar-scanner-cli-8c73aabed5dee00d5e184750984099b63aaf676a.zip |
SQSCANNER-101 Do not parse configuration twice
Diffstat (limited to 'src/main/java/org/sonarsource/scanner/cli/Main.java')
-rw-r--r-- | src/main/java/org/sonarsource/scanner/cli/Main.java | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index 60397e1..63464af 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -19,6 +19,7 @@ */ package org.sonarsource.scanner.cli; +import java.util.Locale; import java.util.Map; import java.util.Properties; import org.sonarsource.scanner.api.EmbeddedScanner; @@ -41,9 +42,9 @@ public class Main { private final Exit exit; private final Cli cli; private final Conf conf; - private EmbeddedScanner runner; - private ScannerFactory runnerFactory; - private Logs logger; + private EmbeddedScanner embeddedScanner; + private final ScannerFactory runnerFactory; + private final Logs logger; Main(Exit exit, Cli cli, Conf conf, ScannerFactory runnerFactory, Logs logger) { this.exit = exit; @@ -70,8 +71,13 @@ public class Main { checkSkip(p); configureLogging(p); init(p); - runner.start(); - logger.info(String.format("Analyzing on %s", conf.isSonarCloud(null) ? "SonarCloud" : ("SonarQube server " + runner.serverVersion()))); + embeddedScanner.start(); + if (isSonarCloud(p)) { + logger.info("Analyzing on SonarCloud"); + } else { + String serverVersion = embeddedScanner.serverVersion(); + logger.info(String.format("Analyzing on SonarQube server %s", serverVersion)); + } execute(stats, p); status = Exit.SUCCESS; } catch (Throwable e) { @@ -81,7 +87,15 @@ public class Main { } finally { exit.exit(status); } + } + + static boolean isSonarCloud(Properties props) { + String hostUrl = props.getProperty(Conf.PROPERTY_SONAR_HOST_URL); + if (hostUrl != null) { + return hostUrl.toLowerCase(Locale.ENGLISH).contains("sonarcloud"); + } + return false; } private void checkSkip(Properties properties) { @@ -97,7 +111,7 @@ public class Main { exit.exit(Exit.SUCCESS); } - runner = runnerFactory.create(p, cli.getInvokedFrom()); + embeddedScanner = runnerFactory.create(p, cli.getInvokedFrom()); } private void configureLogging(Properties props) { @@ -109,7 +123,7 @@ public class Main { } private void execute(Stats stats, Properties p) { - runner.execute((Map) p); + embeddedScanner.execute((Map) p); displayExecutionResult(stats, "SUCCESS"); } |