]> source.dussan.org Git - sonarqube.git/commitdiff
In the rule tag validation message, do not display tag on ui side
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 27 Feb 2014 17:21:15 +0000 (18:21 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 27 Feb 2014 17:23:14 +0000 (18:23 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleDefinitions.java
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleDefinitionsTest.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RuleTagFormatTest.java
sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java

index 596982289baf69484688bf73f077112547cc1aaa..95b7b37c28ec86e750b2d7ee21fc7e4b23bfac0c 100644 (file)
@@ -26,10 +26,12 @@ import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerExtension;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
+import org.sonar.api.utils.MessageException;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -388,7 +390,11 @@ public interface RuleDefinitions extends ServerExtension {
      */
     public NewRule addTags(String... list) {
       for (String tag : list) {
-        RuleTagFormat.validate(tag);
+        try {
+          RuleTagFormat.validate(tag);
+        } catch (IllegalArgumentException e) {
+          throw MessageException.of(String.format("Tag '%s' is invalid. %s", tag, e.getMessage()));
+        }
         tags.add(tag);
       }
       return this;
index 8701e1aa2cf5597740edb997ea395bf7ee241ca0..7120628f58d1060cdc2d51b8c56b20b9327c1f7a 100644 (file)
@@ -40,7 +40,7 @@ public class RuleTagFormat {
 
   public static void validate(String tag) {
     if (!isValid(tag)) {
-      throw new IllegalArgumentException(String.format("Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.' - '%s'", tag));
+      throw new IllegalArgumentException("Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.'");
     }
   }
 }
index 93af6b0e74542e532e1ab2773a87e8c6382bd2fb..921c2d71928ad5a769e74382675878fcc1345ca3 100644 (file)
@@ -20,8 +20,9 @@
 package org.sonar.api.server.rule;
 
 import org.junit.Test;
-import org.sonar.api.rule.Severity;
 import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.rule.Severity;
+import org.sonar.api.utils.MessageException;
 
 import java.net.URL;
 
@@ -227,8 +228,9 @@ public class RuleDefinitionsTest {
       // whitespaces are not allowed in tags
       context.newRepository("findbugs", "java").newRule("NPE").setTags("coding style");
       fail();
-    } catch (IllegalArgumentException e) {
-      assertThat(e).hasMessage("Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.' - 'coding style'");
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(MessageException.class)
+        .hasMessage("Tag 'coding style' is invalid. Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.'");
     }
   }
 
index 0bb5d18acadab448353245d79c9160646b06a395..e78aa298c50794e6a86466c29b4cb196d2a0bcda 100644 (file)
@@ -53,7 +53,7 @@ public class RuleTagFormatTest {
       RuleTagFormat.validate("  ");
       fail();
     } catch (IllegalArgumentException e) {
-      assertThat(e).hasMessage("Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.' - '  '");
+      assertThat(e).hasMessage("Rule tags accept only the following characters: a-z, 0-9, '+', '-', '#', '.'");
     }
   }
 }
index c4346ceab9fe417425c23148ab2e3a591b8a5b7b..cf15e4f18d286a7d264f8fda2e1f26edd727cf39 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.server.user.UserSession;
 import java.util.Collection;
 
 /**
- * Used through ruby code <pre>Internal.quality_profiles</pre>
+ * Used through ruby code <pre>Internal.rule_tags</pre>
  */
 public class RuleTags implements ServerExtension {