diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-04-04 19:02:12 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-04-04 19:02:12 +0400 |
commit | 6f4124e6807435776c9d5bb96eab7a1d7d834687 (patch) | |
tree | 4efe2456e9da1d9140c805d659a52f794bf0cfcb /plugins | |
parent | 9380e275b3c6267ef3b958e5a0127dd924cab493 (diff) | |
download | sonarqube-6f4124e6807435776c9d5bb96eab7a1d7d834687.tar.gz sonarqube-6f4124e6807435776c9d5bb96eab7a1d7d834687.zip |
SONAR-2303 "Architectural constraint" rule should work for patterns with spaces
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/PatternUtils.java | 7 | ||||
-rw-r--r-- | plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/PatternUtilsTest.java | 12 |
2 files changed, 18 insertions, 1 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/PatternUtils.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/PatternUtils.java index fa0041d176f..726e77b8a69 100644 --- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/PatternUtils.java +++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/PatternUtils.java @@ -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; } } diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/PatternUtilsTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/PatternUtilsTest.java index d10b9254f02..6420d4d27b1 100644 --- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/PatternUtilsTest.java +++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/PatternUtilsTest.java @@ -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)); + } + } |