diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-08-12 11:25:00 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-08-12 11:25:00 +0200 |
commit | 2d6a169ec764e30415520ddb51d15506a0727501 (patch) | |
tree | bd1b601480a1c04113362be1fd5279d16898ef0c /sonar-core | |
parent | cf786503239c86eadd59dd518833a4b8bb456e66 (diff) | |
download | sonarqube-2d6a169ec764e30415520ddb51d15506a0727501.tar.gz sonarqube-2d6a169ec764e30415520ddb51d15506a0727501.zip |
SONAR-5526 Support colon character in active rule keys
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleKey.java | 10 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java | 40 |
2 files changed, 46 insertions, 4 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleKey.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleKey.java index 4aa7bc2281c..8ecd3cb43e0 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleKey.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleKey.java @@ -43,7 +43,7 @@ public class ActiveRuleKey implements Serializable { */ public static ActiveRuleKey of(String qualityProfileKey, RuleKey ruleKey) { Preconditions.checkNotNull(qualityProfileKey, "QProfile is missing"); - Preconditions.checkNotNull(ruleKey, "RuleKey is missing key"); + Preconditions.checkNotNull(ruleKey, "RuleKey is missing"); return new ActiveRuleKey(qualityProfileKey, ruleKey); } @@ -52,9 +52,11 @@ public class ActiveRuleKey implements Serializable { * if the format is not valid. */ public static ActiveRuleKey parse(String s) { - String[] split = s.split(":"); - Preconditions.checkArgument(split.length == 3, "Bad format of activeRule key: " + s); - return ActiveRuleKey.of(split[0], RuleKey.of(split[1], split[2])); + Preconditions.checkArgument(s.split(":").length >= 3, "Bad format of activeRule key: " + s); + int semiColonPos = s.indexOf(":"); + String key = s.substring(0, semiColonPos); + String ruleKey = s.substring(semiColonPos + 1); + return ActiveRuleKey.of(key, RuleKey.parse(ruleKey)); } /** diff --git a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java index 10026049cca..165ca07afbd 100644 --- a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java +++ b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleKeyTest.java @@ -23,6 +23,7 @@ import org.junit.Test; import org.sonar.api.rule.RuleKey; import static org.fest.assertions.Assertions.assertThat; +import static org.fest.assertions.Fail.fail; public class ActiveRuleKeyTest { @@ -36,6 +37,35 @@ public class ActiveRuleKeyTest { } @Test + public void rule_key_can_contain_colons() throws Exception { + RuleKey ruleKey = RuleKey.of("squid", "Key:With:Some::Colons"); + ActiveRuleKey key = ActiveRuleKey.of("P1", ruleKey); + assertThat(key.qProfile()).isEqualTo("P1"); + assertThat(key.ruleKey()).isSameAs(ruleKey); + assertThat(key.toString()).isEqualTo("P1:squid:Key:With:Some::Colons"); + } + + @Test + public void profile_must_not_be_null() throws Exception { + try { + ActiveRuleKey.of(null, RuleKey.of("xoo", "R1")); + fail(); + } catch (NullPointerException e) { + assertThat(e).hasMessage("QProfile is missing"); + } + } + + @Test + public void rule_key_must_not_be_null() throws Exception { + try { + ActiveRuleKey.of("P1", null); + fail(); + } catch (NullPointerException e) { + assertThat(e).hasMessage("RuleKey is missing"); + } + } + + @Test public void parse() throws Exception { ActiveRuleKey key = ActiveRuleKey.parse("P1:xoo:R1"); assertThat(key.qProfile()).isEqualTo("P1"); @@ -44,6 +74,16 @@ public class ActiveRuleKeyTest { } @Test + public void parse_fail_when_less_than_three_colons() throws Exception { + try { + ActiveRuleKey.parse("P1:xoo"); + fail(); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessage("Bad format of activeRule key: P1:xoo"); + } + } + + @Test public void equals_and_hashcode() throws Exception { ActiveRuleKey key1 = ActiveRuleKey.parse("P1:xoo:R1"); ActiveRuleKey key1b = ActiveRuleKey.parse("P1:xoo:R1"); |