aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis
diff options
context:
space:
mode:
authorSteve Marion <unknown>2023-07-26 17:49:52 +0200
committersonartech <sonartech@sonarsource.com>2023-08-02 20:03:03 +0000
commit6365d7447e159d3cc255e381b67894f3827bcd6c (patch)
treec0f17c6c12ede18d803cf8397eb4eafabce072e6 /server/sonar-ce-task-projectanalysis
parent40919a571ab3d2b3e87689e47473b64a7eda9e56 (diff)
downloadsonarqube-6365d7447e159d3cc255e381b67894f3827bcd6c.tar.gz
sonarqube-6365d7447e159d3cc255e381b67894f3827bcd6c.zip
SONAR-20061 purge used anticipated_transition
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java49
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepository.java1
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepositoryImpl.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitor.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java27
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto1
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitorTest.java10
8 files changed, 77 insertions, 23 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 4c97694f98b..77e630aaa39 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
@@ -49,6 +49,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.issue.AnticipatedTransitionDto;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.IssueMapper;
@@ -628,4 +629,52 @@ public class PersistIssuesStepIT extends BaseStepTest {
entry("inserts", "0"), entry("updates", "1"), entry("merged", "0"));
}
+ @Test
+ public void when_anticipatedTransitionIsPresent_ItShouldBeDeleted() {
+ periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null));
+ RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
+ db.rules().insert(rule);
+ ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
+ session.commit();
+ String issueKey = "ISSUE-4";
+
+ DefaultIssue newIssue = new DefaultIssue()
+ .setKey(issueKey)
+ .setType(RuleType.CODE_SMELL)
+ .setRuleKey(rule.getKey())
+ .setComponentUuid(file.uuid())
+ .setComponentKey(file.getKey())
+ .setProjectUuid(project.uuid())
+ .setProjectKey(project.getKey())
+ .setSeverity(BLOCKER)
+ .setStatus(STATUS_OPEN)
+ .setCreationDate(new Date(NOW))
+ .setNew(true)
+ .setIsOnChangedLine(true)
+ .setType(RuleType.BUG);
+
+ AnticipatedTransitionDto atDto = db.anticipatedTransitions().createForIssue(newIssue, "test_uuid", file.name());
+ newIssue.setAnticipatedTransitionUuid(atDto.getUuid());
+
+ var defaultIssueCacheAppender = protoIssueCache.newAppender();
+ defaultIssueCacheAppender.append(newIssue).close();
+
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
+
+ IssueDto result = dbClient.issueDao().selectOrFailByKey(session, issueKey);
+ assertThat(result.getKey()).isEqualTo(issueKey);
+ assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
+ assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
+ assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
+ assertThat(result.getSeverity()).isEqualTo(BLOCKER);
+ assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
+ assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
+ assertThat(context.getStatistics().getAll()).contains(
+ entry("inserts", "1"), entry("updates", "0"), entry("merged", "0"));
+ assertThat(result.isNewCodeReferenceIssue()).isTrue();
+
+ assertThat(db.anticipatedTransitions().selectByProjectUuid(project.uuid())).isEmpty();
+ }
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepository.java
index e3d904f795e..06ac651040f 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepository.java
@@ -25,5 +25,4 @@ import org.sonar.core.issue.AnticipatedTransition;
public interface AnticipatedTransitionRepository {
Collection<AnticipatedTransition> getAnticipatedTransitionByComponent(Component component);
-
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepositoryImpl.java
index e2a115a98c2..23ab266bb7a 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepositoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AnticipatedTransitionRepositoryImpl.java
@@ -56,12 +56,13 @@ public class AnticipatedTransitionRepositoryImpl implements AnticipatedTransitio
private Collection<AnticipatedTransition> getAnticipatedTransitions(List<AnticipatedTransitionDto> anticipatedTransitionDtos) {
return anticipatedTransitionDtos
.stream()
- .map(this::getAnticipatedTransition)
+ .map(AnticipatedTransitionRepositoryImpl::getAnticipatedTransition)
.toList();
}
- private AnticipatedTransition getAnticipatedTransition(AnticipatedTransitionDto transitionDto) {
+ private static AnticipatedTransition getAnticipatedTransition(AnticipatedTransitionDto transitionDto) {
return new AnticipatedTransition(
+ transitionDto.getUuid(),
transitionDto.getProjectUuid(),
transitionDto.getUserUuid(),
RuleKey.parse(transitionDto.getRuleKey()),
@@ -73,5 +74,4 @@ public class AnticipatedTransitionRepositoryImpl implements AnticipatedTransitio
transitionDto.getComment()
);
}
-
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitor.java
index 976ab894c2e..8cfb9e4e46f 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitor.java
@@ -67,7 +67,7 @@ public class TransitionIssuesToAnticipatedStatesVisitor extends IssueVisitor {
private void performAnticipatedTransition(DefaultIssue issue, AnticipatedTransition anticipatedTransition) {
issue.setBeingClosed(true);
- issue.setAnticipatedTransitions(true);
+ issue.setAnticipatedTransitionUuid(anticipatedTransition.getUuid());
issueLifecycle.doManualTransition(issue, anticipatedTransition.getTransition(), anticipatedTransition.getUserUuid());
String transitionComment = anticipatedTransition.getComment();
String comment = Strings.isNotBlank(transitionComment) ? transitionComment : "Automatically transitioned from SonarLint";
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
index 371691edae8..363b88507d4 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java
@@ -36,6 +36,7 @@ import org.sonar.core.util.UuidFactory;
import org.sonar.db.BatchSession;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.issue.AnticipatedTransitionMapper;
import org.sonar.db.issue.IssueChangeMapper;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.IssueMapper;
@@ -85,12 +86,13 @@ public class PersistIssuesStep implements ComputationStep {
IssueMapper mapper = dbSession.getMapper(IssueMapper.class);
IssueChangeMapper changeMapper = dbSession.getMapper(IssueChangeMapper.class);
+ AnticipatedTransitionMapper anticipatedTransitionMapper = dbSession.getMapper(AnticipatedTransitionMapper.class);
while (issues.hasNext()) {
DefaultIssue issue = issues.next();
if (issue.isNew() || issue.isCopied()) {
addedIssues.add(issue);
if (addedIssues.size() >= ISSUE_BATCHING_SIZE) {
- persistNewIssues(statistics, addedIssues, mapper, changeMapper);
+ persistNewIssues(statistics, addedIssues, mapper, changeMapper, anticipatedTransitionMapper);
addedIssues.clear();
}
} else if (issue.isChanged()) {
@@ -113,7 +115,7 @@ public class PersistIssuesStep implements ComputationStep {
}
}
}
- persistNewIssues(statistics, addedIssues, mapper, changeMapper);
+ persistNewIssues(statistics, addedIssues, mapper, changeMapper, anticipatedTransitionMapper);
persistUpdatedIssues(statistics, updatedIssues, mapper, changeMapper);
persistNoLongerNewIssues(statistics, noLongerNewIssues, mapper);
persistNewCodeIssuesToMigrate(statistics, newCodeIssuesToMigrate, mapper);
@@ -123,23 +125,22 @@ public class PersistIssuesStep implements ComputationStep {
}
}
- private void persistNewIssues(IssueStatistics statistics, List<DefaultIssue> addedIssues, IssueMapper mapper, IssueChangeMapper changeMapper) {
- if (addedIssues.isEmpty()) {
- return;
- }
+ private void persistNewIssues(IssueStatistics statistics, List<DefaultIssue> addedIssues,
+ IssueMapper mapper, IssueChangeMapper changeMapper, AnticipatedTransitionMapper anticipatedTransitionMapper) {
- long now = system2.now();
- addedIssues.forEach(i -> {
- String ruleUuid = ruleRepository.getByKey(i.ruleKey()).getUuid();
- IssueDto dto = IssueDto.toDtoForComputationInsert(i, ruleUuid, now);
+ final long now = system2.now();
+
+ addedIssues.forEach(addedIssue -> {
+ String ruleUuid = ruleRepository.getByKey(addedIssue.ruleKey()).getUuid();
+ IssueDto dto = IssueDto.toDtoForComputationInsert(addedIssue, ruleUuid, now);
mapper.insert(dto);
- if (isOnBranchUsingReferenceBranch() && i.isOnChangedLine()) {
+ if (isOnBranchUsingReferenceBranch() && addedIssue.isOnChangedLine()) {
mapper.insertAsNewCodeOnReferenceBranch(NewCodeReferenceIssueDto.fromIssueDto(dto, now, uuidFactory));
}
statistics.inserts++;
+ issueStorage.insertChanges(changeMapper, addedIssue, uuidFactory);
+ addedIssue.getAnticipatedTransitionUuid().ifPresent(anticipatedTransitionMapper::delete);
});
-
- addedIssues.forEach(i -> issueStorage.insertChanges(changeMapper, i, uuidFactory));
}
private void persistUpdatedIssues(IssueStatistics statistics, List<DefaultIssue> updatedIssues, IssueMapper mapper, IssueChangeMapper changeMapper) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java
index f0f251f95c3..69653021a60 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java
@@ -136,6 +136,9 @@ public class ProtobufIssueDiskCache implements DiskCache<DefaultIssue> {
defaultIssue.setSelectedAt(next.hasSelectedAt() ? next.getSelectedAt() : null);
defaultIssue.setQuickFixAvailable(next.getQuickFixAvailable());
defaultIssue.setIsNoLongerNewCodeReferenceIssue(next.getIsNoLongerNewCodeReferenceIssue());
+ if (next.hasAnticipatedTransitionUuid()) {
+ defaultIssue.setAnticipatedTransitionUuid(next.getAnticipatedTransitionUuid());
+ }
for (IssueCache.FieldDiffs protoFieldDiffs : next.getChangesList()) {
defaultIssue.addChange(toDefaultIssueChanges(protoFieldDiffs));
@@ -189,6 +192,7 @@ public class ProtobufIssueDiskCache implements DiskCache<DefaultIssue> {
ofNullable(defaultIssue.selectedAt()).ifPresent(builder::setSelectedAt);
builder.setQuickFixAvailable(defaultIssue.isQuickFixAvailable());
builder.setIsNoLongerNewCodeReferenceIssue(defaultIssue.isNoLongerNewCodeReferenceIssue());
+ defaultIssue.getAnticipatedTransitionUuid().ifPresent(builder::setAnticipatedTransitionUuid);
for (FieldDiffs fieldDiffs : defaultIssue.changes()) {
builder.addChanges(toProtoIssueChanges(fieldDiffs));
diff --git a/server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto b/server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto
index 880424a347b..c75e6f58509 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto
+++ b/server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto
@@ -83,6 +83,7 @@ message Issue {
optional sonarqube.db.issues.MessageFormattings messageFormattings = 45;
optional string codeVariants = 46;
optional string assigneeLogin = 47;
+ optional string anticipatedTransitionUuid = 48;
}
message Comment {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitorTest.java
index 4cd4af882e9..0517c680c4a 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TransitionIssuesToAnticipatedStatesVisitorTest.java
@@ -58,7 +58,7 @@ public class TransitionIssuesToAnticipatedStatesVisitorTest {
underTest.onIssue(component, issue);
assertThat(issue.isBeingClosed()).isTrue();
- assertThat(issue.hasAnticipatedTransitions()).isTrue();
+ assertThat(issue.getAnticipatedTransitionUuid()).isPresent();
verify(issueLifecycle).doManualTransition(issue, "wontfix", "admin");
verify(issueLifecycle).addComment(issue, "doing the transition in an anticipated way", "admin");
}
@@ -74,7 +74,7 @@ public class TransitionIssuesToAnticipatedStatesVisitorTest {
underTest.onIssue(component, issue);
assertThat(issue.isBeingClosed()).isFalse();
- assertThat(issue.hasAnticipatedTransitions()).isFalse();
+ assertThat(issue.getAnticipatedTransitionUuid()).isNotPresent();
verifyNoInteractions(issueLifecycle);
}
@@ -89,7 +89,7 @@ public class TransitionIssuesToAnticipatedStatesVisitorTest {
underTest.onIssue(component, issue);
assertThat(issue.isBeingClosed()).isTrue();
- assertThat(issue.hasAnticipatedTransitions()).isTrue();
+ assertThat(issue.getAnticipatedTransitionUuid()).isPresent();
verify(issueLifecycle).doManualTransition(issue, "wontfix", "admin");
verify(issueLifecycle).addComment(issue, "Automatically transitioned from SonarLint", "admin");
}
@@ -115,11 +115,11 @@ public class TransitionIssuesToAnticipatedStatesVisitorTest {
}
private Collection<AnticipatedTransition> getAnticipatedTransitions(String projecKey, String fileName) {
- return Stream.of(new AnticipatedTransition(projecKey, "admin", RuleKey.parse("repo:id"), "issue message", fileName, 1, "abcdefghi", "wontfix", "doing the transition in an anticipated way")).collect(Collectors.toList());
+ return Stream.of(new AnticipatedTransition("atuuid", projecKey, "admin", RuleKey.parse("repo:id"), "issue message", fileName, 1, "abcdefghi", "wontfix", "doing the transition in an anticipated way")).collect(Collectors.toList());
}
private Collection<AnticipatedTransition> getAnticipatedTransitionsWithEmptyComment(String projecKey, String fileName) {
- return Stream.of(new AnticipatedTransition(projecKey, "admin", RuleKey.parse("repo:id"), "issue message", fileName, 1, "abcdefghi", "wontfix", null)).collect(Collectors.toList());
+ return Stream.of(new AnticipatedTransition("atuuid", projecKey, "admin", RuleKey.parse("repo:id"), "issue message", fileName, 1, "abcdefghi", "wontfix", null)).collect(Collectors.toList());
}
private Component getComponent(Component.Type type) {