aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-10-07 13:35:09 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-10-07 13:35:09 +0200
commiteb61eba8a4e2dead826feca34b22ca8fc5fa0ffb (patch)
tree63fb2bccde71e2134d0a99a6e1b3f2f1692f3f75 /sonar-server/src
parenta559fa67ec15486009e7dccdb79d6f488699dbc2 (diff)
downloadsonarqube-eb61eba8a4e2dead826feca34b22ca8fc5fa0ffb.tar.gz
sonarqube-eb61eba8a4e2dead826feca34b22ca8fc5fa0ffb.zip
SONAR-4716 Replace remediation cost by technical debt in issue
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java17
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/technicaldebt/RubyDebtService.java27
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb10
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb18
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/442_add_technical_debt_to_issue.rb (renamed from sonar-server/src/main/webapp/WEB-INF/db/migrate/442_add_remediation_cost_to_issue.rb)4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java23
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/technicaldebt/RubyDebtServiceTest.java43
9 files changed, 116 insertions, 32 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
index 8dde854e09b..de33721f1bb 100644
--- a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
+++ b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
@@ -43,8 +43,6 @@ import org.sonar.core.issue.workflow.Transition;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.sonar.core.resource.ResourceQuery;
-import org.sonar.core.technicaldebt.RemediationCostTimeUnit;
-import org.sonar.core.technicaldebt.WorkUnitConverter;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.user.UserSession;
import org.sonar.server.util.RubyUtils;
@@ -83,14 +81,12 @@ public class InternalRubyIssueService implements ServerComponent {
private final ActionService actionService;
private final IssueFilterService issueFilterService;
private final IssueBulkChangeService issueBulkChangeService;
- private final WorkUnitConverter workUnitConverter;
public InternalRubyIssueService(IssueService issueService,
IssueCommentService commentService,
IssueChangelogService changelogService, ActionPlanService actionPlanService,
IssueStatsFinder issueStatsFinder, ResourceDao resourceDao, ActionService actionService,
- IssueFilterService issueFilterService, IssueBulkChangeService issueBulkChangeService,
- WorkUnitConverter workUnitConverter) {
+ IssueFilterService issueFilterService, IssueBulkChangeService issueBulkChangeService) {
this.issueService = issueService;
this.commentService = commentService;
this.changelogService = changelogService;
@@ -100,7 +96,6 @@ public class InternalRubyIssueService implements ServerComponent {
this.actionService = actionService;
this.issueFilterService = issueFilterService;
this.issueBulkChangeService = issueBulkChangeService;
- this.workUnitConverter = workUnitConverter;
}
public IssueStatsFinder.IssueStatsResult findIssueAssignees(Map<String, Object> params) {
@@ -626,14 +621,4 @@ public class InternalRubyIssueService implements ServerComponent {
}
}
- @CheckForNull
- public RemediationCostTimeUnit remediationCost(Issue issue) {
- Long remediationCost = issue.remediationCost();
- if (remediationCost != null) {
- return workUnitConverter.toRemediationCostTimeUnit(issue.remediationCost());
- } else {
- return null;
- }
- }
-
}
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 152cbff94ac..c3fe96f1505 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -58,7 +58,7 @@ import org.sonar.core.qualitymodel.DefaultModelFinder;
import org.sonar.core.resource.DefaultResourcePermissions;
import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.core.source.HtmlSourceDecorator;
-import org.sonar.core.technicaldebt.WorkUnitConverter;
+import org.sonar.core.technicaldebt.TechnicalDebtConverter;
import org.sonar.core.test.TestPlanPerspectiveLoader;
import org.sonar.core.test.TestablePerspectiveLoader;
import org.sonar.core.timemachine.Periods;
@@ -302,7 +302,7 @@ public final class Platform {
servicesContainer.addSingleton(TechnicalDebtManager.class);
servicesContainer.addSingleton(TechnicalDebtModelFinder.class);
servicesContainer.addSingleton(XMLImporter.class);
- servicesContainer.addSingleton(WorkUnitConverter.class);
+ servicesContainer.addSingleton(TechnicalDebtConverter.class);
// text
servicesContainer.addSingleton(MacroInterpreter.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/technicaldebt/RubyDebtService.java b/sonar-server/src/main/java/org/sonar/server/technicaldebt/RubyDebtService.java
new file mode 100644
index 00000000000..526011b3650
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/technicaldebt/RubyDebtService.java
@@ -0,0 +1,27 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * 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.server.technicaldebt;
+
+import org.sonar.api.ServerComponent;
+
+public class RubyDebtService implements ServerComponent {
+
+
+}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb
index 4b908bcc8e9..11d03ddd820 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb
@@ -32,7 +32,7 @@ class Issue
hash[:message] = issue.message if issue.message
hash[:line] = issue.line.to_i if issue.line
hash[:effortToFix] = issue.effortToFix.to_f if issue.effortToFix
- hash[:remediationCost] = issue.remediationCost.to_i if issue.remediationCost
+ hash[:technicalDebt] = technical_debt_to_hash(issue.technicalDebt) if issue.technicalDebt
hash[:reporter] = issue.reporter if issue.reporter
hash[:assignee] = issue.assignee if issue.assignee
hash[:author] = issue.authorLogin if issue.authorLogin
@@ -56,4 +56,12 @@ class Issue
}
end
+ def self.technical_debt_to_hash(technical_debt)
+ {
+ :days => technical_debt.days(),
+ :hours => technical_debt.hours(),
+ :minutes => technical_debt.minutes()
+ }
+ end
+
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
index eaaa91a7084..dc23a963e63 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
@@ -36,23 +36,21 @@
<span><%= message('issue.authorLogin') -%> <%= issue.authorLogin -%></span>
&nbsp;
<% end %>
- <% if issue.remediationCost %>
+ <% if issue.technicalDebt %>
<img src="<%= ApplicationController.root_context -%>/images/sep12.png"/>
&nbsp;
- <% remediaction_cost_time_unit = Internal.issues.remediationCost(issue)
- if remediaction_cost_time_unit
- days = remediaction_cost_time_unit.days
- hours = remediaction_cost_time_unit.hours
- minutes = remediaction_cost_time_unit.minutes
+ <% technical_debt = issue.technicalDebt
+ days = technical_debt.days
+ hours = technical_debt.hours
+ minutes = technical_debt.minutes
message = ''
- message += message('issue.remedation_cost.x_days', :params => days) + ' ' if days > 0
- message += message('issue.remedation_cost.x_hours', :params => hours) + ' ' if hours > 0
+ message += message('issue.technical_debt.x_days', :params => days) + ' ' if days > 0
+ message += message('issue.technical_debt.x_hours', :params => hours) + ' ' if hours > 0
# Do not display minutes if days is not null to not have too much information
- message += message('issue.remedation_cost.x_minutes', :params => minutes) if minutes > 0 && days == 0
+ message += message('issue.technical_debt.x_minutes', :params => minutes) if minutes > 0 && days == 0
%>
<span><%= message -%></span>
&nbsp;
- <% end %>
<% end %>
</div>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/442_add_remediation_cost_to_issue.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/442_add_technical_debt_to_issue.rb
index 2a5825554f4..de74c3098f5 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/442_add_remediation_cost_to_issue.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/442_add_technical_debt_to_issue.rb
@@ -23,10 +23,10 @@
# SONAR-4716
#
-class AddRemediationCostToIssue < ActiveRecord::Migration
+class AddTechnicalDebtToIssue < ActiveRecord::Migration
def self.up
- add_column 'issues', 'remediation_cost', :integer, :null => true
+ add_column 'issues', 'technical_debt', :integer, :null => true
end
end
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java
index 1ed91d8bbbf..5dbff1a591a 100644
--- a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java
@@ -29,6 +29,7 @@ import org.sonar.api.issue.IssueQuery;
import org.sonar.api.issue.IssueQueryResult;
import org.sonar.api.issue.internal.DefaultIssue;
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;
@@ -285,4 +286,26 @@ public class DefaultIssueFinderTest {
assertThat(results.actionPlans()).isEmpty();
}
+ @Test
+ public void should_find_issue_with_technical_debt() {
+ IssueQuery query = IssueQuery.builder().build();
+
+ IssueDto issue = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
+ .setComponentKey_unit_test_only("Action.java")
+ .setRootComponentKey_unit_test_only("struts")
+ .setRuleKey_unit_test_only("squid", "AvoidCycle")
+ .setStatus("OPEN").setResolution("OPEN")
+ .setTechnicalDebt(10L)
+ ;
+ List<IssueDto> dtoList = newArrayList(issue);
+ when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList);
+
+ IssueQueryResult results = finder.find(query);
+ verify(issueDao).selectIssueIds(eq(query), anyInt(), any(SqlSession.class));
+
+ assertThat(results.issues()).hasSize(1);
+ DefaultIssue result = (DefaultIssue) results.issues().iterator().next();
+ assertThat(result.technicalDebt()).isEqualTo(TechnicalDebt.of(10, 0, 0));
+ }
+
}
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java b/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java
index 658b3155ec4..eb3fc3c561d 100644
--- a/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java
@@ -64,7 +64,7 @@ public class InternalRubyIssueServiceTest {
ResourceDto project = new ResourceDto().setKey("org.sonar.Sample");
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(project);
service = new InternalRubyIssueService(issueService, commentService, changelogService, actionPlanService, issueStatsFinder, resourceDao, actionService,
- issueFilterService, issueBulkChangeService, null);
+ issueFilterService, issueBulkChangeService);
}
@Test
diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/RubyDebtServiceTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/RubyDebtServiceTest.java
new file mode 100644
index 00000000000..65a9f7753e3
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/technicaldebt/RubyDebtServiceTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * 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.server.technicaldebt;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RubyDebtServiceTest {
+
+
+ private RubyDebtService service;
+
+ @Before
+ public void before() {
+ service = new RubyDebtService();
+ }
+
+ @Test
+ public void test(){
+
+ }
+
+}