diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-21 14:32:39 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-25 19:00:03 +0100 |
commit | 7d241801b9a01fbaaebe7209efadabb905aab8d1 (patch) | |
tree | 31840c0bba564143de2165701e04bf137c789b5a /plugins | |
parent | 782c0fa8124eef4e806bad803cf24ea3c2bd9b5c (diff) | |
download | sonarqube-7d241801b9a01fbaaebe7209efadabb905aab8d1.tar.gz sonarqube-7d241801b9a01fbaaebe7209efadabb905aab8d1.zip |
SONAR-4996 Update debt on measures sqale_index
Diffstat (limited to 'plugins')
4 files changed, 52 insertions, 54 deletions
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 3d85ca1edbc..324678a7b5a 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 @@ -40,7 +40,6 @@ import org.sonar.api.resources.ResourceUtils; import org.sonar.api.technicaldebt.batch.Characteristic; import org.sonar.api.technicaldebt.batch.Requirement; import org.sonar.api.technicaldebt.batch.TechnicalDebtModel; -import org.sonar.api.utils.WorkDurationFactory; import java.util.Arrays; import java.util.Collection; @@ -56,16 +55,12 @@ import static com.google.common.collect.Maps.newHashMap; @DependsUpon(DecoratorBarriers.ISSUES_TRACKED) public final class TechnicalDebtDecorator implements Decorator { - private static final int DECIMALS_PRECISION = 5; - private final ResourcePerspectives perspectives; private final TechnicalDebtModel model; - private final WorkDurationFactory workDurationFactory; - public TechnicalDebtDecorator(ResourcePerspectives perspectives, TechnicalDebtModel model, WorkDurationFactory workDurationFactory) { + public TechnicalDebtDecorator(ResourcePerspectives perspectives, TechnicalDebtModel model) { this.perspectives = perspectives; this.model = model; - this.workDurationFactory = workDurationFactory; } public boolean shouldExecuteOnProject(Project project) { @@ -102,7 +97,7 @@ public final class TechnicalDebtDecorator implements Decorator { propagateTechnicalDebtInParents(requirement.characteristic(), value, characteristicCosts); } - context.saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT, total, DECIMALS_PRECISION)); + context.saveMeasure(CoreMetrics.TECHNICAL_DEBT, total); saveOnCharacteristic(context, characteristicCosts); saveOnRequirement(context, requirementCosts); } @@ -126,11 +121,7 @@ public final class TechnicalDebtDecorator implements Decorator { if (value > 0.0 || (ResourceUtils.isProject(context.getResource()) && characteristic.isRoot())) { Measure measure = new Measure(CoreMetrics.TECHNICAL_DEBT); measure.setCharacteristic(characteristic); - measure.setValue(value, DECIMALS_PRECISION); - if (inMemory) { - measure.setPersistenceMode(PersistenceMode.MEMORY); - } - context.saveMeasure(measure); + saveMeasure(context, measure, value, inMemory); } } @@ -141,12 +132,16 @@ public final class TechnicalDebtDecorator implements Decorator { if (value > 0.0) { Measure measure = new Measure(CoreMetrics.TECHNICAL_DEBT); measure.setRequirement(requirement); - measure.setValue(value, DECIMALS_PRECISION); - if (inMemory) { - measure.setPersistenceMode(PersistenceMode.MEMORY); - } - context.saveMeasure(measure); + saveMeasure(context, measure, value, inMemory); + } + } + + private void saveMeasure(DecoratorContext context, Measure measure, Double value, boolean inMemory){ + measure.setValue(value); + if (inMemory) { + measure.setPersistenceMode(PersistenceMode.MEMORY); } + context.saveMeasure(measure); } @VisibleForTesting @@ -176,14 +171,13 @@ public final class TechnicalDebtDecorator implements Decorator { } } - double debtInDays = workDurationFactory.createFromSeconds(debt).toWorkingDays(); for (Measure measure : context.getChildrenMeasures(MeasuresFilters.requirement(metric, requirement))) { Requirement measureRequirement = measure.getRequirement(); if (measureRequirement != null && measureRequirement.equals(requirement) && measure.getValue() != null) { - debtInDays += measure.getValue(); + debt += measure.getValue(); } } - return debtInDays; + return debt; } private void propagateTechnicalDebtInParents(Characteristic characteristic, double value, Map<Characteristic, Double> characteristicCosts) { diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 3dd2f264bad..f928a31b1fb 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -247,6 +247,12 @@ since_previous_version.short=\u0394 version since_previous_version_detailed=since previous version ({0} - {1}) since_previous_version_detailed.short=\u0394 version ({0}) time_changes=Time changes +work_duration.x_days={0} days +work_duration.x_days.short={0}d +work_duration.x_hours={0} hours +work_duration.x_hours.short={0}h +work_duration.x_minutes={0} minutes +work_duration.x_minutes.short={0}m #------------------------------------------------------------------------------ # @@ -586,9 +592,6 @@ issue.component_deleted=Removed issue.debt=Debt: issue.technical_debt=Technical Debt: issue.technical_debt_short=Debt -issue.technical_debt.x_days={0} days -issue.technical_debt.x_hours={0} hours -issue.technical_debt.x_minutes={0} minutes issue.technical_debt_deleted=Rule not configured to generate technical debt estimate. @@ -1094,7 +1097,6 @@ widget.rules.name=Issues and Technical Debt widget.rules.description=Reports issues and technical debt. widget.rules.issues=Issues widget.rules.technical_debt=Technical Debt -widget.rules.technical_debt.days=days widget.rules.added=Added: widget.rules.removed=Removed: diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/issues.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/issues.html.erb index 6e2da2ec2f7..82c5a402303 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/issues.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/issues.html.erb @@ -51,7 +51,6 @@ <span class="big"> <a href="<%= url_for_drilldown('sqale_index') -%>"><%= format_measure(technical_debt) -%></a> </span> - <span><%= message('widget.rules.technical_debt.days') -%></span> <span><%= dashboard_configuration.selected_period? ? format_variation(technical_debt) : trend_icon(technical_debt) -%></span> <% if @dashboard_configuration.selected_period? diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java index ddb0098fa63..6488169995d 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java @@ -22,16 +22,17 @@ package org.sonar.plugins.core.technicaldebt; import com.google.common.collect.ListMultimap; import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.hamcrest.Description; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.CoreProperties; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.config.Settings; import org.sonar.api.issue.Issuable; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; @@ -49,7 +50,6 @@ import org.sonar.api.technicaldebt.batch.TechnicalDebtModel; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; import org.sonar.api.test.IsMeasure; -import org.sonar.api.utils.WorkDurationFactory; import java.util.List; @@ -61,6 +61,8 @@ import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) public class TechnicalDebtDecoratorTest { + final static Long ONE_DAY_DEBT = 1 * 8 * 60 * 60L; + @Mock DecoratorContext context; @@ -80,10 +82,7 @@ public class TechnicalDebtDecoratorTest { ResourcePerspectives perspectives = mock(ResourcePerspectives.class); when(perspectives.as(Issuable.class, resource)).thenReturn(issuable); - Settings settings = new Settings(); - settings.setProperty(CoreProperties.HOURS_IN_DAY, "8"); - - decorator = new TechnicalDebtDecorator(perspectives, defaultTechnicalDebtModel, new WorkDurationFactory(settings)); + decorator = new TechnicalDebtDecorator(perspectives, defaultTechnicalDebtModel); } @Test @@ -129,7 +128,7 @@ public class TechnicalDebtDecoratorTest { @Test public void add_technical_debt_from_one_issue_and_no_parent() throws Exception { - Issue issue = createIssue("rule1", "repo1").setDebt(1 * 8 * 60 * 60L); + Issue issue = createIssue("rule1", "repo1").setDebt(ONE_DAY_DEBT); when(issuable.issues()).thenReturn(newArrayList(issue)); Requirement requirement = mock(Requirement.class); @@ -138,8 +137,8 @@ public class TechnicalDebtDecoratorTest { decorator.decorate(resource, context); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, 1.0))); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, null, requirement, 1.0))); + verify(context).saveMeasure(CoreMetrics.TECHNICAL_DEBT, ONE_DAY_DEBT.doubleValue()); + verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, null, requirement, ONE_DAY_DEBT.doubleValue()))); } @Test @@ -153,12 +152,12 @@ public class TechnicalDebtDecoratorTest { decorator.decorate(resource, context); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, 0.0))); + verify(context).saveMeasure(CoreMetrics.TECHNICAL_DEBT, 0.0); } @Test public void add_technical_debt_from_one_issue_and_propagate_to_parents() throws Exception { - Issue issue = createIssue("rule1", "repo1").setDebt(1 * 8 * 60 * 60L); + Issue issue = createIssue("rule1", "repo1").setDebt(ONE_DAY_DEBT); when(issuable.issues()).thenReturn(newArrayList(issue)); DefaultCharacteristic parentCharacteristic = new DefaultCharacteristic().setKey("parentCharacteristic"); @@ -171,16 +170,16 @@ public class TechnicalDebtDecoratorTest { decorator.decorate(resource, context); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, 1.0))); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, parentCharacteristic, 1.0))); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, characteristic, 1.0))); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, requirement, 1.0))); + verify(context).saveMeasure(CoreMetrics.TECHNICAL_DEBT, ONE_DAY_DEBT.doubleValue()); + verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, parentCharacteristic, ONE_DAY_DEBT.doubleValue()))); + verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, characteristic, ONE_DAY_DEBT.doubleValue()))); + verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, requirement, ONE_DAY_DEBT.doubleValue()))); } @Test public void add_technical_debt_from_issues() throws Exception { - long technicalDebt1 = 1 * 8 * 60 * 60; - long technicalDebt2 = 2 * 8 * 60 * 60L; + Long technicalDebt1 = ONE_DAY_DEBT; + Long technicalDebt2 = 2 * ONE_DAY_DEBT; Issue issue1 = createIssue("rule1", "repo1").setDebt(technicalDebt1); Issue issue2 = createIssue("rule1", "repo1").setDebt(technicalDebt1); @@ -201,17 +200,15 @@ public class TechnicalDebtDecoratorTest { decorator.decorate(resource, context); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, 6.0))); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, requirement1, 2.0))); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, requirement2, 4.0))); + verify(context).saveMeasure(CoreMetrics.TECHNICAL_DEBT, 6d * ONE_DAY_DEBT); + verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, requirement1, 2d * ONE_DAY_DEBT))); + verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, requirement2, 4d * ONE_DAY_DEBT))); } @Test public void add_technical_debt_from_children_measures() throws Exception { - long technicalDebt = 1 * 8 * 60 * 60L; - - Issue issue1 = createIssue("rule1", "repo1").setDebt(technicalDebt); - Issue issue2 = createIssue("rule1", "repo1").setDebt(technicalDebt); + Issue issue1 = createIssue("rule1", "repo1").setDebt(ONE_DAY_DEBT); + Issue issue2 = createIssue("rule1", "repo1").setDebt(ONE_DAY_DEBT); when(issuable.issues()).thenReturn(newArrayList(issue1, issue2)); DefaultCharacteristic rootCharacteristic = new DefaultCharacteristic().setKey("rootCharacteristic"); @@ -222,13 +219,13 @@ public class TechnicalDebtDecoratorTest { when(defaultTechnicalDebtModel.requirementsByRule(ruleKey1)).thenReturn(requirement); doReturn(newArrayList(requirement)).when(defaultTechnicalDebtModel).requirements(); - Measure measure = new Measure().setRequirement(requirement).setValue(5.0); + Measure measure = new Measure().setRequirement(requirement).setValue(5d * ONE_DAY_DEBT); when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(newArrayList(measure)); decorator.decorate(resource, context); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, 7.0))); - verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, requirement, 7.0))); + verify(context).saveMeasure(CoreMetrics.TECHNICAL_DEBT, 7d * ONE_DAY_DEBT); + verify(context).saveMeasure(argThat(new IsCharacteristicMeasure(CoreMetrics.TECHNICAL_DEBT, requirement, 7d * ONE_DAY_DEBT))); } @Test @@ -283,7 +280,7 @@ public class TechnicalDebtDecoratorTest { @Test public void check_definitions() { - assertThat(decorator.definitions()).hasSize(1); + assertThat(TechnicalDebtDecorator.definitions()).hasSize(1); } private DefaultIssue createIssue(String ruleKey, String repositoryKey) { @@ -324,6 +321,7 @@ public class TechnicalDebtDecoratorTest { this.value = value; } + @Override public boolean matches(Object o) { if (!(o instanceof Measure)) { return false; @@ -334,5 +332,10 @@ public class TechnicalDebtDecoratorTest { ObjectUtils.equals(requirement, m.getRequirement()) && ObjectUtils.equals(value, m.getValue()); } + + @Override + public void describeTo(Description description) { + description.appendText(ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE)); + } } } |