Procházet zdrojové kódy

SONARPLUGINS-1372 Allow definitions of properties without white space

tags/2.5-rc1
Evgeny Mandrikov před 12 roky
rodič
revize
0a71a3dbc5

+ 17
- 10
src/main/java/org/sonar/runner/Main.java Zobrazit soubor

printError("Missing argument for option --define"); printError("Missing argument for option --define");
} }
arg = args[i]; arg = args[i];
final String key, value;
int j = arg.indexOf('=');
if (j == -1) {
key = arg;
value = "true";
} else {
key = arg.substring(0, j);
value = arg.substring(j + 1);
}
props.setProperty(key, value);
parseProperty(arg, props);
} else if (arg.startsWith("-D")) {
arg = arg.substring(2);
parseProperty(arg, props);
} else { } else {
printError("Unrecognized option: " + arg); printError("Unrecognized option: " + arg);
} }
return props; return props;
} }


private static void parseProperty(String arg, Properties props) {
final String key, value;
int j = arg.indexOf('=');
if (j == -1) {
key = arg;
value = "true";
} else {
key = arg.substring(0, j);
value = arg.substring(j + 1);
}
props.setProperty(key, value);
}

private static void printUsage() { private static void printUsage() {
log(""); log("");
log("usage: sonar-runner [options]"); log("usage: sonar-runner [options]");

+ 9
- 8
src/test/java/org/sonar/runner/MainTest.java Zobrazit soubor



@Test @Test
public void shouldParseEmptyArguments() { public void shouldParseEmptyArguments() {
Properties props = Main.parseArguments(new String[]{});
Properties props = Main.parseArguments(new String[] {});
assertThat(props.isEmpty(), is(true)); assertThat(props.isEmpty(), is(true));
} }


@Test @Test
public void shouldParseArguments() { public void shouldParseArguments() {
Properties props = Main.parseArguments(new String[]{"-D", "foo=bar", "--define", "hello=world"});
assertThat(props.size(), is(2));
Properties props = Main.parseArguments(new String[] { "-D", "foo=bar", "--define", "hello=world", "-Dboolean" });
assertThat(props.size(), is(3));
assertThat(props.getProperty("foo"), is("bar")); assertThat(props.getProperty("foo"), is("bar"));
assertThat(props.getProperty("hello"), is("world")); assertThat(props.getProperty("hello"), is("world"));
assertThat(props.getProperty("boolean"), is("true"));
} }


@Test @Test
public void shouldEnableDebugMode() { public void shouldEnableDebugMode() {
Properties props = Main.parseArguments(new String[]{"-X"});
Properties props = Main.parseArguments(new String[] { "-X" });
assertThat(props.getProperty(Runner.VERBOSE), is("true")); assertThat(props.getProperty(Runner.VERBOSE), is("true"));
} }


@Test @Test
public void shouldDisableDebugModeByDefault() { public void shouldDisableDebugModeByDefault() {
Properties props = Main.parseArguments(new String[]{});
Properties props = Main.parseArguments(new String[] {});
assertThat(props.getProperty(Runner.VERBOSE), nullValue()); assertThat(props.getProperty(Runner.VERBOSE), nullValue());
} }


public void shouldLoadCompleteConfiguration() throws Exception { public void shouldLoadCompleteConfiguration() throws Exception {
File runnerHome = new File(getClass().getResource("/org/sonar/runner/MainTest/shouldLoadCompleteConfiguration/runner").toURI()); File runnerHome = new File(getClass().getResource("/org/sonar/runner/MainTest/shouldLoadCompleteConfiguration/runner").toURI());
File projectHome = new File(getClass().getResource("/org/sonar/runner/MainTest/shouldLoadCompleteConfiguration/project").toURI()); File projectHome = new File(getClass().getResource("/org/sonar/runner/MainTest/shouldLoadCompleteConfiguration/project").toURI());
Properties props = Main.loadProperties(new String[]{
"-D", "runner.home=" + runnerHome.getCanonicalPath(),
"-D", "project.home=" + projectHome.getCanonicalPath()
Properties props = Main.loadProperties(new String[] {
"-D", "runner.home=" + runnerHome.getCanonicalPath(),
"-D", "project.home=" + projectHome.getCanonicalPath()
}); });


assertThat(props.getProperty("project.prop"), is("foo")); assertThat(props.getProperty("project.prop"), is("foo"));

Načítá se…
Zrušit
Uložit