From 30abc015459aecb07ea2e3fba2b4bba52a652f74 Mon Sep 17 00:00:00 2001 From: Matteo Mara Date: Wed, 19 Jul 2023 15:32:14 +0200 Subject: SONAR-19372 Add a new issue visitor in order to apply anticipated transitions to issues --- .../java/org/sonar/core/issue/DefaultIssue.java | 11 +++++ .../tracking/AnticipatedTransitionTracker.java | 51 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 sonar-core/src/main/java/org/sonar/core/issue/tracking/AnticipatedTransitionTracker.java (limited to 'sonar-core/src/main/java') diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index abfa4154554..32b5154b0b9 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -131,6 +131,8 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. private String ruleDescriptionContextKey = null; + private boolean anticipatedTransitions = false; + @Override public String key() { return key; @@ -689,6 +691,15 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return this; } + public boolean hasAnticipatedTransitions() { + return anticipatedTransitions; + } + + public DefaultIssue setAnticipatedTransitions(boolean anticipatedTransitions) { + this.anticipatedTransitions = anticipatedTransitions; + return this; + } + @Override public Integer getLine() { return line; diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/AnticipatedTransitionTracker.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/AnticipatedTransitionTracker.java new file mode 100644 index 00000000000..d46d3921a85 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/AnticipatedTransitionTracker.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.issue.tracking; + +import java.util.Collection; + +/** + * A simplified version of {@link Tracker}, which doesn't use line hash sequences nor block hash sequences and + * only has two steps instead of 5 steps. + */ +public class AnticipatedTransitionTracker extends AbstractTracker { + + public Tracking track(Collection rawInput, Collection baseInput) { + Tracking tracking = new Tracking<>(rawInput, baseInput); + + // 1. match by rule, line, line hash and message + match(tracking, LineAndLineHashAndMessage::new); + + // 2. match issues with same rule, same line and same line hash, but not necessarily with same message + match(tracking, LineAndLineHashKey::new); + + // 3. match issues with same rule, same message and same line hash + match(tracking, LineHashAndMessageKey::new); + + // 4. match issues with same rule, same line and same message + match(tracking, LineAndMessageKey::new); + + // 5. match issues with same rule and same line hash but different line and different message. + // See SONAR-2812 + match(tracking, LineHashKey::new); + + return tracking; + } +} -- cgit v1.2.3