import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.collect.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.resources.Project;
import org.sonar.plugins.core.timemachine.tracking.*;
import javax.annotation.Nullable;
-
import java.util.*;
public class IssueTracking implements BatchExtension {
- private static final Logger LOG = LoggerFactory.getLogger(IssueTracking.class);
-
private static final Comparator<LinePair> LINE_PAIR_COMPARATOR = new Comparator<LinePair>() {
public int compare(LinePair o1, LinePair o2) {
int weightDiff = o2.weight - o1.weight;
if (weightDiff != 0) {
return weightDiff;
} else {
- return Math.abs(o1.lineA -o1.lineB) - Math.abs(o2.lineA - o2.lineB);
+ return Math.abs(o1.lineA - o1.lineB) - Math.abs(o2.lineA - o2.lineB);
}
}
};
public void decorate(Resource resource, DecoratorContext context) {
if (isComponentSupported(resource)) {
+ // all the issues created by rule engines during this module scan
Collection<DefaultIssue> newIssues = new ArrayList(scanIssues.issues(resource.getEffectiveKey()));
+
+ // all the issues that are open in db before starting this module scan
Collection<IssueDto> openIssues = initialOpenIssuesStack.selectAndRemove(resource.getId());
+
tracking.track(resource, openIssues, newIssues);
+
updateIssues(newIssues);
Set<String> issueKeys = Sets.newHashSet(Collections2.transform(newIssues, new IssueToKeyFunction()));
for (IssueDto openIssue : openIssues) {
+ // not in newIssues
addManualIssuesAndCloseResolvedOnes(openIssue);
+
+
closeResolvedStandardIssues(openIssue, issueKeys);
keepFalsePositiveIssues(openIssue);
reopenUnresolvedIssues(openIssue);
private void reopenAndSave(IssueDto openIssue) {
DefaultIssue issue = openIssue.toDefaultIssue();
issue.setStatus(Issue.STATUS_REOPENED);
- issue.setResolution(null);
+ issue.setResolution(Issue.RESOLUTION_OPEN);
issue.setUpdatedAt(getLoadedDate());
scanIssues.addOrUpdate(issue);
}
// First call is done when updating issues after calling issue tracking and we don't care
DefaultIssue defaultIssue = capturedDefaultIssues.get(1);
assertThat(defaultIssue.status()).isEqualTo(Issue.STATUS_REOPENED);
- assertThat(defaultIssue.resolution()).isNull();
+ assertThat(defaultIssue.resolution()).isEqualTo(Issue.RESOLUTION_OPEN);
assertThat(defaultIssue.updatedAt()).isEqualTo(loadedDate);
}