From f2fecdae009dd0572fa13cd76ac2903b590265b0 Mon Sep 17 00:00:00 2001 From: Aurelien Poscia Date: Wed, 6 Jul 2022 15:36:01 +0200 Subject: [PATCH] SONAR-16611 Adapt project import/export to handle DB field issues.rule_description_context_key --- .../sonar/ce/task/projectexport/issue/ExportIssuesStep.java | 5 ++++- .../src/main/protobuf/project_dump.proto | 2 ++ .../ce/task/projectexport/issue/ExportIssuesStepTest.java | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java index 0351bd6c1a0..b34a38d220b 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java @@ -26,6 +26,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Objects; +import java.util.Optional; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.log.Loggers; import org.sonar.ce.task.projectexport.component.ComponentRepository; @@ -56,7 +57,8 @@ public class ExportIssuesStep implements ComputationStep { " i.component_uuid, i.message, i.line, i.checksum, i.status," + " i.resolution, i.severity, i.manual_severity, i.gap, effort," + " i.assignee, i.author_login, i.tags, i.issue_creation_date," + - " i.issue_update_date, i.issue_close_date, i.locations, i.project_uuid" + + " i.issue_update_date, i.issue_close_date, i.locations, i.project_uuid," + + " i.rule_description_context_key " + " from issues i" + " join rules r on r.uuid = i.rule_uuid and r.status <> ?" + " join components p on p.uuid = i.project_uuid" + @@ -144,6 +146,7 @@ public class ExportIssuesStep implements ComputationStep { .setIssueUpdatedAt(rs.getLong(20)) .setIssueClosedAt(rs.getLong(21)) .setProjectUuid(rs.getString(23)); + Optional.ofNullable(rs.getString(24)).ifPresent(builder::setRuleDescriptionContextKey); setLocations(builder, rs, issueUuid); return builder.build(); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto b/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto index 358d1041e0b..b1e5066d8fe 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto +++ b/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto @@ -121,6 +121,8 @@ message Issue { int64 issue_closed_at = 21; string project_uuid = 22; string rule_ref = 23; + + optional string ruleDescriptionContextKey = 24; } // Stream of issues changelog stored in file issues_changelog.pb diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java index 0eccab91c48..437996f023f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java @@ -219,6 +219,7 @@ public class ExportIssuesStepTest { .setAssigneeUuid("assignee-uuid") .setAuthorLogin("author") .setTagsString("tags") + .setRuleDescriptionContextKey("test_rule_description_context_key") .setIssueCreationTime(963L) .setIssueUpdateTime(852L) .setIssueCloseTime(741L); @@ -251,6 +252,7 @@ public class ExportIssuesStepTest { assertThat(issue.getAssignee()).isEqualTo(issueDto.getAssigneeUuid()); assertThat(issue.getAuthor()).isEqualTo(issueDto.getAuthorLogin()); assertThat(issue.getTags()).isEqualTo(issueDto.getTagsString()); + assertThat(issue.getRuleDescriptionContextKey()).isEqualTo(issue.getRuleDescriptionContextKey()); assertThat(issue.getIssueCreatedAt()).isEqualTo(issueDto.getIssueCreationTime()); assertThat(issue.getIssueUpdatedAt()).isEqualTo(issueDto.getIssueUpdateTime()); assertThat(issue.getIssueClosedAt()).isEqualTo(issueDto.getIssueCloseTime()); @@ -271,6 +273,7 @@ public class ExportIssuesStepTest { assertThat(issue.getIssueCreatedAt()).isEqualTo(DumpElement.NO_DATETIME); assertThat(issue.getIssueUpdatedAt()).isEqualTo(DumpElement.NO_DATETIME); assertThat(issue.getIssueClosedAt()).isEqualTo(DumpElement.NO_DATETIME); + assertThat(issue.hasRuleDescriptionContextKey()).isFalse(); } @Test -- 2.39.5