aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-09 16:12:22 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-09 16:12:22 +0200
commit46a655cc343aba370396d8af5fbc34d5da668a0a (patch)
tree5bc8da82b6e8b4e61d90d273a2e550d2c62ed5b3
parent761002a42c71b6d132e86dbe7e12ecfaca5fd071 (diff)
downloadsonarqube-46a655cc343aba370396d8af5fbc34d5da668a0a.tar.gz
sonarqube-46a655cc343aba370396d8af5fbc34d5da668a0a.zip
SONAR-5437 Support colon character in rule keys
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java8
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java19
2 files changed, 22 insertions, 5 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java
index a474347df74..9d316d5a250 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java
@@ -53,9 +53,11 @@ public class RuleKey implements Serializable {
* if the format is not valid.
*/
public static RuleKey parse(String s) {
- String[] split = s.split(":");
- Preconditions.checkArgument(split.length == 2, "Invalid rule key: " + s);
- return RuleKey.of(split[0], split[1]);
+ int semiColonPos = s.indexOf(":");
+ Preconditions.checkArgument(semiColonPos > 0, "Invalid rule key: " + s);
+ String key = s.substring(0, semiColonPos);
+ String repo = s.substring(semiColonPos + 1);
+ return RuleKey.of(key, repo);
}
/**
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
index 150ed5efac9..d5190d941ae 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleKeyTest.java
@@ -25,6 +25,7 @@ import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
public class RuleKeyTest {
+
@Test
public void testOf() throws Exception {
RuleKey key = RuleKey.of("squid", "NullDeref");
@@ -33,6 +34,13 @@ public class RuleKeyTest {
}
@Test
+ public void key_can_contain_colons() throws Exception {
+ RuleKey key = RuleKey.of("squid", "Key:With:Some::Colons");
+ assertThat(key.repository()).isEqualTo("squid");
+ assertThat(key.rule()).isEqualTo("Key:With:Some::Colons");
+ }
+
+ @Test
public void repository_must_not_be_null() throws Exception {
try {
RuleKey.of(null, "NullDeref");
@@ -73,7 +81,7 @@ public class RuleKeyTest {
}
@Test
- public void should_encode_and_decode_string() throws Exception {
+ public void encode_and_decode_string() throws Exception {
RuleKey key = RuleKey.of("squid", "NullDeref");
String serialized = key.toString();
assertThat(serialized).isEqualTo("squid:NullDeref");
@@ -84,7 +92,14 @@ public class RuleKeyTest {
}
@Test
- public void should_not_accept_bad_format() throws Exception {
+ public void parse_key_with_colons() throws Exception {
+ RuleKey key = RuleKey.parse("squid:Key:With:Some::Colons");
+ assertThat(key.repository()).isEqualTo("squid");
+ assertThat(key.rule()).isEqualTo("Key:With:Some::Colons");
+ }
+
+ @Test
+ public void not_accept_bad_format() throws Exception {
try {
RuleKey.parse("foo");
fail();