aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMark Rekveld <mark.rekveld@sonarsource.com>2020-09-28 13:21:48 +0200
committerGitHub <noreply@github.com>2020-09-28 13:21:48 +0200
commitd9376179e8d3fe1534f0c0d3ef3f04db78d4d85e (patch)
treef34df9dcf95f50d0dc28836ef26b65792cc468f7 /src
parent22b155a580d6ac9d09e15259afd92e4e853c7799 (diff)
downloadsonar-scanner-cli-d9376179e8d3fe1534f0c0d3ef3f04db78d4d85e.tar.gz
sonar-scanner-cli-d9376179e8d3fe1534f0c0d3ef3f04db78d4d85e.zip
SQSCANNER-67 - Warn on duplicate property definitions (#89)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Cli.java14
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/CliTest.java8
2 files changed, 18 insertions, 4 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Cli.java b/src/main/java/org/sonarsource/scanner/cli/Cli.java
index ae1c671..a71bc22 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Cli.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Cli.java
@@ -84,7 +84,8 @@ class Cli {
displayVersionOnly = true;
} else if (asList("-e", "--errors").contains(arg)) {
- logger.info("Option -e/--errors is no longer supported and will be ignored");
+ logger
+ .info("Option -e/--errors is no longer supported and will be ignored");
} else if (asList("-X", "--debug").contains(arg)) {
props.setProperty("sonar.verbose", "true");
@@ -95,7 +96,8 @@ 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.");
+ logger.info(
+ "Option --embedded is deprecated and will be removed in a future release.");
embedded = true;
} else if (arg.startsWith("--from")) {
@@ -130,7 +132,7 @@ class Cli {
displayVersionOnly = false;
}
- private static void appendPropertyTo(String arg, Properties props) {
+ private void appendPropertyTo(String arg, Properties props) {
final String key;
final String value;
int j = arg.indexOf('=');
@@ -141,7 +143,11 @@ class Cli {
key = arg.substring(0, j);
value = arg.substring(j + 1);
}
- props.setProperty(key, value);
+ Object oldValue = props.setProperty(key, value);
+ if (oldValue != null) {
+ logger.warn("Property '" + key + "' with value '" + oldValue + "' is "
+ + "overridden with value '" + value + "'");
+ }
}
private void printErrorAndExit(String message) {
diff --git a/src/test/java/org/sonarsource/scanner/cli/CliTest.java b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
index 5a81e11..2c49c34 100644
--- a/src/test/java/org/sonarsource/scanner/cli/CliTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
@@ -48,6 +48,14 @@ public class CliTest {
}
@Test
+ public void should_warn_on_duplicate_properties() {
+ logs = mock(Logs.class);
+ cli = new Cli(exit, logs);
+ cli.parse(new String[] {"-D", "foo=bar", "--define", "foo=baz"});
+ verify(logs).warn("Property 'foo' with value 'bar' is overridden with value 'baz'");
+ }
+
+ @Test
public void should_fail_on_missing_prop() {
logs = mock(Logs.class);
cli = new Cli(exit, logs);