aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-04-15 22:54:22 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-04-16 09:06:49 +0200
commit8ad882a51708f79204b89cf8fb8b6406a49f04df (patch)
tree4fe0f0193487e355da0381a50f63f977b292f38b
parentc0a188703aa8ae849998dcfec016dd1d64d32107 (diff)
downloadsonarqube-8ad882a51708f79204b89cf8fb8b6406a49f04df.tar.gz
sonarqube-8ad882a51708f79204b89cf8fb8b6406a49f04df.zip
SONAR-6364 Line number should be unset on closed issues
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/workflow/Function.java1
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/workflow/FunctionExecutor.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLife.java (renamed from sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLifeResolution.java)7
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/workflow/SetEndOfLifeTest.java (renamed from sonar-core/src/test/java/org/sonar/core/issue/workflow/SetEndOfLifeResolutionTest.java)12
5 files changed, 28 insertions, 8 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/Function.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/Function.java
index 987031fd909..ad25ff016a3 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/Function.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/Function.java
@@ -30,6 +30,7 @@ interface Function {
Context setAssignee(@Nullable User user);
Context setResolution(@Nullable String s);
Context setCloseDate(boolean b);
+ Context setLine(@Nullable Integer line);
}
void execute(Context context);
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/FunctionExecutor.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/FunctionExecutor.java
index d843eb59828..c530ede249a 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/FunctionExecutor.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/FunctionExecutor.java
@@ -77,7 +77,13 @@ public class FunctionExecutor implements BatchComponent, ServerComponent {
@Override
public Function.Context setCloseDate(boolean b) {
updater.setCloseDate(issue, b ? changeContext.date() : null, changeContext);
- return null;
+ return this;
+ }
+
+ @Override
+ public Function.Context setLine(@Nullable Integer line) {
+ updater.setLine(issue, line);
+ return this;
}
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
index f1b66748c15..10924b43533 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
@@ -131,25 +131,25 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
builder.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_OPEN).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
- .functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
+ .functions(new SetEndOfLife(), new SetCloseDate(true))
.automatic()
.build())
.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_REOPENED).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
- .functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
+ .functions(new SetEndOfLife(), new SetCloseDate(true))
.automatic()
.build())
.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_CONFIRMED).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
- .functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
+ .functions(new SetEndOfLife(), new SetCloseDate(true))
.automatic()
.build())
.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_RESOLVED).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
- .functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
+ .functions(new SetEndOfLife(), new SetCloseDate(true))
.automatic()
.build())
.transition(Transition.builder("automaticclosemanual")
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLifeResolution.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLife.java
index e7b6cfde4b0..ae45caa9390 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLifeResolution.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetEndOfLife.java
@@ -22,7 +22,7 @@ package org.sonar.core.issue.workflow;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
-public class SetEndOfLifeResolution implements Function {
+public class SetEndOfLife implements Function {
@Override
public void execute(Context context) {
DefaultIssue issue = (DefaultIssue) context.issue();
@@ -34,5 +34,10 @@ public class SetEndOfLifeResolution implements Function {
} else {
context.setResolution(Issue.RESOLUTION_FIXED);
}
+
+ // closed issues are not "tracked" -> the line number does not evolve anymore
+ // when code changes. That's misleading for end-users, so line number
+ // is unset.
+ context.setLine(null);
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetEndOfLifeResolutionTest.java b/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetEndOfLifeTest.java
index 4a2f88e0685..a05e9d0e056 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetEndOfLifeResolutionTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetEndOfLifeTest.java
@@ -27,10 +27,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;
-public class SetEndOfLifeResolutionTest {
+public class SetEndOfLifeTest {
Function.Context context = mock(Function.Context.class);
- SetEndOfLifeResolution function = new SetEndOfLifeResolution();
+ SetEndOfLife function = new SetEndOfLife();
@Test
public void should_resolve_as_fixed() throws Exception {
@@ -60,4 +60,12 @@ public class SetEndOfLifeResolutionTest {
verify(context, never()).setResolution(anyString());
}
}
+
+ @Test
+ public void line_number_must_be_unset() throws Exception {
+ Issue issue = new DefaultIssue().setEndOfLife(true).setLine(10);
+ when(context.issue()).thenReturn(issue);
+ function.execute(context);
+ verify(context).setLine(null);
+ }
}