aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java40
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java20
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java7
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java37
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java37
6 files changed, 63 insertions, 86 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 49e7d9c06be..3ee14350358 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
@@ -82,15 +82,9 @@ public class Rule {
private String status = STATUS_READY;
private String language;
private Rule template = null;
- private Integer characteristicId;
- private Integer defaultCharacteristicId;
private List<RuleParam> params = new ArrayList<>();
private Date createdAt;
private Date updatedAt;
- private String defaultCharacteristicKey;
- private String defaultSubCharacteristicKey;
- private String characteristicKey;
- private String subCharacteristicKey;
private String tags;
private String systemTags;
@@ -413,7 +407,7 @@ public class Rule {
@CheckForNull
@Deprecated
public Integer getCharacteristicId() {
- return characteristicId;
+ return null;
}
/**
@@ -424,7 +418,6 @@ public class Rule {
*/
@Deprecated
public Rule setCharacteristicId(@Nullable Integer characteristicId) {
- this.characteristicId = characteristicId;
return this;
}
@@ -437,7 +430,7 @@ public class Rule {
@CheckForNull
@Deprecated
public Integer getDefaultCharacteristicId() {
- return defaultCharacteristicId;
+ return null;
}
/**
@@ -448,7 +441,6 @@ public class Rule {
*/
@Deprecated
public Rule setDefaultCharacteristicId(@Nullable Integer defaultCharacteristicId) {
- this.defaultCharacteristicId = defaultCharacteristicId;
return this;
}
@@ -530,65 +522,77 @@ public class Rule {
/**
* @since 4.4
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
*/
@CheckForNull
+ @Deprecated
public String getDefaultCharacteristicKey() {
- return defaultCharacteristicKey;
+ return null;
}
/**
* @since 4.4
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
*/
+ @Deprecated
public Rule setDefaultCharacteristicKey(@Nullable String defaultCharacteristicKey) {
- this.defaultCharacteristicKey = defaultCharacteristicKey;
return this;
}
/**
* @since 4.4
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
*/
@CheckForNull
+ @Deprecated
public String getDefaultSubCharacteristicKey() {
- return defaultSubCharacteristicKey;
+ return null;
}
/**
* @since 4.4
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
*/
+ @Deprecated
public Rule setDefaultSubCharacteristicKey(@Nullable String defaultSubCharacteristicKey) {
- this.defaultSubCharacteristicKey = defaultSubCharacteristicKey;
return this;
}
/**
* @since 4.4
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
*/
@CheckForNull
+ @Deprecated
public String getCharacteristicKey() {
- return characteristicKey;
+ return null;
}
/**
* @since 4.4
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
*/
+ @Deprecated
public Rule setCharacteristicKey(@Nullable String characteristicKey) {
- this.characteristicKey = characteristicKey;
return this;
}
/**
* @since 4.4
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
*/
@CheckForNull
+ @Deprecated
public String getSubCharacteristicKey() {
- return subCharacteristicKey;
+ return null;
}
/**
* @since 4.4
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
*/
+ @Deprecated
public Rule setSubCharacteristicKey(@Nullable String subCharacteristicKey) {
- this.subCharacteristicKey = subCharacteristicKey;
return this;
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java
index ccf7bd967de..4a30cf91d4c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/DebtModel.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.server.debt;
+import javax.annotation.CheckForNull;
import org.sonar.api.server.ServerSide;
import java.util.List;
@@ -32,18 +33,19 @@ import java.util.List;
public interface DebtModel {
/**
- * @return all characteristics
+ * @return an empty list since 5.5.
*/
List<DebtCharacteristic> allCharacteristics();
/**
- * @return only characteristics of highest level
+ * @return an empty list since 5.5.
*/
List<DebtCharacteristic> characteristics();
/**
- * Return a characteristic or a sub-characteristic by its key
+ * @return null since 5.5.
*/
+ @CheckForNull
DebtCharacteristic characteristicByKey(String key);
}
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 1586b7f8203..f714a336be7 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
@@ -81,7 +81,6 @@ import static org.apache.commons.lang.StringUtils.trimToNull;
* .setSeverity(Severity.MINOR);
*
* x1Rule
- * .setDebtSubCharacteristic("INTEGRATION_TESTABILITY")
* .setDebtRemediationFunction(x1Rule.debtRemediationFunctions().linearWithOffset("1h", "30min"));
*
* x1Rule.createParam("acceptWhitespace")
@@ -149,7 +148,10 @@ public interface RulesDefinition {
/**
* Default sub-characteristics of technical debt model. See http://www.sqale.org
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
+ * See https://jira.sonarsource.com/browse/MMF-184
*/
+ @Deprecated
final class SubCharacteristics {
/**
* Related to characteristic REUSABILITY
@@ -661,7 +663,6 @@ public interface RulesDefinition {
private String severity = Severity.MAJOR;
private boolean template;
private RuleStatus status = RuleStatus.defaultStatus();
- private String debtSubCharacteristic;
private DebtRemediationFunction debtRemediationFunction;
private String effortToFixDescription;
private final Set<String> tags = Sets.newTreeSet();
@@ -764,9 +765,10 @@ public interface RulesDefinition {
* SQALE sub-characteristic. See http://www.sqale.org
*
* @see org.sonar.api.server.rule.RulesDefinition.SubCharacteristics for constant values
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. This method does nothing.
+ * See https://jira.sonarsource.com/browse/MMF-184
*/
public NewRule setDebtSubCharacteristic(@Nullable String s) {
- this.debtSubCharacteristic = s;
return this;
}
@@ -855,9 +857,6 @@ public interface RulesDefinition {
if (Strings.isNullOrEmpty(htmlDescription) && Strings.isNullOrEmpty(markdownDescription)) {
throw new IllegalStateException(format("One of HTML description or Markdown description must be defined for rule %s", this));
}
- if ((Strings.isNullOrEmpty(debtSubCharacteristic) && debtRemediationFunction != null) || (!Strings.isNullOrEmpty(debtSubCharacteristic) && debtRemediationFunction == null)) {
- throw new IllegalStateException(format("Both debt sub-characteristic and debt remediation function should be defined on rule '%s'", this));
- }
}
@Override
@@ -877,7 +876,6 @@ public interface RulesDefinition {
private final String internalKey;
private final String severity;
private final boolean template;
- private final String debtSubCharacteristic;
private final DebtRemediationFunction debtRemediationFunction;
private final String effortToFixDescription;
private final Set<String> tags;
@@ -895,7 +893,6 @@ public interface RulesDefinition {
this.severity = newRule.severity;
this.template = newRule.template;
this.status = newRule.status;
- this.debtSubCharacteristic = newRule.debtSubCharacteristic;
this.debtRemediationFunction = newRule.debtRemediationFunction;
this.effortToFixDescription = newRule.effortToFixDescription;
this.tags = ImmutableSortedSet.copyOf(newRule.tags);
@@ -940,9 +937,14 @@ public interface RulesDefinition {
return status;
}
+ /**
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. {@code null} is
+ * always returned. See https://jira.sonarsource.com/browse/MMF-184
+ */
@CheckForNull
+ @Deprecated
public String debtSubCharacteristic() {
- return debtSubCharacteristic;
+ return null;
}
@CheckForNull
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java
index 9445a1bfb56..ddf1a64e350 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java
@@ -242,7 +242,6 @@ public class RulesDefinitionXmlLoader {
RuleStatus status = RuleStatus.defaultStatus();
boolean template = false;
String effortToFixDescription = null;
- String debtSubCharacteristic = null;
String debtRemediationFunction = null;
String debtRemediationFunctionOffset = null;
String debtRemediationFunctionCoeff = null;
@@ -304,9 +303,6 @@ public class RulesDefinitionXmlLoader {
} else if (equalsIgnoreCase("debtRemediationFunctionCoefficient", nodeName)) {
debtRemediationFunctionCoeff = nodeValue(cursor);
- } else if (equalsIgnoreCase("debtSubCharacteristic", nodeName)) {
- debtSubCharacteristic = nodeValue(cursor);
-
} else if (equalsIgnoreCase("status", nodeName)) {
String s = nodeValue(cursor);
if (s != null) {
@@ -329,8 +325,7 @@ public class RulesDefinitionXmlLoader {
.setTags(tags.toArray(new String[tags.size()]))
.setTemplate(template)
.setStatus(status)
- .setEffortToFixDescription(effortToFixDescription)
- .setDebtSubCharacteristic(debtSubCharacteristic);
+ .setEffortToFixDescription(effortToFixDescription);
fillDescription(rule, descriptionFormat, description);
fillRemediationFunction(rule, debtRemediationFunction, debtRemediationFunctionOffset, debtRemediationFunctionCoeff);
fillParams(rule, params);
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 9c5c745aedb..23aa50f6679 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
@@ -19,13 +19,12 @@
*/
package org.sonar.api.server.rule;
+import java.net.URL;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.server.debt.DebtRemediationFunction;
-
-import java.net.URL;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
@@ -110,13 +109,12 @@ public class RulesDefinitionTest {
}
@Test
- public void define_rules_with_technical_debt() {
+ public void define_rules_with_remediation_function() {
RulesDefinition.NewRepository newRepo = context.createRepository("common-java", "java");
RulesDefinition.NewRule newRule = newRepo.createRule("InsufficientBranchCoverage")
.setName("Insufficient condition coverage")
.setHtmlDescription("Insufficient condition coverage by unit tests")
.setSeverity(Severity.MAJOR)
- .setDebtSubCharacteristic(RulesDefinition.SubCharacteristics.UNIT_TESTS)
.setEffortToFixDescription("Effort to test one uncovered branch");
newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset("1h", "10min"));
newRepo.done();
@@ -125,7 +123,6 @@ public class RulesDefinitionTest {
assertThat(repo.rules()).hasSize(1);
RulesDefinition.Rule rule = repo.rule("InsufficientBranchCoverage");
- assertThat(rule.debtSubCharacteristic()).isEqualTo("UNIT_TESTS");
assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
assertThat(rule.debtRemediationFunction().coefficient()).isEqualTo("1h");
assertThat(rule.debtRemediationFunction().offset()).isEqualTo("10min");
@@ -145,7 +142,6 @@ public class RulesDefinitionTest {
assertThat(rule.internalKey()).isNull();
assertThat(rule.status()).isEqualTo(RuleStatus.defaultStatus());
assertThat(rule.tags()).isEmpty();
- assertThat(rule.debtSubCharacteristic()).isNull();
assertThat(rule.debtRemediationFunction()).isNull();
}
@@ -405,30 +401,13 @@ public class RulesDefinitionTest {
}
@Test
- public void fail_if_define_characteristic_without_function() {
+ public void sqale_characteristic_is_deprecated_and_is_ignored() {
RulesDefinition.NewRepository newRepository = context.createRepository("findbugs", "java");
- newRepository.createRule("NPE").setName("NPE").setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
- .setDebtSubCharacteristic("COMPILER");
- try {
- newRepository.done();
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Both debt sub-characteristic and debt remediation function should be defined on rule '[repository=findbugs, key=NPE]'");
- }
- }
+ newRepository.createRule("NPE").setName("NPE").setHtmlDescription("desc")
+ .setDebtSubCharacteristic(RulesDefinition.SubCharacteristics.API_ABUSE);
+ newRepository.done();
- @Test
- public void fail_if_define_function_without_characteristic() {
- RulesDefinition.NewRepository newRepository = context.createRepository("findbugs", "java");
- RulesDefinition.NewRule newRule = newRepository.createRule("NPE").setName("NPE").setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
- .setDebtSubCharacteristic("");
- newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset("1h", "10min"));
- try {
- newRepository.done();
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Both debt sub-characteristic and debt remediation function should be defined on rule '[repository=findbugs, key=NPE]'");
- }
+ RulesDefinition.Rule rule = context.repository("findbugs").rule("NPE");
+ assertThat(rule.debtSubCharacteristic()).isNull();
}
-
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
index bf394fd9026..b941436390c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
@@ -137,13 +137,11 @@ public class RulesDefinitionXmlLoaderTest {
" <description>Desc</description>" +
" <effortToFixDescription>lines</effortToFixDescription>" +
- " <debtSubCharacteristic>BUG</debtSubCharacteristic>" +
" <debtRemediationFunction>LINEAR</debtRemediationFunction>" +
" <debtRemediationFunctionCoefficient>2d 3h</debtRemediationFunctionCoefficient>" +
" </rule>" +
"</rules>";
RulesDefinition.Rule rule = load(xml).rule("1");
- assertThat(rule.debtSubCharacteristic()).isEqualTo("BUG");
assertThat(rule.effortToFixDescription()).isEqualTo("lines");
DebtRemediationFunction function = rule.debtRemediationFunction();
assertThat(function).isNotNull();
@@ -162,7 +160,6 @@ public class RulesDefinitionXmlLoaderTest {
" <description>Desc</description>" +
" <effortToFixDescription>lines</effortToFixDescription>" +
- " <debtSubCharacteristic>BUG</debtSubCharacteristic>" +
" <debtRemediationFunction>LINEAR_OFFSET</debtRemediationFunction>" +
" <debtRemediationFunctionCoefficient>2d 3h</debtRemediationFunctionCoefficient>" +
" <debtRemediationFunctionOffset>5min</debtRemediationFunctionOffset>" +
@@ -170,7 +167,6 @@ public class RulesDefinitionXmlLoaderTest {
"</rules>";
RulesDefinition.Rule rule = load(xml).rule("1");
assertThat(rule.effortToFixDescription()).isEqualTo("lines");
- assertThat(rule.debtSubCharacteristic()).isEqualTo("BUG");
DebtRemediationFunction function = rule.debtRemediationFunction();
assertThat(function).isNotNull();
assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
@@ -186,13 +182,11 @@ public class RulesDefinitionXmlLoaderTest {
" <key>1</key>" +
" <name>One</name>" +
" <description>Desc</description>" +
- " <debtSubCharacteristic>BUG</debtSubCharacteristic>" +
" <debtRemediationFunction>CONSTANT_ISSUE</debtRemediationFunction>" +
" <debtRemediationFunctionOffset>5min</debtRemediationFunctionOffset>" +
" </rule>" +
"</rules>";
RulesDefinition.Rule rule = load(xml).rule("1");
- assertThat(rule.debtSubCharacteristic()).isEqualTo("BUG");
DebtRemediationFunction function = rule.debtRemediationFunction();
assertThat(function).isNotNull();
assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
@@ -209,7 +203,6 @@ public class RulesDefinitionXmlLoaderTest {
" <key>1</key>" +
" <name>One</name>" +
" <description>Desc</description>" +
- " <debtSubCharacteristic>BUG</debtSubCharacteristic>" +
" <debtRemediationFunction>UNKNOWN</debtRemediationFunction>" +
" </rule>" +
"</rules>");
@@ -221,20 +214,22 @@ public class RulesDefinitionXmlLoaderTest {
}
@Test
- public void fail_if_sub_characteristic_is_missing() {
- try {
- load("<rules>" +
- " <rule>" +
- " <key>1</key>" +
- " <name>One</name>" +
- " <description>Desc</description>" +
- " <debtRemediationFunction>LINEAR</debtRemediationFunction>" +
- " <debtRemediationFunctionCoefficient>1min</debtRemediationFunctionCoefficient>" +
- " </rule>" +
- "</rules>");
- } catch (IllegalStateException e) {
- assertThat(e).hasMessageContaining("Both debt sub-characteristic and debt remediation function should be defined on rule '[repository=squid, key=1]");
- }
+ public void ignore_deprecated_sqale_characteristic() {
+ String xml = "" +
+ "<rules>" +
+ " <rule>" +
+ " <key>1</key>" +
+ " <name>One</name>" +
+ " <description>Desc</description>" +
+ " <effortToFixDescription>lines</effortToFixDescription>" +
+ " <debtSubCharacteristic>BUG</debtSubCharacteristic>" +
+ " <debtRemediationFunction>LINEAR_OFFSET</debtRemediationFunction>" +
+ " <debtRemediationFunctionCoefficient>2d 3h</debtRemediationFunctionCoefficient>" +
+ " <debtRemediationFunctionOffset>5min</debtRemediationFunctionOffset>" +
+ " </rule>" +
+ "</rules>";
+ RulesDefinition.Rule rule = load(xml).rule("1");
+ assertThat(rule.debtSubCharacteristic()).isNull();
}
@Test