diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-06-30 09:02:14 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-07-02 19:44:28 +0200 |
commit | 1c0b9a97e3bc6d58c4697b4350b39adc81a6efc1 (patch) | |
tree | 58dc9e0251604655638d5f9f47611116e6e49cd1 /sonar-batch | |
parent | 44a34aca80bb01c3a7689fe02d34f17718bf9293 (diff) | |
download | sonarqube-1c0b9a97e3bc6d58c4697b4350b39adc81a6efc1.tar.gz sonarqube-1c0b9a97e3bc6d58c4697b4350b39adc81a6efc1.zip |
SONAR-6588 move computation of debt to Compute Engine
Diffstat (limited to 'sonar-batch')
6 files changed, 4 insertions, 144 deletions
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 2ff7190907b..73c7604860c 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 @@ -19,10 +19,8 @@ */ package org.sonar.batch.issue; -import com.google.common.base.Objects; import com.google.common.base.Strings; import javax.annotation.Nullable; -import org.sonar.api.batch.debt.DebtRemediationFunction; import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.Rule; @@ -31,7 +29,6 @@ import org.sonar.api.batch.rule.internal.DefaultActiveRule; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Violation; -import org.sonar.api.utils.Duration; import org.sonar.api.utils.MessageException; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.DefaultIssueBuilder; @@ -118,31 +115,5 @@ public class ModuleIssues { if (issue.severity() == null) { issue.setSeverity(activeRule.severity()); } - if (rule != null) { - DebtRemediationFunction function = rule.debtRemediationFunction(); - if (function != null) { - issue.setDebt(calculateDebt(function, issue.effortToFix(), rule.key())); - } - } - } - - private Duration calculateDebt(DebtRemediationFunction function, @Nullable Double effortToFix, RuleKey ruleKey) { - if (DebtRemediationFunction.Type.CONSTANT_ISSUE.equals(function.type()) && effortToFix != null) { - throw new IllegalArgumentException("Rule '" + ruleKey + "' can not use 'Constant/issue' remediation function " + - "because this rule does not have a fixed remediation cost."); - } - Duration result = Duration.create(0); - Duration factor = function.coefficient(); - Duration offset = function.offset(); - - if (factor != null) { - int effortToFixValue = Objects.firstNonNull(effortToFix, 1).intValue(); - result = factor.multiply(effortToFixValue); - } - if (offset != null) { - result = result.add(offset); - } - return result; } - } diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java index 3a616e62465..e41acc6760d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java @@ -108,7 +108,7 @@ public final class PhaseExecutor { postJobsExecutor.execute(sensorContext); } cleanMemory(); - eventBus.fireEvent(new ProjectAnalysisEvent(module, false)); + eventBus.fireEvent(new ProjectAnalysisEvent(module, false)); } private void publishReportJob() { diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java index 9c56d2404af..b3e3692d937 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java @@ -79,11 +79,6 @@ public class IssuesPublisher implements ReportPublisherStep { if (effortToFix != null) { builder.setEffortToFix(effortToFix); } - Long debtInMinutes = issue.debtInMinutes(); - if (debtInMinutes != null) { - builder.setDebtInMinutes(debtInMinutes); - } - return builder.build(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java index e0fb8bb54a9..b9c8f06511b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java @@ -27,7 +27,6 @@ import org.sonar.api.batch.measure.MetricFinder; import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; import org.sonar.api.measures.PersistenceMode; -import org.sonar.api.technicaldebt.batch.Requirement; class MeasureValueCoder implements ValueCoder { 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 6f9961c681a..356b9f9e436 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 @@ -19,6 +19,8 @@ */ package org.sonar.batch.issue; +import java.util.Calendar; +import java.util.Date; import org.apache.commons.lang.time.DateUtils; import org.junit.Before; import org.junit.Test; @@ -26,10 +28,8 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.batch.debt.DebtRemediationFunction; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.rule.internal.RulesBuilder; -import org.sonar.core.issue.DefaultIssue; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; @@ -37,11 +37,8 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.api.rules.RulePriority; import org.sonar.api.rules.Violation; -import org.sonar.api.utils.Duration; import org.sonar.api.utils.MessageException; - -import java.util.Calendar; -import java.util.Date; +import org.sonar.core.issue.DefaultIssue; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -249,106 +246,6 @@ public class ModuleIssuesTest { verifyZeroInteractions(cache); } - @Test - public void set_debt_with_linear_function() { - ruleBuilder.add(SQUID_RULE_KEY) - .setName(SQUID_RULE_NAME) - .setDebtRemediationFunction(DebtRemediationFunction.createLinear(Duration.create(10L))); - activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate(); - initModuleIssues(); - - Date analysisDate = new Date(); - when(project.getAnalysisDate()).thenReturn(analysisDate); - - DefaultIssue issue = new DefaultIssue() - .setKey("ABCDE") - .setRuleKey(SQUID_RULE_KEY) - .setSeverity(Severity.CRITICAL) - .setEffortToFix(2d); - - when(filters.accept(issue)).thenReturn(true); - moduleIssues.initAndAddIssue(issue); - - ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); - verify(cache).put(argument.capture()); - assertThat(argument.getValue().debt()).isEqualTo(Duration.create(20L)); - } - - @Test - public void set_debt_with_linear_with_offset_function() { - ruleBuilder.add(SQUID_RULE_KEY) - .setName(SQUID_RULE_NAME) - .setDebtRemediationFunction(DebtRemediationFunction.createLinearWithOffset(Duration.create(10L), Duration.create(25L))); - activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate(); - initModuleIssues(); - - Date analysisDate = new Date(); - when(project.getAnalysisDate()).thenReturn(analysisDate); - - DefaultIssue issue = new DefaultIssue() - .setKey("ABCDE") - .setRuleKey(SQUID_RULE_KEY) - .setSeverity(Severity.CRITICAL) - .setEffortToFix(2d); - - when(filters.accept(issue)).thenReturn(true); - moduleIssues.initAndAddIssue(issue); - - ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); - verify(cache).put(argument.capture()); - assertThat(argument.getValue().debt()).isEqualTo(Duration.create(45L)); - } - - @Test - public void set_debt_with_constant_issue_function() { - ruleBuilder.add(SQUID_RULE_KEY) - .setName(SQUID_RULE_NAME) - .setDebtRemediationFunction(DebtRemediationFunction.createConstantPerIssue(Duration.create(10L))); - activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate(); - initModuleIssues(); - - Date analysisDate = new Date(); - when(project.getAnalysisDate()).thenReturn(analysisDate); - - DefaultIssue issue = new DefaultIssue() - .setKey("ABCDE") - .setRuleKey(SQUID_RULE_KEY) - .setSeverity(Severity.CRITICAL) - .setEffortToFix(null); - - when(filters.accept(issue)).thenReturn(true); - moduleIssues.initAndAddIssue(issue); - - ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); - verify(cache).put(argument.capture()); - assertThat(argument.getValue().debt()).isEqualTo(Duration.create(10L)); - } - - @Test - public void fail_to_set_debt_with_constant_issue_function_when_effort_to_fix_is_set() { - ruleBuilder.add(SQUID_RULE_KEY) - .setName(SQUID_RULE_NAME) - .setDebtRemediationFunction(DebtRemediationFunction.createConstantPerIssue(Duration.create(25L))); - activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate(); - initModuleIssues(); - - DefaultIssue issue = new DefaultIssue() - .setKey("ABCDE") - .setRuleKey(SQUID_RULE_KEY) - .setSeverity(Severity.CRITICAL) - .setEffortToFix(2d); - - when(filters.accept(issue)).thenReturn(true); - - try { - moduleIssues.initAndAddIssue(issue); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalArgumentException.class) - .hasMessage("Rule 'squid:AvoidCycle' can not use 'Constant/issue' remediation function because this rule does not have a fixed remediation cost."); - } - } - /** * Every rules and active rules has to be added in builders before creating ModuleIssues */ diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java index bdcce1bd74f..a27ce7d2447 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java @@ -31,7 +31,6 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.Duration; import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.protocol.output.BatchReportReader; @@ -81,7 +80,6 @@ public class IssuesPublisherTest { issue2.setLine(2); issue2.setMessage("msg"); issue2.setEffortToFix(2d); - issue2.setDebt(Duration.create(2)); issue2.setResolution("FIXED"); issue2.setStatus("RESOLVED"); issue2.setChecksum("checksum"); |