From: Julien Lancelot Date: Wed, 26 Feb 2014 14:01:17 +0000 (+0100) Subject: SONAR-5067 Use a MessageException when activating already activated rules on a profile X-Git-Tag: 4.3~671 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=064228c277e5ffd6c2d976959a6a9c07369fbbc3;p=sonarqube.git SONAR-5067 Use a MessageException when activating already activated rules on a profile --- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java index d0abfb4bf92..8d9bacef6f5 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java @@ -30,6 +30,7 @@ import org.apache.commons.lang.builder.HashCodeBuilder; import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; +import org.sonar.api.utils.MessageException; import javax.annotation.CheckForNull; import javax.persistence.*; @@ -377,7 +378,7 @@ public class RulesProfile implements Cloneable { return input.getRule().equals(rule); } })) { - throw new IllegalStateException(String.format( + throw MessageException.of(String.format( "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.", getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey())); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java index 79275aa2422..b13a38226da 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java @@ -22,6 +22,7 @@ package org.sonar.api.profiles; import org.junit.Test; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; +import org.sonar.api.utils.MessageException; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; @@ -71,7 +72,7 @@ public class RulesProfileTest { profile.activateRule(rule, null); fail(); } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class) + assertThat(e).isInstanceOf(MessageException.class) .hasMessage("The definition of the profile 'Default' (language 'java') contains multiple occurrences of the 'repo:key1' rule. The plugin which declares this profile should fix this."); } }