--- /dev/null
+/*
+ * 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;
+ }
+}
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;
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,
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;
@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
--- /dev/null
+/*
+ * 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.junit.Before;
+import org.junit.Test;
+import org.sonar.ce.task.projectanalysis.analysis.AnalysisFromSonarQube94Visitor.AnalysisFromSonarQube94;
+import org.sonar.ce.task.projectanalysis.component.Component;
+import org.sonar.ce.task.projectanalysis.component.PathAwareVisitor;
+import org.sonar.ce.task.projectanalysis.component.ReportAttributes;
+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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.sonar.ce.task.projectanalysis.analysis.AnalysisFromSonarQube94Visitor.*;
+import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
+import static org.sonar.ce.task.projectanalysis.component.ComponentImpl.builder;
+
+public class AnalysisFromSonarQube94VisitorTest {
+
+ private final MeasureRepository measureRepository = mock(MeasureRepository.class);
+ private final MetricRepository metricRepository = mock(MetricRepository.class);
+
+ private final Metric metric = mock(Metric.class);
+
+ private AnalysisFromSonarQube94Visitor underTest;
+
+ @Before
+ public void before() {
+ when(metricRepository.getByKey(anyString())).thenReturn(metric);
+ underTest = new AnalysisFromSonarQube94Visitor(metricRepository, measureRepository);
+ }
+
+ @Test
+ public void visitProject_createMeasureForMetric() {
+ Component project = builder(FILE).setUuid("uuid")
+ .setDbKey("dbKey")
+ .setName("name")
+ .setStatus(Component.Status.SAME)
+ .setReportAttributes(mock(ReportAttributes.class))
+ .build();
+
+ PathAwareVisitor.Path<AnalysisFromSonarQube94> path = mock(PathAwareVisitor.Path.class);
+ when(path.current()).thenReturn(new AnalysisFromSonarQube94());
+
+ underTest.visitProject(project, path);
+
+ Measure expectedMeasure = Measure.newMeasureBuilder().create(true);
+ verify(measureRepository).add(project, metric, expectedMeasure);
+ }
+
+ @Test
+ public void analysisFromSonarQube94StackFactoryCreateForAny_shouldAlwaysReturnAnalysisFromSonarQube94() {
+ AnalysisFromSonarQube94StackFactory factory = new AnalysisFromSonarQube94StackFactory();
+
+ AnalysisFromSonarQube94 analysisFromSonarQube94 = factory.createForAny(mock(Component.class));
+
+ assertThat(analysisFromSonarQube94.sonarQube94OrGreater).isTrue();
+ }
+}
.hasMessage("NaN is not allowed as a Measure value");
}
+ @Test
+ public void valueMeasureImplEquals_instanceNotEqualToNull() {
+ Measure.ValueMeasureImpl valueMeasureImpl = (Measure.ValueMeasureImpl) new Measure.NewMeasureBuilder().create(0, null);
+
+ boolean equal = valueMeasureImpl.equals(null);
+
+ assertThat(equal).isFalse();
+ }
+
+ @Test
+ public void valueMeasureImplEquals_sameInstance_returnTrue() {
+ Measure.ValueMeasureImpl valueMeasureImpl = (Measure.ValueMeasureImpl) new Measure.NewMeasureBuilder().create(0, null);
+
+ boolean equal = valueMeasureImpl.equals(valueMeasureImpl);
+
+ assertThat(equal).isTrue();
+ }
+
}