import java.util.Map;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.core.issue.DefaultIssue;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
import org.sonar.ce.task.projectanalysis.period.Period;
import org.sonar.ce.task.projectanalysis.period.PeriodHolder;
+import org.sonar.core.issue.DefaultIssue;
import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_REMEDIATION_EFFORT_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_REMEDIATION_EFFORT_KEY;
@Override
public void afterComponent(Component component) {
- computeMeasure(component, newMaintainabilityEffortMetric, counter.maintainabilitySum);
- computeMeasure(component, newReliabilityEffortMetric, counter.reliabilitySum);
- computeMeasure(component, newSecurityEffortMetric, counter.securitySum);
+ if (periodHolder.hasPeriod()) {
+ computeMeasure(component, newMaintainabilityEffortMetric, counter.maintainabilitySum);
+ computeMeasure(component, newReliabilityEffortMetric, counter.reliabilitySum);
+ computeMeasure(component, newSecurityEffortMetric, counter.securitySum);
+ }
counter = null;
}
private void computeMeasure(Component component, Metric metric, EffortSum effortSum) {
- if (!effortSum.isEmpty) {
- measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation(effortSum.newEffort).createNoValue());
- }
+ double variation = effortSum.isEmpty ? 0.0 : effortSum.newEffort;
+ measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation(variation).createNoValue());
}
private static class NewEffortCounter {
DefaultIssue unresolved1 = newBugIssue(10L);
DefaultIssue old1 = oldBugIssue(100L);
DefaultIssue unresolved2 = newBugIssue(30L);
+
DefaultIssue old2 = oldBugIssue(300L);
DefaultIssue unresolvedWithoutDebt = newBugIssueWithoutEffort();
DefaultIssue resolved = newBugIssue(50L).setResolution(RESOLUTION_FIXED);
assertThat(measureRepository.getRawMeasures(FILE)).isEmpty();
}
+ @Test
+ public void should_have_empty_measures_if_no_issues() {
+ periodsHolder.setPeriod(PERIOD);
+
+ underTest.beforeComponent(FILE);
+ underTest.afterComponent(FILE);
+
+ assertVariation(FILE, NEW_TECHNICAL_DEBT_KEY, 0);
+ assertVariation(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 0);
+ assertVariation(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 0);
+ }
+
private void assertVariation(Component component, String metricKey, int variation) {
Measure newMeasure = measureRepository.getRawMeasure(component, metricRepository.getByKey(metricKey)).get();
assertThat(newMeasure.getVariation()).isEqualTo(variation);
+ assertThat(newMeasure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
}
private static DefaultIssue newCodeSmellIssue(long effort) {