Browse Source

SQSCANNER-67 - Warn on duplicate property definitions (#89)

tags/4.5.0.2216
Mark Rekveld 3 years ago
parent
commit
d9376179e8
No account linked to committer's email address

+ 10
- 4
src/main/java/org/sonarsource/scanner/cli/Cli.java View File

displayVersionOnly = true; displayVersionOnly = true;


} else if (asList("-e", "--errors").contains(arg)) { } 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)) { } else if (asList("-X", "--debug").contains(arg)) {
props.setProperty("sonar.verbose", "true"); props.setProperty("sonar.verbose", "true");
return processProp(args, pos); return processProp(args, pos);


} else if ("--embedded".equals(arg)) { } 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; embedded = true;


} else if (arg.startsWith("--from")) { } else if (arg.startsWith("--from")) {
displayVersionOnly = false; displayVersionOnly = false;
} }


private static void appendPropertyTo(String arg, Properties props) {
private void appendPropertyTo(String arg, Properties props) {
final String key; final String key;
final String value; final String value;
int j = arg.indexOf('='); int j = arg.indexOf('=');
key = arg.substring(0, j); key = arg.substring(0, j);
value = arg.substring(j + 1); 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) { private void printErrorAndExit(String message) {

+ 8
- 0
src/test/java/org/sonarsource/scanner/cli/CliTest.java View File

assertThat(cli.properties().get("boolean")).isEqualTo("true"); assertThat(cli.properties().get("boolean")).isEqualTo("true");
} }


@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 @Test
public void should_fail_on_missing_prop() { public void should_fail_on_missing_prop() {
logs = mock(Logs.class); logs = mock(Logs.class);

Loading…
Cancel
Save