@@ -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); |
@@ -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; | |||
} | |||
} | |||
} |
@@ -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") |
@@ -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); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |