diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-13 11:46:11 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-13 11:46:11 +0100 |
commit | 3f99ae14192e0cddf06c87a913ccdf69b3c7ba58 (patch) | |
tree | fbf88bb02e8bafdebc3bc9ce2e8ac087f5973715 | |
parent | 1b423fddea159655701ba669523464a9ef86f917 (diff) | |
download | sonarqube-3f99ae14192e0cddf06c87a913ccdf69b3c7ba58.tar.gz sonarqube-3f99ae14192e0cddf06c87a913ccdf69b3c7ba58.zip |
Little improvements of technical debt
4 files changed, 20 insertions, 21 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java index b81e27125d2..9433d65c48d 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java @@ -32,13 +32,11 @@ import org.sonar.api.measures.Metric; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.utils.WorkDuration; -import org.sonar.api.utils.WorkDurationFactory; import org.sonar.batch.components.Period; import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.batch.debt.IssueChangelogDebtCalculator; import javax.annotation.Nullable; - import java.util.Collection; import java.util.Date; import java.util.List; @@ -54,14 +52,12 @@ public final class NewTechnicalDebtDecorator implements Decorator { private final ResourcePerspectives perspectives; private final TimeMachineConfiguration timeMachineConfiguration; private final IssueChangelogDebtCalculator issueChangelogDebtCalculator; - private final WorkDurationFactory workDurationFactory; public NewTechnicalDebtDecorator(ResourcePerspectives perspectives, TimeMachineConfiguration timeMachineConfiguration, - IssueChangelogDebtCalculator issueChangelogDebtCalculator, WorkDurationFactory workDurationFactory) { + IssueChangelogDebtCalculator issueChangelogDebtCalculator) { this.perspectives = perspectives; this.timeMachineConfiguration = timeMachineConfiguration; this.issueChangelogDebtCalculator = issueChangelogDebtCalculator; - this.workDurationFactory = workDurationFactory; } public boolean shouldExecuteOnProject(Project project) { @@ -96,14 +92,14 @@ public final class NewTechnicalDebtDecorator implements Decorator { } private Double calculateNewTechnicalDebtValue(Collection<Issue> issues, @Nullable Date periodDate) { - WorkDuration duration = workDurationFactory.createFromWorkingLong(0l); + WorkDuration duration = null; for (Issue issue : issues) { WorkDuration debt = issueChangelogDebtCalculator.calculateNewTechnicalDebt(issue, periodDate); if (debt != null) { - duration = duration.add(debt); + duration = duration != null ? duration.add(debt) : debt; } } - return duration.toWorkingDays(); + return duration != null ? duration.toWorkingDays() : 0d; } private boolean shouldSaveNewMetrics(DecoratorContext context) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java index 9416ff32530..d56a47f4aad 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java @@ -21,6 +21,7 @@ package org.sonar.plugins.core.technicaldebt; import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.time.DateUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -90,16 +91,16 @@ public class NewTechnicalDebtDecoratorTest { when(perspectives.as(Issuable.class, resource)).thenReturn(issuable); rightNow = new Date(); - elevenDaysAgo = org.apache.commons.lang.time.DateUtils.addDays(rightNow, -11); - tenDaysAgo = org.apache.commons.lang.time.DateUtils.addDays(rightNow, -10); - nineDaysAgo = org.apache.commons.lang.time.DateUtils.addDays(rightNow, -9); - fiveDaysAgo = org.apache.commons.lang.time.DateUtils.addDays(rightNow, -5); - fourDaysAgo = org.apache.commons.lang.time.DateUtils.addDays(rightNow, -4); + elevenDaysAgo = DateUtils.addDays(rightNow, -11); + tenDaysAgo = DateUtils.addDays(rightNow, -10); + nineDaysAgo = DateUtils.addDays(rightNow, -9); + fiveDaysAgo = DateUtils.addDays(rightNow, -5); + fourDaysAgo = DateUtils.addDays(rightNow, -4); when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, fiveDaysAgo), new Period(2, tenDaysAgo))); WorkDurationFactory workDurationFactory = new WorkDurationFactory(settings); - decorator = new NewTechnicalDebtDecorator(perspectives, timeMachineConfiguration, new IssueChangelogDebtCalculator(workDurationFactory), workDurationFactory); + decorator = new NewTechnicalDebtDecorator(perspectives, timeMachineConfiguration, new IssueChangelogDebtCalculator(workDurationFactory)); } @Test 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 04bb3b2b502..d8d99891078 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 @@ -33,7 +33,6 @@ 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; @@ -101,24 +100,26 @@ public class IssueChangelogDebtCalculator implements BatchComponent { return diffs; } + @CheckForNull private WorkDuration newValue(FieldDiffs fieldDiffs) { for (Map.Entry<String, FieldDiffs.Diff> entry : fieldDiffs.diffs().entrySet()) { if (entry.getKey().equals(IssueUpdater.TECHNICAL_DEBT)) { Long newValue = entry.getValue().newValueLong(); - return newValue != null ? workDurationFactory.createFromWorkingLong(newValue) : workDurationFactory.createFromWorkingLong(0l); + return workDurationFactory.createFromWorkingLong(newValue); } } - return workDurationFactory.createFromWorkingLong(0l); + return null; } + @CheckForNull private WorkDuration oldValue(FieldDiffs fieldDiffs) { for (Map.Entry<String, FieldDiffs.Diff> entry : fieldDiffs.diffs().entrySet()) { if (entry.getKey().equals(IssueUpdater.TECHNICAL_DEBT)) { Long value = entry.getValue().oldValueLong(); - return value != null ? workDurationFactory.createFromWorkingLong(value) : workDurationFactory.createFromWorkingLong(0l); + return workDurationFactory.createFromWorkingLong(value); } } - return workDurationFactory.createFromWorkingLong(0l); + return null; } private boolean isAfter(@Nullable Date currentDate, @Nullable Date pastDate) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java index e5d38b5a1d2..30e2e6c8187 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java @@ -20,11 +20,11 @@ package org.sonar.api.utils; +import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import javax.annotation.Nullable; - import java.io.Serializable; /** @@ -164,7 +164,8 @@ public class WorkDuration implements Serializable { return minutes; } - public int hoursInDay() { + @VisibleForTesting + int hoursInDay() { return hoursInDay; } |