@@ -25,17 +25,13 @@ import com.google.common.collect.Lists; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.api.batch.Decorator; | |||
import org.sonar.api.batch.DecoratorBarriers; | |||
import org.sonar.api.batch.DecoratorContext; | |||
import org.sonar.api.batch.DependedUpon; | |||
import org.sonar.api.batch.DependsUpon; | |||
import org.sonar.api.batch.SonarIndex; | |||
import org.sonar.api.batch.*; | |||
import org.sonar.api.component.ResourcePerspectives; | |||
import org.sonar.api.issue.Issuable; | |||
import org.sonar.api.issue.Issue; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.issue.internal.IssueChangeContext; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.profiles.RulesProfile; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.resources.Resource; | |||
@@ -43,7 +39,6 @@ import org.sonar.api.resources.ResourceUtils; | |||
import org.sonar.api.rules.ActiveRule; | |||
import org.sonar.api.rules.Rule; | |||
import org.sonar.api.rules.RuleFinder; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.utils.KeyValueFormat; | |||
import org.sonar.batch.issue.IssueCache; | |||
import org.sonar.batch.scan.LastSnapshots; | |||
@@ -176,7 +171,7 @@ public class IssueTrackingDecorator implements Decorator { | |||
updater.setPastMessage(issue, ref.getMessage(), changeContext); | |||
updater.setPastEffortToFix(issue, ref.getEffortToFix(), changeContext); | |||
Long technicalDebt = ref.getTechnicalDebt(); | |||
TechnicalDebt previousTechnicalDebt = technicalDebt != null ? TechnicalDebt.fromLong(technicalDebt) : null; | |||
WorkDayDuration previousTechnicalDebt = technicalDebt != null ? WorkDayDuration.fromLong(technicalDebt) : null; | |||
updater.setPastTechnicalDebt(issue, previousTechnicalDebt, changeContext); | |||
} | |||
} |
@@ -29,6 +29,7 @@ import org.sonar.api.component.ResourcePerspectives; | |||
import org.sonar.api.issue.Issue; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.issue.internal.IssueChangeContext; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.profiles.RulesProfile; | |||
import org.sonar.api.resources.File; | |||
import org.sonar.api.resources.Project; | |||
@@ -36,7 +37,6 @@ import org.sonar.api.resources.Resource; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rules.Rule; | |||
import org.sonar.api.rules.RuleFinder; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.batch.issue.IssueCache; | |||
import org.sonar.batch.scan.LastSnapshots; | |||
import org.sonar.core.issue.IssueUpdater; | |||
@@ -519,7 +519,7 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase { | |||
verify(updater).setPastLine(eq(issue), eq(10)); | |||
verify(updater).setPastMessage(eq(issue), eq("Message"), any(IssueChangeContext.class)); | |||
verify(updater).setPastEffortToFix(eq(issue), eq(1.5), any(IssueChangeContext.class)); | |||
verify(updater).setPastTechnicalDebt(eq(issue), eq(TechnicalDebt.of(1, 0, 0)), any(IssueChangeContext.class)); | |||
verify(updater).setPastTechnicalDebt(eq(issue), eq(WorkDayDuration.of(1, 0, 0)), any(IssueChangeContext.class)); | |||
} | |||
@Test |
@@ -24,6 +24,7 @@ import org.junit.Before; | |||
import org.junit.Test; | |||
import org.mockito.ArgumentCaptor; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.profiles.RulesProfile; | |||
import org.sonar.api.resources.JavaFile; | |||
import org.sonar.api.resources.Project; | |||
@@ -34,7 +35,6 @@ import org.sonar.api.rules.ActiveRule; | |||
import org.sonar.api.rules.Rule; | |||
import org.sonar.api.rules.RulePriority; | |||
import org.sonar.api.rules.Violation; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.core.technicaldebt.TechnicalDebtCalculator; | |||
import java.util.Calendar; | |||
@@ -201,14 +201,14 @@ public class ModuleIssuesTest { | |||
.setRuleKey(SQUID_RULE_KEY) | |||
.setSeverity(Severity.CRITICAL); | |||
when(technicalDebtCalculator.calculTechnicalDebt(issue)).thenReturn(TechnicalDebt.of(10, 0, 0)); | |||
when(technicalDebtCalculator.calculTechnicalDebt(issue)).thenReturn(WorkDayDuration.of(10, 0, 0)); | |||
when(filters.accept(issue, null)).thenReturn(true); | |||
moduleIssues.initAndAddIssue(issue); | |||
ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); | |||
verify(cache).put(argument.capture()); | |||
assertThat(argument.getValue().technicalDebt()).isEqualTo(TechnicalDebt.of(10, 0, 0)); | |||
assertThat(argument.getValue().technicalDebt()).isEqualTo(WorkDayDuration.of(10, 0, 0)); | |||
} | |||
} |
@@ -28,7 +28,7 @@ import org.sonar.api.issue.ActionPlan; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.issue.internal.DefaultIssueComment; | |||
import org.sonar.api.issue.internal.IssueChangeContext; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.user.User; | |||
import javax.annotation.Nullable; | |||
@@ -200,8 +200,8 @@ public class IssueUpdater implements BatchComponent, ServerComponent { | |||
return setEffortToFix(issue, currentEffort, context); | |||
} | |||
public boolean setTechnicalDebt(DefaultIssue issue, @Nullable TechnicalDebt value, IssueChangeContext context) { | |||
TechnicalDebt oldValue = issue.technicalDebt(); | |||
public boolean setTechnicalDebt(DefaultIssue issue, @Nullable WorkDayDuration value, IssueChangeContext context) { | |||
WorkDayDuration oldValue = issue.technicalDebt(); | |||
if (!Objects.equal(value, oldValue)) { | |||
issue.setTechnicalDebt(value); | |||
issue.setFieldChange(context, TECHNICAL_DEBT, oldValue != null ? oldValue.toLong() : oldValue, value != null ? value.toLong() : null); | |||
@@ -212,8 +212,8 @@ public class IssueUpdater implements BatchComponent, ServerComponent { | |||
return false; | |||
} | |||
public boolean setPastTechnicalDebt(DefaultIssue issue, @Nullable TechnicalDebt previousTechnicalDebt, IssueChangeContext context) { | |||
TechnicalDebt currentTechnicalDebt = issue.technicalDebt(); | |||
public boolean setPastTechnicalDebt(DefaultIssue issue, @Nullable WorkDayDuration previousTechnicalDebt, IssueChangeContext context) { | |||
WorkDayDuration currentTechnicalDebt = issue.technicalDebt(); | |||
issue.setTechnicalDebt(previousTechnicalDebt); | |||
return setTechnicalDebt(issue, currentTechnicalDebt, context); | |||
} |
@@ -24,8 +24,8 @@ import com.google.common.base.Preconditions; | |||
import org.apache.commons.lang.builder.ToStringBuilder; | |||
import org.apache.commons.lang.builder.ToStringStyle; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.utils.KeyValueFormat; | |||
import javax.annotation.CheckForNull; | |||
@@ -422,7 +422,7 @@ public final class IssueDto implements Serializable { | |||
issue.setResolution(resolution); | |||
issue.setMessage(message); | |||
issue.setEffortToFix(effortToFix); | |||
issue.setTechnicalDebt(technicalDebt != null ? TechnicalDebt.fromLong(technicalDebt) : null); | |||
issue.setTechnicalDebt(technicalDebt != null ? WorkDayDuration.fromLong(technicalDebt) : null); | |||
issue.setLine(line); | |||
issue.setSeverity(severity); | |||
issue.setReporter(reporter); |
@@ -27,12 +27,12 @@ import org.slf4j.LoggerFactory; | |||
import org.sonar.api.BatchExtension; | |||
import org.sonar.api.batch.DecoratorContext; | |||
import org.sonar.api.issue.Issue; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.api.measures.Measure; | |||
import org.sonar.api.measures.MeasuresFilters; | |||
import org.sonar.api.measures.Metric; | |||
import org.sonar.api.rules.Violation; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.core.technicaldebt.functions.Functions; | |||
import java.util.Collection; | |||
@@ -58,7 +58,7 @@ public class TechnicalDebtCalculator implements BatchExtension { | |||
this.converter = converter; | |||
} | |||
public TechnicalDebt calculTechnicalDebt(Issue issue) { | |||
public WorkDayDuration calculTechnicalDebt(Issue issue) { | |||
TechnicalDebtRequirement requirement = technicalDebtModel.getRequirementByRule(issue.ruleKey().repository(), issue.ruleKey().rule()); | |||
if (requirement != null) { | |||
return converter.fromMinutes(functions.costInMinutes(requirement, issue)); |
@@ -23,7 +23,7 @@ import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
public class TechnicalDebtConverter implements BatchComponent, ServerComponent { | |||
@@ -65,14 +65,14 @@ public class TechnicalDebtConverter implements BatchComponent, ServerComponent { | |||
} | |||
} | |||
public double toDays(TechnicalDebt technicalDebt) { | |||
public double toDays(WorkDayDuration technicalDebt) { | |||
double resultDays = technicalDebt.days(); | |||
resultDays += Double.valueOf(technicalDebt.hours()) / hoursInDay; | |||
resultDays += Double.valueOf(technicalDebt.minutes()) / (hoursInDay * 60.0); | |||
return resultDays; | |||
} | |||
public TechnicalDebt fromMinutes(Long inMinutes){ | |||
public WorkDayDuration fromMinutes(Long inMinutes){ | |||
int oneHourInMinute = 60; | |||
int days = 0; | |||
int hours = 0; | |||
@@ -93,7 +93,7 @@ public class TechnicalDebtConverter implements BatchComponent, ServerComponent { | |||
minutes = inMinutes.shortValue(); | |||
return TechnicalDebt.of(minutes, hours, days); | |||
return WorkDayDuration.of(minutes, hours, days); | |||
} | |||
} |
@@ -24,7 +24,7 @@ import org.sonar.api.issue.ActionPlan; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.issue.internal.FieldDiffs; | |||
import org.sonar.api.issue.internal.IssueChangeContext; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.user.User; | |||
import org.sonar.core.user.DefaultUser; | |||
@@ -366,42 +366,42 @@ public class IssueUpdaterTest { | |||
@Test | |||
public void set_past_technical_debt() throws Exception { | |||
issue.setTechnicalDebt(TechnicalDebt.of(15, 0, 0)); | |||
TechnicalDebt previousDebt = TechnicalDebt.of(10, 0, 0); | |||
issue.setTechnicalDebt(WorkDayDuration.of(15, 0, 0)); | |||
WorkDayDuration previousDebt = WorkDayDuration.of(10, 0, 0); | |||
boolean updated = updater.setPastTechnicalDebt(issue, previousDebt, context); | |||
assertThat(updated).isTrue(); | |||
assertThat(issue.technicalDebt()).isEqualTo(TechnicalDebt.of(15, 0, 0)); | |||
assertThat(issue.technicalDebt()).isEqualTo(WorkDayDuration.of(15, 0, 0)); | |||
assertThat(issue.mustSendNotifications()).isFalse(); | |||
FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); | |||
assertThat(diff.oldValue()).isEqualTo(TechnicalDebt.of(10, 0, 0).toLong()); | |||
assertThat(diff.newValue()).isEqualTo(TechnicalDebt.of(15, 0, 0).toLong()); | |||
assertThat(diff.oldValue()).isEqualTo(WorkDayDuration.of(10, 0, 0).toLong()); | |||
assertThat(diff.newValue()).isEqualTo(WorkDayDuration.of(15, 0, 0).toLong()); | |||
} | |||
@Test | |||
public void set_past_technical_debt_without_previous_value() throws Exception { | |||
issue.setTechnicalDebt(TechnicalDebt.of(15, 0, 0)); | |||
issue.setTechnicalDebt(WorkDayDuration.of(15, 0, 0)); | |||
boolean updated = updater.setPastTechnicalDebt(issue, null, context); | |||
assertThat(updated).isTrue(); | |||
assertThat(issue.technicalDebt()).isEqualTo(TechnicalDebt.of(15, 0, 0)); | |||
assertThat(issue.technicalDebt()).isEqualTo(WorkDayDuration.of(15, 0, 0)); | |||
assertThat(issue.mustSendNotifications()).isFalse(); | |||
FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); | |||
assertThat(diff.oldValue()).isNull(); | |||
assertThat(diff.newValue()).isEqualTo(TechnicalDebt.of(15, 0, 0).toLong()); | |||
assertThat(diff.newValue()).isEqualTo(WorkDayDuration.of(15, 0, 0).toLong()); | |||
} | |||
@Test | |||
public void set_past_technical_debt_with_null_new_value() throws Exception { | |||
issue.setTechnicalDebt(null); | |||
TechnicalDebt previousDebt = TechnicalDebt.of(10, 0, 0); | |||
WorkDayDuration previousDebt = WorkDayDuration.of(10, 0, 0); | |||
boolean updated = updater.setPastTechnicalDebt(issue, previousDebt, context); | |||
assertThat(updated).isTrue(); | |||
assertThat(issue.technicalDebt()).isNull(); | |||
assertThat(issue.mustSendNotifications()).isFalse(); | |||
FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); | |||
assertThat(diff.oldValue()).isEqualTo(TechnicalDebt.of(10, 0, 0).toLong()); | |||
assertThat(diff.oldValue()).isEqualTo(WorkDayDuration.of(10, 0, 0).toLong()); | |||
assertThat(diff.newValue()).isNull(); | |||
} | |||
@@ -25,7 +25,7 @@ import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.issue.Issue; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import java.util.Calendar; | |||
import java.util.Date; | |||
@@ -87,7 +87,7 @@ public class IssueDtoTest { | |||
assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED); | |||
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE); | |||
assertThat(issue.effortToFix()).isEqualTo(15.0); | |||
assertThat(issue.technicalDebt()).isEqualTo(TechnicalDebt.of(10, 10, 10)); | |||
assertThat(issue.technicalDebt()).isEqualTo(WorkDayDuration.of(10, 10, 10)); | |||
assertThat(issue.line()).isEqualTo(6); | |||
assertThat(issue.severity()).isEqualTo("BLOCKER"); | |||
assertThat(issue.message()).isEqualTo("message"); |
@@ -23,11 +23,11 @@ import org.junit.Test; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.issue.internal.DefaultIssueComment; | |||
import org.sonar.api.issue.internal.IssueChangeContext; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rules.Rule; | |||
import org.sonar.api.rules.RuleFinder; | |||
import org.sonar.api.rules.RuleQuery; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.core.persistence.AbstractDaoTestCase; | |||
import org.sonar.core.persistence.MyBatis; | |||
@@ -54,7 +54,7 @@ public class IssueStorageTest extends AbstractDaoTestCase { | |||
.setRuleKey(RuleKey.of("squid", "AvoidCycle")) | |||
.setLine(5000) | |||
.setTechnicalDebt(TechnicalDebt.of(10, 0, 0)) | |||
.setTechnicalDebt(WorkDayDuration.of(10, 0, 0)) | |||
.setReporter("emmerik") | |||
.setResolution("OPEN") | |||
.setStatus("OPEN") | |||
@@ -88,7 +88,7 @@ public class IssueStorageTest extends AbstractDaoTestCase { | |||
// updated fields | |||
.setLine(5000) | |||
.setTechnicalDebt(TechnicalDebt.of(10, 0, 0)) | |||
.setTechnicalDebt(WorkDayDuration.of(10, 0, 0)) | |||
.setChecksum("FFFFF") | |||
.setAuthorLogin("simon") | |||
.setAssignee("loic") |
@@ -22,7 +22,7 @@ package org.sonar.core.technicaldebt; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import static org.fest.assertions.Assertions.assertThat; | |||
@@ -69,15 +69,15 @@ public class TechnicalDebtConverterTest { | |||
@Test | |||
public void convert_technical_debt_to_days() { | |||
assertThat(converter.toDays(TechnicalDebt.of(0, 0, 6))).isEqualTo(6.0); | |||
assertThat(converter.toDays(TechnicalDebt.of(0, 6, 0))).isEqualTo(0.5); | |||
assertThat(converter.toDays(TechnicalDebt.of(360, 0, 0))).isEqualTo(0.5); | |||
assertThat(converter.toDays(TechnicalDebt.of(45, 0, 0))).isEqualTo(0.0625); | |||
assertThat(converter.toDays(WorkDayDuration.of(0, 0, 6))).isEqualTo(6.0); | |||
assertThat(converter.toDays(WorkDayDuration.of(0, 6, 0))).isEqualTo(0.5); | |||
assertThat(converter.toDays(WorkDayDuration.of(360, 0, 0))).isEqualTo(0.5); | |||
assertThat(converter.toDays(WorkDayDuration.of(45, 0, 0))).isEqualTo(0.0625); | |||
assertThat(converter.toDays(TechnicalDebt.of(45, 6, 1))).isEqualTo(1.5625); | |||
assertThat(converter.toDays(WorkDayDuration.of(45, 6, 1))).isEqualTo(1.5625); | |||
} | |||
private void checkValues(TechnicalDebt technicalDebt, int expectedMinutes, int expectedHours, int expectedDays) { | |||
private void checkValues(WorkDayDuration technicalDebt, int expectedMinutes, int expectedHours, int expectedDays) { | |||
assertThat(technicalDebt.minutes()).isEqualTo(expectedMinutes); | |||
assertThat(technicalDebt.hours()).isEqualTo(expectedHours); | |||
assertThat(technicalDebt.days()).isEqualTo(expectedDays); |
@@ -21,7 +21,6 @@ package org.sonar.api.issue; | |||
import com.google.common.collect.ImmutableList; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import javax.annotation.CheckForNull; | |||
@@ -103,12 +102,6 @@ public interface Issue extends Serializable { | |||
@CheckForNull | |||
Double effortToFix(); | |||
/** | |||
* Elapsed time in minutes to fix the issue | |||
*/ | |||
@CheckForNull | |||
TechnicalDebt technicalDebt(); | |||
/** | |||
* See constant values in {@link Issue}. | |||
*/ |
@@ -34,7 +34,6 @@ import org.sonar.api.issue.Issue; | |||
import org.sonar.api.issue.IssueComment; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rule.Severity; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
@@ -58,7 +57,7 @@ public class DefaultIssue implements Issue { | |||
private String message; | |||
private Integer line; | |||
private Double effortToFix; | |||
private TechnicalDebt technicalDebt; | |||
private WorkDayDuration technicalDebt; | |||
private String status; | |||
private String resolution; | |||
private String reporter; | |||
@@ -188,12 +187,15 @@ public class DefaultIssue implements Issue { | |||
return this; | |||
} | |||
/** | |||
* Elapsed time to fix the issue | |||
*/ | |||
@CheckForNull | |||
public TechnicalDebt technicalDebt() { | |||
public WorkDayDuration technicalDebt() { | |||
return technicalDebt; | |||
} | |||
public DefaultIssue setTechnicalDebt(@Nullable TechnicalDebt t) { | |||
public DefaultIssue setTechnicalDebt(@Nullable WorkDayDuration t) { | |||
this.technicalDebt = t; | |||
return this; | |||
} |
@@ -17,11 +17,11 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.api.technicaldebt; | |||
package org.sonar.api.issue.internal; | |||
import java.io.Serializable; | |||
public class TechnicalDebt implements Serializable { | |||
public class WorkDayDuration implements Serializable { | |||
private static final int DAY = 10000; | |||
private static final int HOUR = 100; | |||
@@ -31,14 +31,14 @@ public class TechnicalDebt implements Serializable { | |||
private int hours; | |||
private int minutes; | |||
private TechnicalDebt(int minutes, int hours, int days) { | |||
private WorkDayDuration(int minutes, int hours, int days) { | |||
this.minutes = minutes; | |||
this.hours = hours; | |||
this.days = days; | |||
} | |||
private TechnicalDebt(long technicalDebtInLong) { | |||
long time = technicalDebtInLong; | |||
private WorkDayDuration(long durationInLong) { | |||
long time = durationInLong; | |||
Long currentTime = time / DAY; | |||
if (currentTime > 0) { | |||
this.days = currentTime.intValue(); | |||
@@ -57,12 +57,12 @@ public class TechnicalDebt implements Serializable { | |||
} | |||
} | |||
public static TechnicalDebt of(int minutes, int hours, int days) { | |||
return new TechnicalDebt(minutes, hours, days); | |||
public static WorkDayDuration of(int minutes, int hours, int days) { | |||
return new WorkDayDuration(minutes, hours, days); | |||
} | |||
public static TechnicalDebt fromLong(long technicalDebtInLong) { | |||
return new TechnicalDebt(technicalDebtInLong); | |||
public static WorkDayDuration fromLong(long durationInLong) { | |||
return new WorkDayDuration(durationInLong); | |||
} | |||
public long toLong() { | |||
@@ -89,14 +89,14 @@ public class TechnicalDebt implements Serializable { | |||
if (o == null || getClass() != o.getClass()) { | |||
return false; | |||
} | |||
TechnicalDebt technicalDebt = (TechnicalDebt) o; | |||
if (days != technicalDebt.days) { | |||
WorkDayDuration workDayDuration = (WorkDayDuration) o; | |||
if (days != workDayDuration.days) { | |||
return false; | |||
} | |||
if (hours != technicalDebt.hours) { | |||
if (hours != workDayDuration.hours) { | |||
return false; | |||
} | |||
if (minutes != technicalDebt.minutes) { | |||
if (minutes != workDayDuration.minutes) { | |||
return false; | |||
} | |||
return true; |
@@ -25,7 +25,6 @@ import org.junit.Test; | |||
import org.sonar.api.issue.Issue; | |||
import org.sonar.api.issue.IssueComment; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import java.text.SimpleDateFormat; | |||
import java.util.List; | |||
@@ -49,7 +48,7 @@ public class DefaultIssueTest { | |||
.setMessage("a message") | |||
.setLine(7) | |||
.setEffortToFix(1.2d) | |||
.setTechnicalDebt(TechnicalDebt.of(1, 0, 0)) | |||
.setTechnicalDebt(WorkDayDuration.of(1, 0, 0)) | |||
.setActionPlanKey("BCDE") | |||
.setStatus(Issue.STATUS_CLOSED) | |||
.setResolution(Issue.RESOLUTION_FIXED) | |||
@@ -77,7 +76,7 @@ public class DefaultIssueTest { | |||
assertThat(issue.message()).isEqualTo("a message"); | |||
assertThat(issue.line()).isEqualTo(7); | |||
assertThat(issue.effortToFix()).isEqualTo(1.2d); | |||
assertThat(issue.technicalDebt()).isEqualTo(TechnicalDebt.of(1, 0, 0)); | |||
assertThat(issue.technicalDebt()).isEqualTo(WorkDayDuration.of(1, 0, 0)); | |||
assertThat(issue.actionPlanKey()).isEqualTo("BCDE"); | |||
assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED); | |||
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED); |
@@ -17,46 +17,46 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.api.technicaldebt; | |||
package org.sonar.api.issue.internal; | |||
import org.junit.Test; | |||
import static org.fest.assertions.Assertions.assertThat; | |||
public class TechnicalDebtTest { | |||
public class WorkDayDurationTest { | |||
@Test | |||
public void from_long_on_simple_values(){ | |||
checkTimes(TechnicalDebt.fromLong(1L), 0, 0, 1); | |||
checkTimes(TechnicalDebt.fromLong(100L), 0, 1, 0); | |||
checkTimes(TechnicalDebt.fromLong(10000L), 1, 0, 0); | |||
checkTimes(WorkDayDuration.fromLong(1L), 0, 0, 1); | |||
checkTimes(WorkDayDuration.fromLong(100L), 0, 1, 0); | |||
checkTimes(WorkDayDuration.fromLong(10000L), 1, 0, 0); | |||
} | |||
@Test | |||
public void from_long_on_complex_values(){ | |||
checkTimes(TechnicalDebt.fromLong(10101L), 1, 1, 1); | |||
checkTimes(TechnicalDebt.fromLong(101L), 0, 1, 1); | |||
checkTimes(TechnicalDebt.fromLong(10001L), 1, 0, 1); | |||
checkTimes(TechnicalDebt.fromLong(10100L), 1, 1, 0); | |||
checkTimes(WorkDayDuration.fromLong(10101L), 1, 1, 1); | |||
checkTimes(WorkDayDuration.fromLong(101L), 0, 1, 1); | |||
checkTimes(WorkDayDuration.fromLong(10001L), 1, 0, 1); | |||
checkTimes(WorkDayDuration.fromLong(10100L), 1, 1, 0); | |||
checkTimes(TechnicalDebt.fromLong(112233L), 11, 22, 33); | |||
checkTimes(WorkDayDuration.fromLong(112233L), 11, 22, 33); | |||
} | |||
@Test | |||
public void to_long(){ | |||
assertThat(TechnicalDebt.of(1, 1, 1).toLong()).isEqualTo(10101L); | |||
assertThat(WorkDayDuration.of(1, 1, 1).toLong()).isEqualTo(10101L); | |||
} | |||
@Test | |||
public void test_equals_and_hashCode() throws Exception { | |||
TechnicalDebt oneMinute = TechnicalDebt.fromLong(1L); | |||
TechnicalDebt oneHours = TechnicalDebt.fromLong(100L); | |||
TechnicalDebt oneDay = TechnicalDebt.fromLong(10000L); | |||
WorkDayDuration oneMinute = WorkDayDuration.fromLong(1L); | |||
WorkDayDuration oneHours = WorkDayDuration.fromLong(100L); | |||
WorkDayDuration oneDay = WorkDayDuration.fromLong(10000L); | |||
assertThat(oneMinute).isEqualTo(oneMinute); | |||
assertThat(oneMinute).isEqualTo(TechnicalDebt.fromLong(1L)); | |||
assertThat(oneHours).isEqualTo(TechnicalDebt.fromLong(100L)); | |||
assertThat(oneDay).isEqualTo(TechnicalDebt.fromLong(10000L)); | |||
assertThat(oneMinute).isEqualTo(WorkDayDuration.fromLong(1L)); | |||
assertThat(oneHours).isEqualTo(WorkDayDuration.fromLong(100L)); | |||
assertThat(oneDay).isEqualTo(WorkDayDuration.fromLong(10000L)); | |||
assertThat(oneMinute).isNotEqualTo(oneHours); | |||
assertThat(oneHours).isNotEqualTo(oneDay); | |||
@@ -64,7 +64,7 @@ public class TechnicalDebtTest { | |||
assertThat(oneMinute.hashCode()).isEqualTo(oneMinute.hashCode()); | |||
} | |||
private void checkTimes(TechnicalDebt technicalDebt, int expectedDays, int expectedHours, int expectedMinutes){ | |||
private void checkTimes(WorkDayDuration technicalDebt, int expectedDays, int expectedHours, int expectedMinutes){ | |||
assertThat(technicalDebt.days()).isEqualTo(expectedDays); | |||
assertThat(technicalDebt.hours()).isEqualTo(expectedHours); | |||
assertThat(technicalDebt.minutes()).isEqualTo(expectedMinutes); |
@@ -21,7 +21,7 @@ package org.sonar.server.issue; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.issue.internal.FieldDiffs; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.core.i18n.I18nManager; | |||
import org.sonar.core.issue.IssueUpdater; | |||
import org.sonar.server.technicaldebt.TechnicalDebtFormatter; | |||
@@ -74,10 +74,10 @@ public class IssueChangelogFormatter implements ServerComponent { | |||
String oldValueString = oldValue != null && !oldValue.equals("") ? oldValue.toString() : null; | |||
if (IssueUpdater.TECHNICAL_DEBT.equals(key)) { | |||
if (newValueString != null) { | |||
newValueString = technicalDebtFormatter.format(locale, TechnicalDebt.fromLong(Long.parseLong(newValueString))); | |||
newValueString = technicalDebtFormatter.format(locale, WorkDayDuration.fromLong(Long.parseLong(newValueString))); | |||
} | |||
if (oldValueString != null) { | |||
oldValueString = technicalDebtFormatter.format(locale, TechnicalDebt.fromLong(Long.parseLong(oldValueString))); | |||
oldValueString = technicalDebtFormatter.format(locale, WorkDayDuration.fromLong(Long.parseLong(oldValueString))); | |||
} | |||
} | |||
return new IssueChangelogDiffFormat(oldValueString, newValueString); |
@@ -21,7 +21,7 @@ | |||
package org.sonar.server.technicaldebt; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.server.user.UserSession; | |||
public class InternalRubyTechnicalDebtService implements ServerComponent { | |||
@@ -32,12 +32,12 @@ public class InternalRubyTechnicalDebtService implements ServerComponent { | |||
this.technicalDebtFormatter = technicalDebtFormatter; | |||
} | |||
public String format(TechnicalDebt technicalDebt){ | |||
public String format(WorkDayDuration technicalDebt){ | |||
return technicalDebtFormatter.format(UserSession.get().locale(), technicalDebt); | |||
} | |||
public TechnicalDebt toTechnicalDebt(String technicalDebtInLong){ | |||
return TechnicalDebt.fromLong(Long.parseLong(technicalDebtInLong)); | |||
public WorkDayDuration toTechnicalDebt(String technicalDebtInLong){ | |||
return WorkDayDuration.fromLong(Long.parseLong(technicalDebtInLong)); | |||
} | |||
} |
@@ -21,7 +21,7 @@ | |||
package org.sonar.server.technicaldebt; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.core.i18n.I18nManager; | |||
import java.util.Locale; | |||
@@ -34,7 +34,7 @@ public class TechnicalDebtFormatter implements ServerComponent { | |||
this.i18nManager = i18nManager; | |||
} | |||
public String format(Locale locale, TechnicalDebt technicalDebt) { | |||
public String format(Locale locale, WorkDayDuration technicalDebt) { | |||
StringBuilder message = new StringBuilder(); | |||
if (technicalDebt.days() > 0) { | |||
message.append(i18nManager.message(locale, "issue.technical_debt.x_days", null, technicalDebt.days())); |
@@ -28,8 +28,8 @@ import org.sonar.api.issue.Issue; | |||
import org.sonar.api.issue.IssueQuery; | |||
import org.sonar.api.issue.IssueQueryResult; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.api.rules.Rule; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.user.User; | |||
import org.sonar.api.user.UserFinder; | |||
import org.sonar.core.component.ComponentDto; | |||
@@ -305,7 +305,7 @@ public class DefaultIssueFinderTest { | |||
assertThat(results.issues()).hasSize(1); | |||
DefaultIssue result = (DefaultIssue) results.issues().iterator().next(); | |||
assertThat(result.technicalDebt()).isEqualTo(TechnicalDebt.of(10, 0, 0)); | |||
assertThat(result.technicalDebt()).isEqualTo(WorkDayDuration.of(10, 0, 0)); | |||
} | |||
} |
@@ -25,7 +25,7 @@ import org.junit.runner.RunWith; | |||
import org.mockito.Mock; | |||
import org.mockito.runners.MockitoJUnitRunner; | |||
import org.sonar.api.issue.internal.FieldDiffs; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.core.i18n.I18nManager; | |||
import org.sonar.server.technicaldebt.TechnicalDebtFormatter; | |||
@@ -130,8 +130,8 @@ public class IssueChangelogFormatterTest { | |||
FieldDiffs diffs = new FieldDiffs(); | |||
diffs.setDiff("technicalDebt", "500", "10000"); | |||
when(technicalDebtFormatter.format(DEFAULT_LOCALE, TechnicalDebt.of(0, 5, 0))).thenReturn("5 hours"); | |||
when(technicalDebtFormatter.format(DEFAULT_LOCALE, TechnicalDebt.of(0, 0, 1))).thenReturn("1 days"); | |||
when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 5, 0))).thenReturn("5 hours"); | |||
when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days"); | |||
when(i18nManager.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt"); | |||
when(i18nManager.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days"); | |||
@@ -148,7 +148,7 @@ public class IssueChangelogFormatterTest { | |||
FieldDiffs diffs = new FieldDiffs(); | |||
diffs.setDiff("technicalDebt", null, "10000"); | |||
when(technicalDebtFormatter.format(DEFAULT_LOCALE, TechnicalDebt.of(0, 0, 1))).thenReturn("1 days"); | |||
when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days"); | |||
when(i18nManager.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt"); | |||
when(i18nManager.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days"); |
@@ -24,7 +24,7 @@ import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.mockito.Mock; | |||
import org.mockito.runners.MockitoJUnitRunner; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import java.util.Locale; | |||
@@ -48,13 +48,13 @@ public class InternalRubyTechnicalDebtServiceTest { | |||
@Test | |||
public void format() { | |||
TechnicalDebt technicalDebt = TechnicalDebt.of(5, 0, 0); | |||
WorkDayDuration technicalDebt = WorkDayDuration.of(5, 0, 0); | |||
service.format(technicalDebt); | |||
verify(technicalDebtFormatter).format(any(Locale.class), eq(technicalDebt)); | |||
} | |||
@Test | |||
public void to_technical_debt() { | |||
assertThat(service.toTechnicalDebt("500")).isEqualTo(TechnicalDebt.of(0, 5, 0)); | |||
assertThat(service.toTechnicalDebt("500")).isEqualTo(WorkDayDuration.of(0, 5, 0)); | |||
} | |||
} |
@@ -25,7 +25,7 @@ import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.mockito.Mock; | |||
import org.mockito.runners.MockitoJUnitRunner; | |||
import org.sonar.api.technicaldebt.TechnicalDebt; | |||
import org.sonar.api.issue.internal.WorkDayDuration; | |||
import org.sonar.core.i18n.I18nManager; | |||
import java.util.Locale; | |||
@@ -54,13 +54,13 @@ public class TechnicalDebtFormatterTest { | |||
when(i18nManager.message(DEFAULT_LOCALE, "issue.technical_debt.x_hours", null, 2)).thenReturn("2 hours"); | |||
when(i18nManager.message(DEFAULT_LOCALE, "issue.technical_debt.x_minutes", null, 1)).thenReturn("1 minutes"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, TechnicalDebt.of(0, 0, 5))).isEqualTo("5 days"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, TechnicalDebt.of(0, 2, 0))).isEqualTo("2 hours"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, TechnicalDebt.of(1, 0, 0))).isEqualTo("1 minutes"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 5))).isEqualTo("5 days"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 2, 0))).isEqualTo("2 hours"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 0, 0))).isEqualTo("1 minutes"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, TechnicalDebt.of(0, 2, 5))).isEqualTo("5 days 2 hours"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, TechnicalDebt.of(1, 2, 0))).isEqualTo("2 hours 1 minutes"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, TechnicalDebt.of(1, 2, 5))).isEqualTo("5 days 2 hours"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 2, 5))).isEqualTo("5 days 2 hours"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 2, 0))).isEqualTo("2 hours 1 minutes"); | |||
assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 2, 5))).isEqualTo("5 days 2 hours"); | |||
} | |||
@@ -53,7 +53,7 @@ public interface Issue { | |||
Double effortToFix(); | |||
@CheckForNull | |||
TechnicalDebt technicalDebt(); | |||
WorkDayDuration technicalDebt(); | |||
String status(); | |||
@@ -22,7 +22,7 @@ package org.sonar.wsclient.issue; | |||
/** | |||
* @since 4.0 | |||
*/ | |||
public interface TechnicalDebt { | |||
public interface WorkDayDuration { | |||
Integer days(); | |||
@@ -21,7 +21,7 @@ package org.sonar.wsclient.issue.internal; | |||
import org.sonar.wsclient.issue.Issue; | |||
import org.sonar.wsclient.issue.IssueComment; | |||
import org.sonar.wsclient.issue.TechnicalDebt; | |||
import org.sonar.wsclient.issue.WorkDayDuration; | |||
import org.sonar.wsclient.unmarshallers.JsonUtils; | |||
import javax.annotation.CheckForNull; | |||
@@ -78,10 +78,10 @@ public class DefaultIssue implements Issue { | |||
} | |||
@CheckForNull | |||
public TechnicalDebt technicalDebt() { | |||
Map technicalDebt = (Map) json.get(DefaultTechnicalDebt.KEY); | |||
public WorkDayDuration technicalDebt() { | |||
Map technicalDebt = (Map) json.get("technicalDebt"); | |||
if (technicalDebt != null) { | |||
return new DefaultTechnicalDebt(technicalDebt); | |||
return new DefaultWorkDayDuration(technicalDebt); | |||
} | |||
return null; | |||
} |
@@ -53,17 +53,17 @@ public class DefaultIssueChangeDiff implements IssueChangeDiff { | |||
} | |||
private Object parseValue(String attribute) { | |||
if (DefaultTechnicalDebt.KEY.equals(key())) { | |||
if ("technicalDebt".equals(key())) { | |||
return parseDefaultTechnicalDebt(attribute); | |||
} else { | |||
return JsonUtils.getString(json, attribute); | |||
} | |||
} | |||
private DefaultTechnicalDebt parseDefaultTechnicalDebt(String attribute){ | |||
private DefaultWorkDayDuration parseDefaultTechnicalDebt(String attribute){ | |||
Map technicalDebt = (Map) json.get(attribute); | |||
if (technicalDebt != null) { | |||
return new DefaultTechnicalDebt(technicalDebt); | |||
return new DefaultWorkDayDuration(technicalDebt); | |||
} | |||
return null; | |||
} |
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.wsclient.issue.internal; | |||
import org.sonar.wsclient.issue.TechnicalDebt; | |||
import org.sonar.wsclient.issue.WorkDayDuration; | |||
import org.sonar.wsclient.unmarshallers.JsonUtils; | |||
import java.util.Map; | |||
@@ -27,13 +27,11 @@ import java.util.Map; | |||
/** | |||
* @since 4.0 | |||
*/ | |||
public class DefaultTechnicalDebt implements TechnicalDebt { | |||
public static final String KEY = "technicalDebt"; | |||
public class DefaultWorkDayDuration implements WorkDayDuration { | |||
private final Map json; | |||
DefaultTechnicalDebt(Map json) { | |||
DefaultWorkDayDuration(Map json) { | |||
this.json = json; | |||
} | |||
@@ -255,12 +255,12 @@ public class IssueJsonParserTest { | |||
IssueChangeDiff changeDiff = change.diffs().get(0); | |||
assertThat(changeDiff.key()).isEqualTo("technicalDebt"); | |||
TechnicalDebt newTechnicalDebt = (TechnicalDebt) changeDiff.newValue(); | |||
WorkDayDuration newTechnicalDebt = (WorkDayDuration) changeDiff.newValue(); | |||
assertThat(newTechnicalDebt.days()).isEqualTo(2); | |||
assertThat(newTechnicalDebt.hours()).isEqualTo(1); | |||
assertThat(newTechnicalDebt.minutes()).isEqualTo(0); | |||
TechnicalDebt oldTechnicalDebt = (TechnicalDebt) changeDiff.oldValue(); | |||
WorkDayDuration oldTechnicalDebt = (WorkDayDuration) changeDiff.oldValue(); | |||
assertThat(oldTechnicalDebt.days()).isEqualTo(3); | |||
assertThat(oldTechnicalDebt.hours()).isEqualTo(0); | |||
assertThat(oldTechnicalDebt.minutes()).isEqualTo(10); | |||
@@ -281,12 +281,12 @@ public class IssueJsonParserTest { | |||
IssueChangeDiff changeDiff = change.diffs().get(0); | |||
assertThat(changeDiff.key()).isEqualTo("technicalDebt"); | |||
TechnicalDebt newTechnicalDebt = (TechnicalDebt) changeDiff.newValue(); | |||
WorkDayDuration newTechnicalDebt = (WorkDayDuration) changeDiff.newValue(); | |||
assertThat(newTechnicalDebt.days()).isEqualTo(2); | |||
assertThat(newTechnicalDebt.hours()).isEqualTo(1); | |||
assertThat(newTechnicalDebt.minutes()).isEqualTo(0); | |||
TechnicalDebt oldTechnicalDebt = (TechnicalDebt) changeDiff.oldValue(); | |||
WorkDayDuration oldTechnicalDebt = (WorkDayDuration) changeDiff.oldValue(); | |||
assertThat(oldTechnicalDebt).isNull(); | |||
} | |||