diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-01-29 17:09:19 +0100 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-02-07 11:32:38 +0100 |
commit | 8b3584e7ad88c5b97207101d6f6ed3f64e86060d (patch) | |
tree | 243a4da0eeac37f4753b082546248037e86abd94 /sonar-plugin-api/src | |
parent | e019c97d3173c44402c4f38e9acca8d579f4816d (diff) | |
download | sonarqube-8b3584e7ad88c5b97207101d6f6ed3f64e86060d.tar.gz sonarqube-8b3584e7ad88c5b97207101d6f6ed3f64e86060d.zip |
SONAR-10321 Add scope to rule definition API
Diffstat (limited to 'sonar-plugin-api/src')
3 files changed, 45 insertions, 16 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleScope.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleScope.java new file mode 100644 index 00000000000..2d476e2ce25 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleScope.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.api.rule; + +/** + * @since 7.1 + * + */ +public enum RuleScope { + MAIN, TEST, ALL; + + public static RuleScope defaultScope() { + return MAIN; + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index 58f3d47b9e6..c7633fc3c54 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -38,6 +38,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.ExtensionPoint; import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.rule.RuleScope; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; import org.sonar.api.rules.RuleType; @@ -693,7 +694,7 @@ public interface RulesDefinition { private final Map<String, NewParam> paramsByKey = new HashMap<>(); private final DebtRemediationFunctions functions; private boolean activatedByDefault; - private Scope scope; + private RuleScope scope; private NewRule(@Nullable String pluginKey, String repoKey, String key) { this.pluginKey = pluginKey; @@ -710,14 +711,14 @@ public interface RulesDefinition { * @since 7.1 */ @CheckForNull - public Scope scope() { + public RuleScope scope() { return this.scope; } /** * @since 7.1 */ - public NewRule setScope(Scope scope) { + public NewRule setScope(RuleScope scope) { this.scope = scope; return this; } @@ -967,7 +968,7 @@ public interface RulesDefinition { private final Map<String, Param> params; private final RuleStatus status; private final boolean activatedByDefault; - private final Scope scope; + private final RuleScope scope; private Rule(Repository repository, NewRule newRule) { this.pluginKey = newRule.pluginKey; @@ -983,7 +984,7 @@ public interface RulesDefinition { this.status = newRule.status; this.debtRemediationFunction = newRule.debtRemediationFunction; this.gapDescription = newRule.gapDescription; - this.scope = newRule.scope == null ? Scope.MAIN : newRule.scope; + this.scope = newRule.scope == null ? RuleScope.MAIN : newRule.scope; this.type = newRule.type == null ? RuleTagsToTypeConverter.convert(newRule.tags) : newRule.type; this.tags = ImmutableSortedSet.copyOf(Sets.difference(newRule.tags, RuleTagsToTypeConverter.RESERVED_TAGS)); Map<String, Param> paramsBuilder = new HashMap<>(); @@ -1013,12 +1014,12 @@ public interface RulesDefinition { public String name() { return name; } - + /** * @since 7.1 * @return */ - public Scope scope() { + public RuleScope scope() { return scope; } @@ -1180,10 +1181,6 @@ public interface RulesDefinition { } } - enum Scope { - ALL, MAIN, TEST; - } - @Immutable class Param { private final String key; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java index 7a426129bb7..64f3b0a96e3 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java @@ -23,11 +23,11 @@ import java.net.URL; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.sonar.api.rule.RuleScope; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; import org.sonar.api.rules.RuleType; import org.sonar.api.server.debt.DebtRemediationFunction; -import org.sonar.api.server.rule.RulesDefinition.Scope; import org.sonar.api.utils.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; @@ -82,7 +82,7 @@ public class RulesDefinitionTest { .setInternalKey("/something") .setStatus(RuleStatus.BETA) .setTags("one", "two") - .setScope(Scope.ALL) + .setScope(RuleScope.ALL) .addTags("two", "three", "four"); newRepo.createRule("ABC").setName("ABC").setMarkdownDescription("ABC"); @@ -92,7 +92,7 @@ public class RulesDefinitionTest { assertThat(repo.rules()).hasSize(2); RulesDefinition.Rule rule = repo.rule("NPE"); - assertThat(rule.scope()).isEqualTo(Scope.ALL); + assertThat(rule.scope()).isEqualTo(RuleScope.ALL); assertThat(rule.key()).isEqualTo("NPE"); assertThat(rule.name()).isEqualTo("Detect NPE"); assertThat(rule.severity()).isEqualTo(Severity.BLOCKER); @@ -209,7 +209,7 @@ public class RulesDefinitionTest { RulesDefinition.Rule rule = context.repository("findbugs").rule("NPE"); assertThat(rule.name()).isEqualTo("NullPointer"); } - + @Test public void default_scope_should_be_main() { RulesDefinition.NewRepository newFindbugs = context.createRepository("findbugs", "java"); @@ -217,7 +217,7 @@ public class RulesDefinitionTest { newFindbugs.done(); RulesDefinition.Rule rule = context.repository("findbugs").rule("key"); - assertThat(rule.scope()).isEqualTo(Scope.MAIN); + assertThat(rule.scope()).isEqualTo(RuleScope.MAIN); } @Test |