rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
rule.setCardinality(ruleAnnotation.cardinality());
rule.setStatus(ruleAnnotation.status());
+ rule.setTags(ruleAnnotation.tags());
List<Field> fields = FieldUtils2.getFields(clazz, true);
for (Field field : fields) {
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.Closeables;
import org.apache.commons.io.FileUtils;
rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
}
+ List<String> tags = Lists.newArrayList();
SMInputCursor cursor = ruleC.childElementCursor();
while (cursor.getNext() != null) {
} else if (StringUtils.equalsIgnoreCase("param", nodeName)) {
processParameter(rule, cursor);
+
+ } else if (StringUtils.equalsIgnoreCase("tag", nodeName)) {
+ tags.add(StringUtils.trim(cursor.collectDescendantText(false)));
}
}
if (Strings.isNullOrEmpty(rule.getKey())) {
throw new SonarException("Node <key> is missing in <rule>");
}
+ rule.setTags(tags.toArray(new String[tags.size()]));
}
private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException {
import javax.annotation.Nullable;
import javax.persistence.*;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
@Entity
@Table(name = "rules")
*/
private static final Set<String> STATUS_LIST = ImmutableSet.of(STATUS_READY, STATUS_BETA, STATUS_DEPRECATED, STATUS_REMOVED);
+ /**
+ * @since 4.2
+ */
+ private static final String[] DEFAULT_TAGS = new String[0];
+
@Id
@Column(name = "id")
@GeneratedValue
@Column(name = "updated_at", updatable = true, nullable = true)
private Date updatedAt;
+ private transient String[] tags = DEFAULT_TAGS;
+
/**
* @deprecated since 2.3. Use the factory method {@link #create()}
*/
@Deprecated
public Rule() {
- // TODO reduce visibility to packaete
}
/**
return this;
}
+ /**
+ * For definition of rule only
+ */
+ public String[] getTags() {
+ return tags;
+ }
+
+ /**
+ * For definition of rule only
+ */
+ public void setTags(String[] tags) {
+ this.tags = tags;
+ }
+
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Rule)) {
newRule.setTemplate(Cardinality.MULTIPLE.equals(rule.getCardinality()));
newRule.setSeverity(rule.getSeverity().toString());
newRule.setStatus(rule.getStatus() == null ? RuleStatus.defaultStatus() : RuleStatus.valueOf(rule.getStatus()));
+ newRule.setTags(rule.getTags());
for (RuleParam param : rule.getParams()) {
NewParam newParam = newRule.newParam(param.getKey());
newParam.setDefaultValue(param.getDefaultValue());
rule.setConfigKey("Checker/TreeWalker/ConstantName");
rule.setSeverity(RulePriority.BLOCKER);
rule.setStatus(Rule.STATUS_BETA);
+ rule.setTags(new String[]{"style", "security"});
rule.createParameter("format").setDescription("Regular expression").setDefaultValue("A-Z").setType("REGULAR_EXPRESSION");
return Arrays.asList(rule);
}
assertThat(rule.severity()).isEqualTo(Severity.BLOCKER);
assertThat(rule.internalKey()).isEqualTo("Checker/TreeWalker/ConstantName");
assertThat(rule.status()).isEqualTo(RuleStatus.BETA);
- assertThat(rule.tags()).isEmpty();
+ assertThat(rule.tags()).containsOnly("style", "security");
assertThat(rule.params()).hasSize(1);
RuleDefinitions.Param param = rule.param("format");
assertThat(param).isNotNull();