summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-09-30 14:49:36 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-09-30 17:39:33 +0200
commit59df886c33a506e3224ca8b195fefc895f73d0a4 (patch)
tree27336bdfee3921fd9c008ea8329adce51d53153c
parent6717ba01fec9c0f99e34a5d9a148f084a9eb7467 (diff)
downloadsonarqube-59df886c33a506e3224ca8b195fefc895f73d0a4.tar.gz
sonarqube-59df886c33a506e3224ca8b195fefc895f73d0a4.zip
Renamed Requirement and Characteristic used by technical debt decorator
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculator.java24
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCharacteristic.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/Characteristic.java)22
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtModel.java25
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtRequirement.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/Requirement.java)8
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/AbstractFunction.java4
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunction.java4
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Function.java4
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Functions.java6
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunction.java4
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunction.java4
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunction.java4
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculatorTest.java20
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtRequirementTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/RequirementTest.java)38
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunctionTest.java6
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunctionTest.java6
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunctionTest.java6
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunctionTest.java6
18 files changed, 101 insertions, 95 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculator.java
index 0c4e737ec96..13d19318cca 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculator.java
@@ -43,8 +43,8 @@ import java.util.Map;
public class TechnicalDebtCalculator implements BatchExtension {
private double total = 0.0;
- private Map<Characteristic, Double> characteristicCosts = Maps.newHashMap();
- private Map<Requirement, Double> requirementCosts = Maps.newHashMap();
+ private Map<TechnicalDebtCharacteristic, Double> characteristicCosts = Maps.newHashMap();
+ private Map<TechnicalDebtRequirement, Double> requirementCosts = Maps.newHashMap();
private Functions functions;
private TechnicalDebtModel technicalDebtModel;
@@ -58,10 +58,10 @@ public class TechnicalDebtCalculator implements BatchExtension {
reset();
// group violations by requirement
- ListMultimap<Requirement, Violation> violationsByRequirement = groupViolations(context);
+ ListMultimap<TechnicalDebtRequirement, Violation> violationsByRequirement = groupViolations(context);
// the total cost is: cost(violations)
- for (Requirement requirement : technicalDebtModel.getAllRequirements()) {
+ for (TechnicalDebtRequirement requirement : technicalDebtModel.getAllRequirements()) {
List<Violation> violations = violationsByRequirement.get(requirement);
double allViolationsCost = computeRemediationCost(CoreMetrics.TECHNICAL_DEBT, context, requirement, violations);
updateRequirementCosts(requirement, allViolationsCost);
@@ -72,21 +72,21 @@ public class TechnicalDebtCalculator implements BatchExtension {
return total;
}
- public Map<Characteristic, Double> getCharacteristicCosts() {
+ public Map<TechnicalDebtCharacteristic, Double> getCharacteristicCosts() {
return characteristicCosts;
}
- public Map<Requirement, Double> getRequirementCosts() {
+ public Map<TechnicalDebtRequirement, Double> getRequirementCosts() {
return requirementCosts;
}
@VisibleForTesting
- protected ListMultimap<Requirement, Violation> groupViolations(DecoratorContext context) {
- ListMultimap<Requirement, Violation> violationsByRequirement = ArrayListMultimap.create();
+ protected ListMultimap<TechnicalDebtRequirement, Violation> groupViolations(DecoratorContext context) {
+ ListMultimap<TechnicalDebtRequirement, Violation> violationsByRequirement = ArrayListMultimap.create();
for (Violation violation : context.getViolations()) {
String repositoryKey = violation.getRule().getRepositoryKey();
String key = violation.getRule().getKey();
- Requirement requirement = technicalDebtModel.getRequirementByRule(repositoryKey, key);
+ TechnicalDebtRequirement requirement = technicalDebtModel.getRequirementByRule(repositoryKey, key);
if (requirement == null) {
LoggerFactory.getLogger(getClass()).debug("No technical debt requirement for: " + repositoryKey + "/" + key);
} else {
@@ -97,13 +97,13 @@ public class TechnicalDebtCalculator implements BatchExtension {
}
@VisibleForTesting
- protected void updateRequirementCosts(Requirement requirement, double cost) {
+ protected void updateRequirementCosts(TechnicalDebtRequirement requirement, double cost) {
requirementCosts.put(requirement, cost);
total += cost;
propagateCostInParents(characteristicCosts, requirement.getParent(), cost);
}
- private double computeRemediationCost(Metric metric, DecoratorContext context, Requirement requirement, Collection<Violation> violations) {
+ private double computeRemediationCost(Metric metric, DecoratorContext context, TechnicalDebtRequirement requirement, Collection<Violation> violations) {
double cost = 0.0;
if (violations != null) {
cost = functions.calculateCost(requirement, violations);
@@ -123,7 +123,7 @@ public class TechnicalDebtCalculator implements BatchExtension {
requirementCosts.clear();
}
- private void propagateCostInParents(Map<Characteristic, Double> hierarchyMap, Characteristic characteristic, double cost) {
+ private void propagateCostInParents(Map<TechnicalDebtCharacteristic, Double> hierarchyMap, TechnicalDebtCharacteristic characteristic, double cost) {
if (characteristic != null) {
Double parentCost = hierarchyMap.get(characteristic);
if (parentCost == null) {
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/Characteristic.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCharacteristic.java
index a3b7cbfe3a4..104aceeb6e8 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/Characteristic.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCharacteristic.java
@@ -25,28 +25,28 @@ import javax.annotation.Nullable;
import java.util.List;
-public final class Characteristic implements Characteristicable {
+public final class TechnicalDebtCharacteristic implements Characteristicable {
private String key;
private org.sonar.api.qualitymodel.Characteristic characteristic;
- private Characteristic parent = null;
- private List<Characteristic> subCharacteristics = Lists.newArrayList();
- private List<Requirement> requirements = Lists.newArrayList();
+ private TechnicalDebtCharacteristic parent = null;
+ private List<TechnicalDebtCharacteristic> subCharacteristics = Lists.newArrayList();
+ private List<TechnicalDebtRequirement> requirements = Lists.newArrayList();
- public Characteristic(org.sonar.api.qualitymodel.Characteristic c) {
+ public TechnicalDebtCharacteristic(org.sonar.api.qualitymodel.Characteristic c) {
this(c, null);
}
- public Characteristic(org.sonar.api.qualitymodel.Characteristic c, @Nullable Characteristic parent) {
+ public TechnicalDebtCharacteristic(org.sonar.api.qualitymodel.Characteristic c, @Nullable TechnicalDebtCharacteristic parent) {
this.characteristic = c;
this.key = c.getKey();
this.parent = parent;
for (org.sonar.api.qualitymodel.Characteristic subc : c.getChildren()) {
if (subc.getEnabled()) {
if (subc.getRule() != null) {
- requirements.add(new Requirement(subc, this));
+ requirements.add(new TechnicalDebtRequirement(subc, this));
} else {
- subCharacteristics.add(new Characteristic(subc, this));
+ subCharacteristics.add(new TechnicalDebtCharacteristic(subc, this));
}
}
}
@@ -56,15 +56,15 @@ public final class Characteristic implements Characteristicable {
return key;
}
- public List<Characteristic> getSubCharacteristics() {
+ public List<TechnicalDebtCharacteristic> getSubCharacteristics() {
return subCharacteristics;
}
- public Characteristic getParent() {
+ public TechnicalDebtCharacteristic getParent() {
return parent;
}
- public List<Requirement> getRequirements() {
+ public List<TechnicalDebtRequirement> getRequirements() {
return requirements;
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java
index 00d11f46343..c55d65f6edf 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java
@@ -58,7 +58,6 @@ public final class TechnicalDebtDecorator implements Decorator {
return Arrays.asList(CoreMetrics.TECHNICAL_DEBT);
}
- @SuppressWarnings("rawtypes")
public void decorate(Resource resource, DecoratorContext context) {
if (!ResourceUtils.isUnitTestClass(resource)) {
costCalculator.compute(context);
@@ -73,13 +72,13 @@ public final class TechnicalDebtDecorator implements Decorator {
}
private void saveCharacteristicCosts(DecoratorContext context) {
- for (Map.Entry<Characteristic, Double> entry : costCalculator.getCharacteristicCosts().entrySet()) {
+ for (Map.Entry<TechnicalDebtCharacteristic, Double> entry : costCalculator.getCharacteristicCosts().entrySet()) {
saveCost(context, entry.getKey().toCharacteristic(), entry.getValue(), false);
}
}
private void saveRequirementCosts(DecoratorContext context) {
- for (Map.Entry<Requirement, Double> entry : costCalculator.getRequirementCosts().entrySet()) {
+ for (Map.Entry<TechnicalDebtRequirement, Double> entry : costCalculator.getRequirementCosts().entrySet()) {
saveCost(context, entry.getKey().toCharacteristic(), entry.getValue(), ResourceUtils.isEntity(context.getResource()));
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtModel.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtModel.java
index b5a969d363b..1cd1f33b63d 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtModel.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtModel.java
@@ -21,11 +21,14 @@ package org.sonar.plugins.core.technicaldebt;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
import org.sonar.api.qualitymodel.Model;
import org.sonar.api.qualitymodel.ModelFinder;
import org.sonar.api.rules.Rule;
import org.sonar.api.utils.SonarException;
+import org.sonar.api.utils.TimeProfiler;
import java.util.Collection;
import java.util.List;
@@ -33,18 +36,22 @@ import java.util.Map;
public class TechnicalDebtModel implements BatchExtension {
+ private static final Logger LOGGER = LoggerFactory.getLogger(TechnicalDebtModel.class);
+
// FIXME Use the same as in RegisterTechnicalDebtModel
public static final String MODEL_NAME = "TECHNICAL_DEBT";
- private List<Characteristic> characteristics = Lists.newArrayList();
- private Map<Rule, Requirement> requirementsByRule = Maps.newHashMap();
+ private List<TechnicalDebtCharacteristic> characteristics = Lists.newArrayList();
+ private Map<Rule, TechnicalDebtRequirement> requirementsByRule = Maps.newHashMap();
public TechnicalDebtModel(ModelFinder modelFinder) {
+ TimeProfiler profiler = new TimeProfiler(LOGGER).start("TechnicalDebtModel");
Model model = modelFinder.findByName(MODEL_NAME);
if (model == null) {
throw new SonarException("Can not find the model in database: " + MODEL_NAME);
}
init(model);
+ profiler.stop();
}
/**
@@ -64,34 +71,34 @@ public class TechnicalDebtModel implements BatchExtension {
private void init(Model model) {
for (org.sonar.api.qualitymodel.Characteristic characteristic : model.getRootCharacteristics()) {
if (characteristic.getEnabled()) {
- Characteristic sc = new Characteristic(characteristic);
+ TechnicalDebtCharacteristic sc = new TechnicalDebtCharacteristic(characteristic);
characteristics.add(sc);
registerRequirements(sc);
}
}
}
- private void registerRequirements(Characteristic c) {
- for (Requirement requirement : c.getRequirements()) {
+ private void registerRequirements(TechnicalDebtCharacteristic c) {
+ for (TechnicalDebtRequirement requirement : c.getRequirements()) {
if (requirement.getRule() != null) {
requirementsByRule.put(requirement.getRule(), requirement);
}
}
- for (Characteristic subCharacteristic : c.getSubCharacteristics()) {
+ for (TechnicalDebtCharacteristic subCharacteristic : c.getSubCharacteristics()) {
registerRequirements(subCharacteristic);
}
}
- public List<Characteristic> getCharacteristics() {
+ public List<TechnicalDebtCharacteristic> getCharacteristics() {
return characteristics;
}
- public Collection<Requirement> getAllRequirements() {
+ public Collection<TechnicalDebtRequirement> getAllRequirements() {
return requirementsByRule.values();
}
- public Requirement getRequirementByRule(String repositoryKey, String key) {
+ public TechnicalDebtRequirement getRequirementByRule(String repositoryKey, String key) {
return requirementsByRule.get(Rule.create().setUniqueKey(repositoryKey, key));
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/Requirement.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtRequirement.java
index c10dc52f2a0..3dad2072ea9 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/Requirement.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtRequirement.java
@@ -24,20 +24,20 @@ import org.sonar.plugins.core.technicaldebt.functions.LinearFunction;
import org.sonar.plugins.core.technicaldebt.functions.LinearWithOffsetFunction;
import org.sonar.plugins.core.technicaldebt.functions.LinearWithThresholdFunction;
-public class Requirement implements Characteristicable {
+public class TechnicalDebtRequirement implements Characteristicable {
public static final String PROPERTY_REMEDIATION_FUNCTION = "remediationFunction";
public static final String PROPERTY_REMEDIATION_FACTOR = "remediationFactor";
public static final String PROPERTY_OFFSET = "offset";
private Rule rule;
- private Characteristic parent;
+ private TechnicalDebtCharacteristic parent;
private org.sonar.api.qualitymodel.Characteristic characteristic;
private String function;
private WorkUnit factor;
private WorkUnit offset;
- public Requirement(org.sonar.api.qualitymodel.Characteristic requirement, Characteristic parent) {
+ public TechnicalDebtRequirement(org.sonar.api.qualitymodel.Characteristic requirement, TechnicalDebtCharacteristic parent) {
this.characteristic = requirement;
this.rule = requirement.getRule();
this.parent = parent;
@@ -67,7 +67,7 @@ public class Requirement implements Characteristicable {
return rule;
}
- public Characteristic getParent() {
+ public TechnicalDebtCharacteristic getParent() {
return parent;
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/AbstractFunction.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/AbstractFunction.java
index d04d3f0dd99..98b596e1be4 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/AbstractFunction.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/AbstractFunction.java
@@ -20,7 +20,7 @@
package org.sonar.plugins.core.technicaldebt.functions;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
import java.util.Collection;
@@ -39,6 +39,6 @@ public abstract class AbstractFunction implements Function {
public abstract String getKey();
- public abstract double calculateCost(Requirement requirement, Collection<Violation> violations);
+ public abstract double calculateCost(TechnicalDebtRequirement requirement, Collection<Violation> violations);
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunction.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunction.java
index 91d57632acd..7739230c205 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunction.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunction.java
@@ -20,7 +20,7 @@
package org.sonar.plugins.core.technicaldebt.functions;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
import java.util.Collection;
@@ -37,7 +37,7 @@ public final class ConstantFunction extends AbstractFunction {
return FUNCTION_CONSTANT_RESOURCE;
}
- public double calculateCost(Requirement requirement, Collection<Violation> violations) {
+ public double calculateCost(TechnicalDebtRequirement requirement, Collection<Violation> violations) {
double cost = 0.0;
if (!violations.isEmpty()) {
cost = getConverter().toDays(requirement.getRemediationFactor());
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Function.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Function.java
index 8d6d6ba564d..4fcb51290ba 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Function.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Function.java
@@ -21,7 +21,7 @@ package org.sonar.plugins.core.technicaldebt.functions;
import org.sonar.api.BatchExtension;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import java.util.Collection;
@@ -29,6 +29,6 @@ public interface Function extends BatchExtension {
String getKey();
- double calculateCost(Requirement requirement, Collection<Violation> violations);
+ double calculateCost(TechnicalDebtRequirement requirement, Collection<Violation> violations);
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Functions.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Functions.java
index 7d149a5ae53..37576e40f28 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Functions.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/Functions.java
@@ -22,7 +22,7 @@ package org.sonar.plugins.core.technicaldebt.functions;
import com.google.common.collect.Maps;
import org.sonar.api.BatchExtension;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import java.util.Collection;
import java.util.Map;
@@ -41,11 +41,11 @@ public class Functions implements BatchExtension {
return functionsByKey.get(key);
}
- public Function getFunction(Requirement requirement) {
+ public Function getFunction(TechnicalDebtRequirement requirement) {
return getFunction(requirement.getRemediationFunction());
}
- public double calculateCost(Requirement requirement, Collection<Violation> violations) {
+ public double calculateCost(TechnicalDebtRequirement requirement, Collection<Violation> violations) {
return getFunction(requirement).calculateCost(requirement, violations);
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunction.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunction.java
index 3718e2a6967..a883470c67b 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunction.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunction.java
@@ -20,7 +20,7 @@
package org.sonar.plugins.core.technicaldebt.functions;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
import java.util.Collection;
@@ -39,7 +39,7 @@ public class LinearFunction extends AbstractFunction {
return FUNCTION_LINEAR;
}
- public double calculateCost(Requirement requirement, Collection<Violation> violations) {
+ public double calculateCost(TechnicalDebtRequirement requirement, Collection<Violation> violations) {
double points = 0.0;
for (Violation violation : violations) {
points += (violation.getCost() != null ? violation.getCost() : DEFAULT_VIOLATION_COST);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunction.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunction.java
index 5c402408db5..27a6e7a282f 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunction.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunction.java
@@ -20,7 +20,7 @@
package org.sonar.plugins.core.technicaldebt.functions;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
import java.util.Collection;
@@ -37,7 +37,7 @@ public final class LinearWithOffsetFunction extends LinearFunction {
return FUNCTION_LINEAR_WITH_OFFSET;
}
- public double calculateCost(Requirement requirement, Collection<Violation> violations) {
+ public double calculateCost(TechnicalDebtRequirement requirement, Collection<Violation> violations) {
if (violations.isEmpty()) {
return 0.0;
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunction.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunction.java
index 502aa33202e..f7eb514afb7 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunction.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunction.java
@@ -20,7 +20,7 @@
package org.sonar.plugins.core.technicaldebt.functions;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
import java.util.Collection;
@@ -37,7 +37,7 @@ public final class LinearWithThresholdFunction extends LinearFunction {
return FUNCTION_LINEAR_WITH_THRESHOLD;
}
- public double calculateCost(Requirement requirement, Collection<Violation> violations) {
+ public double calculateCost(TechnicalDebtRequirement requirement, Collection<Violation> violations) {
if (violations.isEmpty()) {
return 0.0;
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculatorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculatorTest.java
index 95205e2084f..4c87fcaeb1d 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculatorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtCalculatorTest.java
@@ -59,8 +59,8 @@ public class TechnicalDebtCalculatorTest {
@Test
public void group_violations_by_requirement() throws Exception {
- Requirement requirement1 = mock(Requirement.class);
- Requirement requirement2 = mock(Requirement.class);
+ TechnicalDebtRequirement requirement1 = mock(TechnicalDebtRequirement.class);
+ TechnicalDebtRequirement requirement2 = mock(TechnicalDebtRequirement.class);
Violation violation1 = buildViolation("rule1", "repo1", NOW);
Violation violation2 = buildViolation("rule1", "repo1", NOW);
@@ -75,7 +75,7 @@ public class TechnicalDebtCalculatorTest {
DecoratorContext context = mock(DecoratorContext.class);
when(context.getViolations()).thenReturn(violations);
- ListMultimap<Requirement, Violation> groupedViolations = remediationCostCalculator.groupViolations(context);
+ ListMultimap<TechnicalDebtRequirement, Violation> groupedViolations = remediationCostCalculator.groupViolations(context);
assertThat(groupedViolations.keySet().size()).isEqualTo(2);
assertThat(groupedViolations.get(requirement1)).containsExactly(violation1, violation2);
@@ -87,7 +87,7 @@ public class TechnicalDebtCalculatorTest {
double requirementCost = 1.0;
- Requirement requirement = mock(Requirement.class);
+ TechnicalDebtRequirement requirement = mock(TechnicalDebtRequirement.class);
when(requirement.getParent()).thenReturn(null);
remediationCostCalculator.updateRequirementCosts(requirement, requirementCost);
@@ -101,11 +101,11 @@ public class TechnicalDebtCalculatorTest {
double requirementCost = 1.0;
- Characteristic parentCharacteristic = new Characteristic(org.sonar.api.qualitymodel.Characteristic.create());
+ TechnicalDebtCharacteristic parentCharacteristic = new TechnicalDebtCharacteristic(org.sonar.api.qualitymodel.Characteristic.create());
- Characteristic characteristic = new Characteristic(org.sonar.api.qualitymodel.Characteristic.create(), parentCharacteristic);
+ TechnicalDebtCharacteristic characteristic = new TechnicalDebtCharacteristic(org.sonar.api.qualitymodel.Characteristic.create(), parentCharacteristic);
- Requirement requirement = mock(Requirement.class);
+ TechnicalDebtRequirement requirement = mock(TechnicalDebtRequirement.class);
when(requirement.getParent()).thenReturn(characteristic);
remediationCostCalculator.updateRequirementCosts(requirement, requirementCost);
@@ -118,8 +118,8 @@ public class TechnicalDebtCalculatorTest {
@Test
public void compute_totals_costs() throws Exception {
- Requirement requirement1 = mock(Requirement.class);
- Requirement requirement2 = mock(Requirement.class);
+ TechnicalDebtRequirement requirement1 = mock(TechnicalDebtRequirement.class);
+ TechnicalDebtRequirement requirement2 = mock(TechnicalDebtRequirement.class);
Violation violation1 = buildViolation("rule1", "repo1", NOW);
Violation violation2 = buildViolation("rule1", "repo1", NOW);
@@ -132,7 +132,7 @@ public class TechnicalDebtCalculatorTest {
stub(technicalDebtModel.getRequirementByRule("repo2", "rule2")).toReturn(requirement2);
stub(technicalDebtModel.getAllRequirements()).toReturn(Lists.newArrayList(requirement1, requirement2));
- stub(functions.calculateCost(any(Requirement.class), any(Collection.class))).toReturn(1.0);
+ stub(functions.calculateCost(any(TechnicalDebtRequirement.class), any(Collection.class))).toReturn(1.0);
DecoratorContext context = mock(DecoratorContext.class);
stub(context.getViolations()).toReturn(violations);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/RequirementTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtRequirementTest.java
index 97fb8ce4026..1eeabeaf274 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/RequirementTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtRequirementTest.java
@@ -30,12 +30,12 @@ import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class RequirementTest {
+public class TechnicalDebtRequirementTest {
@Test
public void defaultFactor() {
Characteristic persistedRequirement = Characteristic.createByName("Efficiency");
- Requirement requirement = new Requirement(persistedRequirement, null);
+ TechnicalDebtRequirement requirement = new TechnicalDebtRequirement(persistedRequirement, null);
assertThat(requirement.getRemediationFactor().getValue(), is(WorkUnit.DEFAULT_VALUE));
assertThat(requirement.getRemediationFactor().getUnit(), is(WorkUnit.DEFAULT_UNIT));
}
@@ -43,8 +43,8 @@ public class RequirementTest {
@Test
public void testOverriddenFactor() {
Characteristic persistedRequirement = Characteristic.createByName("Efficiency");
- persistedRequirement.setProperty(Requirement.PROPERTY_REMEDIATION_FACTOR, 3.14);
- Requirement requirement = new Requirement(persistedRequirement, null);
+ persistedRequirement.setProperty(TechnicalDebtRequirement.PROPERTY_REMEDIATION_FACTOR, 3.14);
+ TechnicalDebtRequirement requirement = new TechnicalDebtRequirement(persistedRequirement, null);
assertThat(requirement.getRemediationFactor().getValue(), is(3.14));
assertThat(requirement.getRemediationFactor().getUnit(), is(WorkUnit.DAYS));
}
@@ -52,7 +52,7 @@ public class RequirementTest {
@Test
public void defaultFunctionIsLinear() {
Characteristic persistedRequirement = Characteristic.createByName("Efficiency");
- Requirement requirement = new Requirement(persistedRequirement, null);
+ TechnicalDebtRequirement requirement = new TechnicalDebtRequirement(persistedRequirement, null);
assertThat(requirement.getRemediationFunction(), is(LinearFunction.FUNCTION_LINEAR));
assertThat(requirement.getOffset(), is(nullValue()));
}
@@ -60,16 +60,16 @@ public class RequirementTest {
@Test
public void testOverriddenFunction() {
Characteristic persistedRequirement = Characteristic.createByName("Efficiency");
- persistedRequirement.setProperty(Requirement.PROPERTY_REMEDIATION_FUNCTION, ConstantFunction.FUNCTION_CONSTANT_RESOURCE);
- Requirement requirement = new Requirement(persistedRequirement, null);
+ persistedRequirement.setProperty(TechnicalDebtRequirement.PROPERTY_REMEDIATION_FUNCTION, ConstantFunction.FUNCTION_CONSTANT_RESOURCE);
+ TechnicalDebtRequirement requirement = new TechnicalDebtRequirement(persistedRequirement, null);
assertThat(requirement.getRemediationFunction(), is(ConstantFunction.FUNCTION_CONSTANT_RESOURCE));
}
@Test
public void testDefaultLinearWithOffset() {
Characteristic persistedRequirement = Characteristic.createByName("Efficiency");
- persistedRequirement.setProperty(Requirement.PROPERTY_REMEDIATION_FUNCTION, LinearWithOffsetFunction.FUNCTION_LINEAR_WITH_OFFSET);
- Requirement requirement = new Requirement(persistedRequirement, null);
+ persistedRequirement.setProperty(TechnicalDebtRequirement.PROPERTY_REMEDIATION_FUNCTION, LinearWithOffsetFunction.FUNCTION_LINEAR_WITH_OFFSET);
+ TechnicalDebtRequirement requirement = new TechnicalDebtRequirement(persistedRequirement, null);
assertThat(requirement.getRemediationFunction(), is(LinearWithOffsetFunction.FUNCTION_LINEAR_WITH_OFFSET));
assertThat(requirement.getRemediationFactor().getValue(), is(WorkUnit.DEFAULT_VALUE));
assertThat(requirement.getRemediationFactor().getUnit(), is(WorkUnit.DEFAULT_UNIT));
@@ -80,10 +80,10 @@ public class RequirementTest {
@Test
public void testCustomizedLinearWithOffset() {
Characteristic persistedRequirement = Characteristic.createByName("Efficiency");
- persistedRequirement.setProperty(Requirement.PROPERTY_REMEDIATION_FUNCTION, LinearWithOffsetFunction.FUNCTION_LINEAR_WITH_OFFSET);
- persistedRequirement.setProperty(Requirement.PROPERTY_OFFSET, 5.0);
- persistedRequirement.addProperty(persistedRequirement.getProperty(Requirement.PROPERTY_OFFSET).setTextValue("h"));
- Requirement requirement = new Requirement(persistedRequirement, null);
+ persistedRequirement.setProperty(TechnicalDebtRequirement.PROPERTY_REMEDIATION_FUNCTION, LinearWithOffsetFunction.FUNCTION_LINEAR_WITH_OFFSET);
+ persistedRequirement.setProperty(TechnicalDebtRequirement.PROPERTY_OFFSET, 5.0);
+ persistedRequirement.addProperty(persistedRequirement.getProperty(TechnicalDebtRequirement.PROPERTY_OFFSET).setTextValue("h"));
+ TechnicalDebtRequirement requirement = new TechnicalDebtRequirement(persistedRequirement, null);
assertThat(requirement.getRemediationFunction(), is(LinearWithOffsetFunction.FUNCTION_LINEAR_WITH_OFFSET));
assertThat(requirement.getOffset().getValue(), is(5.0));
assertThat(requirement.getOffset().getUnit(), is(WorkUnit.HOURS));
@@ -92,8 +92,8 @@ public class RequirementTest {
@Test
public void testDefaultLinearWithThreshold() {
Characteristic persistedRequirement = Characteristic.createByName("Efficiency");
- persistedRequirement.setProperty(Requirement.PROPERTY_REMEDIATION_FUNCTION, LinearWithThresholdFunction.FUNCTION_LINEAR_WITH_THRESHOLD);
- Requirement requirement = new Requirement(persistedRequirement, null);
+ persistedRequirement.setProperty(TechnicalDebtRequirement.PROPERTY_REMEDIATION_FUNCTION, LinearWithThresholdFunction.FUNCTION_LINEAR_WITH_THRESHOLD);
+ TechnicalDebtRequirement requirement = new TechnicalDebtRequirement(persistedRequirement, null);
assertThat(requirement.getRemediationFunction(), is(LinearWithThresholdFunction.FUNCTION_LINEAR_WITH_THRESHOLD));
assertThat(requirement.getRemediationFactor().getValue(), is(WorkUnit.DEFAULT_VALUE));
assertThat(requirement.getRemediationFactor().getUnit(), is(WorkUnit.DEFAULT_UNIT));
@@ -104,10 +104,10 @@ public class RequirementTest {
@Test
public void testCustomizedLinearWithThreshold() {
Characteristic persistedRequirement = Characteristic.createByName("Efficiency");
- persistedRequirement.setProperty(Requirement.PROPERTY_REMEDIATION_FUNCTION, LinearWithThresholdFunction.FUNCTION_LINEAR_WITH_THRESHOLD);
- persistedRequirement.setProperty(Requirement.PROPERTY_OFFSET, 5.0);
- persistedRequirement.addProperty(persistedRequirement.getProperty(Requirement.PROPERTY_OFFSET).setTextValue("h"));
- Requirement requirement = new Requirement(persistedRequirement, null);
+ persistedRequirement.setProperty(TechnicalDebtRequirement.PROPERTY_REMEDIATION_FUNCTION, LinearWithThresholdFunction.FUNCTION_LINEAR_WITH_THRESHOLD);
+ persistedRequirement.setProperty(TechnicalDebtRequirement.PROPERTY_OFFSET, 5.0);
+ persistedRequirement.addProperty(persistedRequirement.getProperty(TechnicalDebtRequirement.PROPERTY_OFFSET).setTextValue("h"));
+ TechnicalDebtRequirement requirement = new TechnicalDebtRequirement(persistedRequirement, null);
assertThat(requirement.getRemediationFunction(), is(LinearWithThresholdFunction.FUNCTION_LINEAR_WITH_THRESHOLD));
assertThat(requirement.getOffset().getValue(), is(5.0));
assertThat(requirement.getOffset().getUnit(), is(WorkUnit.HOURS));
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunctionTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunctionTest.java
index 06dca29af8c..56ee4bb7662 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunctionTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/ConstantFunctionTest.java
@@ -25,7 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnit;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
@@ -39,13 +39,13 @@ import static org.mockito.Mockito.when;
public class ConstantFunctionTest {
- private Requirement requirement;
+ private TechnicalDebtRequirement requirement;
private Function function;
@Before
public void before() {
function = new ConstantFunction(new WorkUnitConverter(new PropertiesConfiguration()));
- requirement = mock(Requirement.class);
+ requirement = mock(TechnicalDebtRequirement.class);
when(requirement.getRemediationFactor()).thenReturn(WorkUnit.createInDays(3.14));
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunctionTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunctionTest.java
index 40955e95089..48ef4b152ec 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunctionTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearFunctionTest.java
@@ -25,7 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnit;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
@@ -39,12 +39,12 @@ import static org.mockito.Mockito.when;
public class LinearFunctionTest {
- private Requirement requirement;
+ private TechnicalDebtRequirement requirement;
private Function function = new LinearFunction(new WorkUnitConverter(new PropertiesConfiguration()));
@Before
public void before() {
- requirement = mock(Requirement.class);
+ requirement = mock(TechnicalDebtRequirement.class);
when(requirement.getRemediationFactor()).thenReturn(WorkUnit.createInDays(3.14));
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunctionTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunctionTest.java
index 46fa3d92b2c..0ce120d1f1f 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunctionTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithOffsetFunctionTest.java
@@ -25,7 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnit;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
@@ -39,12 +39,12 @@ import static org.mockito.Mockito.when;
public class LinearWithOffsetFunctionTest {
- private Requirement requirement;
+ private TechnicalDebtRequirement requirement;
private Function function = new LinearWithOffsetFunction(new WorkUnitConverter(new PropertiesConfiguration()));
@Before
public void before() {
- requirement = mock(Requirement.class);
+ requirement = mock(TechnicalDebtRequirement.class);
when(requirement.getRemediationFactor()).thenReturn(WorkUnit.createInDays(3.14));
when(requirement.getOffset()).thenReturn(WorkUnit.createInDays(2.12));
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunctionTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunctionTest.java
index 51e17f25966..efef36a8270 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunctionTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/functions/LinearWithThresholdFunctionTest.java
@@ -25,7 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.technicaldebt.Requirement;
+import org.sonar.plugins.core.technicaldebt.TechnicalDebtRequirement;
import org.sonar.plugins.core.technicaldebt.WorkUnit;
import org.sonar.plugins.core.technicaldebt.WorkUnitConverter;
@@ -39,12 +39,12 @@ import static org.mockito.Mockito.when;
public class LinearWithThresholdFunctionTest {
- private Requirement requirement;
+ private TechnicalDebtRequirement requirement;
private Function function = new LinearWithThresholdFunction(new WorkUnitConverter(new PropertiesConfiguration()));
@Before
public void before() {
- requirement = mock(Requirement.class);
+ requirement = mock(TechnicalDebtRequirement.class);
when(requirement.getRemediationFactor()).thenReturn(WorkUnit.createInDays(2.0));
when(requirement.getOffset()).thenReturn(WorkUnit.createInDays(5.0));
}