* The rule status. Can be READY, BETA or DEPRECATED
* @since 3.6
*/
- Status status() default Status.READY;
+ String status() default "READY";
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.check;
-
-/**
- * @since 3.6
- */
-public enum Status {
- READY, BETA, DEPRECATED;
-}
*/
package org.sonar.core.rule;
+import java.util.EnumSet;
+
public enum RuleStatus {
READY, BETA, DEPRECATED, REMOVED;
- public static RuleStatus defaultValue() {
- return RuleStatus.READY;
+ public static String defaultValue() {
+ return RuleStatus.READY.name();
}
+
+ public static final EnumSet<RuleStatus> STATUS_FOR_PLUGIN = EnumSet.range(READY, DEPRECATED);
+
+ public final boolean isAvailableForPlugin() {
+ return STATUS_FOR_PLUGIN.contains(this);
+ }
+
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.core.rule;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class RuleStatusTest {
+
+ @Test
+ public void should_validate_status_for_user() {
+ assertThat(RuleStatus.READY.isAvailableForPlugin()).isTrue();
+ assertThat(RuleStatus.BETA.isAvailableForPlugin()).isTrue();
+ assertThat(RuleStatus.DEPRECATED.isAvailableForPlugin()).isTrue();
+
+ assertThat(RuleStatus.REMOVED.isAvailableForPlugin()).isFalse();
+ }
+
+ @Test
+ public void should_return_ready_as_default_value() {
+ assertThat(RuleStatus.defaultValue()).isEqualTo("READY");
+ }
+
+}
rule.setDescription(description);
rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
rule.setCardinality(ruleAnnotation.cardinality());
- rule.setStatus(ruleAnnotation.status().name());
+ rule.setStatus(ruleAnnotation.status());
List<Field> fields = FieldUtils2.getFields(clazz, true);
for (Field field : fields) {
import static org.fest.assertions.Assertions.assertThat;
public class AnnotationRuleParserTest {
+
@org.junit.Rule
public final ExpectedException exception = ExpectedException.none();
@Test
- public void ruleWithProperty() {
+ public void rule_with_property() {
List<Rule> rules = parseAnnotatedClass(RuleWithProperty.class);
assertThat(rules).hasSize(1);
Rule rule = rules.get(0);
assertThat(rule.getName()).isEqualTo("bar");
assertThat(rule.getDescription()).isEqualTo("Foo Bar");
assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
+ assertThat(rule.getStatus()).isEqualTo("READY");
assertThat(rule.getParams()).hasSize(1);
+
RuleParam prop = rule.getParam("property");
assertThat(prop.getKey()).isEqualTo("property");
assertThat(prop.getDescription()).isEqualTo("Ignore ?");
}
@Test
- public void ruleWithIntegerProperty() {
+ public void rule_with_integer_property() {
List<Rule> rules = parseAnnotatedClass(RuleWithIntegerProperty.class);
RuleParam prop = rules.get(0).getParam("property");
}
@Test
- public void ruleWithTextProperty() {
+ public void rule_with_text_property() {
List<Rule> rules = parseAnnotatedClass(RuleWithTextProperty.class);
RuleParam prop = rules.get(0).getParam("property");
}
@Test
- public void ruleWithoutNameNorDescription() {
+ public void rule_without_name_nor_description() {
List<Rule> rules = parseAnnotatedClass(RuleWithoutNameNorDescription.class);
assertThat(rules).hasSize(1);
Rule rule = rules.get(0);
}
@Test
- public void ruleWithoutKey() {
+ public void rule_without_key() {
List<Rule> rules = parseAnnotatedClass(RuleWithoutKey.class);
assertThat(rules).hasSize(1);
Rule rule = rules.get(0);
static class RuleWithoutNameNorDescription {
}
- @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)
+ @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", status = "READY", priority = Priority.BLOCKER)
static class RuleWithProperty {
@org.sonar.check.RuleProperty(description = "Ignore ?", defaultValue = "false")
private String property;
private String additionalProperty;
}
- @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)
+ @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", status = "READY", priority = Priority.BLOCKER)
static class RuleWithIntegerProperty {
@org.sonar.check.RuleProperty(description = "Max", defaultValue = "12")
private Integer property;
}
- @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)
+ @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", status = "READY", priority = Priority.BLOCKER)
static class RuleWithTextProperty {
@org.sonar.check.RuleProperty(description = "text", defaultValue = "Long text", type = "TEXT")
protected String property;
}
- @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)
+ @org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", status = "READY", priority = Priority.BLOCKER)
static class RuleWithInvalidPropertyType {
@org.sonar.check.RuleProperty(description = "text", defaultValue = "Long text", type = "INVALID")
public String property;
import org.sonar.api.PropertyType;
import org.sonar.api.utils.SonarException;
import org.sonar.check.Cardinality;
-import org.sonar.check.Status;
import java.io.File;
import java.io.StringReader;
"<rule><key>foo</key><status>BETA</status></rule>"+
"<rule><key>foo</key><status>DEPRECATED</status></rule>"+
"</rules>"));
- assertThat(rules.get(0).getStatus(), is(Status.READY.name()));
- assertThat(rules.get(1).getStatus(), is(Status.BETA.name()));
- assertThat(rules.get(2).getStatus(), is(Status.DEPRECATED.name()));
+ assertThat(rules.get(0).getStatus(), is("READY"));
+ assertThat(rules.get(1).getStatus(), is("BETA"));
+ assertThat(rules.get(2).getStatus(), is("DEPRECATED"));
}
}
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleParam;
import org.sonar.api.rules.RulePriority;
-import org.sonar.check.Status;
import org.sonar.core.rule.RuleStatus;
import org.sonar.jpa.dao.RulesDao;
matchingRuleInDb.setDescription(rule.getDescription());
matchingRuleInDb.setSeverity(rule.getSeverity());
matchingRuleInDb.setParams(rule.getParams());
- matchingRuleInDb.setStatus(Status.READY.name());
+ matchingRuleInDb.setStatus(RuleStatus.defaultValue());
matchingRuleInDb.setLanguage(rule.getLanguage());
matchingRuleInDb.setUpdatedAt(new Date());
session.save(matchingRuleInDb);
} else {
- rule.setStatus(Status.READY.name());
+ rule.setStatus(RuleStatus.defaultValue());
rule.setCreatedAt(new Date());
session.save(rule);
}
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.TimeProfiler;
-import org.sonar.check.Status;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.rule.RuleStatus;
import org.sonar.jpa.session.DatabaseSessionFactory;
for (Rule rule : repository.createRules()) {
rule.setRepositoryKey(repository.getKey());
rule.setLanguage(repository.getLanguage());
- rule.setStatus(!Strings.isNullOrEmpty(rule.getStatus()) ? rule.getStatus() : RuleStatus.defaultValue().name());
+ rule.setStatus(!Strings.isNullOrEmpty(rule.getStatus()) ? rule.getStatus() : RuleStatus.defaultValue());
validateRule(rule, repository.getKey());
ruleByKey.put(rule.getKey(), rule);
registeredRules.add(rule);
private void validateStatus(Rule rule) {
try {
- Status.valueOf(rule.getStatus());
+ RuleStatus ruleStatus = RuleStatus.valueOf(rule.getStatus());
+ if (!ruleStatus.isAvailableForPlugin()) {
+ throw new IllegalArgumentException();
+ }
} catch (IllegalArgumentException e) {
- throw new SonarException("The status of a rule can only contains : " + Joiner.on(", ").join(Status.values()), e);
+ throw new SonarException("The status of a rule can only contains : " + Joiner.on(", ").join(RuleStatus.STATUS_FOR_PLUGIN), e);
}
}
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.utils.SonarException;
-import org.sonar.check.Status;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.rule.RuleStatus;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
assertThat(first.getRepositoryKey(), is("fake"));
assertThat(first.isEnabled(), is(true));
assertThat(first.getCreatedAt(), notNullValue());
- assertThat(first.getStatus(), is(Status.READY.name()));
+ assertThat(first.getStatus(), is(RuleStatus.READY.name()));
assertThat(first.getLanguage(), is("java"));
assertThat(first.getParams().size(), is(2));
}
assertThat(rule1.getUpdatedAt(), notNullValue());
Rule rule2 = getSession().getSingleResult(Rule.class, "id", 2);
- assertThat(rule2.getStatus(), is(Status.DEPRECATED.name()));
+ assertThat(rule2.getStatus(), is(RuleStatus.DEPRECATED.name()));
assertThat(rule2.getUpdatedAt(), notNullValue());
}
Rule rule2 = Rule.create("fake", "rule2", "Two");
rule2.setDescription("Description of Two");
rule2.setSeverity(RulePriority.INFO);
- rule2.setStatus(Status.DEPRECATED.name());
+ rule2.setStatus(RuleStatus.DEPRECATED.name());
return Arrays.asList(rule1, rule2);
}