]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2303 "Architectural constraint" rule should work for patterns with spaces
authorEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 4 Apr 2011 15:02:12 +0000 (19:02 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 4 Apr 2011 15:02:12 +0000 (19:02 +0400)
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/PatternUtils.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/PatternUtilsTest.java

index fa0041d176f3b450d7b5fb0f5210109256354e9b..726e77b8a69b12f63902236a8d09067be6d948dc 100644 (file)
@@ -29,7 +29,12 @@ public final class PatternUtils {
   }
 
   public static WildcardPattern[] createPatterns(String patterns) {
-    return WildcardPattern.create(StringUtils.split(StringUtils.replace(patterns, ".", "/"), ','));
+    String[] p = StringUtils.split(patterns, ',');
+    WildcardPattern[] result = new WildcardPattern[p.length];
+    for (int i = 0; i < result.length; i++) {
+      result[i] = WildcardPattern.create(StringUtils.trim(StringUtils.replace(p[i], ".", "/")));
+    }
+    return result;
   }
 
 }
index d10b9254f02e886f998a4054fa9cd3e60d1d2612..6420d4d27b10427fe29eb686d712bd0e9b970bd0 100644 (file)
@@ -36,4 +36,16 @@ public class PatternUtilsTest {
     assertThat(patterns[0].match("org/sonar/Foo"), is(true));
     assertThat(patterns[1].match("javax/Bar"), is(true));
   }
+
+  /**
+   * See http://jira.codehaus.org/browse/SONAR-2303
+   */
+  @Test
+  public void shouldTrim() {
+    WildcardPattern[] patterns = PatternUtils.createPatterns("org.foo.*,\n org.bar.*");
+
+    assertThat(patterns[0].match("org/foo/Foo"), is(true));
+    assertThat(patterns[1].match("org/bar/Bar"), is(true));
+  }
+
 }