aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-10-19 12:10:27 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-10-20 18:45:15 +1000
commitf185740ba7aa84579af60781ed9282e31fa4d94a (patch)
treeacc3a51c1cfe6e1ad0bc0b96afceb3e0c5ba91dd /server/sonar-db-dao/src
parentc521266eb060e5af522583c74f0bfb8c145f5f9f (diff)
downloadsonarqube-f185740ba7aa84579af60781ed9282e31fa4d94a.tar.gz
sonarqube-f185740ba7aa84579af60781ed9282e31fa4d94a.zip
SONAR-9949 Also merge open issues from short living branches
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java7
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java10
7 files changed, 26 insertions, 14 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 f6c6bcd977b..e9058d626b4 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
@@ -19,6 +19,7 @@
*/
package org.sonar.core.issue;
+import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@@ -34,8 +35,9 @@ public class ShortBranchIssue implements Trackable {
private final RuleKey ruleKey;
private final String status;
private final String branchName;
+ private final Date creationDate;
- public ShortBranchIssue(String key, @Nullable Integer line, String message, @Nullable String lineHash, RuleKey ruleKey, String status, String branchName) {
+ public ShortBranchIssue(String key, @Nullable Integer line, String message, @Nullable String lineHash, RuleKey ruleKey, String status, String branchName, Date creationDate) {
this.key = key;
this.line = line;
this.message = message;
@@ -43,6 +45,7 @@ public class ShortBranchIssue implements Trackable {
this.ruleKey = ruleKey;
this.status = status;
this.branchName = branchName;
+ this.creationDate = creationDate;
}
public String getKey() {
@@ -81,6 +84,11 @@ public class ShortBranchIssue implements Trackable {
}
@Override
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ @Override
public int hashCode() {
return key.hashCode();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java
index 164f56d5b35..ab8ccd3871f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java
@@ -103,8 +103,8 @@ public class IssueDao implements Dao {
mapper(dbSession).scrollNonClosedByModuleOrProject(module.projectUuid(), likeModuleUuidPath, handler);
}
- public List<ShortBranchIssueDto> selectResolvedOrConfirmedByComponentUuids(DbSession dbSession, Collection<String> componentUuids) {
- return executeLargeInputs(componentUuids, mapper(dbSession)::selectResolvedOrConfirmedByComponentUuids);
+ public List<ShortBranchIssueDto> selectOpenByComponentUuids(DbSession dbSession, Collection<String> componentUuids) {
+ return executeLargeInputs(componentUuids, mapper(dbSession)::selectOpenByComponentUuids);
}
public void insert(DbSession session, IssueDto dto) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java
index 4335a471126..75ec4c9d542 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java
@@ -32,7 +32,7 @@ public interface IssueMapper {
List<IssueDto> selectByKeys(List<String> keys);
- List<ShortBranchIssueDto> selectResolvedOrConfirmedByComponentUuids(List<String> componentUuids);
+ List<ShortBranchIssueDto> selectOpenByComponentUuids(List<String> componentUuids);
void insert(IssueDto issue);
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 3c1901041e4..79208ddd20d 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
@@ -27,6 +27,8 @@ import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.rule.RuleKey;
import org.sonar.core.issue.ShortBranchIssue;
+import static org.sonar.api.utils.DateUtils.longToDate;
+
public final class ShortBranchIssueDto implements Serializable {
private String kee;
@@ -34,6 +36,7 @@ public final class ShortBranchIssueDto implements Serializable {
private Integer line;
private String checksum;
private String status;
+ private Long issueCreationDate;
// joins
private String ruleKey;
@@ -114,7 +117,7 @@ public final class ShortBranchIssueDto implements Serializable {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
- public static ShortBranchIssue toShortBranchIssue(ShortBranchIssueDto dto) {
- return new ShortBranchIssue(dto.getKey(), dto.getLine(), dto.getMessage(), dto.getChecksum(), dto.getRuleKey(), dto.getStatus(), dto.getBranchName());
+ public ShortBranchIssue toShortBranchIssue() {
+ return new ShortBranchIssue(getKey(), getLine(), getMessage(), getChecksum(), getRuleKey(), getStatus(), getBranchName(), longToDate(issueCreationDate));
}
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 0a4b557880c..5d7e051032f 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -665,7 +665,7 @@
ON i.project_uuid = b.uuid
AND b.branch_type = 'SHORT'
AND b.merge_branch_uuid = #{mergeBranchUuid,jdbcType=VARCHAR}
- AND (i.status = 'CONFIRMED' OR i.status = 'RESOLVED')
+ AND i.status != 'CLOSED'
</select>
</mapper>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
index 09d43435502..545963ea5e5 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
@@ -213,13 +213,14 @@
</foreach>
</select>
- <select id="selectResolvedOrConfirmedByComponentUuids" parameterType="map" resultType="ShortBranchIssue">
+ <select id="selectOpenByComponentUuids" parameterType="map" resultType="ShortBranchIssue">
select
i.kee as kee,
i.message as message,
i.line as line,
i.status as status,
i.checksum as checksum,
+ i.issue_creation_date as issueCreationDate,
r.plugin_rule_key as ruleKey,
r.plugin_name as ruleRepo,
b.kee as branchName
@@ -230,7 +231,7 @@
<foreach collection="list" open="(" close=")" item="key" separator=",">
#{key,jdbcType=VARCHAR}
</foreach>
- and (i.status = 'CONFIRMED' OR i.status = 'RESOLVED')
+ and i.status &lt;&gt; 'CLOSED'
</select>
<select id="scrollNonClosedByModuleOrProject" parameterType="map" resultType="Issue" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
index 8c4682215c1..cc31fa3d9c7 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
@@ -184,7 +184,7 @@ public class IssueDaoTest {
}
@Test
- public void selectResolvedOrConfirmedByComponentUuid() {
+ public void selectOpenByComponentUuid() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertMainBranch();
ComponentDto projectBranch = db.components().insertProjectBranch(project,
@@ -200,13 +200,13 @@ public class IssueDaoTest {
IssueDto wontfixIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus(Issue.STATUS_RESOLVED).setResolution(Issue.RESOLUTION_WONT_FIX));
IssueDto fpIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus(Issue.STATUS_RESOLVED).setResolution(Issue.RESOLUTION_FALSE_POSITIVE));
- assertThat(underTest.selectResolvedOrConfirmedByComponentUuids(db.getSession(), Collections.singletonList(file.uuid())))
+ assertThat(underTest.selectOpenByComponentUuids(db.getSession(), Collections.singletonList(file.uuid())))
.extracting("kee")
- .containsOnly(confirmedIssue.getKey(), wontfixIssue.getKey(), fpIssue.getKey());
+ .containsOnly(openIssue.getKey(), reopenedIssue.getKey(), confirmedIssue.getKey(), wontfixIssue.getKey(), fpIssue.getKey());
}
@Test
- public void selectResolvedOrConfirmedByComponentUuid_should_correctly_map_required_fields() {
+ public void selectOpenByComponentUuid_should_correctly_map_required_fields() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertMainBranch();
ComponentDto projectBranch = db.components().insertProjectBranch(project,
@@ -216,7 +216,7 @@ public class IssueDaoTest {
ComponentDto file = db.components().insertComponent(newFileDto(projectBranch));
IssueDto fpIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus("RESOLVED").setResolution("FALSE-POSITIVE"));
- ShortBranchIssueDto fp = underTest.selectResolvedOrConfirmedByComponentUuids(db.getSession(), Collections.singletonList(file.uuid())).get(0);
+ ShortBranchIssueDto fp = underTest.selectOpenByComponentUuids(db.getSession(), Collections.singletonList(file.uuid())).get(0);
assertThat(fp.getLine()).isEqualTo(fpIssue.getLine());
assertThat(fp.getMessage()).isEqualTo(fpIssue.getMessage());
assertThat(fp.getChecksum()).isEqualTo(fpIssue.getChecksum());