From 59c61bf59fd3778f723021f5710d27165901760f Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 12 Oct 2017 17:53:52 +0200 Subject: [PATCH] SONAR-9949 Copy all issue attributes when merging a short in a long living branch --- .../sonar/core/issue/ShortBranchIssue.java | 31 +++++++++++--- .../org/sonar/db/issue/IssueChangeDao.java | 4 ++ .../org/sonar/db/issue/IssueChangeMapper.java | 2 + .../sonar/db/issue/ShortBranchIssueDto.java | 17 +------- .../org/sonar/db/issue/IssueChangeMapper.xml | 10 +++++ .../org/sonar/db/issue/IssueMapper.xml | 1 - .../sonar/db/issue/IssueChangeDaoTest.java | 9 ++++ .../java/org/sonar/db/issue/IssueDaoTest.java | 3 -- .../issue/IntegrateIssuesVisitor.java | 6 +-- .../projectanalysis/issue/IssueLifecycle.java | 23 ++++++++--- .../issue/ShortBranchIssueStatusCopier.java | 17 ++++---- .../issue/ShortBranchIssuesLoader.java | 41 +++++++++++++++++++ .../step/PersistIssuesStep.java | 22 +--------- .../org/sonar/server/issue/IssueStorage.java | 7 +++- .../issue/IssueLifecycleTest.java | 15 ++++--- .../ShortBranchIssueStatusCopierTest.java | 22 +++++++--- .../org/sonar/core/issue/DefaultIssue.java | 2 +- .../sonar/core/issue/DefaultIssueComment.java | 15 +++++++ .../java/org/sonar/core/issue/FieldDiffs.java | 13 ++++++ 19 files changed, 187 insertions(+), 73 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java b/server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java index 0e2f88f94b9..11095124c97 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java @@ -27,20 +27,24 @@ import org.sonar.core.issue.tracking.Trackable; @Immutable public class ShortBranchIssue implements Trackable { + private final String key; private final Integer line; private final String message; private final String lineHash; private final RuleKey ruleKey; private final String status; - private final String resolution; - public ShortBranchIssue(@Nullable Integer line, String message, @Nullable String lineHash, RuleKey ruleKey, String status, @Nullable String resolution) { + public ShortBranchIssue(String key, @Nullable Integer line, String message, @Nullable String lineHash, RuleKey ruleKey, String status) { + this.key = key; this.line = line; this.message = message; this.lineHash = lineHash; this.ruleKey = ruleKey; this.status = status; - this.resolution = resolution; + } + + public String getKey() { + return key; } @CheckForNull @@ -70,7 +74,24 @@ public class ShortBranchIssue implements Trackable { return status; } - public String getResolution() { - return resolution; + @Override + public int hashCode() { + return key.hashCode(); } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ShortBranchIssue other = (ShortBranchIssue) obj; + return key.equals(other.key); + } + } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java index 9a9fa026968..eb22bc65c71 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java @@ -48,6 +48,10 @@ public class IssueChangeDao implements Dao { return executeLargeInputs(issueKeys, issueKeys1 -> mapper(session).selectByIssuesAndType(issueKeys1, changeType)); } + public List selectByIssueKeys(DbSession session, Collection issueKeys) { + return executeLargeInputs(issueKeys, issueKeys1 -> mapper(session).selectByIssues(issueKeys1)); + } + public Optional selectCommentByKey(DbSession session, String commentKey) { return Optional.ofNullable(mapper(session).selectByKeyAndType(commentKey, IssueChangeDto.TYPE_COMMENT)); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java index 1d6db5b2994..3b6aef0cff8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java @@ -40,5 +40,7 @@ public interface IssueChangeMapper { List selectByIssuesAndType(@Param("issueKeys") List issueKeys, @Param("changeType") String changeType); + List selectByIssues(@Param("issueKeys") List issueKeys); + List selectChangelogOfNonClosedIssuesByComponent(@Param("componentUuid") String componentUuid, @Param("changeType") String changeType); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java index 3674cdc7af8..3a68ea03af2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java @@ -19,7 +19,6 @@ */ package org.sonar.db.issue; -import com.google.common.base.Preconditions; import java.io.Serializable; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -27,9 +26,6 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.rule.RuleKey; import org.sonar.core.issue.ShortBranchIssue; -import org.sonar.db.rule.RuleDefinitionDto; - -import static com.google.common.base.Preconditions.checkArgument; public final class ShortBranchIssueDto implements Serializable { @@ -38,7 +34,6 @@ public final class ShortBranchIssueDto implements Serializable { private Integer line; private String checksum; private String status; - private String resolution; // joins private String ruleKey; @@ -82,16 +77,6 @@ public final class ShortBranchIssueDto implements Serializable { return this; } - @CheckForNull - public String getResolution() { - return resolution; - } - - public ShortBranchIssueDto setResolution(@Nullable String s) { - this.resolution = s; - return this; - } - @CheckForNull public String getChecksum() { return checksum; @@ -120,6 +105,6 @@ public final class ShortBranchIssueDto implements Serializable { } public static ShortBranchIssue toShortBranchIssue(ShortBranchIssueDto dto) { - return new ShortBranchIssue(dto.getLine(), dto.getMessage(), dto.getChecksum(), dto.getRuleKey(), dto.getStatus(), dto.getResolution()); + return new ShortBranchIssue(dto.getKey(), dto.getLine(), dto.getMessage(), dto.getChecksum(), dto.getRuleKey(), dto.getStatus()); } } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml index 46a732b0719..8b315466eb7 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml @@ -42,6 +42,16 @@ order by c.created_at + +