aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis
diff options
context:
space:
mode:
authorDDMili <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com>2024-05-28 11:48:44 +0200
committersonartech <sonartech@sonarsource.com>2024-06-03 20:02:58 +0000
commitd3fcde30b4218129c1ef0834e2ae717e4732c923 (patch)
tree20d93c6ee2088d4dedafaadd2c7f44c9087ec06e /server/sonar-ce-task-projectanalysis
parentf1525ab2b1fb18209f2cce91161a57c527f4c751 (diff)
downloadsonarqube-d3fcde30b4218129c1ef0834e2ae717e4732c923.tar.gz
sonarqube-d3fcde30b4218129c1ef0834e2ae717e4732c923.zip
SONAR-22224 Create issue visitor
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualityprofile/PrioritizedRulesHolder.java35
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualityprofile/PrioritizedRulesHolderImpl.java37
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPrioritizedRulesStep.java63
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java1
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPrioritizedRulesStepTest.java72
6 files changed, 210 insertions, 0 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java
index 476ca2cf47f..c7df68041a4 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java
@@ -125,6 +125,7 @@ import org.sonar.ce.task.projectanalysis.qualitymodel.RatingSettings;
import org.sonar.ce.task.projectanalysis.qualitymodel.ReliabilityAndSecurityRatingMeasuresVisitor;
import org.sonar.ce.task.projectanalysis.qualitymodel.SecurityReviewMeasuresVisitor;
import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRulesHolderImpl;
+import org.sonar.ce.task.projectanalysis.qualityprofile.PrioritizedRulesHolderImpl;
import org.sonar.ce.task.projectanalysis.qualityprofile.QProfileStatusRepositoryImpl;
import org.sonar.ce.task.projectanalysis.qualityprofile.QualityProfileRuleChangeResolver;
import org.sonar.ce.task.projectanalysis.scm.ScmInfoDbLoader;
@@ -206,6 +207,7 @@ public final class ProjectAnalysisTaskContainerPopulator implements ContainerPop
BatchReportDirectoryHolderImpl.class,
TreeRootHolderImpl.class,
PeriodHolderImpl.class,
+ PrioritizedRulesHolderImpl.class,
QualityGateHolderImpl.class,
QualityGateStatusHolderImpl.class,
RatingSettings.class,
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualityprofile/PrioritizedRulesHolder.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualityprofile/PrioritizedRulesHolder.java
new file mode 100644
index 00000000000..0f09079f1dc
--- /dev/null
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualityprofile/PrioritizedRulesHolder.java
@@ -0,0 +1,35 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.ce.task.projectanalysis.qualityprofile;
+
+import java.util.Set;
+
+/**
+ * Repository of prioritized rules defined in the quality profile
+ **/
+public interface PrioritizedRulesHolder {
+
+ /**
+ * Returns the rules Uuids marked as "Priority rules"
+ */
+ Set<String> getPrioritizedRulesUuids();
+
+}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualityprofile/PrioritizedRulesHolderImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualityprofile/PrioritizedRulesHolderImpl.java
new file mode 100644
index 00000000000..45a0ec8c436
--- /dev/null
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualityprofile/PrioritizedRulesHolderImpl.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.ce.task.projectanalysis.qualityprofile;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+
+public class PrioritizedRulesHolderImpl implements PrioritizedRulesHolder{
+
+ private Set<String> prioritizedRulesUuids;
+
+ @Override
+ public Set<String> getPrioritizedRulesUuids() {
+ return ImmutableSet.copyOf(prioritizedRulesUuids);
+ }
+
+ public void setPrioritizedRulesUuids(Set<String> prioritizedRulesUuids) {
+ this.prioritizedRulesUuids = prioritizedRulesUuids;
+ }
+}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPrioritizedRulesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPrioritizedRulesStep.java
new file mode 100644
index 00000000000..ce35ccd1be8
--- /dev/null
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPrioritizedRulesStep.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.ce.task.projectanalysis.step;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
+import org.sonar.ce.task.projectanalysis.qualityprofile.PrioritizedRulesHolderImpl;
+import org.sonar.ce.task.step.ComputationStep;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.server.qualityprofile.QualityProfile;
+
+/**
+ * Populates the {@link org.sonar.ce.task.projectanalysis.qualityprofile.PrioritizedRulesHolder}
+ */
+public class LoadPrioritizedRulesStep implements ComputationStep {
+
+ private final AnalysisMetadataHolder analysisMetadataHolder;
+ private final PrioritizedRulesHolderImpl prioritizedRulesHolder;
+ private final DbClient dbClient;
+
+ public LoadPrioritizedRulesStep(AnalysisMetadataHolder analysisMetadataHolder, PrioritizedRulesHolderImpl prioritizedRulesHolder,
+ DbClient dbClient) {
+ this.analysisMetadataHolder = analysisMetadataHolder;
+ this.prioritizedRulesHolder = prioritizedRulesHolder;
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Load prioritized rules";
+ }
+
+ @Override
+ public void execute(Context context) {
+
+ Set<String> qpKeys =
+ analysisMetadataHolder.getQProfilesByLanguage().values().stream().map(QualityProfile::getQpKey).collect(Collectors.toSet());
+
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ Set<String> prioritizedRulesUuids = dbClient.activeRuleDao().selectPrioritizedRulesUuids(dbSession, qpKeys);
+ prioritizedRulesHolder.setPrioritizedRulesUuids(prioritizedRulesUuids);
+ }
+ }
+}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java
index ce87c20288b..6095afe8a71 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ReportComputationSteps.java
@@ -60,6 +60,7 @@ public class ReportComputationSteps extends AbstractComputationSteps {
LoadFileHashesAndStatusStep.class,
LoadQualityGateStep.class,
LoadPeriodsStep.class,
+ LoadPrioritizedRulesStep.class,
FileMoveDetectionStep.class,
PullRequestFileMoveDetectionStep.class,
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPrioritizedRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPrioritizedRulesStepTest.java
new file mode 100644
index 00000000000..afeb3ef180f
--- /dev/null
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPrioritizedRulesStepTest.java
@@ -0,0 +1,72 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.ce.task.projectanalysis.step;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.jupiter.api.Test;
+import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
+import org.sonar.ce.task.projectanalysis.qualityprofile.PrioritizedRulesHolderImpl;
+import org.sonar.ce.task.step.ComputationStep;
+import org.sonar.db.DbClient;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class LoadPrioritizedRulesStepTest {
+
+ AnalysisMetadataHolder analysisMetadataHolder = mock();
+ DbClient dbClient = mock();
+ PrioritizedRulesHolderImpl prioritizedRulesHolder = new PrioritizedRulesHolderImpl();
+ LoadPrioritizedRulesStep underTest = new LoadPrioritizedRulesStep(analysisMetadataHolder, prioritizedRulesHolder, dbClient);
+
+ @Test
+ void execute_whenNoPrioritizedRules_shouldHaveEmptyHolder() {
+ when(dbClient.activeRuleDao()).thenReturn(mock());
+ when(dbClient.activeRuleDao().selectPrioritizedRulesUuids(any(), any())).thenReturn(new HashSet<>());
+ underTest.execute(mock());
+ assertThat(prioritizedRulesHolder.getPrioritizedRulesUuids()).isEmpty();
+ }
+
+ @Test
+ void execute_whenPrioritizedRules_shouldHaveNonEmptyHolder() {
+ when(dbClient.activeRuleDao()).thenReturn(mock());
+ when(dbClient.activeRuleDao().selectPrioritizedRulesUuids(any(), any())).thenReturn(Set.of("ruleUuid"));
+ underTest.execute(mock());
+ assertThat(prioritizedRulesHolder.getPrioritizedRulesUuids()).isNotEmpty();
+ }
+
+ @Test
+ void execute_whenDBError_shouldThrow() {
+ when(dbClient.activeRuleDao()).thenReturn(mock());
+ when(dbClient.activeRuleDao().selectPrioritizedRulesUuids(any(), any())).thenThrow(new RuntimeException());
+
+ ComputationStep.Context context = mock();
+ assertThatThrownBy(() -> underTest.execute(context)).isInstanceOf(RuntimeException.class);
+ }
+
+ @Test
+ void getDescription_shouldReturnValue() {
+ assertThat(underTest.getDescription()).isEqualTo("Load prioritized rules");
+ }
+}