]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
SONARPLUGINS-1372 Allow definitions of properties without white space
authorEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 15 Dec 2011 07:11:55 +0000 (07:11 +0000)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 15 Dec 2011 07:11:55 +0000 (07:11 +0000)
src/main/java/org/sonar/runner/Main.java
src/test/java/org/sonar/runner/MainTest.java

index 722c954eb63d19cf02dc0bdd3768fa28870535af..89157ccf153a157f0fb73e0b56e6d6ee5af1e218 100644 (file)
@@ -133,16 +133,10 @@ public final class Main {
           printError("Missing argument for option --define");
         }
         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 {
         printError("Unrecognized option: " + arg);
       }
@@ -150,6 +144,19 @@ public final class Main {
     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() {
     log("");
     log("usage: sonar-runner [options]");
index aa4bf1d6169095f559f3a9d5d38a0a0ff0f855ee..01aab24be7ecd80b7c9f320610edcd0e7c876e87 100644 (file)
@@ -33,27 +33,28 @@ public class MainTest {
 
   @Test
   public void shouldParseEmptyArguments() {
-    Properties props = Main.parseArguments(new String[]{});
+    Properties props = Main.parseArguments(new String[] {});
     assertThat(props.isEmpty(), is(true));
   }
 
   @Test
   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("hello"), is("world"));
+    assertThat(props.getProperty("boolean"), is("true"));
   }
 
   @Test
   public void shouldEnableDebugMode() {
-    Properties props = Main.parseArguments(new String[]{"-X"});
+    Properties props = Main.parseArguments(new String[] { "-X" });
     assertThat(props.getProperty(Runner.VERBOSE), is("true"));
   }
 
   @Test
   public void shouldDisableDebugModeByDefault() {
-    Properties props = Main.parseArguments(new String[]{});
+    Properties props = Main.parseArguments(new String[] {});
     assertThat(props.getProperty(Runner.VERBOSE), nullValue());
   }
 
@@ -90,9 +91,9 @@ public class MainTest {
   public void shouldLoadCompleteConfiguration() throws Exception {
     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());
-    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"));