diff options
author | Viktor Vorona <viktor.vorona@sonarsource.com> | 2024-12-03 15:36:17 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-12-04 20:03:23 +0000 |
commit | 33ab48ae6fc78cd3e67029d402dc1861ea787251 (patch) | |
tree | 90c3a5bb21dc36dd9d3ef641ddc7e90466910cd3 | |
parent | 8b42a96a0d85de0a88667c0881ba3df7a9dab3c0 (diff) | |
download | sonarqube-33ab48ae6fc78cd3e67029d402dc1861ea787251.tar.gz sonarqube-33ab48ae6fc78cd3e67029d402dc1861ea787251.zip |
SONAR-23063, SONAR-23804 Add Prioritized rule flag to import/export and fix first analysis bug
7 files changed, 21 insertions, 5 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java index b2efb56fec7..cb627c7e1a9 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java @@ -161,7 +161,8 @@ public class PersistIssuesStepIT extends BaseStepTest { .setUserUuid("john_uuid") .setDiff("technicalDebt", null, 1L) .setCreationDate(new Date(NOW))) - .addImpact(SoftwareQuality.SECURITY, Severity.MEDIUM)) + .addImpact(SoftwareQuality.SECURITY, Severity.MEDIUM) + .setPrioritizedRule(true)) .close(); TestComputationStepContext context = new TestComputationStepContext(); @@ -181,6 +182,7 @@ public class PersistIssuesStepIT extends BaseStepTest { assertThat(result.getImpacts()) .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity) .containsExactlyInAnyOrder(Tuple.tuple(SoftwareQuality.SECURITY, Severity.MEDIUM)); + assertThat(result.isPrioritizedRule()).isTrue(); List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList(issueKey)); assertThat(changes).extracting(IssueChangeDto::getChangeType).containsExactly(IssueChangeDto.TYPE_COMMENT, IssueChangeDto.TYPE_FIELD_CHANGE); @@ -278,7 +280,8 @@ public class PersistIssuesStepIT extends BaseStepTest { .setUserUuid("john_uuid") .setDiff("technicalDebt", null, 1L) .setCreationDate(new Date(NOW))) - .addImpact(SoftwareQuality.SECURITY, Severity.MEDIUM)) + .addImpact(SoftwareQuality.SECURITY, Severity.MEDIUM) + .setPrioritizedRule(true)) .close(); TestComputationStepContext context = new TestComputationStepContext(); @@ -296,6 +299,7 @@ public class PersistIssuesStepIT extends BaseStepTest { assertThat(result.getImpacts()) .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity) .containsExactlyInAnyOrder(Tuple.tuple(SoftwareQuality.SECURITY, Severity.MEDIUM)); + assertThat(result.isPrioritizedRule()).isTrue(); List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList(issueKey)); assertThat(changes).extracting(IssueChangeDto::getChangeType).containsExactly(IssueChangeDto.TYPE_COMMENT, IssueChangeDto.TYPE_FIELD_CHANGE); @@ -361,7 +365,8 @@ public class PersistIssuesStepIT extends BaseStepTest { .setNew(true) .setIsOnChangedLine(true) .addImpact(SoftwareQuality.SECURITY, Severity.MEDIUM) - .setType(RuleType.BUG)).close(); + .setType(RuleType.BUG) + .setPrioritizedRule(true)).close(); TestComputationStepContext context = new TestComputationStepContext(); underTest.execute(context); @@ -379,6 +384,7 @@ public class PersistIssuesStepIT extends BaseStepTest { assertThat(context.getStatistics().getAll()).contains( entry("inserts", "1"), entry("updates", "0"), entry("merged", "0")); assertThat(result.isNewCodeReferenceIssue()).isTrue(); + assertThat(result.isPrioritizedRule()).isTrue(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java index fbd952c6cd6..5690dcb3ad2 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java @@ -235,7 +235,8 @@ public class ExportIssuesStepIT { .addImpact(new ImpactDto().setSoftwareQuality(SoftwareQuality.MAINTAINABILITY).setSeverity(Severity.HIGH).setManualSeverity(true)) .addImpact(new ImpactDto().setSoftwareQuality(SoftwareQuality.SECURITY).setSeverity(Severity.BLOCKER).setManualSeverity(false)) .setIssueCloseTime(741L) - .setCodeVariants(List.of("v1", "v2")); + .setCodeVariants(List.of("v1", "v2")) + .setPrioritizedRule(true); // fields tested separately and/or required to match SQL request issueDto @@ -276,6 +277,7 @@ public class ExportIssuesStepIT { assertThat(issue.getMessageFormattingsList()) .isEqualTo(ExportIssuesStep.dbToDumpMessageFormatting(messageFormattings.getMessageFormattingList())); assertThat(issue.getCodeVariants()).isEqualTo(issueDto.getCodeVariantsString()); + assertThat(issue.getPrioritizedRule()).isEqualTo(issueDto.isPrioritizedRule()); } @Test 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 44982ffe6d9..95fcb75f227 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 @@ -114,7 +114,8 @@ public class ExportIssuesStep implements ComputationStep { .setIssueUpdatedAt(Optional.of(issueDto).map(IssueDto::getIssueUpdateTime).orElse(0L)) .setIssueClosedAt(Optional.of(issueDto).map(IssueDto::getIssueCloseTime).orElse(0L)) .setProjectUuid(issueDto.getProjectUuid()) - .setCodeVariants(Optional.of(issueDto).map(IssueDto::getCodeVariantsString).orElse("")); + .setCodeVariants(Optional.of(issueDto).map(IssueDto::getCodeVariantsString).orElse("")) + .setPrioritizedRule(issueDto.isPrioritizedRule()); setLocations(builder, issueDto); setMessageFormattings(builder, issueDto); mergeImpacts(builder, issueDto); 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 29ccf1c6cb2..7253b7cf81e 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 @@ -126,6 +126,8 @@ message Issue { string code_variants = 26; repeated Impact impacts = 27; + + bool prioritized_rule = 28; } message Impact { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java index 537b28db3a2..b7241058c82 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java @@ -163,6 +163,7 @@ public final class IssueDto implements Serializable { .setIsNewCodeReferenceIssue(issue.isNewCodeReferenceIssue()) .setCodeVariants(issue.codeVariants()) .setCleanCodeAttribute(issue.getCleanCodeAttribute()) + .setPrioritizedRule(issue.isPrioritizedRule()) // technical dates .setCreatedAt(now) .setUpdatedAt(now) diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectExportMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectExportMapper.xml index fbd9d82b547..6a29cee6681 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectExportMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectExportMapper.xml @@ -129,6 +129,7 @@ i.rule_description_context_key as ruleDescriptionContextKey, i.message_formattings as messageFormattings, i.code_variants as codeVariantsString, + i.prioritized_rule as prioritizedRule, ii.software_quality as ii_softwareQuality, ii.severity as ii_severity, ii.manual_severity as ii_manualSeverity, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java index 537a2d5e963..0bef2358f86 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java @@ -313,6 +313,7 @@ class IssueDtoTest { assertThat(issueDto.getOptionalRuleDescriptionContextKey()).contains(TEST_CONTEXT_KEY); assertThat(issueDto.getImpacts()).extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity, ImpactDto::isManualSeverity) .containsExactlyInAnyOrder(tuple(MAINTAINABILITY, HIGH, true), tuple(RELIABILITY, LOW, false)); + assertThat(issueDto.isPrioritizedRule()).isTrue(); } @Test @@ -346,6 +347,7 @@ class IssueDtoTest { assertThat(issueDto.getOptionalRuleDescriptionContextKey()).contains(TEST_CONTEXT_KEY); assertThat(issueDto.getImpacts()).extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity, ImpactDto::isManualSeverity) .containsExactlyInAnyOrder(tuple(MAINTAINABILITY, HIGH, true), tuple(RELIABILITY, LOW, false)); + assertThat(issueDto.isPrioritizedRule()).isTrue(); } @Test @@ -401,6 +403,7 @@ class IssueDtoTest { .setIsNewCodeReferenceIssue(true) .setRuleDescriptionContextKey(TEST_CONTEXT_KEY) .setCodeVariants(List.of("variant1", "variant2")) + .setPrioritizedRule(true) .addImpact(MAINTAINABILITY, HIGH, true) .addImpact(RELIABILITY, LOW, false); return defaultIssue; |