// fields coming from raw
updater.setPastLine(raw, base.getLine());
+ updater.setPastLocations(raw, base.getLocations());
updater.setPastMessage(raw, base.getMessage(), changeContext);
updater.setPastEffortToFix(raw, base.effortToFix(), changeContext);
updater.setPastTechnicalDebt(raw, base.debt(), changeContext);
*/
package org.sonar.server.computation.issue;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.log.Loggers;
import org.sonar.server.computation.source.SourceLinesRepository;
import org.sonar.server.rule.CommonRuleKeys;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
import static com.google.common.collect.Lists.newArrayList;
public class TrackerRawInputFactory {
}
}
- private DbCommons.TextRange.Builder convertTextRange(BatchReport.TextRange sourceRange) {
+ private static DbCommons.TextRange.Builder convertTextRange(BatchReport.TextRange sourceRange) {
DbCommons.TextRange.Builder targetRange = DbCommons.TextRange.newBuilder();
if (sourceRange.hasStartLine()) {
targetRange.setStartLine(sourceRange.getStartLine());
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.core.issue.workflow.IssueWorkflow;
+import org.sonar.db.protobuf.DbCommons;
+import org.sonar.db.protobuf.DbIssues;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
.setCreationDate(parseDate("2015-10-01"))
.setUpdateDate(parseDate("2015-10-02"))
.setCloseDate(parseDate("2015-10-03"));
+
+ DbIssues.Locations issueLocations = DbIssues.Locations.newBuilder()
+ .setTextRange(DbCommons.TextRange.newBuilder()
+ .setStartLine(10)
+ .setEndLine(12)
+ .build())
+ .build();
DefaultIssue base = new DefaultIssue()
.setKey("BASE_KEY")
.setCreationDate(parseDate("2015-01-01"))
.setMessage("message")
.setEffortToFix(15d)
.setDebt(Duration.create(15L))
- .setManualSeverity(false);
+ .setManualSeverity(false)
+ .setLocations(issueLocations);
when(debtCalculator.calculate(raw)).thenReturn(DEFAULT_DURATION);
verify(updater).setPastLine(raw, 10);
verify(updater).setPastMessage(raw, "message", issueChangeContext);
verify(updater).setPastTechnicalDebt(raw, Duration.create(15L), issueChangeContext);
+ verify(updater).setPastLocations(raw, issueLocations);
}
@Test
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.utils.Duration;
import org.sonar.core.issue.tracking.Trackable;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import static java.lang.String.format;
public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.Issue {
return this;
}
+ @CheckForNull
public <T> T getLocations() {
return (T)locations;
}
- public void setLocations(Object locations) {
+ public DefaultIssue setLocations(@Nullable Object locations) {
this.locations = locations;
+ return this;
}
@Override
return setLine(issue, currentLine);
}
+ public boolean setLocations(DefaultIssue issue, @Nullable Object locations) {
+ if (!Objects.equal(locations, issue.getLocations())) {
+ issue.setLocations(locations);
+ issue.setChanged(true);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean setPastLocations(DefaultIssue issue, @Nullable Object previousLocations) {
+ Object currentLocations = issue.getLocations();
+ issue.setLocations(previousLocations);
+ return setLocations(issue, currentLocations);
+
+ }
+
public boolean setResolution(DefaultIssue issue, @Nullable String resolution, IssueChangeContext context) {
if (!Objects.equal(resolution, issue.resolution())) {
issue.setFieldChange(context, RESOLUTION, issue.resolution(), resolution);
return false;
}
+
}
}
@Test
- public void not_change_line() {
+ public void line_is_not_changed() {
issue.setLine(123);
boolean updated = updater.setLine(issue, 123);
assertThat(updated).isFalse();
assertThat(issue.mustSendNotifications()).isFalse();
}
+ @Test
+ public void change_locations() {
+ issue.setLocations("[1-3]");
+ boolean updated = updater.setLocations(issue, "[1-4]");
+ assertThat(updated).isTrue();
+ assertThat(issue.getLocations()).isEqualTo("[1-4]");
+ assertThat(issue.currentChange()).isNull();
+ assertThat(issue.mustSendNotifications()).isFalse();
+ }
+
+ @Test
+ public void do_not_change_locations() {
+ issue.setLocations("[1-3]");
+ boolean updated = updater.setLocations(issue, "[1-3]");
+ assertThat(updated).isFalse();
+ assertThat(issue.getLocations()).isEqualTo("[1-3]");
+ assertThat(issue.currentChange()).isNull();
+ assertThat(issue.mustSendNotifications()).isFalse();
+ }
+
+ @Test
+ public void set_locations_for_the_first_time() {
+ issue.setLocations(null);
+ boolean updated = updater.setLocations(issue, "[1-4]");
+ assertThat(updated).isTrue();
+ assertThat(issue.getLocations()).isEqualTo("[1-4]");
+ assertThat(issue.currentChange()).isNull();
+ assertThat(issue.mustSendNotifications()).isFalse();
+ }
+
@Test
public void set_resolution() {
boolean updated = updater.setResolution(issue, "OPEN", context);