summaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-05 19:22:20 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-05 19:22:20 +0100
commit6c7dcb3a2af976d6cfdf7ac7dec2cedbe6013619 (patch)
treef8e4f151a9f103568db3f006de6661baf9b098f8 /sonar-batch
parent1c8bb2241f785b7e83827ea1d4d74d881f415612 (diff)
downloadsonarqube-6c7dcb3a2af976d6cfdf7ac7dec2cedbe6013619.tar.gz
sonarqube-6c7dcb3a2af976d6cfdf7ac7dec2cedbe6013619.zip
SONAR-5056 Update Issue.debt from Long to Duration
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java20
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java3
7 files changed, 22 insertions, 20 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java
index 276671185f0..9b352136b6e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java
@@ -31,6 +31,7 @@ import org.sonar.core.issue.IssueUpdater;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.util.*;
import static com.google.common.collect.Lists.newArrayList;
@@ -39,7 +40,7 @@ public class IssueChangelogDebtCalculator implements BatchComponent {
@CheckForNull
public Long calculateNewTechnicalDebt(Issue issue, @Nullable Date periodDate) {
- Long debt = ((DefaultIssue) issue).debt();
+ Long debt = ((DefaultIssue) issue).debtInMinutes();
Date periodDatePlusOneSecond = periodDate != null ? DateUtils.addSeconds(periodDate, 1) : null;
if (isAfter(issue.creationDate(), periodDatePlusOneSecond)) {
return debt;
@@ -129,5 +130,4 @@ public class IssueChangelogDebtCalculator implements BatchComponent {
return (currentDate != null) && (pastDate == null || (DateUtils.truncatedCompareTo(currentDate, pastDate, Calendar.SECOND) <= 0));
}
-
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
index 442dfbd71f9..d19ad5de7ad 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
@@ -28,6 +28,7 @@ import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.Violation;
+import org.sonar.api.utils.Duration;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.debt.RuleDebtCalculator;
import org.sonar.core.issue.DefaultIssueBuilder;
@@ -111,7 +112,8 @@ public class ModuleIssues {
if (issue.severity() == null) {
issue.setSeverity(activeRule.getSeverity().name());
}
- issue.setDebt(technicalDebtCalculator.calculateTechnicalDebt(issue.ruleKey(), issue.effortToFix()));
+ Long debt = technicalDebtCalculator.calculateTechnicalDebt(issue.ruleKey(), issue.effortToFix());
+ issue.setDebt(debt != null ? Duration.create(debt) : null);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java
index 50d09eed2f5..016d24a6d25 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java
@@ -32,6 +32,7 @@ import org.sonar.api.profiles.Alert;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
+import org.sonar.api.utils.Duration;
import org.sonar.core.timemachine.Periods;
import java.util.Collection;
@@ -151,7 +152,7 @@ public class QualityGateVerifier implements Decorator {
private String alertValue(Alert alert, Metric.Level level){
String value = level.equals(Metric.Level.ERROR) ? alert.getValueError() : alert.getValueWarning();
if (alert.getMetric().getType().equals(Metric.ValueType.WORK_DUR)) {
- return i18n.formatWorkDuration(Locale.ENGLISH, Long.parseLong(value));
+ return i18n.formatWorkDuration(Locale.ENGLISH, Duration.create(Long.parseLong(value)));
} else {
return value;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java
index 479b8e2f888..ca022819bc8 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java
@@ -23,11 +23,10 @@ package org.sonar.batch.debt;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.FieldDiffs;
+import org.sonar.api.utils.Duration;
import java.util.Date;
@@ -51,17 +50,18 @@ public class IssueChangelogDebtCalculatorTest {
long twoDays = 2 * HOURS_IN_DAY * 60 * 60L;
long fiveDays = 5 * HOURS_IN_DAY * 60 * 60L;
+ Duration oneDayDebt = Duration.create(oneDay);
+ Duration twoDaysDebt = Duration.create(twoDays);
+ Duration fiveDaysDebt = Duration.create(fiveDays);
+
@Before
public void setUp() throws Exception {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.HOURS_IN_DAY, Integer.toString(HOURS_IN_DAY));
-
issueChangelogDebtCalculator = new IssueChangelogDebtCalculator();
}
@Test
public void calculate_new_technical_debt_with_one_diff_in_changelog() throws Exception {
- Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(twoDays).setChanges(
+ Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(twoDaysDebt).setChanges(
newArrayList(
// changelog created at is null because it has just been created on the current analysis
new FieldDiffs().setDiff("technicalDebt", oneDay, twoDays).setCreationDate(null)
@@ -76,7 +76,7 @@ public class IssueChangelogDebtCalculatorTest {
@Test
public void calculate_new_technical_debt_with_many_diffs_in_changelog() throws Exception {
- Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(fiveDays).setChanges(
+ Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(fiveDaysDebt).setChanges(
newArrayList(
new FieldDiffs().setDiff("technicalDebt", twoDays, fiveDays).setCreationDate(null),
new FieldDiffs().setDiff("technicalDebt", oneDay, twoDays).setCreationDate(fourDaysAgo)
@@ -90,7 +90,7 @@ public class IssueChangelogDebtCalculatorTest {
@Test
public void changelog_can_be_in_wrong_order() {
- Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(fiveDays).setChanges(
+ Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(fiveDaysDebt).setChanges(
newArrayList(
// 3rd
new FieldDiffs().setDiff("technicalDebt", null, oneDay).setCreationDate(nineDaysAgo),
@@ -107,7 +107,7 @@ public class IssueChangelogDebtCalculatorTest {
@Test
public void calculate_new_technical_debt_with_null_date() throws Exception {
- Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(twoDays).setChanges(
+ Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(twoDaysDebt).setChanges(
newArrayList(
new FieldDiffs().setDiff("technicalDebt", oneDay, twoDays).setCreationDate(null)
)
@@ -137,7 +137,7 @@ public class IssueChangelogDebtCalculatorTest {
@Test
public void not_return_negative_debt() {
- Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(oneDay).setChanges(
+ Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(oneDayDebt).setChanges(
newArrayList(
new FieldDiffs().setDiff("technicalDebt", twoDays, oneDay).setCreationDate(null)
)
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java
index 59cd9c3efbd..c53cdcdc2d5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java
@@ -48,9 +48,7 @@ public class RuleDebtCalculatorTest {
@Before
public void before() {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.HOURS_IN_DAY, HOURS_IN_DAY);
- calculator = new RuleDebtCalculator(model, settings);
+ calculator = new RuleDebtCalculator(model, new Settings().setProperty(CoreProperties.HOURS_IN_DAY, 8));
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
index 0835389fdf0..1150211081e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
@@ -34,6 +34,7 @@ import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.*;
+import org.sonar.api.utils.Duration;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.debt.RuleDebtCalculator;
@@ -277,7 +278,6 @@ public class ModuleIssuesTest {
Date analysisDate = new Date();
when(project.getAnalysisDate()).thenReturn(analysisDate);
-
DefaultIssue issue = new DefaultIssue()
.setKey("ABCDE")
.setRuleKey(SQUID_RULE_KEY)
@@ -291,7 +291,7 @@ public class ModuleIssuesTest {
ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class);
verify(cache).put(argument.capture());
- assertThat(argument.getValue().debt()).isEqualTo(debt);
+ assertThat(argument.getValue().debt()).isEqualTo(Duration.create(debt));
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java
index 8cfc816b46c..bf1d149df9c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java
@@ -37,6 +37,7 @@ import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.test.IsMeasure;
+import org.sonar.api.utils.Duration;
import org.sonar.core.timemachine.Periods;
import java.util.Locale;
@@ -350,7 +351,7 @@ public class QualityGateVerifierTest {
// metric name is declared in l10n bundle
when(i18n.message(any(Locale.class), eq("metric.tech_debt.name"), anyString())).thenReturn("The Debt");
- when(i18n.formatWorkDuration(any(Locale.class), eq(3600L))).thenReturn("1h");
+ when(i18n.formatWorkDuration(any(Locale.class), eq(Duration.create(3600L)))).thenReturn("1h");
when(context.getMeasure(metric)).thenReturn(new Measure(metric, 1800d));
projectAlerts.addAll(Lists.newArrayList(new Alert(null, metric, Alert.OPERATOR_SMALLER, "3600", null)));