aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJenkins CI <ci@sonarsource.com>2014-07-09 16:29:39 +0200
committerJenkins CI <ci@sonarsource.com>2014-07-09 16:29:39 +0200
commit016723c452f78fa41c1f9098a8a28ccff940c1c4 (patch)
treea09591d5d5825f4d88a4c5b34076e75aca726c4a /sonar-plugin-api
parent9078aa7e35bd95a9c9ef75827e61ee2fdbe1a7f6 (diff)
parent46a655cc343aba370396d8af5fbc34d5da668a0a (diff)
downloadsonarqube-016723c452f78fa41c1f9098a8a28ccff940c1c4.tar.gz
sonarqube-016723c452f78fa41c1f9098a8a28ccff940c1c4.zip
Merge commit '46a655cc343aba370396d8af5fbc34d5da668a0a' into HEAD
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/pom.xml3
-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
3 files changed, 23 insertions, 7 deletions
diff --git a/sonar-plugin-api/pom.xml b/sonar-plugin-api/pom.xml
index 39d64959d70..46985b00c84 100644
--- a/sonar-plugin-api/pom.xml
+++ b/sonar-plugin-api/pom.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
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();