aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java36
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java32
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRules.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java29
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rule/RemediationFunction.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java12
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java36
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java14
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java15
16 files changed, 187 insertions, 10 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
index 1db2c7b50ed..10f49666326 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
@@ -20,14 +20,16 @@
package org.sonar.api.batch.rule;
import com.google.common.annotations.Beta;
+import org.sonar.api.rule.RemediationFunction;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.utils.Duration;
import javax.annotation.CheckForNull;
+
import java.util.Collection;
/**
- * Not used
* @since 4.2
*/
@Beta
@@ -52,4 +54,36 @@ public interface Rule {
RuleStatus status();
+ /**
+ * Characteristic key.
+ *
+ * @since 4.3
+ */
+ @CheckForNull
+ String characteristic();
+
+ /**
+ * Remediation function : one of LINEAR, LINEAR_OFFSET or CONSTANT_ISSUE.
+ *
+ * @since 4.3
+ */
+ @CheckForNull
+ RemediationFunction function();
+
+ /**
+ * Remediation factor duration (used for LINEAR function).
+ *
+ * @since 4.3
+ */
+ @CheckForNull
+ Duration factor();
+
+ /**
+ * Remediation offset duration (used for LINEAR_OFFSET or CONSTANT_ISSUE function).
+ *
+ * @since 4.3
+ */
+ @CheckForNull
+ Duration offset();
+
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java
index b322ebf8571..80fd72fef55 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java
@@ -22,7 +22,6 @@ package org.sonar.api.batch.rule;
import com.google.common.annotations.Beta;
/**
- * Not used
* @since 4.2
*/
@Beta
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java
index ae3b41f8333..3b417972000 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java
@@ -23,10 +23,10 @@ import com.google.common.annotations.Beta;
import org.sonar.api.rule.RuleKey;
import javax.annotation.CheckForNull;
+
import java.util.Collection;
/**
- * Not used yet
* @since 4.2
*/
@Beta
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
index 784425b5d2a..8e4f6e86287 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
@@ -22,11 +22,14 @@ package org.sonar.api.batch.rule.internal;
import com.google.common.collect.ImmutableMap;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.batch.rule.RuleParam;
+import org.sonar.api.rule.RemediationFunction;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.utils.Duration;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
+
import java.util.Collection;
import java.util.Map;
@@ -35,8 +38,11 @@ public class DefaultRule implements Rule {
private final RuleKey key;
private final Integer id;
- private final String name, severity, description, metadata;
+ private final String name, severity, description, metadata, characteristic;
private final RuleStatus status;
+ RemediationFunction function;
+ Duration factor, offset;
+
private final Map<String, RuleParam> params;
DefaultRule(NewRule newRule) {
@@ -47,6 +53,10 @@ public class DefaultRule implements Rule {
this.description = newRule.description;
this.metadata = newRule.metadata;
this.status = newRule.status;
+ this.characteristic = newRule.characteristic;
+ this.function = newRule.function;
+ this.factor = newRule.factor;
+ this.offset = newRule.offset;
ImmutableMap.Builder<String, RuleParam> builder = ImmutableMap.builder();
for (NewRuleParam newRuleParam : newRule.params.values()) {
@@ -91,6 +101,26 @@ public class DefaultRule implements Rule {
}
@Override
+ public String characteristic() {
+ return characteristic;
+ }
+
+ @Override
+ public RemediationFunction function() {
+ return function;
+ }
+
+ @Override
+ public Duration factor() {
+ return factor;
+ }
+
+ @Override
+ public Duration offset() {
+ return offset;
+ }
+
+ @Override
public RuleParam param(String paramKey) {
return params.get(paramKey);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRules.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRules.java
index b55e0104ea9..9a20e04fb7e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRules.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRules.java
@@ -27,6 +27,7 @@ import org.sonar.api.batch.rule.Rules;
import org.sonar.api.rule.RuleKey;
import javax.annotation.concurrent.Immutable;
+
import java.util.Collection;
import java.util.List;
@@ -45,7 +46,6 @@ class DefaultRules implements Rules {
rulesByRepository = builder.build();
}
-
@Override
public Rule find(RuleKey ruleKey) {
List<Rule> rules = rulesByRepository.get(ruleKey.repository());
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
index 4e22c0da58d..8bb25749a7f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
@@ -21,11 +21,14 @@ package org.sonar.api.batch.rule.internal;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
+import org.sonar.api.rule.RemediationFunction;
import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rule.Severity;
import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.rule.Severity;
+import org.sonar.api.utils.Duration;
import javax.annotation.Nullable;
+
import java.util.HashMap;
import java.util.Map;
@@ -35,7 +38,9 @@ public class NewRule {
final RuleKey key;
Integer id;
- String name, description, severity = DEFAULT_SEVERITY, metadata;
+ String name, description, severity = DEFAULT_SEVERITY, metadata, characteristic;
+ RemediationFunction function;
+ Duration factor, offset;
RuleStatus status = RuleStatus.defaultStatus();
Map<String, NewRuleParam> params = new HashMap<String, NewRuleParam>();
@@ -73,6 +78,26 @@ public class NewRule {
return this;
}
+ public NewRule setCharacteristic(@Nullable String c) {
+ this.characteristic = c;
+ return this;
+ }
+
+ public NewRule setFunction(@Nullable RemediationFunction f) {
+ this.function = f;
+ return this;
+ }
+
+ public NewRule setFactor(@Nullable Duration f) {
+ this.factor = f;
+ return this;
+ }
+
+ public NewRule setOffset(@Nullable Duration o) {
+ this.offset = o;
+ return this;
+ }
+
public NewRuleParam addParam(String paramKey) {
if (params.containsKey(paramKey)) {
throw new IllegalStateException(String.format("Parameter '%s' already exists on rule '%s'", paramKey, key));
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RemediationFunction.java
index 851700262e7..0161bc738be 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RemediationFunction.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RemediationFunction.java
@@ -21,6 +21,8 @@
package org.sonar.api.rule;
/**
+ * List of availables remediation function
+ *
* @since 4.3
*/
public enum RemediationFunction {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
index 2f670b2bb76..b669135b684 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
@@ -43,8 +43,6 @@ public interface Characteristic {
List<? extends Characteristic> children();
- List<? extends Requirement> requirements();
-
boolean isRoot();
Date createdAt();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java
index 31f2ff781ed..d6eb82895b5 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java
@@ -28,7 +28,9 @@ import java.util.Date;
/**
* @since 4.1
+ * @deprecated since 4.3
*/
+@Deprecated
public interface Requirement {
Integer id();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java
index a4d1bf42509..ad99777dc58 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java
@@ -37,12 +37,24 @@ public interface TechnicalDebtModel {
@CheckForNull
Characteristic characteristicByKey(String key);
+ /**
+ * @deprecated since 4.3
+ */
@CheckForNull
+ @Deprecated
Requirement requirementsByRule(RuleKey ruleKey);
+ /**
+ * @deprecated since 4.3
+ */
@CheckForNull
+ @Deprecated
Requirement requirementsById(Integer id);
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
List<? extends Requirement> requirements();
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java
index b46196312a2..cf604216971 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java
@@ -32,6 +32,10 @@ import javax.annotation.CheckForNull;
import java.util.Date;
+/**
+ * @deprecated since 4.3
+ */
+@Deprecated
public class DefaultRequirement implements Requirement {
public static final String FUNCTION_LINEAR = "linear";
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java
index 1befa3cb282..a1347ecacd5 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java
@@ -89,6 +89,10 @@ public interface Characteristic {
boolean isRoot();
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
boolean isRequirement();
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java
index e013aee2be0..f97294c381e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java
@@ -33,6 +33,10 @@ public interface TechnicalDebtManager extends ServerComponent {
List<Characteristic> findRootCharacteristics();
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
Characteristic findRequirementByRule(Rule rule);
Characteristic findCharacteristicById(Integer id);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java
index 12e8d64d562..06918b3b3a6 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java
@@ -151,11 +151,19 @@ public class DefaultCharacteristic implements Characteristic {
return this;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
@CheckForNull
public Integer factorValue() {
return factorValue;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
public DefaultCharacteristic setFactorValue(@Nullable Integer factorValue) {
this.factorValue = factorValue;
return this;
@@ -166,6 +174,10 @@ public class DefaultCharacteristic implements Characteristic {
return factorUnit;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
public DefaultCharacteristic setFactorUnit(@Nullable WorkDuration.UNIT factorUnit) {
this.factorUnit = factorUnit;
return this;
@@ -194,26 +206,46 @@ public class DefaultCharacteristic implements Characteristic {
return this;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
@CheckForNull
public Integer offsetValue() {
return offsetValue;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
public DefaultCharacteristic setOffsetValue(@Nullable Integer offsetValue) {
this.offsetValue = offsetValue;
return this;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
@CheckForNull
public WorkDuration.UNIT offsetUnit() {
return offsetUnit;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
public DefaultCharacteristic setOffsetUnit(@Nullable WorkDuration.UNIT offsetUnit) {
this.offsetUnit = offsetUnit;
return this;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
public static WorkDuration.UNIT toUnit(@Nullable String requirementUnit) {
if (requirementUnit != null) {
if (WorkUnit.DAYS.equals(requirementUnit)) {
@@ -243,6 +275,10 @@ public class DefaultCharacteristic implements Characteristic {
return parentId == null;
}
+ /**
+ * @deprecated since 4.3
+ */
+ @Deprecated
public boolean isRequirement() {
return ruleKey != null;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java
index ac61864d84b..504e6be2649 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Duration.java
@@ -97,10 +97,22 @@ public class Duration implements Serializable {
return durationInMinutes;
}
- public boolean isGreaterThan(Duration other){
+ public boolean isGreaterThan(Duration other) {
return toMinutes() > other.toMinutes();
}
+ public Duration add(Duration with) {
+ return Duration.create(durationInMinutes + with.durationInMinutes);
+ }
+
+ public Duration subtract(Duration with) {
+ return Duration.create(durationInMinutes - with.durationInMinutes);
+ }
+
+ public Duration multiply(int factor) {
+ return Duration.create(durationInMinutes * factor);
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java
index cf7eb04d72b..ed99a98301e 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java
@@ -76,6 +76,21 @@ public class DurationTest {
}
@Test
+ public void add() throws Exception {
+ assertThat(Duration.decode("1h", HOURS_IN_DAY).add(Duration.decode("1min", HOURS_IN_DAY))).isEqualTo(Duration.decode("1h1min", HOURS_IN_DAY));
+ }
+
+ @Test
+ public void subtract() throws Exception {
+ assertThat(Duration.decode("1h", HOURS_IN_DAY).subtract(Duration.decode("1min", HOURS_IN_DAY))).isEqualTo(Duration.decode("59min", HOURS_IN_DAY));
+ }
+
+ @Test
+ public void multiply() throws Exception {
+ assertThat(Duration.decode("1h", HOURS_IN_DAY).multiply(2)).isEqualTo(Duration.decode("2h", HOURS_IN_DAY));
+ }
+
+ @Test
public void test_equals_and_hashcode() throws Exception {
Duration duration = Duration.create(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE);
Duration durationWithSameValue = Duration.create(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE);