aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authormickael-caro-sonarsource <mickael.caro@sonarsource.com>2020-06-22 13:27:00 +0200
committerGitHub <noreply@github.com>2020-06-22 13:27:00 +0200
commit38398d7c11f3ef6866d834017e4b2d2c1c6409b7 (patch)
treee2ce87af64650d888233bec4130fd2214a8f4192 /src/main
parent90a36e384448c3f3b419ddfbab3071e00392d267 (diff)
downloadsonar-scanner-cli-38398d7c11f3ef6866d834017e4b2d2c1c6409b7.tar.gz
sonar-scanner-cli-38398d7c11f3ef6866d834017e4b2d2c1c6409b7.zip
SQSCANNER-65 Add a new flag to get the Scanner that invoked the CLI a… (#84)
* SQSCANNER-65 Add a new flag to get the Scanner that invoked the CLI and its version from the invocation commandLine
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Cli.java12
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Main.java2
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/ScannerFactory.java11
3 files changed, 22 insertions, 3 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Cli.java b/src/main/java/org/sonarsource/scanner/cli/Cli.java
index d072221..1c928ad 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Cli.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Cli.java
@@ -29,6 +29,7 @@ class Cli {
private boolean debugEnabled = false;
private boolean displayVersionOnly = false;
private boolean embedded = false;
+ private String invokedFrom = "";
private final Properties props = new Properties();
private final Exit exit;
private final Logs logger;
@@ -50,6 +51,10 @@ class Cli {
return embedded;
}
+ String getInvokedFrom() {
+ return invokedFrom;
+ }
+
Properties properties() {
return props;
}
@@ -90,7 +95,14 @@ class Cli {
return processProp(args, pos);
} else if ("--embedded".equals(arg)) {
+ logger.info("Option --embedded is deprecated and will be removed in a future release.");
+ embedded = true;
+
+ } else if (arg.startsWith("--from")) {
embedded = true;
+ if (arg.length() > "--from=".length()) {
+ invokedFrom = arg.substring("--from=".length());
+ }
} else if (arg.startsWith("-D")) {
arg = arg.substring(2);
diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java
index 37e6748..56f34ac 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Main.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Main.java
@@ -97,7 +97,7 @@ public class Main {
exit.exit(Exit.SUCCESS);
}
- runner = runnerFactory.create(p);
+ runner = runnerFactory.create(p, cli.getInvokedFrom());
}
private void configureLogging(Properties props) {
diff --git a/src/main/java/org/sonarsource/scanner/cli/ScannerFactory.java b/src/main/java/org/sonarsource/scanner/cli/ScannerFactory.java
index 0a96ae6..820f651 100644
--- a/src/main/java/org/sonarsource/scanner/cli/ScannerFactory.java
+++ b/src/main/java/org/sonarsource/scanner/cli/ScannerFactory.java
@@ -32,8 +32,15 @@ class ScannerFactory {
this.logger = logger;
}
- EmbeddedScanner create(Properties props) {
- return EmbeddedScanner.create("ScannerCli", ScannerVersion.version(), new DefaultLogOutput())
+ EmbeddedScanner create(Properties props, String isInvokedFrom) {
+ String appName = "ScannerCLI";
+ String appVersion = ScannerVersion.version();
+ if (!isInvokedFrom.equals("") && isInvokedFrom.contains("/")) {
+ appName = isInvokedFrom.split("/")[0];
+ appVersion = isInvokedFrom.split("/")[1];
+ }
+
+ return EmbeddedScanner.create(appName, appVersion, new DefaultLogOutput())
.addGlobalProperties((Map) props);
}