aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java97
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowAction.java28
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java4
3 files changed, 110 insertions, 19 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
index 63cb14defff..b783ac11844 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
@@ -34,8 +34,20 @@ import org.sonar.check.Cardinality;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import javax.persistence.*;
-
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -138,6 +150,15 @@ public class Rule {
@Column(name = "updated_at", updatable = true, nullable = true)
private Date updatedAt;
+ @Transient
+ private String defaultCharacteristic;
+ @Transient
+ private String defaultSubCharacteristic;
+ @Transient
+ private String characteristic;
+ @Transient
+ private String subCharacteristic;
+
private transient String[] tags = DEFAULT_TAGS;
/**
@@ -497,9 +518,11 @@ public class Rule {
/**
* For internal use only.
*
+ * @deprecated since 4.4, use {@link #getCharacteristic()}
* @since 4.3
*/
@CheckForNull
+ @Deprecated
public Integer getCharacteristicId() {
return characteristicId;
}
@@ -507,8 +530,10 @@ public class Rule {
/**
* For internal use only.
*
+ * @deprecated since 4.4, use {@link #setCharacteristic(@Nullable String characteristic)}
* @since 4.3
*/
+ @Deprecated
public Rule setCharacteristicId(@Nullable Integer characteristicId) {
this.characteristicId = characteristicId;
return this;
@@ -517,9 +542,11 @@ public class Rule {
/**
* For internal use only.
*
+ * @deprecated since 4.4, use {@link #getDefaultCharacteristic()}
* @since 4.3
*/
@CheckForNull
+ @Deprecated
public Integer getDefaultCharacteristicId() {
return defaultCharacteristicId;
}
@@ -527,8 +554,10 @@ public class Rule {
/**
* For internal use only.
*
+ * @deprecated since 4.4, use {@link #setDefaultCharacteristic(@Nullable String defaultCharacteristic)}
* @since 4.3
*/
+ @Deprecated
public Rule setDefaultCharacteristicId(@Nullable Integer defaultCharacteristicId) {
this.defaultCharacteristicId = defaultCharacteristicId;
return this;
@@ -609,4 +638,68 @@ public class Rule {
public RuleKey ruleKey() {
return RuleKey.of(getRepositoryKey(), getKey());
}
+
+ /**
+ * @since 4.4
+ */
+ @CheckForNull
+ public String getDefaultCharacteristic() {
+ return defaultCharacteristic;
+ }
+
+ /**
+ * @since 4.4
+ */
+ public Rule setDefaultCharacteristic(@Nullable String defaultCharacteristic) {
+ this.defaultCharacteristic = defaultCharacteristic;
+ return this;
+ }
+
+ /**
+ * @since 4.4
+ */
+ @CheckForNull
+ public String getDefaultSubCharacteristic() {
+ return defaultSubCharacteristic;
+ }
+
+ /**
+ * @since 4.4
+ */
+ public Rule setDefaultSubCharacteristic(@Nullable String defaultSubCharacteristic) {
+ this.defaultSubCharacteristic = defaultSubCharacteristic;
+ return this;
+ }
+
+ /**
+ * @since 4.4
+ */
+ @CheckForNull
+ public String getCharacteristic() {
+ return characteristic;
+ }
+
+ /**
+ * @since 4.4
+ */
+ public Rule setCharacteristic(@Nullable String characteristic) {
+ this.characteristic = characteristic;
+ return this;
+ }
+
+ /**
+ * @since 4.4
+ */
+ @CheckForNull
+ public String getSubCharacteristic() {
+ return subCharacteristic;
+ }
+
+ /**
+ * @since 4.4
+ */
+ public Rule setSubCharacteristic(@Nullable String subCharacteristic) {
+ this.subCharacteristic = subCharacteristic;
+ return this;
+ }
}
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowAction.java b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowAction.java
index 8ee532f928a..3936daf64f8 100644
--- a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowAction.java
+++ b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowAction.java
@@ -24,11 +24,14 @@ import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
import org.sonar.api.component.Component;
import org.sonar.api.i18n.I18n;
-import org.sonar.api.issue.*;
+import org.sonar.api.issue.ActionPlan;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.IssueComment;
+import org.sonar.api.issue.IssueFinder;
+import org.sonar.api.issue.IssueQuery;
+import org.sonar.api.issue.IssueQueryResult;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.FieldDiffs;
-import org.sonar.api.server.debt.DebtCharacteristic;
-import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
@@ -49,7 +52,6 @@ import org.sonar.server.user.UserSession;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@@ -271,20 +273,12 @@ public class IssueShowAction implements RequestHandler {
}
private void addCharacteristics(IssueQueryResult result, DefaultIssue issue, JsonWriter json) {
- Integer subCharacteristicId = result.rule(issue).getCharacteristicId() != null ? result.rule(issue).getCharacteristicId() : result.rule(issue).getDefaultCharacteristicId();
- DebtCharacteristic subCharacteristic = characteristicById(subCharacteristicId);
- if (subCharacteristic != null) {
- json.prop("subCharacteristic", subCharacteristic.name());
- DebtCharacteristic characteristic = characteristicById(((DefaultDebtCharacteristic) subCharacteristic).parentId());
- json.prop("characteristic", characteristic != null ? characteristic.name() : null);
- }
- }
+ String subCharacteristic = result.rule(issue).getSubCharacteristic() != null ? result.rule(issue).getSubCharacteristic() : result.rule(issue).getDefaultSubCharacteristic();
+ String characteristic = result.rule(issue).getCharacteristic() != null ? result.rule(issue).getCharacteristic() : result.rule(issue).getDefaultCharacteristic();
- @CheckForNull
- private DebtCharacteristic characteristicById(@Nullable Integer id) {
- if (id != null) {
- return debtModel.characteristicById(id);
+ if (subCharacteristic != null) {
+ json.prop("subCharacteristic", subCharacteristic);
+ json.prop("characteristic", characteristic != null ? characteristic : null);
}
- return null;
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java b/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
index fd9bbd9a64a..00fa7a8c72a 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
@@ -116,6 +116,10 @@ public class DefaultRuleFinder implements RuleFinder {
.setRepositoryKey(rule.key().repository())
.setSeverity(RulePriority.valueOf(rule.severity()))
.setStatus(rule.status().name())
+ .setDefaultCharacteristic(rule.defaultDebtCharacteristicKey())
+ .setDefaultSubCharacteristic(rule.defaultDebtSubCharacteristicKey())
+ .setCharacteristic(rule.debtCharacteristicKey())
+ .setSubCharacteristic(rule.debtSubCharacteristicKey())
.setTags(rule.tags().toArray(new String[rule.tags().size()]));
List<org.sonar.api.rules.RuleParam> apiParams = newArrayList();