aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis/src/main
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2022-03-29 14:05:47 +0200
committersonartech <sonartech@sonarsource.com>2022-03-31 20:02:59 +0000
commit000a8e84e0495628c282640fe62dd8cc84f98800 (patch)
tree0e54a53f1a2550e22e2d210385bc8584ff43186d /server/sonar-ce-task-projectanalysis/src/main
parent5db8293aeefbd683b9288bbc5d0dee5d9e407546 (diff)
downloadsonarqube-000a8e84e0495628c282640fe62dd8cc84f98800.tar.gz
sonarqube-000a8e84e0495628c282640fe62dd8cc84f98800.zip
SONAR-16039 populating measure for new metric analysis_from_sonarqube_9_4
Diffstat (limited to 'server/sonar-ce-task-projectanalysis/src/main')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisFromSonarQube94Visitor.java65
-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/measure/Measure.java15
3 files changed, 82 insertions, 0 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisFromSonarQube94Visitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisFromSonarQube94Visitor.java
new file mode 100644
index 00000000000..d9dcfb07d2a
--- /dev/null
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisFromSonarQube94Visitor.java
@@ -0,0 +1,65 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.analysis;
+
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.ce.task.projectanalysis.component.Component;
+import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
+import org.sonar.ce.task.projectanalysis.component.PathAwareVisitorAdapter;
+import org.sonar.ce.task.projectanalysis.measure.Measure;
+import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
+import org.sonar.ce.task.projectanalysis.metric.Metric;
+import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
+
+public class AnalysisFromSonarQube94Visitor extends PathAwareVisitorAdapter<AnalysisFromSonarQube94Visitor.AnalysisFromSonarQube94> {
+
+ private final MeasureRepository measureRepository;
+ private final Metric analysisFromSonarQube94Metric;
+
+ public AnalysisFromSonarQube94Visitor(MetricRepository metricRepository, MeasureRepository measureRepository) {
+ super(CrawlerDepthLimit.PROJECT, Order.PRE_ORDER, new AnalysisFromSonarQube94StackFactory());
+
+ this.measureRepository = measureRepository;
+ this.analysisFromSonarQube94Metric = metricRepository.getByKey(CoreMetrics.ANALYSIS_FROM_SONARQUBE_9_4_KEY);
+ }
+
+ @Override
+ public void visitProject(Component project, Path<AnalysisFromSonarQube94Visitor.AnalysisFromSonarQube94> path) {
+ measureRepository.add(project, analysisFromSonarQube94Metric, Measure.newMeasureBuilder().create(path.current().sonarQube94OrGreater));
+ }
+
+ public static final class AnalysisFromSonarQube94StackFactory extends SimpleStackElementFactory<AnalysisFromSonarQube94> {
+
+ @Override
+ public AnalysisFromSonarQube94 createForAny(Component component) {
+ return new AnalysisFromSonarQube94();
+ }
+
+ /** Stack item is not used at ProjectView level, saves on instantiating useless objects */
+ @Override
+ public AnalysisFromSonarQube94 createForProjectView(Component projectView) {
+ return null;
+ }
+ }
+
+ public static final class AnalysisFromSonarQube94 {
+ final boolean sonarQube94OrGreater = true;
+ }
+}
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 faa28a22ba6..e236cfdd0b3 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
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import org.sonar.ce.task.CeTask;
import org.sonar.ce.task.container.TaskContainer;
import org.sonar.ce.task.log.CeTaskMessagesImpl;
+import org.sonar.ce.task.projectanalysis.analysis.AnalysisFromSonarQube94Visitor;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderImpl;
import org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor;
import org.sonar.ce.task.projectanalysis.batch.BatchReportDirectoryHolderImpl;
@@ -270,6 +271,7 @@ public final class ProjectAnalysisTaskContainerPopulator implements ContainerPop
IssueOnReferenceBranchVisitor.class,
// visitors : order is important, measure computers must be executed at the end in order to access to every measures / issues
+ AnalysisFromSonarQube94Visitor.class,
LoadComponentUuidsHavingOpenIssuesVisitor.class,
IntegrateIssuesVisitor.class,
CloseIssuesOnRemovedComponentsVisitor.class,
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java
index 4159f8c57bd..1be2e0f1e50 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.measure;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Locale;
+import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -348,7 +349,21 @@ public interface Measure {
@Override
public double getVariation() {
throw new IllegalStateException("Measure does not have variation");
+ }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ ValueMeasureImpl that = (ValueMeasureImpl) o;
+ return valueType == that.valueType && Objects.equals(value, that.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(valueType, value);
}
@Override