aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-10-31 14:40:32 -0500
committersonartech <sonartech@sonarsource.com>2022-11-05 20:03:18 +0000
commit9b62ebf3361b96a2d693660236f1bce89d71edfa (patch)
tree8837dc35b5e6dfafa7df62f62bf2c1e55688d87a
parent717613ac072b0cb9b49fff79354b99f26060be72 (diff)
downloadsonarqube-9b62ebf3361b96a2d693660236f1bce89d71edfa.tar.gz
sonarqube-9b62ebf3361b96a2d693660236f1bce89d71edfa.zip
SONAR-16455 Merge measure's 'variation' and 'value'
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/FileStatusesImpl.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java83
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java48
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java49
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java48
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationFormula.java46
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationCounter.java41
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationFormula.java46
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueCounter.java11
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java9
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java66
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java115
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluator.java29
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java15
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitor.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitor.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStep.java15
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStep.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java94
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java39
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntValueTest.java40
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/RatingValueTest.java26
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java20
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java19
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregatorTest.java29
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java35
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java41
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java23
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java45
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java20
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStepTest.java98
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java97
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCaseTest.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java38
-rw-r--r--server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java59
-rw-r--r--server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepoEntry.java15
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java13
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java13
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml5
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java58
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java8
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java6
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DbVersion98.java35
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumn.java33
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumn.java33
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValue.java28
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValue.java28
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/VariationMigration.java65
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DbVersion98Test.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumnTest.java53
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumnTest.java53
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValueTest.java80
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValueTest.java78
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumnTest/schema.sql16
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumnTest/schema.sql17
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValueTest/schema.sql16
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValueTest/schema.sql17
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java2
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluator.java2
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluatorImpl.java4
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java31
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java13
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateEvaluatorImplTest.java11
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java49
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java13
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormula.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java89
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java14
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/HasMeasure.java28
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java46
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java12
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java13
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json12
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json10
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/search-example.json12
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java50
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImplTest.java26
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java8
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java61
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java116
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java15
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java42
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java18
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java16
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java20
112 files changed, 1220 insertions, 1826 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/FileStatusesImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/FileStatusesImpl.java
index 045b7ffa14e..21471cbf0d1 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/FileStatusesImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/FileStatusesImpl.java
@@ -22,6 +22,8 @@ package org.sonar.ce.task.projectanalysis.component;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.source.SourceHashRepository;
import org.sonar.db.source.FileHashesDto;
@@ -30,11 +32,14 @@ import static com.google.common.base.Preconditions.checkState;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
public class FileStatusesImpl implements FileStatuses {
+ private static final Logger LOG = Loggers.get(FileStatusesImpl.class);
+
private final PreviousSourceHashRepository previousSourceHashRepository;
private final SourceHashRepository sourceHashRepository;
private final AnalysisMetadataHolder analysisMetadataHolder;
private final TreeRootHolder treeRootHolder;
private Set<String> fileUuidsMarkedAsUnchanged;
+ private int notMarkedAsUnchanged = 0;
public FileStatusesImpl(AnalysisMetadataHolder analysisMetadataHolder, TreeRootHolder treeRootHolder, PreviousSourceHashRepository previousSourceHashRepository,
SourceHashRepository sourceHashRepository) {
@@ -49,6 +54,8 @@ public class FileStatusesImpl implements FileStatuses {
if (!analysisMetadataHolder.isPullRequest() && !analysisMetadataHolder.isFirstAnalysis()) {
new DepthTraversalTypeAwareCrawler(new Visitor()).visit(treeRootHolder.getRoot());
}
+ LOG.warn("FILES MARKED AS UNCHANGED: " + fileUuidsMarkedAsUnchanged.size());
+ LOG.warn("FILES NOT MARKED AS UNCHANGED: " + notMarkedAsUnchanged);
}
private class Visitor extends TypeAwareVisitorAdapter {
@@ -68,8 +75,11 @@ public class FileStatusesImpl implements FileStatuses {
if (canTrustUnchangedFlags) {
if (file.getFileAttributes().isMarkedAsUnchanged()) {
fileUuidsMarkedAsUnchanged.add(file.getUuid());
+ } else {
+ notMarkedAsUnchanged++;
}
} else {
+ LOG.error("FILE HAS DIFFERENT HASH: " + file.getName());
fileUuidsMarkedAsUnchanged.clear();
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java
deleted file mode 100644
index 9543fa60be4..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/VariationSumFormula.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.formula;
-
-import java.util.Optional;
-import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
-import org.sonar.ce.task.projectanalysis.formula.counter.DoubleValue;
-import org.sonar.ce.task.projectanalysis.measure.Measure;
-
-import static java.util.Objects.requireNonNull;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
-
-/**
- * A Formula which aggregates variations of a specific metric by simply making the sums of its variations. It supports
- * make the sum of only specific periods.
- */
-public class VariationSumFormula implements Formula<VariationSumFormula.VariationSumCounter> {
- private final String metricKey;
-
- public VariationSumFormula(String metricKey) {
- this.metricKey = requireNonNull(metricKey, "Metric key cannot be null");
- }
-
- @Override
- public VariationSumCounter createNewCounter() {
- return new VariationSumCounter(metricKey);
- }
-
- @Override
- public Optional<Measure> createMeasure(VariationSumCounter counter, CreateMeasureContext context) {
- if (!CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType()) || !counter.doubleValue.isSet()) {
- return Optional.empty();
- }
- return Optional.of(newMeasureBuilder().setVariation(counter.doubleValue.getValue()).createNoValue());
- }
-
- @Override
- public String[] getOutputMetricKeys() {
- return new String[] {metricKey};
- }
-
- public static final class VariationSumCounter implements Counter<VariationSumCounter> {
- private final DoubleValue doubleValue = new DoubleValue();
- private final String metricKey;
-
- private VariationSumCounter(String metricKey) {
- this.metricKey = metricKey;
- }
-
- @Override
- public void aggregate(VariationSumCounter counter) {
- doubleValue.increment(counter.doubleValue);
- }
-
- @Override
- public void initialize(CounterInitializationContext context) {
- Optional<Measure> measure = context.getMeasure(metricKey);
- if (!measure.isPresent() || !measure.get().hasVariation()) {
- return;
- }
- double variation = measure.get().getVariation();
- doubleValue.increment(variation);
- }
-
- }
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java
index ea7f8d51b58..876ce18cc4c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java
@@ -26,7 +26,8 @@ import org.sonar.ce.task.projectanalysis.measure.Measure;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public final class CoverageUtils {
- private static final Measure DEFAULT_MEASURE = newMeasureBuilder().create(0L);
+ private static final Measure DEFAULT_MEASURE_LONG = newMeasureBuilder().create(0L);
+ private static final Measure DEFAULT_MEASURE_INT = newMeasureBuilder().create(0);
private CoverageUtils() {
// prevents instantiation
@@ -37,7 +38,7 @@ public final class CoverageUtils {
}
static long getLongMeasureValue(CounterInitializationContext counterContext, String metricKey) {
- Measure measure = counterContext.getMeasure(metricKey).orElse(DEFAULT_MEASURE);
+ Measure measure = counterContext.getMeasure(metricKey).orElse(DEFAULT_MEASURE_LONG);
if (measure.getValueType() == Measure.ValueType.NO_VALUE) {
return 0L;
}
@@ -47,12 +48,11 @@ public final class CoverageUtils {
return measure.getLongValue();
}
- static double getMeasureVariations(CounterInitializationContext counterContext, String metricKey) {
- Optional<Measure> measure = counterContext.getMeasure(metricKey);
- if (!measure.isPresent() || !measure.get().hasVariation()) {
- return 0D;
+ static int getIntMeasureValue(CounterInitializationContext counterContext, String metricKey) {
+ Measure measure = counterContext.getMeasure(metricKey).orElse(DEFAULT_MEASURE_INT);
+ if (measure.getValueType() == Measure.ValueType.NO_VALUE) {
+ return 0;
}
- return measure.get().getVariation();
+ return measure.getIntValue();
}
-
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java
deleted file mode 100644
index f9e47497627..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageVariationFormula.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.formula.coverage;
-
-import java.util.Optional;
-import org.sonar.ce.task.projectanalysis.formula.CreateMeasureContext;
-import org.sonar.ce.task.projectanalysis.formula.Formula;
-import org.sonar.ce.task.projectanalysis.formula.counter.LongValue;
-import org.sonar.ce.task.projectanalysis.measure.Measure;
-
-import static org.sonar.ce.task.projectanalysis.formula.coverage.CoverageUtils.calculateCoverage;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
-
-/**
- * An abstract Formula which implements the aggregation of a Counter of type ElementsAndCoveredElementsVariationCounter
- * with another counter.
- */
-public abstract class CoverageVariationFormula<T extends ElementsAndCoveredElementsVariationCounter> implements Formula<T> {
-
- @Override
- public Optional<Measure> createMeasure(T counter, CreateMeasureContext context) {
- LongValue elements = counter.elements;
- if (elements.isSet() && elements.getValue() > 0D) {
- LongValue coveredElements = counter.coveredElements;
- double variation = calculateCoverage(coveredElements.getValue(), elements.getValue());
- return Optional.of(newMeasureBuilder().setVariation(variation).createNoValue());
- }
- return Optional.empty();
- }
-
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java
deleted file mode 100644
index 411d9e260b8..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.formula.coverage;
-
-import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.formula.Counter;
-import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.ce.task.projectanalysis.formula.counter.LongValue;
-
-/**
- * A counter used to create measure variations which are based on a count of elements and coveredElements.
- */
-public abstract class ElementsAndCoveredElementsVariationCounter implements Counter<ElementsAndCoveredElementsVariationCounter> {
- protected final LongValue elements = new LongValue();
- protected final LongValue coveredElements = new LongValue();
-
- @Override
- public void aggregate(ElementsAndCoveredElementsVariationCounter counter) {
- elements.increment(counter.elements);
- coveredElements.increment(counter.coveredElements);
- }
-
- @Override
- public void initialize(CounterInitializationContext context) {
- if (context.getLeaf().getType() == Component.Type.FILE && context.getLeaf().getFileAttributes().isUnitTest()) {
- return;
- }
- initializeForSupportedLeaf(context);
- }
-
- protected abstract void initializeForSupportedLeaf(CounterInitializationContext counterContext);
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java
deleted file mode 100644
index 28cf0d1c905..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.formula.coverage;
-
-import java.util.Optional;
-import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.ce.task.projectanalysis.measure.Measure;
-
-public final class LinesAndConditionsWithUncoveredVariationCounter extends ElementsAndCoveredElementsVariationCounter {
- private final LinesAndConditionsWithUncoveredMetricKeys metricKeys;
-
- public LinesAndConditionsWithUncoveredVariationCounter(LinesAndConditionsWithUncoveredMetricKeys metricKeys) {
- this.metricKeys = metricKeys;
- }
-
- @Override
- public void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
- Optional<Measure> newLinesMeasure = counterContext.getMeasure(metricKeys.getLines());
- if (!newLinesMeasure.isPresent() || !newLinesMeasure.get().hasVariation()) {
- return;
- }
- double newLines = newLinesMeasure.get().getVariation();
- long newConditions = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getConditions());
- long uncoveredLines = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredLines());
- long uncoveredConditions = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredConditions());
-
- long elements = (long) newLines + newConditions;
- this.elements.increment(elements);
- coveredElements.increment(elements - uncoveredConditions - uncoveredLines);
- }
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationFormula.java
deleted file mode 100644
index c7312c92de5..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationFormula.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.formula.coverage;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * A Formula which implements the aggregation the variations of lines and conditions measures (and their associated "uncovered" measures)
- * into the variations of a fifth measure.
- */
-public class LinesAndConditionsWithUncoveredVariationFormula extends CoverageVariationFormula<LinesAndConditionsWithUncoveredVariationCounter> {
- private final LinesAndConditionsWithUncoveredMetricKeys inputKeys;
- private final String outputKey;
-
- public LinesAndConditionsWithUncoveredVariationFormula(LinesAndConditionsWithUncoveredMetricKeys inputKeys, String outputKey) {
- this.inputKeys = requireNonNull(inputKeys);
- this.outputKey = requireNonNull(outputKey);
- }
-
- @Override
- public LinesAndConditionsWithUncoveredVariationCounter createNewCounter() {
- return new LinesAndConditionsWithUncoveredVariationCounter(inputKeys);
- }
-
- @Override
- public String[] getOutputMetricKeys() {
- return new String[] {outputKey};
- }
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationCounter.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationCounter.java
deleted file mode 100644
index b2615e7ab2c..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationCounter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.formula.coverage;
-
-import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
-
-import static java.util.Objects.requireNonNull;
-import static org.sonar.ce.task.projectanalysis.formula.coverage.CoverageUtils.getMeasureVariations;
-
-public final class SingleWithUncoveredVariationCounter extends ElementsAndCoveredElementsVariationCounter {
- private final SingleWithUncoveredMetricKeys metricKeys;
-
- public SingleWithUncoveredVariationCounter(SingleWithUncoveredMetricKeys metricKeys) {
- this.metricKeys = requireNonNull(metricKeys);
- }
-
- @Override
- protected void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
- long newConditions = (long) getMeasureVariations(counterContext, metricKeys.getCovered());
- long uncoveredConditions = (long) getMeasureVariations(counterContext, metricKeys.getUncovered());
- this.elements.increment(newConditions);
- coveredElements.increment(newConditions - uncoveredConditions);
- }
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationFormula.java
deleted file mode 100644
index 57f3d736496..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationFormula.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.formula.coverage;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * A Formula which implements the aggregation of the variations of a measure and its associated "uncovered" measure
- * into the variations of a third measure.
- */
-public class SingleWithUncoveredVariationFormula extends CoverageVariationFormula<SingleWithUncoveredVariationCounter> {
- private final SingleWithUncoveredMetricKeys inputKeys;
- private final String outputKey;
-
- protected SingleWithUncoveredVariationFormula(SingleWithUncoveredMetricKeys inputKeys, String outputKey) {
- this.inputKeys = requireNonNull(inputKeys);
- this.outputKey = requireNonNull(outputKey);
- }
-
- @Override
- public SingleWithUncoveredVariationCounter createNewCounter() {
- return new SingleWithUncoveredVariationCounter(inputKeys);
- }
-
- @Override
- public String[] getOutputMetricKeys() {
- return new String[] {outputKey};
- }
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueCounter.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueCounter.java
index 77590b96107..8d44422f572 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueCounter.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueCounter.java
@@ -187,10 +187,9 @@ public class IssueCounter extends IssueVisitor {
if (!newIssueClassifier.isEnabled()) {
return;
}
- double unresolvedVariations = currentCounters.counterForPeriod().unresolved;
+ int unresolved = currentCounters.counterForPeriod().unresolved;
measureRepository.add(component, metricRepository.getByKey(NEW_VIOLATIONS_KEY), Measure.newMeasureBuilder()
- .setVariation(unresolvedVariations)
- .createNoValue());
+ .create(unresolved));
for (Map.Entry<String, String> entry : SEVERITY_TO_NEW_METRIC_KEY.entrySet()) {
String severity = entry.getKey();
@@ -198,8 +197,7 @@ public class IssueCounter extends IssueVisitor {
Multiset<String> bag = currentCounters.counterForPeriod().severityBag;
Metric metric = metricRepository.getByKey(metricKey);
measureRepository.add(component, metric, Measure.newMeasureBuilder()
- .setVariation(bag.count(severity))
- .createNoValue());
+ .create(bag.count(severity)));
}
// waiting for Java 8 lambda in order to factor this loop with the previous one
@@ -210,8 +208,7 @@ public class IssueCounter extends IssueVisitor {
Multiset<RuleType> bag = currentCounters.counterForPeriod().typeBag;
Metric metric = metricRepository.getByKey(metricKey);
measureRepository.add(component, metric, Measure.newMeasureBuilder()
- .setVariation(bag.count(type))
- .createNoValue());
+ .create(bag.count(type)));
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java
index 1578d3716b4..9b2444cd85c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java
@@ -90,8 +90,8 @@ public class NewEffortAggregator extends IssueVisitor {
}
private void computeMeasure(Component component, Metric metric, EffortSum effortSum) {
- double variation = effortSum.isEmpty ? 0.0 : effortSum.newEffort;
- measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation(variation).createNoValue());
+ long value = effortSum.isEmpty ? 0 : effortSum.newEffort;
+ measureRepository.add(component, metric, Measure.newMeasureBuilder().create(value));
}
private class NewEffortCounter {
@@ -135,19 +135,19 @@ public class NewEffortAggregator extends IssueVisitor {
}
private static class EffortSum {
- private Double newEffort;
+ private Long newEffort;
private boolean isEmpty = true;
void add(long newEffort) {
- double previous = MoreObjects.firstNonNull(this.newEffort, 0D);
+ long previous = MoreObjects.firstNonNull(this.newEffort, 0L);
this.newEffort = previous + newEffort;
isEmpty = false;
}
void add(EffortSum other) {
- Double otherValue = other.newEffort;
+ Long otherValue = other.newEffort;
if (otherValue != null) {
- add(otherValue.longValue());
+ add(otherValue);
}
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java
index 7ad8866bfbf..e30cf81f572 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java
@@ -58,18 +58,9 @@ public class BestValueOptimization implements Predicate<Measure> {
private boolean isBestValueOptimized(Measure measure) {
return measure.getData() == null
&& !measure.hasQualityGateStatus()
- && hasNoVariation(measure, metric.getBestValue())
&& (measure.getValueType() == NO_VALUE || isBestValue(measure, metric.getBestValue()));
}
- private static boolean hasNoVariation(Measure measure, Double bestValue) {
- return !measure.hasVariation() || isVariationEmptyOrBestValue(measure.getVariation(), bestValue);
- }
-
- private static boolean isVariationEmptyOrBestValue(double variation, Double bestValue) {
- return compare(variation, 0D) == 0 || compare(variation, bestValue) == 0;
- }
-
private static boolean isBestValue(Measure measure, Double bestValue) {
switch (measure.getValueType()) {
case BOOLEAN:
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java
index 7007ca7a3d8..e197ec8e041 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasure.java
@@ -39,82 +39,72 @@ public class LiveMeasureDtoToMeasure {
String data = measureDto.getDataAsString();
switch (metric.getType().getValueType()) {
case INT:
- return toIntegerMeasure(measureDto, value, data);
+ return toIntegerMeasure(value, data);
case LONG:
- return toLongMeasure(measureDto, value, data);
+ return toLongMeasure(value, data);
case DOUBLE:
- return toDoubleMeasure(measureDto, value, data);
+ return toDoubleMeasure(value, data);
case BOOLEAN:
- return toBooleanMeasure(measureDto, value, data);
+ return toBooleanMeasure(value, data);
case STRING:
- return toStringMeasure(measureDto, data);
+ return toStringMeasure(data);
case LEVEL:
- return toLevelMeasure(measureDto, data);
+ return toLevelMeasure(data);
case NO_VALUE:
- return toNoValueMeasure(measureDto);
+ return toNoValueMeasure();
default:
throw new IllegalArgumentException("Unsupported Measure.ValueType " + metric.getType().getValueType());
}
}
- private static Optional<Measure> toIntegerMeasure(LiveMeasureDto measureDto, @Nullable Double value, @Nullable String data) {
+ private static Optional<Measure> toIntegerMeasure(@Nullable Double value, @Nullable String data) {
if (value == null) {
- return toNoValueMeasure(measureDto);
+ return toNoValueMeasure();
}
- return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto).create(value.intValue(), data));
+ return of(Measure.newMeasureBuilder().create(value.intValue(), data));
}
- private static Optional<Measure> toLongMeasure(LiveMeasureDto measureDto, @Nullable Double value, @Nullable String data) {
+ private static Optional<Measure> toLongMeasure(@Nullable Double value, @Nullable String data) {
if (value == null) {
- return toNoValueMeasure(measureDto);
+ return toNoValueMeasure();
}
- return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto).create(value.longValue(), data));
+ return of(Measure.newMeasureBuilder().create(value.longValue(), data));
}
- private static Optional<Measure> toDoubleMeasure(LiveMeasureDto measureDto, @Nullable Double value, @Nullable String data) {
+ private static Optional<Measure> toDoubleMeasure(@Nullable Double value, @Nullable String data) {
if (value == null) {
- return toNoValueMeasure(measureDto);
+ return toNoValueMeasure();
}
- return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto)
- .create(value, org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE, data));
+ return of(Measure.newMeasureBuilder().create(value, org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE, data));
}
- private static Optional<Measure> toBooleanMeasure(LiveMeasureDto measureDto, @Nullable Double value, @Nullable String data) {
+ private static Optional<Measure> toBooleanMeasure(@Nullable Double value, @Nullable String data) {
if (value == null) {
- return toNoValueMeasure(measureDto);
+ return toNoValueMeasure();
}
- return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto).create(Double.compare(value, 1.0D) == 0, data));
+ return of(Measure.newMeasureBuilder().create(Double.compare(value, 1.0D) == 0, data));
}
- private static Optional<Measure> toStringMeasure(LiveMeasureDto measureDto, @Nullable String data) {
+ private static Optional<Measure> toStringMeasure(@Nullable String data) {
if (data == null) {
- return toNoValueMeasure(measureDto);
+ return toNoValueMeasure();
}
- return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto).create(data));
+ return of(Measure.newMeasureBuilder().create(data));
}
- private static Optional<Measure> toLevelMeasure(LiveMeasureDto measureDto, @Nullable String data) {
+ private static Optional<Measure> toLevelMeasure(@Nullable String data) {
if (data == null) {
- return toNoValueMeasure(measureDto);
+ return toNoValueMeasure();
}
Optional<Measure.Level> level = toLevel(data);
if (!level.isPresent()) {
- return toNoValueMeasure(measureDto);
+ return toNoValueMeasure();
}
- return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto).create(level.get()));
+ return of(Measure.newMeasureBuilder().create(level.get()));
}
- private static Optional<Measure> toNoValueMeasure(LiveMeasureDto measureDto) {
- return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto).createNoValue());
+ private static Optional<Measure> toNoValueMeasure() {
+ return of(Measure.newMeasureBuilder().createNoValue());
}
-
- private static Measure.NewMeasureBuilder setCommonProperties(Measure.NewMeasureBuilder builder, LiveMeasureDto measureDto) {
- Double variation = measureDto.getVariation();
- if (variation != null) {
- builder.setVariation(variation);
- }
- return builder;
- }
-
}
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 1be2e0f1e50..bedb74a3fbd 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
@@ -28,6 +28,7 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.util.cache.DoubleCache;
+import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
@@ -139,20 +140,8 @@ public interface Measure {
*/
QualityGateStatus getQualityGateStatus();
- /**
- * Any Measure, which ever is its value type, can have a variation.
- */
- boolean hasVariation();
-
- /**
- * The variation of this measure.
- *
- * @throws IllegalStateException if the measure has no variation
- */
- double getVariation();
-
default boolean isEmpty() {
- return getValueType() == ValueType.NO_VALUE && !hasVariation() && getData() == null;
+ return getValueType() == ValueType.NO_VALUE && getData() == null;
}
static NewMeasureBuilder newMeasureBuilder() {
@@ -173,17 +162,13 @@ public interface Measure {
private final Level dataLevel;
@CheckForNull
private final QualityGateStatus qualityGateStatus;
- @CheckForNull
- private final Double variation;
- private MeasureImpl(ValueType valueType, @Nullable Double value, @Nullable String data, @Nullable Level dataLevel,
- @Nullable QualityGateStatus qualityGateStatus, @Nullable Double variation) {
+ private MeasureImpl(ValueType valueType, @Nullable Double value, @Nullable String data, @Nullable Level dataLevel, @Nullable QualityGateStatus qualityGateStatus) {
this.valueType = valueType;
this.value = DoubleCache.intern(value);
this.data = data;
this.dataLevel = dataLevel;
this.qualityGateStatus = qualityGateStatus;
- this.variation = variation;
}
@Override
@@ -243,17 +228,6 @@ public interface Measure {
return this.qualityGateStatus;
}
- @Override
- public boolean hasVariation() {
- return variation != null;
- }
-
- @Override
- public double getVariation() {
- checkState(variation != null, "Measure does not have variation");
- return variation;
- }
-
private static void checkValueType(ValueType expected, ValueType valueType) {
if (valueType != expected) {
throw new IllegalStateException(
@@ -266,13 +240,12 @@ public interface Measure {
@Override
public String toString() {
- return com.google.common.base.MoreObjects.toStringHelper(this)
+ return toStringHelper(this)
.add("valueType", valueType)
.add("value", value)
.add("data", data)
.add("dataLevel", dataLevel)
.add("qualityGateStatus", qualityGateStatus)
- .add("variations", variation)
.toString();
}
}
@@ -342,16 +315,6 @@ public interface Measure {
}
@Override
- public boolean hasVariation() {
- return false;
- }
-
- @Override
- public double getVariation() {
- throw new IllegalStateException("Measure does not have variation");
- }
-
- @Override
public boolean equals(Object o) {
if (this == o)
return true;
@@ -368,21 +331,14 @@ public interface Measure {
@Override
public String toString() {
- return com.google.common.base.MoreObjects.toStringHelper(this)
+ return toStringHelper(this)
.add("valueType", valueType)
.add("value", value)
.toString();
}
}
- class NoValueVariationMeasureImpl implements Measure {
- @Nullable
- private Double variation;
-
- private NoValueVariationMeasureImpl(@Nullable Double variation) {
- this.variation = variation;
- }
-
+ class NoValueMeasureImpl implements Measure {
@Override
public ValueType getValueType() {
return ValueType.NO_VALUE;
@@ -416,7 +372,6 @@ public interface Measure {
@Override
public Level getLevelValue() {
throw new IllegalStateException();
-
}
@Override
@@ -435,39 +390,21 @@ public interface Measure {
}
@Override
- public boolean hasVariation() {
- return variation != null;
- }
-
- @Override
- public double getVariation() {
- checkState(variation != null, "Measure does not have variation");
- return variation;
- }
-
- @Override
public String toString() {
- return com.google.common.base.MoreObjects.toStringHelper(this)
+ return toStringHelper(this)
.add("valueType", ValueType.NO_VALUE)
- .add("variations", variation)
.toString();
}
}
class NewMeasureBuilder {
private QualityGateStatus qualityGateStatus;
- private Double variation;
public NewMeasureBuilder setQualityGateStatus(QualityGateStatus qualityGateStatus) {
this.qualityGateStatus = requireNonNull(qualityGateStatus, "QualityGateStatus can not be set to null");
return this;
}
- public NewMeasureBuilder setVariation(double variation) {
- this.variation = variation;
- return this;
- }
-
public Measure create(boolean value, @Nullable String data) {
return createInternal(ValueType.BOOLEAN, value ? 1.0D : 0.0D, data);
}
@@ -499,30 +436,34 @@ public interface Measure {
}
private Measure createInternal(ValueType type, double value, @Nullable String data) {
- if (data == null && qualityGateStatus == null && variation == null) {
+ if (data == null && qualityGateStatus == null) {
return new ValueMeasureImpl(type, value);
}
- return new MeasureImpl(type, value, data, null, qualityGateStatus, variation);
+ return new MeasureImpl(type, value, data, null, qualityGateStatus);
}
public Measure create(double value, int decimalScale) {
return create(value, decimalScale, null);
}
+ public Measure create(double value) {
+ return create(value, org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE);
+ }
+
public Measure create(String value) {
- return new MeasureImpl(ValueType.STRING, null, requireNonNull(value), null, qualityGateStatus, variation);
+ return new MeasureImpl(ValueType.STRING, null, requireNonNull(value), null, qualityGateStatus);
}
public Measure create(Level level) {
- return new MeasureImpl(ValueType.LEVEL, null, null, requireNonNull(level), qualityGateStatus, variation);
+ return new MeasureImpl(ValueType.LEVEL, null, null, requireNonNull(level), qualityGateStatus);
}
public Measure createNoValue() {
if (qualityGateStatus == null) {
- return new NoValueVariationMeasureImpl(variation);
+ return new NoValueMeasureImpl();
}
- return new MeasureImpl(ValueType.NO_VALUE, null, null, null, qualityGateStatus, variation);
+ return new MeasureImpl(ValueType.NO_VALUE, null, null, null, qualityGateStatus);
}
private static double scale(double value, int decimalScale) {
@@ -534,7 +475,6 @@ public interface Measure {
final class UpdateMeasureBuilder {
private final Measure source;
private QualityGateStatus qualityGateStatus;
- private Double variation;
public UpdateMeasureBuilder(Measure source) {
this.source = requireNonNull(source, "Can not create a measure from null");
@@ -554,19 +494,6 @@ public interface Measure {
return this;
}
- /**
- * Sets the variation of the updated Measure to create.
- *
- * @throws UnsupportedOperationException if the source measure already has a variation
- */
- public UpdateMeasureBuilder setVariation(double variation) {
- if (source.hasVariation()) {
- throw new UnsupportedOperationException("Variation can not be changed if already set on source Measure");
- }
- this.variation = variation;
- return this;
- }
-
public Measure create() {
Double value;
switch (source.getValueType()) {
@@ -589,13 +516,7 @@ public interface Measure {
}
Level level = source.getValueType() == ValueType.LEVEL ? source.getLevelValue() : null;
QualityGateStatus status = source.hasQualityGateStatus() ? source.getQualityGateStatus() : qualityGateStatus;
- Double var;
- if (source.hasVariation()) {
- var = source.getVariation();
- } else {
- var = variation;
- }
- return new MeasureImpl(source.getValueType(), value, source.getData(), level, status, var);
+ return new MeasureImpl(source.getValueType(), value, source.getData(), level, status);
}
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java
index 0ed0ec491ce..2494c1a3eca 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasure.java
@@ -116,14 +116,6 @@ public class MeasureDtoToMeasure {
builder.setQualityGateStatus(new QualityGateStatus(qualityGateStatus.get(), measureDto.getAlertText()));
}
}
- if (hasAnyVariation(measureDto)) {
- builder.setVariation(measureDto.getVariation());
- }
return builder;
}
-
- private static boolean hasAnyVariation(MeasureDto measureDto) {
- return measureDto.getVariation() != null;
- }
-
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
index e456a66c0f8..edb91a9fb8b 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
@@ -42,9 +42,6 @@ public class MeasureToMeasureDto {
out.setMetricUuid(metric.getUuid());
out.setComponentUuid(component.getUuid());
out.setAnalysisUuid(analysisMetadataHolder.getUuid());
- if (measure.hasVariation()) {
- out.setVariation(measure.getVariation());
- }
if (measure.hasQualityGateStatus()) {
setAlert(out, measure.getQualityGateStatus());
}
@@ -58,9 +55,6 @@ public class MeasureToMeasureDto {
out.setMetricUuid(metric.getUuid());
out.setComponentUuid(component.getUuid());
out.setProjectUuid(treeRootHolder.getRoot().getUuid());
- if (measure.hasVariation()) {
- out.setVariation(measure.getVariation());
- }
out.setValue(valueAsDouble(measure));
out.setData(data(measure));
return out;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluator.java
index 83d9731bdd5..db8e1556cdf 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluator.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluator.java
@@ -45,7 +45,7 @@ public final class ConditionEvaluator {
public EvaluationResult evaluate(Condition condition, Measure measure) {
checkArgument(SUPPORTED_METRIC_TYPE.contains(condition.getMetric().getType()), "Conditions on MetricType %s are not supported", condition.getMetric().getType());
- Comparable measureComparable = parseMeasure(condition, measure);
+ Comparable measureComparable = parseMeasure(measure);
if (measureComparable == null) {
return new EvaluationResult(Measure.Level.OK, null);
}
@@ -100,10 +100,7 @@ public final class ConditionEvaluator {
}
@CheckForNull
- private static Comparable parseMeasure(Condition condition, Measure measure) {
- if (condition.useVariation()) {
- return parseMeasureFromVariation(condition, measure);
- }
+ private static Comparable parseMeasure(Measure measure) {
switch (measure.getValueType()) {
case INT:
return measure.getIntValue();
@@ -120,26 +117,4 @@ public final class ConditionEvaluator {
String.format("Unsupported measure ValueType %s. Can not parse measure to a Comparable", measure.getValueType()));
}
}
-
- @CheckForNull
- private static Comparable parseMeasureFromVariation(Condition condition, Measure measure) {
- if (!measure.hasVariation()) {
- return null;
- }
-
- Double variation = measure.getVariation();
- Metric.MetricType metricType = condition.getMetric().getType();
- switch (metricType.getValueType()) {
- case INT:
- return variation.intValue();
- case LONG:
- return variation.longValue();
- case DOUBLE:
- return variation;
- case NO_VALUE:
- case LEVEL:
- default:
- throw new IllegalArgumentException("Unsupported metric type " + metricType);
- }
- }
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java
index 421bd2b789d..007c8bc9b71 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java
@@ -110,11 +110,11 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<N
}
double density = computeDensity(path.current());
double newDebtRatio = 100.0 * density;
- double newMaintainability = ratingSettings.getDebtRatingGrid().getRatingForDensity(density).getIndex();
- long newDevelopmentCost = path.current().getDevCost().getValue();
- measureRepository.add(component, this.newDevelopmentCostMetric, newMeasureBuilder().setVariation(newDevelopmentCost).createNoValue());
- measureRepository.add(component, this.newDebtRatioMetric, newMeasureBuilder().setVariation(newDebtRatio).createNoValue());
- measureRepository.add(component, this.newMaintainabilityRatingMetric, newMeasureBuilder().setVariation(newMaintainability).createNoValue());
+ int newMaintainability = ratingSettings.getDebtRatingGrid().getRatingForDensity(density).getIndex();
+ float newDevelopmentCost = path.current().getDevCost().getValue();
+ measureRepository.add(component, this.newDevelopmentCostMetric, newMeasureBuilder().create(newDevelopmentCost));
+ measureRepository.add(component, this.newDebtRatioMetric, newMeasureBuilder().create(newDebtRatio));
+ measureRepository.add(component, this.newMaintainabilityRatingMetric, newMeasureBuilder().create(newMaintainability));
}
private static double computeDensity(Counter counter) {
@@ -133,10 +133,7 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<N
}
private static long getLongValue(Measure measure) {
- if (measure.hasVariation()) {
- return (long) measure.getVariation();
- }
- return 0L;
+ return measure.getLongValue();
}
private void initNewDebtRatioCounter(Component file, Path<Counter> path) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitor.java
index d29faba43f5..7880c70c866 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitor.java
@@ -112,7 +112,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis
entry -> measureRepository.add(
component,
metricsByKey.get(entry.getKey()),
- newMeasureBuilder().setVariation(entry.getValue().getValue().getIndex()).createNoValue()));
+ newMeasureBuilder().create(entry.getValue().getValue().getIndex())));
addToParent(path);
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitor.java
index da25f1f0a3d..6eb0638a54b 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitor.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitor.java
@@ -69,8 +69,8 @@ public class NewSecurityReviewMeasuresVisitor extends PathAwareVisitorAdapter<Se
computeMeasure(project, path);
// The following measures are only computed on projects level as they are required to compute the others measures on applications
- measureRepository.add(project, newSecurityHotspotsReviewedStatusMetric, Measure.newMeasureBuilder().setVariation(path.current().getHotspotsReviewed()).createNoValue());
- measureRepository.add(project, newSecurityHotspotsToReviewStatusMetric, Measure.newMeasureBuilder().setVariation(path.current().getHotspotsToReview()).createNoValue());
+ measureRepository.add(project, newSecurityHotspotsReviewedStatusMetric, Measure.newMeasureBuilder().create(path.current().getHotspotsReviewed()));
+ measureRepository.add(project, newSecurityHotspotsToReviewStatusMetric, Measure.newMeasureBuilder().create(path.current().getHotspotsToReview()));
}
@Override
@@ -91,8 +91,8 @@ public class NewSecurityReviewMeasuresVisitor extends PathAwareVisitorAdapter<Se
.forEach(issue -> path.current().processHotspot(issue));
Optional<Double> percent = computePercent(path.current().getHotspotsToReview(), path.current().getHotspotsReviewed());
- measureRepository.add(component, newSecurityReviewRatingMetric, Measure.newMeasureBuilder().setVariation(computeRating(percent.orElse(null)).getIndex()).createNoValue());
- percent.ifPresent(p -> measureRepository.add(component, newSecurityHotspotsReviewedMetric, Measure.newMeasureBuilder().setVariation(p).createNoValue()));
+ measureRepository.add(component, newSecurityReviewRatingMetric, Measure.newMeasureBuilder().create(computeRating(percent.orElse(null)).getIndex()));
+ percent.ifPresent(p -> measureRepository.add(component, newSecurityHotspotsReviewedMetric, Measure.newMeasureBuilder().create(p)));
if (!path.isRoot()) {
path.parent().add(path.current());
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
index ae5eb75170c..54d006056a9 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
@@ -35,10 +35,10 @@ import org.sonar.ce.task.projectanalysis.formula.CreateMeasureContext;
import org.sonar.ce.task.projectanalysis.formula.Formula;
import org.sonar.ce.task.projectanalysis.formula.FormulaExecutorComponentVisitor;
import org.sonar.ce.task.projectanalysis.formula.counter.IntValue;
+import org.sonar.ce.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredFormula;
import org.sonar.ce.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredMetricKeys;
-import org.sonar.ce.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredVariationFormula;
+import org.sonar.ce.task.projectanalysis.formula.coverage.SingleWithUncoveredFormula;
import org.sonar.ce.task.projectanalysis.formula.coverage.SingleWithUncoveredMetricKeys;
-import org.sonar.ce.task.projectanalysis.formula.coverage.SingleWithUncoveredVariationFormula;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
import org.sonar.ce.task.projectanalysis.metric.Metric;
@@ -56,7 +56,7 @@ import static org.sonar.api.measures.CoreMetrics.NEW_UNCOVERED_LINES_KEY;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
/**
- * Computes measures related to the New Coverage. These measures do not have values, only variations.
+ * Computes measures related to the New Coverage.
*/
public class NewCoverageMeasuresStep implements ComputationStep {
private static final List<Formula<?>> FORMULAS = List.of(
@@ -95,7 +95,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
return "Compute new coverage";
}
- private static class NewCoverageFormula extends LinesAndConditionsWithUncoveredVariationFormula {
+ private static class NewCoverageFormula extends LinesAndConditionsWithUncoveredFormula {
NewCoverageFormula() {
super(
new LinesAndConditionsWithUncoveredMetricKeys(
@@ -105,7 +105,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
}
}
- private static class NewBranchCoverageFormula extends SingleWithUncoveredVariationFormula {
+ private static class NewBranchCoverageFormula extends SingleWithUncoveredFormula {
NewBranchCoverageFormula() {
super(
new SingleWithUncoveredMetricKeys(NEW_CONDITIONS_TO_COVER_KEY, NEW_UNCOVERED_CONDITIONS_KEY),
@@ -113,7 +113,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
}
}
- private static class NewLineCoverageFormula extends SingleWithUncoveredVariationFormula {
+ private static class NewLineCoverageFormula extends SingleWithUncoveredFormula {
NewLineCoverageFormula() {
super(
new SingleWithUncoveredMetricKeys(NEW_LINES_TO_COVER_KEY, NEW_UNCOVERED_LINES_KEY),
@@ -143,7 +143,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
public Optional<Measure> createMeasure(NewCoverageCounter counter, CreateMeasureContext context) {
if (counter.hasNewCode()) {
int value = computeValueForMetric(counter, context.getMetric());
- return Optional.of(newMeasureBuilder().setVariation(value).createNoValue());
+ return Optional.of(newMeasureBuilder().create(value));
}
return Optional.empty();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java
index 395bcf96e3a..87dde1e356d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java
@@ -205,7 +205,7 @@ public class NewSizeMeasuresStep implements ComputationStep {
private static Optional<Measure> createMeasure(IntValue intValue) {
return intValue.isSet()
- ? Optional.of(Measure.newMeasureBuilder().setVariation(intValue.getValue()).createNoValue())
+ ? Optional.of(Measure.newMeasureBuilder().create(intValue.getValue()))
: Optional.empty();
}
@@ -213,11 +213,11 @@ public class NewSizeMeasuresStep implements ComputationStep {
IntValue newLines = counter.newLines;
IntValue newDuplicatedLines = counter.newDuplicatedLines;
if (newLines.isSet() && newDuplicatedLines.isSet()) {
- int newLinesVariations = newLines.getValue();
- int newDuplicatedLinesVariations = newDuplicatedLines.getValue();
- if (newLinesVariations > 0D) {
- double density = Math.min(100D, 100D * newDuplicatedLinesVariations / newLinesVariations);
- return Optional.of(Measure.newMeasureBuilder().setVariation(density).createNoValue());
+ int newLinesValue = newLines.getValue();
+ int newDuplicatedLinesValue = newDuplicatedLines.getValue();
+ if (newLinesValue > 0D) {
+ double density = Math.min(100D, 100D * newDuplicatedLinesValue / newLinesValue);
+ return Optional.of(Measure.newMeasureBuilder().create(density));
}
}
return Optional.empty();
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
index e9dd25a1df1..69d44182495 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
@@ -217,7 +217,7 @@ public class PersistLiveMeasuresStep implements ComputationStep {
@Override
public boolean test(@Nonnull Measure input) {
- return input.getValueType() != Measure.ValueType.NO_VALUE || input.hasVariation() || input.getData() != null;
+ return input.getValueType() != Measure.ValueType.NO_VALUE || input.getData() != null;
}
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java
index 027b0b42bab..f69f7f7f039 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCase.java
@@ -59,7 +59,7 @@ public class SmallChangesetQualityGateSpecialCase {
private boolean isSmallChangeset(Component project) {
return measureRepository.getRawMeasure(project, metricRepository.getByKey(CoreMetrics.NEW_LINES_KEY))
- .map(newLines -> newLines.hasVariation() && newLines.getVariation() < MAXIMUM_NEW_LINES_FOR_SMALL_CHANGESETS)
+ .map(newLines -> newLines.getIntValue() < MAXIMUM_NEW_LINES_FOR_SMALL_CHANGESETS)
.orElse(false);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStep.java
index 84f0013a619..f47661d59ab 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStep.java
@@ -36,7 +36,7 @@ import static org.sonar.db.DatabaseUtils.getString;
public class ExportLiveMeasuresStep implements ComputationStep {
- private static final String QUERY = "select pm.metric_uuid, pm.component_uuid, pm.text_value, pm.value, pm.variation" +
+ private static final String QUERY = "select pm.metric_uuid, pm.component_uuid, pm.text_value, pm.value, m.name" +
" from live_measures pm" +
" join metrics m on m.uuid=pm.metric_uuid" +
" join components p on p.uuid = pm.component_uuid" +
@@ -95,12 +95,13 @@ public class ExportLiveMeasuresStep implements ComputationStep {
.setComponentRef(componentRef)
.setTextValue(defaultString(getString(rs, 3)));
Double value = getDouble(rs, 4);
- if (value != null) {
- builder.setDoubleValue(doubleBuilder.setValue(value).build());
- }
- Double variation = getDouble(rs, 5);
- if (variation != null) {
- builder.setVariation(doubleBuilder.setValue(variation).build());
+ String metricKey = getString(rs, 5);
+ if (value != null && metricKey != null) {
+ if (metricKey.startsWith("new_")) {
+ builder.setVariation(doubleBuilder.setValue(value).build());
+ } else {
+ builder.setDoubleValue(doubleBuilder.setValue(value).build());
+ }
}
return builder.build();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStep.java
index ac5969d5d55..a0bbfc71061 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStep.java
@@ -39,7 +39,7 @@ import static org.sonar.db.DatabaseUtils.getString;
public class ExportMeasuresStep implements ComputationStep {
private static final String QUERY = "select pm.metric_uuid, pm.analysis_uuid, pm.component_uuid, pm.text_value, pm.value," +
- " pm.alert_status, pm.alert_text, pm.variation_value_1" +
+ " pm.alert_status, pm.alert_text, m.name" +
" from project_measures pm" +
" join metrics m on m.uuid=pm.metric_uuid" +
" join snapshots s on s.uuid=pm.analysis_uuid" +
@@ -104,6 +104,7 @@ public class ExportMeasuresStep implements ComputationStep {
ProjectDump.DoubleValue.Builder doubleBuilder) throws SQLException {
long componentRef = componentRepository.getRef(rs.getString(3));
int metricRef = metricHolder.add(rs.getString(1));
+ String metricKey = rs.getString(8);
builder
.clear()
@@ -112,15 +113,16 @@ public class ExportMeasuresStep implements ComputationStep {
.setComponentRef(componentRef)
.setTextValue(defaultString(getString(rs, 4)));
Double value = getDouble(rs, 5);
+
if (value != null) {
- builder.setDoubleValue(doubleBuilder.setValue(value).build());
+ if (metricKey.startsWith("new_")) {
+ builder.setVariation1(doubleBuilder.setValue(value).build());
+ } else {
+ builder.setDoubleValue(doubleBuilder.setValue(value).build());
+ }
}
builder.setAlertStatus(defaultString(getString(rs, 6)));
builder.setAlertText(defaultString(getString(rs, 7)));
- Double var1 = getDouble(rs, 8);
- if (var1 != null) {
- builder.setVariation1(doubleBuilder.setValue(var1).build());
- }
return builder.build();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java
index 17a5aa9b85a..486f73af574 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java
@@ -28,7 +28,6 @@ import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler;
import org.sonar.ce.task.projectanalysis.component.ReportComponent;
import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
-import org.sonar.ce.task.projectanalysis.formula.counter.IntValue;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule;
import org.sonar.ce.task.projectanalysis.metric.Metric;
@@ -130,25 +129,6 @@ public class ReportFormulaExecutorComponentVisitorTest {
}
@Test
- public void verify_aggregation_on_variation() {
- treeRootHolder.setRoot(BALANCED_COMPONENT_TREE);
-
- measureRepository.addRawMeasure(FILE_1_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(10));
- measureRepository.addRawMeasure(FILE_2_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(8));
- measureRepository.addRawMeasure(FILE_3_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(2));
-
- new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeVariationFormula()))
- .visit(BALANCED_COMPONENT_TREE);
-
- assertAddedRawMeasureVariation(ROOT_REF, 20);
- assertAddedRawMeasureVariation(DIRECTORY_1_REF, 18);
- assertAddedRawMeasureVariation(FILE_1_REF, 10);
- assertAddedRawMeasureVariation(FILE_2_REF, 8);
- assertAddedRawMeasureVariation(DIRECTORY_2_REF, 2);
- assertAddedRawMeasureVariation(FILE_3_REF, 2);
- }
-
- @Test
public void measures_are_0_when_there_is_no_input_measure() {
ReportComponent project = ReportComponent.builder(PROJECT, ROOT_REF)
.addChildren(
@@ -219,13 +199,13 @@ public class ReportFormulaExecutorComponentVisitorTest {
treeRootHolder.setRoot(root);
measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(2));
-// expectedException.expectCause(
-// hasType(UnsupportedOperationException.class)
-// .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY))
-// );
+ // expectedException.expectCause(
+ // hasType(UnsupportedOperationException.class)
+ // .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY))
+ // );
assertThatThrownBy(() -> new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(root))
- .hasCause( new UnsupportedOperationException(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY)));
+ .hasCause(new UnsupportedOperationException(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY)));
}
@Test
@@ -234,8 +214,8 @@ public class ReportFormulaExecutorComponentVisitorTest {
treeRootHolder.setRoot(root);
measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(10));
-// expectedException.expectCause(hasType(UnsupportedOperationException.class)
-// .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", ROOT_REF, NCLOC_KEY)));
+ // expectedException.expectCause(hasType(UnsupportedOperationException.class)
+ // .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", ROOT_REF, NCLOC_KEY)));
assertThatThrownBy(() -> {
new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula()))
@@ -249,19 +229,10 @@ public class ReportFormulaExecutorComponentVisitorTest {
.buildFor(ImmutableList.of(formula));
}
- private static Measure createMeasureWithVariation(double variation) {
- return newMeasureBuilder().setVariation(variation).createNoValue();
- }
-
private void assertAddedRawMeasure(int componentRef, int expectedValue) {
assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))).containsOnly(entryOf(NCLOC_KEY, newMeasureBuilder().create(expectedValue)));
}
- private void assertAddedRawMeasureVariation(int componentRef, int variation) {
- assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef)))
- .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation)));
- }
-
private class FakeFormula implements Formula<FakeCounter> {
@Override
@@ -336,55 +307,4 @@ public class ReportFormulaExecutorComponentVisitorTest {
}
}
}
-
- private class FakeVariationFormula implements Formula<FakeVariationCounter> {
-
- @Override
- public FakeVariationCounter createNewCounter() {
- return new FakeVariationCounter();
- }
-
- @Override
- public Optional<Measure> createMeasure(FakeVariationCounter counter, CreateMeasureContext context) {
- // verify the context which is passed to the method
- assertThat(context.getComponent()).isNotNull();
- assertThat(context.getMetric()).isSameAs(metricRepository.getByKey(NEW_COVERAGE_KEY));
-
- IntValue measureVariations = counter.values;
- if (measureVariations.isSet()) {
- return Optional.of(
- newMeasureBuilder()
- .setVariation(measureVariations.getValue())
- .createNoValue());
- }
- return Optional.empty();
- }
-
- @Override
- public String[] getOutputMetricKeys() {
- return new String[] {NEW_COVERAGE_KEY};
- }
- }
-
- private static class FakeVariationCounter implements Counter<FakeVariationCounter> {
- private final IntValue values = new IntValue();
-
- @Override
- public void aggregate(FakeVariationCounter counter) {
- values.increment(counter.values);
- }
-
- @Override
- public void initialize(CounterInitializationContext context) {
- // verify the context which is passed to the method
- assertThat(context.getLeaf().getChildren()).isEmpty();
-
- Optional<Measure> measureOptional = context.getMeasure(NEW_LINES_TO_COVER_KEY);
- if (!measureOptional.isPresent()) {
- return;
- }
- this.values.increment((int) measureOptional.get().getVariation());
- }
- }
-
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java
index 2ff98d57503..328b3d9dc31 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java
@@ -125,38 +125,6 @@ public class ViewsFormulaExecutorComponentVisitorTest {
}
@Test
- public void verify_aggregation_on_variations() {
- treeRootHolder.setRoot(BALANCED_COMPONENT_TREE);
-
- addRawMeasureWithVariation(PROJECT_VIEW_1_REF, NEW_LINES_TO_COVER_KEY, 10);
- addRawMeasureWithVariation(PROJECT_VIEW_2_REF, NEW_LINES_TO_COVER_KEY, 8);
- addRawMeasureWithVariation(PROJECT_VIEW_3_REF, NEW_LINES_TO_COVER_KEY, 2);
- addRawMeasureWithVariation(PROJECT_VIEW_4_REF, NEW_LINES_TO_COVER_KEY, 3);
-
- new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeVariationFormula()))
- .visit(BALANCED_COMPONENT_TREE);
-
- verifyProjectViewsHasNoAddedRawMeasures();
- verifySingleMetricWithVariation(SUB_SUBVIEW_REF, 18);
- verifySingleMetricWithVariation(SUBVIEW_1_REF, 18);
- verifySingleMetricWithVariation(SUBVIEW_2_REF, 2);
- verifySingleMetricWithVariation(ROOT_REF, 23);
- }
-
- private void verifySingleMetricWithVariation(int componentRef, int variation) {
- assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef)))
- .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation)));
- }
-
- private MeasureRepositoryRule addRawMeasureWithVariation(int componentRef, String metricKey, int variation) {
- return measureRepository.addRawMeasure(componentRef, metricKey, createMeasureWithVariation(variation));
- }
-
- private static Measure createMeasureWithVariation(double variation) {
- return newMeasureBuilder().setVariation(variation).createNoValue();
- }
-
- @Test
public void verify_no_measure_added_on_projectView() {
ViewsComponent project = ViewsComponent.builder(VIEW, ROOT_REF)
.addChildren(
@@ -287,10 +255,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
IntValue measureVariations = counter.values;
if (measureVariations.isSet()) {
- return Optional.of(
- newMeasureBuilder()
- .setVariation(measureVariations.getValue())
- .createNoValue());
+ return Optional.of(newMeasureBuilder().create(measureVariations.getValue()));
}
return Optional.empty();
}
@@ -317,7 +282,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
if (!measureOptional.isPresent()) {
return;
}
- this.values.increment((int) measureOptional.get().getVariation());
+ this.values.increment(measureOptional.get().getIntValue());
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntValueTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntValueTest.java
index ed0d0d28c42..1d398d6a316 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntValueTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/IntValueTest.java
@@ -25,58 +25,58 @@ import static org.assertj.core.api.Assertions.assertThat;
public class IntValueTest {
@Test
- public void newly_created_IntVariationValue_is_unset_and_has_value_0() {
- verifyUnsetVariationValue(new IntValue());
+ public void newly_created_IntValue_is_unset_and_has_value_0() {
+ verifyUnsetValue(new IntValue());
}
@Test
- public void increment_int_sets_IntVariationValue_and_increments_value() {
- verifySetVariationValue(new IntValue().increment(10), 10);
+ public void increment_int_sets_IntValue_and_increments_value() {
+ verifySetValue(new IntValue().increment(10), 10);
}
@Test
- public void increment_IntVariationValue_has_no_effect_if_arg_is_null() {
- verifyUnsetVariationValue(new IntValue().increment(null));
+ public void increment_IntValue_has_no_effect_if_arg_is_null() {
+ verifyUnsetValue(new IntValue().increment(null));
}
@Test
- public void increment_IntVariationValue_has_no_effect_if_arg_is_unset() {
- verifyUnsetVariationValue(new IntValue().increment(new IntValue()));
+ public void increment_IntValue_has_no_effect_if_arg_is_unset() {
+ verifyUnsetValue(new IntValue().increment(new IntValue()));
}
@Test
- public void increment_IntVariationValue_increments_by_the_value_of_the_arg() {
+ public void increment_IntValue_increments_by_the_value_of_the_arg() {
IntValue source = new IntValue().increment(10);
IntValue target = new IntValue().increment(source);
- verifySetVariationValue(target, 10);
+ verifySetValue(target, 10);
}
@Test
- public void multiple_calls_to_increment_IntVariationValue_increments_by_the_value_of_the_arg() {
+ public void multiple_calls_to_increment_IntValue_increments_by_the_value_of_the_arg() {
IntValue target = new IntValue()
.increment(new IntValue().increment(35))
.increment(new IntValue().increment(10));
- verifySetVariationValue(target, 45);
+ verifySetValue(target, 45);
}
@Test
public void multiples_calls_to_increment_int_increment_the_value() {
- IntValue variationValue = new IntValue()
+ IntValue value = new IntValue()
.increment(10)
.increment(95);
- verifySetVariationValue(variationValue, 105);
+ verifySetValue(value, 105);
}
- private static void verifyUnsetVariationValue(IntValue variationValue) {
- assertThat(variationValue.isSet()).isFalse();
- assertThat(variationValue.getValue()).isZero();
+ private static void verifyUnsetValue(IntValue value) {
+ assertThat(value.isSet()).isFalse();
+ assertThat(value.getValue()).isZero();
}
- private static void verifySetVariationValue(IntValue variationValue, int expected) {
- assertThat(variationValue.isSet()).isTrue();
- assertThat(variationValue.getValue()).isEqualTo(expected);
+ private static void verifySetValue(IntValue value, int expected) {
+ assertThat(value.isSet()).isTrue();
+ assertThat(value.getValue()).isEqualTo(expected);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/RatingValueTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/RatingValueTest.java
index b57c3e2bfe6..d9d6a929dcf 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/RatingValueTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/RatingValueTest.java
@@ -32,22 +32,22 @@ public class RatingValueTest {
@Test
public void newly_created_value_is_unset_and_has_value_0() {
- verifyUnsetVariationValue(new RatingValue());
+ verifyUnsetValue(new RatingValue());
}
@Test
public void increment_sets_value_and_increments_value() {
- verifySetVariationValue(new RatingValue().increment(B), B);
+ verifySetValue(new RatingValue().increment(B), B);
}
@Test
public void increment_has_no_effect_if_arg_is_null() {
- verifyUnsetVariationValue(new RatingValue().increment((RatingValue) null));
+ verifyUnsetValue(new RatingValue().increment((RatingValue) null));
}
@Test
public void increment_has_no_effect_if_arg_is_unset() {
- verifyUnsetVariationValue(new RatingValue().increment(new RatingValue()));
+ verifyUnsetValue(new RatingValue().increment(new RatingValue()));
}
@Test
@@ -55,7 +55,7 @@ public class RatingValueTest {
RatingValue source = new RatingValue().increment(B);
RatingValue target = new RatingValue().increment(source);
- verifySetVariationValue(target, B);
+ verifySetValue(target, B);
}
@Test
@@ -64,7 +64,7 @@ public class RatingValueTest {
.increment(new RatingValue().increment(B))
.increment(new RatingValue().increment(D));
- verifySetVariationValue(target, D);
+ verifySetValue(target, D);
}
@Test
@@ -73,17 +73,17 @@ public class RatingValueTest {
.increment(B)
.increment(C);
- verifySetVariationValue(variationValue, C);
+ verifySetValue(variationValue, C);
}
- private static void verifyUnsetVariationValue(RatingValue variationValue) {
- assertThat(variationValue.isSet()).isFalse();
- assertThat(variationValue.getValue()).isEqualTo(A);
+ private static void verifyUnsetValue(RatingValue ratingValue) {
+ assertThat(ratingValue.isSet()).isFalse();
+ assertThat(ratingValue.getValue()).isEqualTo(A);
}
- private static void verifySetVariationValue(RatingValue variationValue, Rating expected) {
- assertThat(variationValue.isSet()).isTrue();
- assertThat(variationValue.getValue()).isEqualTo(expected);
+ private static void verifySetValue(RatingValue ratingValue, Rating expected) {
+ assertThat(ratingValue.isSet()).isTrue();
+ assertThat(ratingValue.getValue()).isEqualTo(expected);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java
index 15631b50117..9af01ffcb7b 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java
@@ -34,7 +34,6 @@ import static com.google.common.base.Preconditions.checkState;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.ce.task.projectanalysis.formula.coverage.CoverageUtils.getLongMeasureValue;
-import static org.sonar.ce.task.projectanalysis.formula.coverage.CoverageUtils.getMeasureVariations;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public class CoverageUtilsTest {
@@ -86,25 +85,6 @@ public class CoverageUtilsTest {
.hasMessage("value can not be converted to long because current value type is a DOUBLE");
}
- @Test
- public void getMeasureVariations_returns_0_in_all_MeasureVariations_if_there_is_no_measure() {
- assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATION);
- }
-
- @Test
- public void getMeasureVariations_returns_0_in_all_MeasureVariations_if_there_is_measure_has_no_variations() {
- fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().createNoValue());
-
- assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATION);
- }
-
- @Test
- public void getMeasureVariations_returns_MeasureVariations_of_measure_when_it_has_one() {
- fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().setVariation(5d).createNoValue());
-
- assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(5d);
- }
-
private static class CounterInitializationContextRule extends ExternalResource implements CounterInitializationContext {
private final Map<String, Measure> measures = new HashMap<>();
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java
index 77ccd9f620a..2646cfd3157 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java
@@ -34,7 +34,6 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule;
import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule;
-import org.sonar.ce.task.projectanalysis.period.Period;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.db.rule.RuleTesting;
@@ -284,9 +283,9 @@ public class IssueCounterTest {
underTest.beforeComponent(PROJECT);
underTest.afterComponent(PROJECT);
- assertVariations(FILE1, entry(NEW_VIOLATIONS_KEY, 2), entry(NEW_CRITICAL_VIOLATIONS_KEY, 2), entry(NEW_BLOCKER_VIOLATIONS_KEY, 0), entry(NEW_MAJOR_VIOLATIONS_KEY, 0),
+ assertValues(FILE1, entry(NEW_VIOLATIONS_KEY, 2), entry(NEW_CRITICAL_VIOLATIONS_KEY, 2), entry(NEW_BLOCKER_VIOLATIONS_KEY, 0), entry(NEW_MAJOR_VIOLATIONS_KEY, 0),
entry(NEW_CODE_SMELLS_KEY, 1), entry(NEW_BUGS_KEY, 1), entry(NEW_VULNERABILITIES_KEY, 0), entry(NEW_SECURITY_HOTSPOTS_KEY, 1));
- assertVariations(PROJECT, entry(NEW_VIOLATIONS_KEY, 2), entry(NEW_CRITICAL_VIOLATIONS_KEY, 2), entry(NEW_BLOCKER_VIOLATIONS_KEY, 0), entry(NEW_MAJOR_VIOLATIONS_KEY, 0),
+ assertValues(PROJECT, entry(NEW_VIOLATIONS_KEY, 2), entry(NEW_CRITICAL_VIOLATIONS_KEY, 2), entry(NEW_BLOCKER_VIOLATIONS_KEY, 0), entry(NEW_MAJOR_VIOLATIONS_KEY, 0),
entry(NEW_CODE_SMELLS_KEY, 1), entry(NEW_BUGS_KEY, 1), entry(NEW_VULNERABILITIES_KEY, 0), entry(NEW_SECURITY_HOTSPOTS_KEY, 1));
}
@@ -339,18 +338,17 @@ public class IssueCounterTest {
underTest.beforeComponent(PROJECT);
underTest.afterComponent(PROJECT);
- assertVariations(FILE1, entry(NEW_VIOLATIONS_KEY, 0), entry(NEW_CRITICAL_VIOLATIONS_KEY, 0), entry(NEW_BLOCKER_VIOLATIONS_KEY, 0), entry(NEW_MAJOR_VIOLATIONS_KEY, 0),
+ assertValues(FILE1, entry(NEW_VIOLATIONS_KEY, 0), entry(NEW_CRITICAL_VIOLATIONS_KEY, 0), entry(NEW_BLOCKER_VIOLATIONS_KEY, 0), entry(NEW_MAJOR_VIOLATIONS_KEY, 0),
entry(NEW_VULNERABILITIES_KEY, 0));
- assertVariations(PROJECT, entry(NEW_VIOLATIONS_KEY, 0), entry(NEW_CRITICAL_VIOLATIONS_KEY, 0), entry(NEW_BLOCKER_VIOLATIONS_KEY, 0), entry(NEW_MAJOR_VIOLATIONS_KEY, 0),
+ assertValues(PROJECT, entry(NEW_VIOLATIONS_KEY, 0), entry(NEW_CRITICAL_VIOLATIONS_KEY, 0), entry(NEW_BLOCKER_VIOLATIONS_KEY, 0), entry(NEW_MAJOR_VIOLATIONS_KEY, 0),
entry(NEW_VULNERABILITIES_KEY, 0));
}
@SafeVarargs
- private final void assertVariations(Component componentRef, MapEntry<String, Integer>... entries) {
+ private final void assertValues(Component componentRef, MapEntry<String, Integer>... entries) {
assertThat(measureRepository.getRawMeasures(componentRef).entrySet()
.stream()
- .filter(e -> e.getValue().hasVariation())
- .map(e -> entry(e.getKey(), (int) e.getValue().getVariation())))
+ .map(e -> entry(e.getKey(), e.getValue().getIntValue())))
.contains(entries);
}
@@ -392,9 +390,4 @@ public class IssueCounterTest {
private DefaultIssue createNewSecurityHotspot() {
return createNewIssue(null, STATUS_OPEN, "MAJOR", RuleType.SECURITY_HOTSPOT);
}
-
- private static Period newPeriod(long date) {
- return new Period("mode", null, date);
- }
-
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregatorTest.java
index 9e94cf41e28..3aeb72fda96 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregatorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregatorTest.java
@@ -85,7 +85,7 @@ public class NewEffortAggregatorTest {
underTest.onIssue(FILE, resolved);
underTest.afterComponent(FILE);
- assertVariation(FILE, NEW_TECHNICAL_DEBT_KEY, 10 + 30);
+ assertValue(FILE, NEW_TECHNICAL_DEBT_KEY, 10 + 30);
}
@Test
@@ -110,7 +110,7 @@ public class NewEffortAggregatorTest {
underTest.afterComponent(FILE);
// Only effort of CODE SMELL issue is used
- assertVariation(FILE, NEW_TECHNICAL_DEBT_KEY, 10);
+ assertValue(FILE, NEW_TECHNICAL_DEBT_KEY, 10);
}
@Test
@@ -134,7 +134,7 @@ public class NewEffortAggregatorTest {
underTest.onIssue(FILE, resolved);
underTest.afterComponent(FILE);
- assertVariation(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 10 + 30);
+ assertValue(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 10 + 30);
}
@Test
@@ -159,7 +159,7 @@ public class NewEffortAggregatorTest {
underTest.afterComponent(FILE);
// Only effort of BUG issue is used
- assertVariation(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 15);
+ assertValue(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 15);
}
@Test
@@ -183,7 +183,7 @@ public class NewEffortAggregatorTest {
underTest.onIssue(FILE, oldResolved);
underTest.afterComponent(FILE);
- assertVariation(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 10 + 30);
+ assertValue(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 10 + 30);
}
@Test
@@ -208,7 +208,7 @@ public class NewEffortAggregatorTest {
underTest.afterComponent(FILE);
// Only effort of VULNERABILITY issue is used
- assertVariation(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 12);
+ assertValue(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 12);
}
@Test
@@ -247,9 +247,9 @@ public class NewEffortAggregatorTest {
underTest.onIssue(PROJECT, oldVulnerabilityProjectIssue);
underTest.afterComponent(PROJECT);
- assertVariation(PROJECT, NEW_TECHNICAL_DEBT_KEY, 10 + 30);
- assertVariation(PROJECT, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 8 + 28);
- assertVariation(PROJECT, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 12 + 32);
+ assertValue(PROJECT, NEW_TECHNICAL_DEBT_KEY, 10 + 30);
+ assertValue(PROJECT, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 8 + 28);
+ assertValue(PROJECT, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 12 + 32);
}
@Test
@@ -275,15 +275,14 @@ public class NewEffortAggregatorTest {
underTest.beforeComponent(FILE);
underTest.afterComponent(FILE);
- assertVariation(FILE, NEW_TECHNICAL_DEBT_KEY, 0);
- assertVariation(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 0);
- assertVariation(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 0);
+ assertValue(FILE, NEW_TECHNICAL_DEBT_KEY, 0);
+ assertValue(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 0);
+ assertValue(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 0);
}
- private void assertVariation(Component component, String metricKey, int variation) {
+ private void assertValue(Component component, String metricKey, int value) {
Measure newMeasure = measureRepository.getRawMeasure(component, metricRepository.getByKey(metricKey)).get();
- assertThat(newMeasure.getVariation()).isEqualTo(variation);
- assertThat(newMeasure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
+ assertThat(newMeasure.getLongValue()).isEqualTo(value);
}
private DefaultIssue newCodeSmellIssue(long effort) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
index affc1e194d3..f0b8d25cbd8 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
@@ -38,28 +38,13 @@ public class BestValueOptimizationTest {
private static final String SOME_DATA = "some_data";
private static final MetricImpl METRIC_BOOLEAN_FALSE = createMetric(Metric.MetricType.BOOL, 6d);
private static final MetricImpl METRIC_BOOLEAN_TRUE = createMetric(Metric.MetricType.BOOL, 1d);
- private static final double SOME_EMPTY_VARIATIONS = 0d;
-
- private static Measure.NewMeasureBuilder[] builders_of_non_bestValueOptimized_measures() {
- QualityGateStatus someQualityGateStatus = new QualityGateStatus(Measure.Level.ERROR, null);
- double someVariations = 2d;
- return new Measure.NewMeasureBuilder[] {
- newMeasureBuilder().setQualityGateStatus(someQualityGateStatus),
- newMeasureBuilder().setQualityGateStatus(someQualityGateStatus).setVariation(someVariations),
- newMeasureBuilder().setVariation(someVariations),
- newMeasureBuilder().setQualityGateStatus(someQualityGateStatus),
- newMeasureBuilder().setQualityGateStatus(someQualityGateStatus).setVariation(someVariations),
- };
- }
@Test
public void apply_returns_true_for_value_true_for_Boolean_Metric_and_best_value_1() {
Predicate<Measure> underTest = BestValueOptimization.from(METRIC_BOOLEAN_TRUE, FILE_COMPONENT);
assertThat(underTest.test(newMeasureBuilder().create(true))).isTrue();
- assertThat(underTest.test(newMeasureBuilder().setVariation(SOME_EMPTY_VARIATIONS).create(true))).isTrue();
assertThat(underTest.test(newMeasureBuilder().create(false))).isFalse();
- assertThat(underTest.test(newMeasureBuilder().setVariation(SOME_EMPTY_VARIATIONS).create(false))).isFalse();
}
@Test
@@ -74,10 +59,9 @@ public class BestValueOptimizationTest {
public void apply_returns_false_if_measure_has_anything_else_than_value_for_Boolean_Metric_and_best_value_1() {
Predicate<Measure> underTest = BestValueOptimization.from(METRIC_BOOLEAN_TRUE, FILE_COMPONENT);
- for (Measure.NewMeasureBuilder builder : builders_of_non_bestValueOptimized_measures()) {
- assertThat(underTest.test(builder.create(true))).isFalse();
- assertThat(underTest.test(builder.create(false))).isFalse();
- }
+ Measure.NewMeasureBuilder builder = newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(Measure.Level.ERROR, null));
+ assertThat(underTest.test(builder.create(true))).isFalse();
+ assertThat(underTest.test(builder.create(false))).isFalse();
}
@Test
@@ -94,7 +78,6 @@ public class BestValueOptimizationTest {
assertThat(underTest.test(newMeasureBuilder().create(true))).isFalse();
assertThat(underTest.test(newMeasureBuilder().create(false))).isTrue();
- assertThat(underTest.test(newMeasureBuilder().setVariation(SOME_EMPTY_VARIATIONS).create(false))).isTrue();
}
@Test
@@ -109,10 +92,9 @@ public class BestValueOptimizationTest {
public void apply_returns_false_if_measure_has_anything_else_than_value_for_Boolean_Metric_and_best_value_not_1() {
Predicate<Measure> underTest = BestValueOptimization.from(METRIC_BOOLEAN_FALSE, FILE_COMPONENT);
- for (Measure.NewMeasureBuilder builder : builders_of_non_bestValueOptimized_measures()) {
- assertThat(underTest.test(builder.create(true))).isFalse();
- assertThat(underTest.test(builder.create(false))).isFalse();
- }
+ Measure.NewMeasureBuilder builder = newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(Measure.Level.ERROR, null));
+ assertThat(underTest.test(builder.create(true))).isFalse();
+ assertThat(underTest.test(builder.create(false))).isFalse();
}
@Test
@@ -128,7 +110,6 @@ public class BestValueOptimizationTest {
Predicate<Measure> underTest = BestValueOptimization.from(createMetric(Metric.MetricType.INT, 10), FILE_COMPONENT);
assertThat(underTest.test(newMeasureBuilder().create(10))).isTrue();
- assertThat(underTest.test(newMeasureBuilder().setVariation(SOME_EMPTY_VARIATIONS).create(10))).isTrue();
assertThat(underTest.test(newMeasureBuilder().create(11))).isFalse();
}
@@ -137,7 +118,6 @@ public class BestValueOptimizationTest {
Predicate<Measure> underTest = BestValueOptimization.from(createMetric(Metric.MetricType.WORK_DUR, 9511L), FILE_COMPONENT);
assertThat(underTest.test(newMeasureBuilder().create(9511L))).isTrue();
- assertThat(underTest.test(newMeasureBuilder().setVariation(SOME_EMPTY_VARIATIONS).create(9511L))).isTrue();
assertThat(underTest.test(newMeasureBuilder().create(963L))).isFalse();
}
@@ -146,9 +126,7 @@ public class BestValueOptimizationTest {
Predicate<Measure> underTest = BestValueOptimization.from(createMetric(Metric.MetricType.RATING, A.getIndex()), FILE_COMPONENT);
assertThat(underTest.test(newMeasureBuilder().create(A.getIndex()))).isTrue();
- assertThat(underTest.test(newMeasureBuilder().setVariation(A.getIndex()).createNoValue())).isTrue();
assertThat(underTest.test(newMeasureBuilder().create(B.getIndex()))).isFalse();
- assertThat(underTest.test(newMeasureBuilder().setVariation(B.getIndex()).createNoValue())).isFalse();
}
@Test
@@ -156,7 +134,6 @@ public class BestValueOptimizationTest {
Predicate<Measure> underTest = BestValueOptimization.from(createMetric(Metric.MetricType.FLOAT, 36.5d), FILE_COMPONENT);
assertThat(underTest.test(newMeasureBuilder().create(36.5d, 1))).isTrue();
- assertThat(underTest.test(newMeasureBuilder().setVariation(SOME_EMPTY_VARIATIONS).create(36.5d, 1))).isTrue();
assertThat(underTest.test(newMeasureBuilder().create(36.6d, 1))).isFalse();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
index 1026bb9a684..9786ed4fc3c 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
@@ -19,9 +19,7 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.Optional;
import org.assertj.core.data.Offset;
import org.junit.Test;
@@ -42,12 +40,8 @@ public class LiveMeasureDtoToMeasureTest {
private static final Metric SOME_STRING_METRIC = new MetricImpl("42", "string", "name", Metric.MetricType.STRING);
private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl("42", "boolean", "name", Metric.MetricType.BOOL);
private static final Metric SOME_LEVEL_METRIC = new MetricImpl("42", "level", "name", Metric.MetricType.LEVEL);
-
- private static final String SOME_DATA = "some_data man!";
- private static final String SOME_ALERT_TEXT = "some alert text_be_careFul!";
private static final LiveMeasureDto EMPTY_MEASURE_DTO = new LiveMeasureDto();
-
private LiveMeasureDtoToMeasure underTest = new LiveMeasureDtoToMeasure();
@Test
@@ -190,41 +184,6 @@ public class LiveMeasureDtoToMeasureTest {
assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
}
- @DataProvider
- public static Object[][] all_types_LiveMeasureDtos() {
- return new Object[][] {
- {new LiveMeasureDto().setValue(1d), SOME_BOOLEAN_METRIC},
- {new LiveMeasureDto().setValue(1d), SOME_INT_METRIC},
- {new LiveMeasureDto().setValue(1d), SOME_LONG_METRIC},
- {new LiveMeasureDto().setValue(1d), SOME_DOUBLE_METRIC},
- {new LiveMeasureDto().setData("1"), SOME_STRING_METRIC},
- {new LiveMeasureDto().setData(Level.OK.name()), SOME_LEVEL_METRIC}
- };
- }
-
- @Test
- @UseDataProvider("all_types_LiveMeasureDtos")
- public void toMeasure_creates_no_MeasureVariation_if_dto_has_none_whichever_the_ValueType(LiveMeasureDto LiveMeasureDto, Metric metric) {
- assertThat(underTest.toMeasure(LiveMeasureDto, metric).get().hasVariation()).isFalse();
- }
-
- @Test
- @UseDataProvider("all_types_LiveMeasureDtos")
- public void toMeasure_creates_MeasureVariation_and_maps_the_right_one(LiveMeasureDto builder, Metric metric) {
- assertThat(underTest.toMeasure(builder.setVariation(1d), metric).get().getVariation()).isOne();
- }
-
- @Test
- public void toMeasure_creates_MeasureVariation_and_maps_the_right_one() {
- LiveMeasureDto LiveMeasureDto = new LiveMeasureDto()
- .setData("1")
- .setVariation(2d);
-
- Optional<Measure> measure = underTest.toMeasure(LiveMeasureDto, SOME_STRING_METRIC);
-
- assertThat(measure.get().getVariation()).isEqualTo(2);
- }
-
@Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
index 29156db000c..810eecc2312 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
@@ -298,29 +298,6 @@ public class MeasureDtoToMeasureTest {
}
@Test
- @UseDataProvider("all_types_MeasureDtos")
- public void toMeasure_creates_no_MeasureVariation_if_dto_has_none_whichever_the_ValueType(MeasureDto measureDto, Metric metric) {
- assertThat(underTest.toMeasure(measureDto, metric).get().hasVariation()).isFalse();
- }
-
- @Test
- @UseDataProvider("all_types_MeasureDtos")
- public void toMeasure_creates_MeasureVariation_and_maps_the_right_one(MeasureDto builder, Metric metric) {
- assertThat(underTest.toMeasure(builder.setVariation(1d), metric).get().getVariation()).isOne();
- }
-
- @Test
- public void toMeasure_creates_MeasureVariation_and_maps_the_right_one() {
- MeasureDto measureDto = new MeasureDto()
- .setData("1")
- .setVariation(2d);
-
- Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_STRING_METRIC);
-
- assertThat(measure.get().getVariation()).isEqualTo(2);
- }
-
- @Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
MeasureDto measureDto = new MeasureDto()
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java
index cfb2b5f308e..9131d5122cd 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java
@@ -252,19 +252,12 @@ public class MeasureTest {
}
@Test
- public void updateMeasureBuilder_setVariations_throws_USO_if_measure_already_has_Variations() {
- assertThatThrownBy(() -> Measure.updatedMeasureBuilder(newMeasureBuilder().setVariation(1d).createNoValue()).setVariation(2d))
- .isInstanceOf(UnsupportedOperationException.class);
- }
-
- @Test
@UseDataProvider("all")
public void updateMeasureBuilder_creates_Measure_with_same_immutable_properties(Measure measure) {
Measure newMeasure = Measure.updatedMeasureBuilder(measure).create();
assertThat(newMeasure.getValueType()).isEqualTo(measure.getValueType());
assertThat(newMeasure.hasQualityGateStatus()).isEqualTo(measure.hasQualityGateStatus());
- assertThat(newMeasure.hasVariation()).isEqualTo(measure.hasVariation());
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
index 0a9158cb922..ca73796327a 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
@@ -43,7 +43,6 @@ public class MeasureToMeasureDtoTest {
private static final MetricImpl SOME_METRIC = new MetricImpl("42", "metric_key", "metric_name", Metric.MetricType.STRING);
private static final String SOME_DATA = "some_data";
private static final String SOME_STRING = "some_string";
- private static final double SOME_VARIATIONS = 1d;
private static final MetricImpl SOME_BOOLEAN_METRIC = new MetricImpl("1", "1", "1", Metric.MetricType.BOOL);
private static final MetricImpl SOME_INT_METRIC = new MetricImpl("2", "2", "2", Metric.MetricType.INT);
private static final MetricImpl SOME_LONG_METRIC = new MetricImpl("3", "3", "3", Metric.MetricType.DISTRIB);
@@ -92,21 +91,6 @@ public class MeasureToMeasureDtoTest {
@Test
@UseDataProvider("all_types_Measures")
- public void toMeasureDto_returns_Dto_without_any_variation_if_Measure_has_no_MeasureVariations(Measure measure, Metric metric) {
- MeasureDto measureDto = underTest.toMeasureDto(measure, metric, SOME_COMPONENT);
-
- assertThat(measureDto.getVariation()).isNull();
- }
-
- @Test
- public void toMeasureDto_returns_Dto_with_variation_if_Measure_has_MeasureVariations() {
- MeasureDto measureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().setVariation(SOME_VARIATIONS).create(SOME_STRING), SOME_STRING_METRIC, SOME_COMPONENT);
-
- assertThat(measureDto.getVariation()).isEqualTo(1d);
- }
-
- @Test
- @UseDataProvider("all_types_Measures")
public void toMeasureDto_returns_Dto_without_alertStatus_nor_alertText_if_Measure_has_no_QualityGateStatus(Measure measure, Metric metric) {
MeasureDto measureDto = underTest.toMeasureDto(measure, metric, SOME_COMPONENT);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
index 1438d697713..853a5c3d5b6 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
@@ -35,16 +35,15 @@ import static com.google.common.collect.FluentIterable.from;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.fail;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK;
+import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.BOOL;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.DATA;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.DISTRIB;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.FLOAT;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.INT;
-import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.LEVEL;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.PERCENT;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.RATING;
import static org.sonar.ce.task.projectanalysis.metric.Metric.MetricType.STRING;
@@ -159,44 +158,6 @@ public class ConditionEvaluatorTest {
}
@Test
- @UseDataProvider("numericNewMetricTypes")
- public void test_condition_on_numeric_new_metric(MetricType metricType) {
- Metric metric = createNewMetric(metricType);
- Measure measure = newMeasureBuilder().setVariation(3d).createNoValue();
-
- assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3"), measure)).hasLevel(OK);
- assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2"), measure)).hasLevel(ERROR);
- }
-
- @Test
- @UseDataProvider("numericNewMetricTypes")
- public void condition_on_new_metric_without_value_is_OK(MetricType metricType) {
- Metric metric = createNewMetric(metricType);
- Measure measure = newMeasureBuilder().createNoValue();
-
- assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3"), measure)).hasLevel(OK).hasValue(null);
- }
-
- @DataProvider
- public static Object[][] numericNewMetricTypes() {
- return new Object[][] {
- {FLOAT},
- {INT},
- {WORK_DUR},
- };
- }
-
- @Test
- public void fail_when_condition_on_leak_period_is_using_unsupported_metric() {
- Metric metric = createNewMetric(LEVEL);
- Measure measure = newMeasureBuilder().setVariation(0d).createNoValue();
-
- assertThatThrownBy(() -> underTest.evaluate(new Condition(metric, LESS_THAN.getDbValue(), "3"), measure))
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Unsupported metric type LEVEL");
- }
-
- @Test
public void test_condition_on_rating() {
Metric metric = createMetric(RATING);
Measure measure = newMeasureBuilder().create(4, "D");
@@ -212,8 +173,4 @@ public class ConditionEvaluatorTest {
private static MetricImpl createMetric(MetricType metricType) {
return new MetricImpl("1", "key", "name", metricType);
}
-
- private static MetricImpl createNewMetric(MetricType metricType) {
- return new MetricImpl("1", "new_key", "name", metricType);
- }
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java
index bd54b6c5353..75a5d5f26b7 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java
@@ -64,7 +64,7 @@ import static org.sonar.ce.task.projectanalysis.measure.MeasureAssert.assertThat
import static org.sonar.server.measure.Rating.A;
import static org.sonar.server.measure.Rating.D;
-public class NewMaintainabilityMeasuresVisitorTest {
+public class NewMaintainabilityMeasuresVisitorTest {
private static final double[] RATING_GRID = new double[] {0.1, 0.2, 0.5, 1};
@@ -72,7 +72,7 @@ public class NewMaintainabilityMeasuresVisitorTest {
private static final long LANGUAGE_1_DEV_COST = 30L;
private static final int ROOT_REF = 1;
private static final int LANGUAGE_1_FILE_REF = 11111;
- private static final Offset<Double> VARIATION_COMPARISON_OFFSET = Offset.offset(0.01);
+ private static final Offset<Double> VALUE_COMPARISON_OFFSET = Offset.offset(0.01);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@@ -422,8 +422,8 @@ public class NewMaintainabilityMeasuresVisitorTest {
return ReportComponent.builder(type, ref).setKey(String.valueOf(ref));
}
- private Measure createNewDebtMeasure(double variation) {
- return newMeasureBuilder().setVariation(variation).createNoValue();
+ private Measure createNewDebtMeasure(long value) {
+ return newMeasureBuilder().create(value);
}
private static Measure createNclocDataMeasure(Integer... nclocLines) {
@@ -449,16 +449,16 @@ public class NewMaintainabilityMeasuresVisitorTest {
.isAbsent();
}
- private void assertNewDebtRatioValues(int componentRef, double expectedVariation) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SQALE_DEBT_RATIO_KEY)).hasVariation(expectedVariation, VARIATION_COMPARISON_OFFSET);
+ private void assertNewDebtRatioValues(int componentRef, double expectedValue) {
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SQALE_DEBT_RATIO_KEY)).hasValue(expectedValue, VALUE_COMPARISON_OFFSET);
}
- private void assertNewDevelopmentCostValues(int componentRef, long expectedVariation) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_DEVELOPMENT_COST_KEY)).hasVariation(expectedVariation, VARIATION_COMPARISON_OFFSET);
+ private void assertNewDevelopmentCostValues(int componentRef, float expectedValue) {
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_DEVELOPMENT_COST_KEY)).hasValue(expectedValue, VALUE_COMPARISON_OFFSET);
}
- private void assertNewMaintainability(int componentRef, Rating expectedVariation) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_MAINTAINABILITY_RATING_KEY)).hasVariation(expectedVariation.getIndex());
+ private void assertNewMaintainability(int componentRef, Rating expectedValue) {
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_MAINTAINABILITY_RATING_KEY)).hasValue(expectedValue.getIndex());
}
private void assertNoNewMaintainability(int componentRef) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java
index ced065021fc..259d5377aed 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java
@@ -322,8 +322,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitorTest {
}
private void verifyAddedRawMeasureOnLeakPeriod(int componentRef, String metricKey, Rating rating) {
- MeasureAssert.assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey))
- .hasVariation(rating.getIndex());
+ MeasureAssert.assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)).hasValue(rating.getIndex());
}
private DefaultIssue newBugIssue(long effort, String severity) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java
index 292e73edd61..174e056486a 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java
@@ -70,7 +70,7 @@ import static org.sonar.server.measure.Rating.D;
import static org.sonar.server.measure.Rating.E;
public class NewSecurityReviewMeasuresVisitorTest {
- private static final Offset<Double> VARIATION_COMPARISON_OFFSET = Offset.offset(0.01);
+ private static final Offset<Double> VALUE_COMPARISON_OFFSET = Offset.offset(0.01);
private static final String LANGUAGE_KEY_1 = "lKey1";
private static final int PROJECT_REF = 1;
@@ -341,10 +341,10 @@ public class NewSecurityReviewMeasuresVisitorTest {
}
private void verifyRatingAndReviewedMeasures(int componentRef, Rating expectedReviewRating, @Nullable Double expectedHotspotsReviewed) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_REVIEW_RATING_KEY)).hasVariation(expectedReviewRating.getIndex());
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_REVIEW_RATING_KEY)).hasValue(expectedReviewRating.getIndex());
if (expectedHotspotsReviewed != null) {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY)).hasVariation(expectedHotspotsReviewed,
- VARIATION_COMPARISON_OFFSET);
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY)).hasValue(expectedHotspotsReviewed,
+ VALUE_COMPARISON_OFFSET);
} else {
assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY)).isAbsent();
}
@@ -354,12 +354,12 @@ public class NewSecurityReviewMeasuresVisitorTest {
if (hotspotsReviewed == null) {
Assertions.assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY)).isEmpty();
} else {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY)).hasVariation(hotspotsReviewed);
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY)).hasValue(hotspotsReviewed);
}
if (hotspotsReviewed == null) {
Assertions.assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS_KEY)).isEmpty();
} else {
- assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS_KEY)).hasVariation(hotspotsToReview);
+ assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS_KEY)).hasValue(hotspotsToReview);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStepTest.java
index e2f16909b0c..f0599de2bfa 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStepTest.java
@@ -179,10 +179,10 @@ public class NewCoverageMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_COMPONENT.getReportAttributes().getRef()))).contains(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(2d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(1d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(0d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(0d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(2)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(1)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(0)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(0)));
}
@Test
@@ -204,36 +204,36 @@ public class NewCoverageMeasuresStepTest {
// files
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).contains(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(3d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(7d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(4d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(3)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(7)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(4)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).contains(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(4d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(27d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(14d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(4)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(27)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(14)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_3_REF))).contains(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(2d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(17d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(9d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(2)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(17)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(9)));
// directories
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_1_REF))).contains(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(3d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(7d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(4d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(3)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(7)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(4)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_2_REF))).contains(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(10d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(6d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(44d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(23d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(10)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(6)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(44)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(23)));
// submodule
- MeasureRepoEntry[] repoEntriesFromProject = {entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(15d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(9d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(51d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(27d))};
+ MeasureRepoEntry[] repoEntriesFromProject = {entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(15)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(9)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(51)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(27))};
// project
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(repoEntriesFromProject);
}
@@ -266,15 +266,15 @@ public class NewCoverageMeasuresStepTest {
private void verify_aggregates_variations(LinesAndConditionsWithUncoveredMetricKeys metricKeys, String codeCoverageKey, String lineCoverageKey, String branchCoverageKey) {
treeRootHolder.setRoot(MULTIPLE_FILES_TREE);
measureRepository
- .addRawMeasure(FILE_1_REF, metricKeys.getLines(), createMeasure(3000d))
- .addRawMeasure(FILE_1_REF, metricKeys.getConditions(), createMeasure(300d))
- .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredLines(), createMeasure(30d))
- .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9d))
+ .addRawMeasure(FILE_1_REF, metricKeys.getLines(), createMeasure(3000))
+ .addRawMeasure(FILE_1_REF, metricKeys.getConditions(), createMeasure(300))
+ .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredLines(), createMeasure(30))
+ .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9))
- .addRawMeasure(FILE_2_REF, metricKeys.getLines(), createMeasure(2000d))
- .addRawMeasure(FILE_2_REF, metricKeys.getConditions(), createMeasure(400d))
- .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d))
- .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d));
+ .addRawMeasure(FILE_2_REF, metricKeys.getLines(), createMeasure(2000))
+ .addRawMeasure(FILE_2_REF, metricKeys.getConditions(), createMeasure(400))
+ .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), createMeasure(200))
+ .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16));
underTest.execute(new TestComputationStepContext());
@@ -309,10 +309,10 @@ public class NewCoverageMeasuresStepTest {
private void verify_only_zero_measures_on_new_lines_and_conditions_measures(Component component) {
assertThat(toEntries(measureRepository.getAddedRawMeasures(component.getReportAttributes().getRef()))).containsOnly(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(0d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(0d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(0d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(0d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(0)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(0)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(0)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(0)));
}
private static final class LineCoverageValues {
@@ -334,16 +334,18 @@ public class NewCoverageMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_COMPONENT.getReportAttributes().getRef()))).contains(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(3d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(7d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(4d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(5)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(3)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(7)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(4)));
}
- private static Measure createMeasure(Double expectedVariation) {
- return newMeasureBuilder()
- .setVariation(expectedVariation)
- .createNoValue();
+ private static Measure createMeasure(int expectedValue) {
+ return newMeasureBuilder().create(expectedValue);
+ }
+
+ private static Measure createMeasure(double expectedValue) {
+ return newMeasureBuilder().create(expectedValue);
}
private void setNewLines(Component c, Integer... lines) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java
index 48ec1d6df0b..62d518e53b2 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStepTest.java
@@ -103,13 +103,13 @@ public class NewSizeMeasuresStepTest {
setNewLines(FILE_1, FILE_2, FILE_4);
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_LINES_KEY, 11);
- assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_LINES_KEY, 11);
+ assertRawMeasureValue(FILE_1_REF, NEW_LINES_KEY, 11);
+ assertRawMeasureValue(FILE_2_REF, NEW_LINES_KEY, 11);
assertNoRawMeasure(FILE_3_REF, NEW_LINES_KEY);
- assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_LINES_KEY, 11);
- assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_LINES_KEY, 22);
+ assertRawMeasureValue(FILE_4_REF, NEW_LINES_KEY, 11);
+ assertRawMeasureValue(DIRECTORY_REF, NEW_LINES_KEY, 22);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_LINES_KEY);
- assertRawMeasureValueOnPeriod(ROOT_REF, NEW_LINES_KEY, 33);
+ assertRawMeasureValue(ROOT_REF, NEW_LINES_KEY, 33);
}
@Test
@@ -118,13 +118,13 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_LINES_KEY, 2);
- assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_LINES_KEY, 2);
+ assertRawMeasureValue(FILE_1_REF, NEW_LINES_KEY, 2);
+ assertRawMeasureValue(FILE_2_REF, NEW_LINES_KEY, 2);
assertNoRawMeasure(FILE_3_REF, NEW_LINES_KEY);
- assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_LINES_KEY, 2);
- assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_LINES_KEY, 4);
+ assertRawMeasureValue(FILE_4_REF, NEW_LINES_KEY, 2);
+ assertRawMeasureValue(DIRECTORY_REF, NEW_LINES_KEY, 4);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_LINES_KEY);
- assertRawMeasureValueOnPeriod(ROOT_REF, NEW_LINES_KEY, 6);
+ assertRawMeasureValue(ROOT_REF, NEW_LINES_KEY, 6);
}
@Test
@@ -141,7 +141,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2);
}
@Test
@@ -152,7 +152,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d);
+ assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1);
}
@Test
@@ -163,7 +163,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d);
+ assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1);
}
@Test
@@ -174,7 +174,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 6d);
+ assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 6);
}
@Test
@@ -186,7 +186,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 11d);
+ assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 11);
}
@Test
@@ -198,13 +198,13 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
- assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0d);
- assertRawMeasureValueOnPeriod(FILE_3_REF, NEW_DUPLICATED_LINES_KEY, 9d);
- assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 11d);
- assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2);
+ assertRawMeasureValue(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0);
+ assertRawMeasureValue(FILE_3_REF, NEW_DUPLICATED_LINES_KEY, 9);
+ assertRawMeasureValue(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 11);
+ assertRawMeasureValue(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_DUPLICATED_LINES_KEY);
- assertRawMeasureValueOnPeriod(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 22d);
+ assertRawMeasureValue(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 22);
}
@Test
@@ -217,13 +217,13 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
- assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0d);
- assertRawMeasureValueOnPeriod(FILE_3_REF, NEW_DUPLICATED_LINES_KEY, 2d);
- assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 2d);
- assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2);
+ assertRawMeasureValue(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0);
+ assertRawMeasureValue(FILE_3_REF, NEW_DUPLICATED_LINES_KEY, 2);
+ assertRawMeasureValue(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 2);
+ assertRawMeasureValue(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_DUPLICATED_LINES_KEY);
- assertRawMeasureValueOnPeriod(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 6d);
+ assertRawMeasureValue(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 6);
}
@Test
@@ -243,7 +243,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
+ assertRawMeasureValue(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
}
@Test
@@ -254,7 +254,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
+ assertRawMeasureValue(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
}
@Test
@@ -264,7 +264,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1);
+ assertRawMeasureValue(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1);
}
@Test
@@ -274,7 +274,7 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1);
+ assertRawMeasureValue(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1);
}
@Test
@@ -286,12 +286,12 @@ public class NewSizeMeasuresStepTest {
underTest.execute(new TestComputationStepContext());
- assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 10);
- assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_BLOCKS_DUPLICATED_KEY, 2);
- assertRawMeasureValueOnPeriod(FILE_3_REF, NEW_BLOCKS_DUPLICATED_KEY, 0);
- assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_BLOCKS_DUPLICATED_KEY, 6);
- assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_BLOCKS_DUPLICATED_KEY, 12);
- assertRawMeasureValueOnPeriod(ROOT_REF, NEW_BLOCKS_DUPLICATED_KEY, 18);
+ assertRawMeasureValue(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 10);
+ assertRawMeasureValue(FILE_2_REF, NEW_BLOCKS_DUPLICATED_KEY, 2);
+ assertRawMeasureValue(FILE_3_REF, NEW_BLOCKS_DUPLICATED_KEY, 0);
+ assertRawMeasureValue(FILE_4_REF, NEW_BLOCKS_DUPLICATED_KEY, 6);
+ assertRawMeasureValue(DIRECTORY_REF, NEW_BLOCKS_DUPLICATED_KEY, 12);
+ assertRawMeasureValue(ROOT_REF, NEW_BLOCKS_DUPLICATED_KEY, 18);
}
@Test
@@ -358,22 +358,23 @@ public class NewSizeMeasuresStepTest {
}
}
- private void assertRawMeasureValueOnPeriod(int componentRef, String metricKey, double expectedVariation) {
- assertRawMeasureValue(componentRef, metricKey, expectedVariation);
+ private void assertRawMeasureValue(int componentRef, String metricKey, int expectedValue) {
+ int value = measureRepository.getAddedRawMeasure(componentRef, metricKey).get().getIntValue();
+ assertThat(value).isEqualTo(expectedValue);
}
- private void assertRawMeasureValue(int componentRef, String metricKey, double expectedVariation) {
- double variation = measureRepository.getAddedRawMeasure(componentRef, metricKey).get().getVariation();
- assertThat(variation).isEqualTo(expectedVariation, DEFAULT_OFFSET);
+ private void assertRawMeasureValue(int componentRef, String metricKey, double expectedValue) {
+ double value = measureRepository.getAddedRawMeasure(componentRef, metricKey).get().getDoubleValue();
+ assertThat(value).isEqualTo(expectedValue, DEFAULT_OFFSET);
}
private void assertComputedAndAggregatedToZeroInt(String metricKey) {
- assertRawMeasureValueOnPeriod(FILE_1_REF, metricKey, 0);
- assertRawMeasureValueOnPeriod(FILE_2_REF, metricKey, 0);
- assertRawMeasureValueOnPeriod(FILE_3_REF, metricKey, 0);
- assertRawMeasureValueOnPeriod(FILE_4_REF, metricKey, 0);
- assertRawMeasureValueOnPeriod(DIRECTORY_REF, metricKey, 0);
- assertRawMeasureValueOnPeriod(ROOT_REF, metricKey, 0);
+ assertRawMeasureValue(FILE_1_REF, metricKey, 0);
+ assertRawMeasureValue(FILE_2_REF, metricKey, 0);
+ assertRawMeasureValue(FILE_3_REF, metricKey, 0);
+ assertRawMeasureValue(FILE_4_REF, metricKey, 0);
+ assertRawMeasureValue(DIRECTORY_REF, metricKey, 0);
+ assertRawMeasureValue(ROOT_REF, metricKey, 0);
}
private void assertNoRawMeasure(int componentRef, String metricKey) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
index a4a2a343b2b..47938c2cbd4 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
@@ -135,13 +135,12 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest {
@Test
public void measures_on_new_code_period_are_persisted() {
prepareProject();
- measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().setVariation(42.0).createNoValue());
+ measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().create(42.0));
step().execute(context);
LiveMeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get();
- assertThat(persistedMeasure.getValue()).isNull();
- assertThat(persistedMeasure.getVariation()).isEqualTo(42.0);
+ assertThat(persistedMeasure.getValue()).isEqualTo(42.0);
verifyStatistics(context, 1);
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
index c293d0a4538..d34e61d7f0c 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
@@ -136,13 +136,12 @@ public class PersistMeasuresStepTest extends BaseStepTest {
@Test
public void measures_on_new_code_period_are_persisted() {
prepareProject();
- measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().setVariation(42.0).createNoValue());
+ measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().create(42.0));
TestComputationStepContext context = execute();
MeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get();
- assertThat(persistedMeasure.getValue()).isNull();
- assertThat(persistedMeasure.getVariation()).isEqualTo(42.0);
+ assertThat(persistedMeasure.getValue()).isEqualTo(42.0);
assertNbOfInserts(context, 1);
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
index 01b5000b00d..88557dd807b 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
@@ -261,9 +261,7 @@ public class QualityGateMeasuresStepTest {
Condition periodCondition = createLessThanCondition(INT_METRIC_1, "1");
qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(fixedCondition, periodCondition)));
- Measure measure = newMeasureBuilder()
- .setVariation(rawValue)
- .create(rawValue, null);
+ Measure measure = newMeasureBuilder().create(rawValue);
measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, measure);
underTest.execute(new TestComputationStepContext());
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCaseTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCaseTest.java
index 2a57b37d21a..2ca91cf3219 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCaseTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCaseTest.java
@@ -66,7 +66,7 @@ public class SmallChangesetQualityGateSpecialCaseTest {
mapSettings.setProperty(CoreProperties.QUALITY_GATE_IGNORE_SMALL_CHANGES, true);
QualityGateMeasuresStep.MetricEvaluationResult metricEvaluationResult = generateEvaluationResult(NEW_COVERAGE_KEY, ERROR);
Component project = generateNewRootProject();
- measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().setVariation(19).create(1000));
+ measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().create(19));
boolean result = underTest.appliesTo(project, metricEvaluationResult);
@@ -78,7 +78,7 @@ public class SmallChangesetQualityGateSpecialCaseTest {
mapSettings.setProperty(CoreProperties.QUALITY_GATE_IGNORE_SMALL_CHANGES, false);
QualityGateMeasuresStep.MetricEvaluationResult metricEvaluationResult = generateEvaluationResult(NEW_COVERAGE_KEY, ERROR);
Component project = generateNewRootProject();
- measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().setVariation(19).create(1000));
+ measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().create(19));
boolean result = underTest.appliesTo(project, metricEvaluationResult);
@@ -89,7 +89,7 @@ public class SmallChangesetQualityGateSpecialCaseTest {
public void should_not_change_for_bigger_changesets() {
QualityGateMeasuresStep.MetricEvaluationResult metricEvaluationResult = generateEvaluationResult(NEW_COVERAGE_KEY, ERROR);
Component project = generateNewRootProject();
- measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().setVariation(20).create(1000));
+ measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().create(20));
boolean result = underTest.appliesTo(project, metricEvaluationResult);
@@ -100,7 +100,7 @@ public class SmallChangesetQualityGateSpecialCaseTest {
public void should_not_change_issue_related_metrics() {
QualityGateMeasuresStep.MetricEvaluationResult metricEvaluationResult = generateEvaluationResult(NEW_BUGS_KEY, ERROR);
Component project = generateNewRootProject();
- measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().setVariation(19).create(1000));
+ measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().create(19));
boolean result = underTest.appliesTo(project, metricEvaluationResult);
@@ -111,7 +111,7 @@ public class SmallChangesetQualityGateSpecialCaseTest {
public void should_not_change_green_conditions() {
QualityGateMeasuresStep.MetricEvaluationResult metricEvaluationResult = generateEvaluationResult(NEW_BUGS_KEY, OK);
Component project = generateNewRootProject();
- measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().setVariation(19).create(1000));
+ measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().create(19));
boolean result = underTest.appliesTo(project, metricEvaluationResult);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java
index acaaafa00dd..05800d8cf9c 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java
@@ -70,8 +70,8 @@ public class ExportLiveMeasuresStepTest {
public void export_measures() {
ComponentDto project = createProject(true);
componentRepository.register(1, project.uuid(), false);
- MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()));
- dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(4711.0d).setVariation(null));
+ MetricDto metric = dbTester.measures().insertMetric(m -> m.setKey("metric1").setValueType(INT.name()));
+ dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(4711.0d));
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(project));
when(projectHolder.branches()).thenReturn(newArrayList(new BranchDto()
.setProjectUuid(project.uuid())
@@ -131,8 +131,8 @@ public class ExportLiveMeasuresStepTest {
public void test_exported_fields() {
ComponentDto project = createProject(true);
componentRepository.register(1, project.uuid(), false);
- MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()));
- dbTester.measures().insertLiveMeasure(project, metric, m -> m.setProjectUuid(project.uuid()).setValue(4711.0d).setData("test").setVariation(7.0d));
+ MetricDto metric = dbTester.measures().insertMetric(m -> m.setKey("new_metric").setValueType(INT.name()));
+ dbTester.measures().insertLiveMeasure(project, metric, m -> m.setProjectUuid(project.uuid()).setValue(7.0d).setData("test"));
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(project));
when(projectHolder.branches()).thenReturn(newArrayList(new BranchDto()
.setProjectUuid(project.uuid())
@@ -154,7 +154,7 @@ public class ExportLiveMeasuresStepTest {
.containsOnly(tuple(
1L,
0,
- 4711.0d,
+ 0.0d,
"test",
7.0d));
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
@@ -166,7 +166,7 @@ public class ExportLiveMeasuresStepTest {
ComponentDto project = createProject(true);
componentRepository.register(1, project.uuid(), false);
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()));
- dbTester.measures().insertLiveMeasure(project, metric, m -> m.setProjectUuid(project.uuid()).setValue(null).setData((String) null).setVariation(null));
+ dbTester.measures().insertLiveMeasure(project, metric, m -> m.setProjectUuid(project.uuid()).setValue(null).setData((String) null));
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(project));
when(projectHolder.branches()).thenReturn(newArrayList(new BranchDto()
.setProjectUuid(project.uuid())
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java
index faccb9279b3..60e51e242a6 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java
@@ -82,6 +82,12 @@ public class ExportMeasuresStepTest {
.setShortName("Coverage")
.setEnabled(false);
+ private static final MetricDto NEW_NCLOC = new MetricDto()
+ .setUuid("5")
+ .setKey("new_ncloc")
+ .setShortName("New Lines of code")
+ .setEnabled(true);
+
private static final List<BranchDto> BRANCHES = newArrayList(
new BranchDto()
.setBranchType(BranchType.BRANCH)
@@ -107,7 +113,7 @@ public class ExportMeasuresStepTest {
String projectUuid = dbTester.components().insertPublicProject(PROJECT).uuid();
componentRepository.register(1, projectUuid, false);
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), FILE, ANOTHER_PROJECT);
- dbTester.getDbClient().metricDao().insert(dbTester.getSession(), NCLOC, DISABLED_METRIC);
+ dbTester.getDbClient().metricDao().insert(dbTester.getSession(), NCLOC, DISABLED_METRIC, NEW_NCLOC);
dbTester.commit();
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(PROJECT));
when(projectHolder.branches()).thenReturn(BRANCHES);
@@ -174,8 +180,7 @@ public class ExportMeasuresStepTest {
.setValue(100.0)
.setData("data")
.setAlertStatus("OK")
- .setAlertText("alert text")
- .setVariation(1.0);
+ .setAlertText("alert text");
insertMeasure(analysis, PROJECT, dto);
dbTester.commit();
@@ -189,7 +194,32 @@ public class ExportMeasuresStepTest {
assertThat(measure.getTextValue()).isEqualTo(dto.getData());
assertThat(measure.getMetricRef()).isZero();
assertThat(measure.getAnalysisUuid()).isEqualTo(analysis.getUuid());
- assertThat(measure.getVariation1().getValue()).isEqualTo(dto.getVariation());
+ assertThat(measure.getVariation1().getValue()).isZero();
+ }
+
+ @Test
+ public void test_exported_fields_new_metric() {
+ SnapshotDto analysis = insertSnapshot("U_1", PROJECT, STATUS_PROCESSED);
+ MeasureDto dto = new MeasureDto()
+ .setMetricUuid(NEW_NCLOC.getUuid())
+ .setValue(100.0)
+ .setData("data")
+ .setAlertStatus("OK")
+ .setAlertText("alert text");
+ insertMeasure(analysis, PROJECT, dto);
+ dbTester.commit();
+
+ underTest.execute(new TestComputationStepContext());
+
+ List<ProjectDump.Measure> exportedMeasures = dumpWriter.getWrittenMessagesOf(DumpElement.MEASURES);
+ ProjectDump.Measure measure = exportedMeasures.get(0);
+ assertThat(measure.getAlertStatus()).isEqualTo(dto.getAlertStatus());
+ assertThat(measure.getAlertText()).isEqualTo(dto.getAlertText());
+ assertThat(measure.getDoubleValue().getValue()).isZero();
+ assertThat(measure.getTextValue()).isEqualTo(dto.getData());
+ assertThat(measure.getMetricRef()).isZero();
+ assertThat(measure.getAnalysisUuid()).isEqualTo(analysis.getUuid());
+ assertThat(measure.getVariation1().getValue()).isEqualTo(dto.getValue());
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java
index 400d3e927d8..10cc6bbc355 100644
--- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java
+++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java
@@ -89,6 +89,25 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> {
return this;
}
+ public MeasureAssert hasValue(double expected, Offset<Double> offset) {
+ isNotNull();
+
+ if (actual.getValueType() != Measure.ValueType.DOUBLE) {
+ failWithMessage(
+ "Expected Measure to have a double value and therefore its ValueType to be <%s> but was <%s>",
+ Measure.ValueType.DOUBLE, actual.getValueType());
+ }
+
+ double value = actual.getDoubleValue();
+ if (abs(expected - value) > offset.value) {
+ failWithMessage(
+ "Expected value of Measure to be close to <%s> by less than <%s> but was <%s>",
+ expected, offset.value, value);
+ }
+
+ return this;
+ }
+
public MeasureAssert hasValue(boolean expected) {
isNotNull();
@@ -197,46 +216,6 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> {
}
}
- public MeasureAssert hasVariation(double expected) {
- isNotNull();
- hasVariation();
-
- if (!actual.hasVariation()) {
- failWithMessage("Expected Measure to have a variation but it did not");
- }
-
- double variation = actual.getVariation();
- if (variation != expected) {
- failWithMessage("Expected variation of Measure to be <%s> but was <%s>", expected, variation);
- }
-
- return this;
- }
-
- public MeasureAssert hasVariation(double expected, Offset<Double> offset) {
- isNotNull();
- hasVariation();
-
- if (!actual.hasVariation()) {
- failWithMessage("Expected Measure to have a variation but it did not");
- }
-
- double variation = actual.getVariation();
- if (abs(expected - variation) > offset.value) {
- failWithMessage(
- "Expected variation of Measure to be close to <%s> by less than <%s> but was <%s>",
- expected, offset.value, variation);
- }
-
- return this;
- }
-
- private void hasVariation() {
- if (!actual.hasVariation()) {
- failWithMessage("Expected Measure to have a variation but it did not");
- }
- }
-
public void isAbsent() {
if (actual != null) {
failWithMessage("Expected measure to be absent");
diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepoEntry.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepoEntry.java
index 59809bfefa6..e3be5887f4a 100644
--- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepoEntry.java
+++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepoEntry.java
@@ -19,8 +19,6 @@
*/
package org.sonar.ce.task.projectanalysis.measure;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
@@ -73,7 +71,6 @@ public final class MeasureRepoEntry {
public static boolean deepEquals(Measure measure, Measure measure1) {
return measure.getValueType() == measure1.getValueType()
&& equalsByValue(measure, measure1)
- && equalsByVariation(measure, measure1)
&& equalsByQualityGateStatus(measure, measure1)
&& Objects.equals(measure.getData(), measure1.getData());
}
@@ -99,18 +96,6 @@ public final class MeasureRepoEntry {
}
}
- private static boolean equalsByVariation(Measure measure, Measure measure1) {
- return measure.hasVariation() == measure1.hasVariation() && (!measure.hasVariation()
- || Double.compare(scale(measure.getVariation()), scale(measure1.getVariation())) == 0);
- }
-
- private static final int DOUBLE_PRECISION = 1;
-
- private static double scale(double value) {
- BigDecimal bd = BigDecimal.valueOf(value);
- return bd.setScale(DOUBLE_PRECISION, RoundingMode.HALF_UP).doubleValue();
- }
-
private static boolean equalsByQualityGateStatus(Measure measure, Measure measure1) {
if (measure.hasQualityGateStatus() != measure1.hasQualityGateStatus()) {
return false;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java
index b4efadc12ec..7a6277851b4 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java
@@ -44,8 +44,6 @@ public class LiveMeasureDto {
private String textValue;
@Nullable
private byte[] data;
- @Nullable
- private Double variation;
void setUuidForUpsert(@Nullable String s) {
this.uuidForUpsert = s;
@@ -126,16 +124,6 @@ public class LiveMeasureDto {
return this;
}
- @CheckForNull
- public Double getVariation() {
- return variation;
- }
-
- public LiveMeasureDto setVariation(@Nullable Double variation) {
- this.variation = variation;
- return this;
- }
-
@Override
public String toString() {
StringBuilder sb = new StringBuilder("LiveMeasureDto{");
@@ -143,7 +131,6 @@ public class LiveMeasureDto {
sb.append(", projectUuid='").append(projectUuid).append('\'');
sb.append(", metricUuid=").append(metricUuid);
sb.append(", value=").append(value);
- sb.append(", variation=").append(variation);
sb.append(", textValue='").append(textValue).append('\'');
sb.append(", data=").append(Arrays.toString(data));
sb.append('}');
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
index c930a899a6e..d2a435d966b 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
@@ -31,7 +31,6 @@ public class MeasureDto {
private Double value;
private String textValue;
private byte[] dataValue;
- private Double variation;
private String alertStatus;
private String alertText;
private String componentUuid;
@@ -89,16 +88,6 @@ public class MeasureDto {
}
@CheckForNull
- public Double getVariation() {
- return variation;
- }
-
- public MeasureDto setVariation(@Nullable Double d) {
- variation = d;
- return this;
- }
-
- @CheckForNull
public String getAlertStatus() {
return alertStatus;
}
@@ -142,7 +131,6 @@ public class MeasureDto {
.add("value", value)
.add("textValue", textValue)
.add("dataValue", dataValue)
- .add("variation", variation)
.add("alertStatus", alertStatus)
.add("alertText", alertText)
.add("componentUuid", componentUuid)
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
index e4dba2dce99..45c5389bc33 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
@@ -79,18 +79,18 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
private static final String PROJECT_FILTER = " AND p.uuid=?";
- private static final String SQL_MEASURES = "SELECT m.name, pm.value, pm.variation, pm.text_value FROM live_measures pm " +
+ private static final String SQL_MEASURES = "SELECT m.name, pm.value, pm.text_value FROM live_measures pm " +
"INNER JOIN metrics m ON m.uuid = pm.metric_uuid " +
"WHERE pm.component_uuid = ? " +
"AND m.name IN ({metricNames}) " +
- "AND (pm.value IS NOT NULL OR pm.variation IS NOT NULL OR pm.text_value IS NOT NULL) " +
+ "AND (pm.value IS NOT NULL OR pm.text_value IS NOT NULL) " +
"AND m.enabled = ? ";
- private static final String SQL_NCLOC_LANGUAGE_DISTRIBUTION = "SELECT m.name, pm.value, pm.variation, pm.text_value FROM live_measures pm " +
+ private static final String SQL_NCLOC_LANGUAGE_DISTRIBUTION = "SELECT m.name, pm.value, pm.text_value FROM live_measures pm " +
"INNER JOIN metrics m ON m.uuid = pm.metric_uuid " +
"WHERE pm.component_uuid = ? " +
"AND m.name = ? " +
- "AND (pm.value IS NOT NULL OR pm.variation IS NOT NULL OR pm.text_value IS NOT NULL) " +
+ "AND (pm.value IS NOT NULL OR pm.text_value IS NOT NULL) " +
"AND m.enabled = ? ";
private static final String SQL_PROJECT_BRANCHES = "SELECT uuid FROM project_branches pb " +
@@ -109,8 +109,7 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
private static final boolean ENABLED = true;
private static final int FIELD_METRIC_NAME = 1;
private static final int FIELD_MEASURE_VALUE = 2;
- private static final int FIELD_MEASURE_VARIATION = 3;
- private static final int FIELD_MEASURE_TEXT_VALUE = 4;
+ private static final int FIELD_MEASURE_TEXT_VALUE = 3;
private final DbSession dbSession;
private final PreparedStatement measuresStatement;
@@ -310,7 +309,7 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
private static void readMeasure(ResultSet rs, Measures measures) throws SQLException {
String metricKey = rs.getString(FIELD_METRIC_NAME);
- Optional<Double> value = metricKey.startsWith("new_") ? getDouble(rs, FIELD_MEASURE_VARIATION) : getDouble(rs, FIELD_MEASURE_VALUE);
+ Optional<Double> value = getDouble(rs, FIELD_MEASURE_VALUE);
if (value.isPresent()) {
measures.addNumericMeasure(metricKey, value.get());
return;
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
index f0664d0a558..efdb50c965c 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
@@ -9,8 +9,7 @@
lm.metric_uuid as metricUuid,
lm.value as value,
lm.text_value as textValue,
- lm.measure_data as data,
- lm.variation as variation
+ lm.measure_data as data
</sql>
<select id="selectByComponentUuidsAndMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
@@ -118,7 +117,6 @@
metric_uuid,
value,
text_value,
- variation,
measure_data,
created_at,
updated_at
@@ -129,7 +127,6 @@
#{dto.metricUuid, jdbcType=VARCHAR},
#{dto.value, jdbcType=DOUBLE},
#{dto.textValue, jdbcType=VARCHAR},
- #{dto.variation, jdbcType=DOUBLE},
#{dto.data, jdbcType=BINARY},
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
@@ -139,7 +136,6 @@
<update id="update" parameterType="map">
update live_measures set
value = #{dto.value, jdbcType=DOUBLE},
- variation = #{dto.variation, jdbcType=DOUBLE},
text_value = #{dto.textValue, jdbcType=VARCHAR},
measure_data = #{dto.data, jdbcType=BINARY},
updated_at = #{now, jdbcType=BIGINT}
@@ -162,7 +158,6 @@
metric_uuid,
value,
text_value,
- variation,
measure_data,
created_at,
updated_at
@@ -173,20 +168,17 @@
#{dto.metricUuid, jdbcType=VARCHAR},
#{dto.value, jdbcType=DOUBLE},
#{dto.textValue, jdbcType=VARCHAR},
- #{dto.variation, jdbcType=DOUBLE},
#{dto.data, jdbcType=BINARY},
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
)
on conflict(component_uuid, metric_uuid) do update set
value = excluded.value,
- variation = excluded.variation,
text_value = excluded.text_value,
measure_data = excluded.measure_data,
updated_at = excluded.updated_at
where
live_measures.value is distinct from excluded.value or
- live_measures.variation is distinct from excluded.variation or
live_measures.text_value is distinct from excluded.text_value or
live_measures.measure_data is distinct from excluded.measure_data
</update>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
index 8fa3ab066b1..3071c777ecd 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
@@ -12,8 +12,7 @@
pm.text_value as textValue,
pm.alert_status as alertStatus,
pm.alert_text as alertText,
- pm.measure_data as dataValue,
- pm.variation_value_1 as variation
+ pm.measure_data as dataValue
</sql>
<select id="selectLastMeasure" parameterType="map" resultType="Measure">
@@ -106,7 +105,6 @@
text_value,
alert_status,
alert_text,
- variation_value_1,
measure_data)
VALUES (
#{uuid, jdbcType=VARCHAR},
@@ -117,7 +115,6 @@
#{textValue, jdbcType=VARCHAR},
#{alertStatus, jdbcType=VARCHAR},
#{alertText, jdbcType=VARCHAR},
- #{variation, jdbcType=DOUBLE},
#{dataValue, jdbcType=BINARY}
)
</insert>
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 89f6761b83c..3e0f5bcdde0 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -446,7 +446,6 @@ CREATE TABLE "LIVE_MEASURES"(
"METRIC_UUID" CHARACTER VARYING(40) NOT NULL,
"VALUE" DOUBLE PRECISION,
"TEXT_VALUE" CHARACTER VARYING(4000),
- "VARIATION" DOUBLE PRECISION,
"MEASURE_DATA" BINARY LARGE OBJECT,
"UPDATE_MARKER" CHARACTER VARYING(40),
"CREATED_AT" BIGINT NOT NULL,
@@ -690,7 +689,6 @@ CREATE TABLE "PROJECT_MEASURES"(
"ALERT_STATUS" CHARACTER VARYING(5),
"ALERT_TEXT" CHARACTER VARYING(4000),
"PERSON_ID" INTEGER,
- "VARIATION_VALUE_1" DOUBLE PRECISION,
"MEASURE_DATA" BINARY LARGE OBJECT,
"METRIC_UUID" CHARACTER VARYING(40) NOT NULL
);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
index d080a7223ba..5e9fabdafb0 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
@@ -291,14 +291,14 @@ public class LiveMeasureDaoTest {
MetricDto metric = db.measures().insertMetric();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- underTest.insert(db.getSession(), newLiveMeasure(file, metric).setValue(3.14).setVariation(0.1).setData("text_value"));
+ underTest.insert(db.getSession(), newLiveMeasure(file, metric).setValue(3.14).setData("text_value"));
LiveMeasureDto result = underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not found"));
assertThat(result).as("Fail to map fields of %s", result.toString()).extracting(
- LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getVariation,
+ LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
- .contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, 0.1, "text_value", "text_value");
+ .contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, "text_value", "text_value");
}
@Test
@@ -403,7 +403,6 @@ public class LiveMeasureDaoTest {
// update
dto.setValue(dto.getValue() + 1);
- dto.setVariation(dto.getVariation() + 10);
dto.setData(dto.getDataAsString() + "_new");
underTest.insertOrUpdate(db.getSession(), dto);
verifyPersisted(dto);
@@ -491,7 +490,6 @@ public class LiveMeasureDaoTest {
// update
dto.setValue(dto.getValue() + 1);
- dto.setVariation(dto.getVariation() + 10);
dto.setData(dto.getDataAsString() + "_new");
count = underTest.upsert(db.getSession(), dto);
assertThat(count).isOne();
@@ -565,54 +563,6 @@ public class LiveMeasureDaoTest {
}
@Test
- public void upsert_updates_row_if_variation_is_changed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setVariation(40.0);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setVariation(50.0);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- public void upsert_updates_row_if_variation_is_removed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setVariation(40.0);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setVariation(null);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- public void upsert_updates_row_if_variation_is_added() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setVariation(null);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setVariation(40.0);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
public void upsert_updates_row_if_value_is_changed() {
if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
return;
@@ -698,7 +648,7 @@ public class LiveMeasureDaoTest {
assertThat(selected).hasSize(1);
assertThat(selected.get(0)).isEqualToComparingOnlyGivenFields(dto,
// do not compare the field "uuid", which is used only for insert, not select
- "componentUuid", "projectUuid", "metricUuid", "value", "textValue", "data", "variation");
+ "componentUuid", "projectUuid", "metricUuid", "value", "textValue", "data");
}
private void setupProjectsWithLoc() {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java
index 1937ea5cff7..3e5fb8c4bbc 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java
@@ -32,12 +32,9 @@ public class MeasureDtoTest {
public void test_getter_and_setter() {
underTest
.setValue(2d)
- .setData("text value")
- .setVariation(1d);
-
+ .setData("text value");
assertThat(underTest.getValue()).isEqualTo(2d);
assertThat(underTest.getData()).isNotNull();
- assertThat(underTest.getVariation()).isEqualTo(1d);
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
index ce4bbe75132..d5de79c7837 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
@@ -113,7 +113,7 @@ public class ProjectMeasuresIndexerIteratorTest {
c -> c.setKey("Project-Key").setName("Project Name"),
p -> p.setTagsString("platform,java"));
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines"));
- dbTester.measures().insertLiveMeasure(project, metric, m -> m.setVariation(10d));
+ dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(10d));
Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
@@ -139,7 +139,7 @@ public class ProjectMeasuresIndexerIteratorTest {
public void does_not_fail_when_quality_gate_has_no_value() {
ComponentDto project = dbTester.components().insertPrivateProject();
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status"));
- dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setVariation(null).setData((String) null));
+ dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData((String) null));
Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
@@ -210,8 +210,8 @@ public class ProjectMeasuresIndexerIteratorTest {
ComponentDto project = dbTester.components().insertPrivateProject();
dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d));
- dbTester.measures().insertLiveMeasure(project, leakMetric, m -> m.setValue(null).setVariation(20d));
- dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(null).setVariation(null));
+ dbTester.measures().insertLiveMeasure(project, leakMetric, m -> m.setValue(20d));
+ dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(null));
Map<String, Double> numericMeasures = createResultSetAndReturnDocsById().get(project.uuid()).getMeasures().getNumericMeasures();
assertThat(numericMeasures).containsOnly(entry(metric1.getKey(), 10d), entry(leakMetric.getKey(), 20d));
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
index 330f6cbb9e8..45da41f3e73 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
@@ -62,8 +62,7 @@ public class MeasureTesting {
.setComponentUuid(String.valueOf(cursor++))
.setProjectUuid(String.valueOf(cursor++))
.setData(String.valueOf(cursor++))
- .setValue((double) cursor++)
- .setVariation((double) cursor++);
+ .setValue((double) cursor++);
}
public static LiveMeasureDto newLiveMeasure(ComponentDto component, MetricDto metric) {
@@ -72,7 +71,6 @@ public class MeasureTesting {
.setComponentUuid(component.uuid())
.setProjectUuid(component.branchUuid())
.setData(String.valueOf(cursor++))
- .setValue((double) cursor++)
- .setVariation((double) cursor++);
+ .setValue((double) cursor++);
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
index d6481dcbe9d..1208b855f29 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
@@ -36,6 +36,7 @@ import org.sonar.server.platform.db.migration.version.v94.DbVersion94;
import org.sonar.server.platform.db.migration.version.v95.DbVersion95;
import org.sonar.server.platform.db.migration.version.v96.DbVersion96;
import org.sonar.server.platform.db.migration.version.v97.DbVersion97;
+import org.sonar.server.platform.db.migration.version.v98.DbVersion98;
public class MigrationConfigurationModule extends Module {
@Override
@@ -52,6 +53,7 @@ public class MigrationConfigurationModule extends Module {
DbVersion95.class,
DbVersion96.class,
DbVersion97.class,
+ DbVersion98.class,
// migration steps
MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DbVersion98.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DbVersion98.java
new file mode 100644
index 00000000000..f792305f9c7
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DbVersion98.java
@@ -0,0 +1,35 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+public class DbVersion98 implements DbVersion {
+ @Override
+ public void addSteps(MigrationStepRegistry registry) {
+ registry
+ .add(6700, "Move live measure variations to values", MoveLiveMeasureVariationToValue.class)
+ .add(6701, "Drop live measure variation column", DropLiveMeasureVariationColumn.class)
+ .add(6702, "Move project measure variations to values", MoveProjectMeasureVariationToValue.class)
+ .add(6703, "Drop project measure variation column", DropProjectMeasureVariationColumn.class)
+ ;
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumn.java
new file mode 100644
index 00000000000..0838f68b8e2
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumn.java
@@ -0,0 +1,33 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropColumnChange;
+
+public class DropLiveMeasureVariationColumn extends DropColumnChange {
+
+ public static final String TABLE_NAME = "live_measures";
+ public static final String COLUMN_NAME = "variation";
+
+ public DropLiveMeasureVariationColumn(Database db) {
+ super(db, TABLE_NAME, COLUMN_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumn.java
new file mode 100644
index 00000000000..4371b71b911
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumn.java
@@ -0,0 +1,33 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropColumnChange;
+
+public class DropProjectMeasureVariationColumn extends DropColumnChange {
+
+ public static final String TABLE_NAME = "project_measures";
+ public static final String COLUMN_NAME = "variation_value_1";
+
+ public DropProjectMeasureVariationColumn(Database db) {
+ super(db, TABLE_NAME, COLUMN_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValue.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValue.java
new file mode 100644
index 00000000000..8b0fffd2c73
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValue.java
@@ -0,0 +1,28 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import org.sonar.db.Database;
+
+public class MoveLiveMeasureVariationToValue extends VariationMigration {
+ public MoveLiveMeasureVariationToValue(Database db) {
+ super(db, "live_measures", "variation");
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValue.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValue.java
new file mode 100644
index 00000000000..dddcb9e23b2
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValue.java
@@ -0,0 +1,28 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import org.sonar.db.Database;
+
+public class MoveProjectMeasureVariationToValue extends VariationMigration {
+ public MoveProjectMeasureVariationToValue(Database db) {
+ super(db, "project_measures", "variation_value_1");
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/VariationMigration.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/VariationMigration.java
new file mode 100644
index 00000000000..2746fc9976d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v98/VariationMigration.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.server.platform.db.migration.version.v98;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class VariationMigration extends DataChange {
+ private final String tableName;
+ private final String variationColumnName;
+
+ public VariationMigration(Database db, String tableName, String variationColumnName) {
+ super(db);
+ this.tableName = tableName;
+ this.variationColumnName = variationColumnName;
+ }
+
+ @Override
+ protected void execute(DataChange.Context context) throws SQLException {
+ if (columnExists()) {
+ migrateVariation(context,
+ "select uuid, " + variationColumnName + " from " + tableName + " where " + variationColumnName + " is not null and value is null",
+ "update " + tableName + " set value = ? where uuid = ?");
+ }
+ }
+
+ static void migrateVariation(DataChange.Context context, String selectQuery, String updateQuery) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select(selectQuery);
+ massUpdate.update(updateQuery);
+ massUpdate.execute((row, update) -> {
+ String uuid = row.getString(1);
+ double variation = row.getDouble(2);
+ update.setDouble(1, variation);
+ update.setString(2, uuid);
+ return true;
+ });
+ }
+
+ private boolean columnExists() throws SQLException {
+ try (var connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.tableColumnExists(connection, tableName, variationColumnName);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DbVersion98Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DbVersion98Test.java
new file mode 100644
index 00000000000..909ed479e9c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DbVersion98Test.java
@@ -0,0 +1,42 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import org.junit.Test;
+import org.sonar.server.platform.db.migration.version.v97.DbVersion97;
+
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion98Test {
+
+ private final DbVersion98 underTest = new DbVersion98();
+
+ @Test
+ public void migrationNumber_starts_at_6600() {
+ verifyMinimumMigrationNumber(underTest, 6700);
+ }
+
+ @Test
+ public void verify_migration_is_not_empty() {
+ verifyMigrationNotEmpty(underTest);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumnTest.java
new file mode 100644
index 00000000000..b3395dd1806
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumnTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropLiveMeasureVariationColumnTest {
+ private static final String COLUMN_NAME = "variation";
+ private static final String TABLE_NAME = "live_measures";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropLiveMeasureVariationColumnTest.class, "schema.sql");
+
+ private final DdlChange dropColumn = new DropLiveMeasureVariationColumn(db.database());
+
+ @Test
+ public void migration_should_drop_action_plan_column() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.DOUBLE, null, true);
+ dropColumn.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.DOUBLE, null, true);
+ dropColumn.execute();
+ // re-entrant
+ dropColumn.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumnTest.java
new file mode 100644
index 00000000000..bbd26a599e8
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumnTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropProjectMeasureVariationColumnTest {
+ private static final String COLUMN_NAME = "variation_value_1";
+ private static final String TABLE_NAME = "project_measures";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropProjectMeasureVariationColumnTest.class, "schema.sql");
+
+ private final DdlChange dropColumn = new DropProjectMeasureVariationColumn(db.database());
+
+ @Test
+ public void migration_should_drop_action_plan_column() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.DOUBLE, null, true);
+ dropColumn.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.DOUBLE, null, true);
+ dropColumn.execute();
+ // re-entrant
+ dropColumn.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValueTest.java
new file mode 100644
index 00000000000..c2b669c3317
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValueTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class MoveLiveMeasureVariationToValueTest {
+ private static final String TABLE = "live_measures";
+ private int counter = 0;
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(MoveLiveMeasureVariationToValueTest.class, "schema.sql");
+
+ private final DataChange underTest = new MoveLiveMeasureVariationToValue(db.database());
+
+ @Test
+ public void moves_value_to_value_if_value_is_null() throws SQLException {
+ insertMeasure("1", null, 1000D);
+ insertMeasure("2", null, 2000D);
+
+ underTest.execute();
+
+ List<Map<String, Object>> select = db.select("select uuid as \"UUID\", value as \"VALUE\", variation as \"VARIATION\" from live_measures");
+ assertThat(select)
+ .extracting(t -> t.get("UUID"), t -> t.get("VALUE"), t -> t.get("VARIATION"))
+ .containsOnly(tuple("1", 1000D, 1000D), tuple("2", 2000D, 2000D));
+ }
+
+ @Test
+ public void does_not_move_if_row_contains_value() throws SQLException {
+ insertMeasure("1", 1100D, 1000D);
+ insertMeasure("2", 2100D, 2000D);
+
+ underTest.execute();
+
+ List<Map<String, Object>> select = db.select("select uuid as \"UUID\", value as \"VALUE\", variation as \"VARIATION\" from live_measures");
+ assertThat(select)
+ .extracting(t -> t.get("UUID"), t -> t.get("VALUE"), t -> t.get("VARIATION"))
+ .containsOnly(tuple("1", 1100D, 1000D), tuple("2", 2100D, 2000D));
+ }
+
+ private void insertMeasure(String uuid, @Nullable Double value, @Nullable Double variation) {
+ db.executeInsert(TABLE,
+ "uuid", uuid,
+ "project_uuid", "p1",
+ "component_uuid", "c1",
+ "metric_uuid", counter++,
+ "value", value,
+ "variation", variation,
+ "created_at", counter++,
+ "updated_at", counter++);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValueTest.java
new file mode 100644
index 00000000000..f2ecb6529b5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValueTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.server.platform.db.migration.version.v98;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class MoveProjectMeasureVariationToValueTest {
+ private static final String TABLE = "project_measures";
+ private int counter = 0;
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(MoveProjectMeasureVariationToValueTest.class, "schema.sql");
+
+ private final DataChange underTest = new MoveProjectMeasureVariationToValue(db.database());
+
+ @Test
+ public void moves_value_to_value_if_value_is_null() throws SQLException {
+ insertMeasure("1", null, 1000D);
+ insertMeasure("2", null, 2000D);
+
+ underTest.execute();
+
+ List<Map<String, Object>> select = db.select("select uuid as \"UUID\", value as \"VALUE\", variation_value_1 as \"VARIATION\" from project_measures");
+ assertThat(select)
+ .extracting(t -> t.get("UUID"), t -> t.get("VALUE"), t -> t.get("VARIATION"))
+ .containsOnly(tuple("1", 1000D, 1000D), tuple("2", 2000D, 2000D));
+ }
+
+ @Test
+ public void does_not_move_if_row_contains_value() throws SQLException {
+ insertMeasure("1", 1100D, 1000D);
+ insertMeasure("2", 2100D, 2000D);
+
+ underTest.execute();
+
+ List<Map<String, Object>> select = db.select("select uuid as \"UUID\", value as \"VALUE\", variation_value_1 as \"VARIATION\" from project_measures");
+ assertThat(select)
+ .extracting(t -> t.get("UUID"), t -> t.get("VALUE"), t -> t.get("VARIATION"))
+ .containsOnly(tuple("1", 1100D, 1000D), tuple("2", 2100D, 2000D));
+ }
+
+ private void insertMeasure(String uuid, @Nullable Double value, @Nullable Double variation) {
+ db.executeInsert(TABLE,
+ "uuid", uuid,
+ "analysis_uuid", "a1",
+ "component_uuid", "c1",
+ "metric_uuid", counter++,
+ "value", value,
+ "variation_value_1", variation);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumnTest/schema.sql
new file mode 100644
index 00000000000..2b87580a266
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/DropLiveMeasureVariationColumnTest/schema.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "LIVE_MEASURES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "PROJECT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "METRIC_UUID" CHARACTER VARYING(40) NOT NULL,
+ "VALUE" DOUBLE PRECISION,
+ "TEXT_VALUE" CHARACTER VARYING(4000),
+ "VARIATION" DOUBLE PRECISION,
+ "MEASURE_DATA" BINARY LARGE OBJECT,
+ "UPDATE_MARKER" CHARACTER VARYING(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID" NULLS FIRST, "METRIC_UUID" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumnTest/schema.sql
new file mode 100644
index 00000000000..d48cf02d070
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/DropProjectMeasureVariationColumnTest/schema.sql
@@ -0,0 +1,17 @@
+CREATE TABLE "PROJECT_MEASURES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "VALUE" DOUBLE PRECISION,
+ "ANALYSIS_UUID" CHARACTER VARYING(50) NOT NULL,
+ "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "TEXT_VALUE" CHARACTER VARYING(4000),
+ "ALERT_STATUS" CHARACTER VARYING(5),
+ "ALERT_TEXT" CHARACTER VARYING(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE PRECISION,
+ "MEASURE_DATA" BINARY LARGE OBJECT,
+ "METRIC_UUID" CHARACTER VARYING(40) NOT NULL
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID" NULLS FIRST, "METRIC_UUID" NULLS FIRST);
+CREATE INDEX "PROJECT_MEASURES_METRIC" ON "PROJECT_MEASURES"("METRIC_UUID" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValueTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValueTest/schema.sql
new file mode 100644
index 00000000000..2b87580a266
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/MoveLiveMeasureVariationToValueTest/schema.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "LIVE_MEASURES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "PROJECT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "METRIC_UUID" CHARACTER VARYING(40) NOT NULL,
+ "VALUE" DOUBLE PRECISION,
+ "TEXT_VALUE" CHARACTER VARYING(4000),
+ "VARIATION" DOUBLE PRECISION,
+ "MEASURE_DATA" BINARY LARGE OBJECT,
+ "UPDATE_MARKER" CHARACTER VARYING(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID" NULLS FIRST, "METRIC_UUID" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValueTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValueTest/schema.sql
new file mode 100644
index 00000000000..d48cf02d070
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v98/MoveProjectMeasureVariationToValueTest/schema.sql
@@ -0,0 +1,17 @@
+CREATE TABLE "PROJECT_MEASURES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "VALUE" DOUBLE PRECISION,
+ "ANALYSIS_UUID" CHARACTER VARYING(50) NOT NULL,
+ "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "TEXT_VALUE" CHARACTER VARYING(4000),
+ "ALERT_STATUS" CHARACTER VARYING(5),
+ "ALERT_TEXT" CHARACTER VARYING(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE PRECISION,
+ "MEASURE_DATA" BINARY LARGE OBJECT,
+ "METRIC_UUID" CHARACTER VARYING(40) NOT NULL
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID" NULLS FIRST, "METRIC_UUID" NULLS FIRST);
+CREATE INDEX "PROJECT_MEASURES_METRIC" ON "PROJECT_MEASURES"("METRIC_UUID" NULLS FIRST);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java
index 67a1e388a0f..49b0e9d97c4 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java
@@ -121,7 +121,7 @@ class ConditionEvaluator {
@CheckForNull
private static Comparable getLeakValue(QualityGateEvaluator.Measure measure) {
if (NUMERICAL_TYPES.contains(measure.getType())) {
- return measure.getNewMetricValue().isPresent() ? getNumericValue(measure.getType(), measure.getNewMetricValue().getAsDouble()) : null;
+ return measure.getValue().isPresent() ? getNumericValue(measure.getType(), measure.getValue().getAsDouble()) : null;
}
throw new IllegalArgumentException("Condition on leak period is not allowed for type " + measure.getType());
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluator.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluator.java
index af6a541a774..3d9ad7fb196 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluator.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluator.java
@@ -55,7 +55,5 @@ public interface QualityGateEvaluator {
OptionalDouble getValue();
Optional<String> getStringValue();
-
- OptionalDouble getNewMetricValue();
}
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluatorImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluatorImpl.java
index 4cab41f8c89..65b7c40f5e2 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluatorImpl.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluatorImpl.java
@@ -83,8 +83,8 @@ public class QualityGateEvaluatorImpl implements QualityGateEvaluator {
private static boolean isSmallChangeset(Measures measures) {
Optional<Measure> newLines = measures.get(CoreMetrics.NEW_LINES_KEY);
return newLines.isPresent() &&
- newLines.get().getNewMetricValue().isPresent() &&
- newLines.get().getNewMetricValue().getAsDouble() < MAXIMUM_NEW_LINES_FOR_SMALL_CHANGESETS;
+ newLines.get().getValue().isPresent() &&
+ newLines.get().getValue().getAsDouble() < MAXIMUM_NEW_LINES_FOR_SMALL_CHANGESETS;
}
private static Level overallStatusOf(Set<EvaluatedCondition> conditions) {
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java
index 374c2178828..665c4cd4f04 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java
@@ -34,7 +34,6 @@ import static org.sonar.api.measures.Metric.ValueType.BOOL;
import static org.sonar.api.measures.Metric.ValueType.DATA;
import static org.sonar.api.measures.Metric.ValueType.DISTRIB;
import static org.sonar.api.measures.Metric.ValueType.STRING;
-import static org.sonar.server.qualitygate.FakeMeasure.newMeasureOnLeak;
@RunWith(DataProviderRunner.class)
public class ConditionEvaluatorTest {
@@ -59,9 +58,9 @@ public class ConditionEvaluatorTest {
test(new FakeMeasure(10), Condition.Operator.GREATER_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
test(new FakeMeasure(10), Condition.Operator.GREATER_THAN, "11", EvaluatedCondition.EvaluationStatus.OK, "10");
- testOnLeak(newMeasureOnLeak(10), Condition.Operator.GREATER_THAN, "9", EvaluatedCondition.EvaluationStatus.ERROR, "10");
- testOnLeak(newMeasureOnLeak(10), Condition.Operator.GREATER_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
- testOnLeak(newMeasureOnLeak(10), Condition.Operator.GREATER_THAN, "11", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10), Condition.Operator.GREATER_THAN, "9", EvaluatedCondition.EvaluationStatus.ERROR, "10");
+ test(new FakeMeasure(10), Condition.Operator.GREATER_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10), Condition.Operator.GREATER_THAN, "11", EvaluatedCondition.EvaluationStatus.OK, "10");
}
@Test
@@ -70,9 +69,9 @@ public class ConditionEvaluatorTest {
test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "11", EvaluatedCondition.EvaluationStatus.ERROR, "10");
- testOnLeak(newMeasureOnLeak(10), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, "10");
- testOnLeak(newMeasureOnLeak(10), Condition.Operator.LESS_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
- testOnLeak(newMeasureOnLeak(10), Condition.Operator.LESS_THAN, "11", EvaluatedCondition.EvaluationStatus.ERROR, "10");
+ test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "11", EvaluatedCondition.EvaluationStatus.ERROR, "10");
}
@Test
@@ -88,7 +87,6 @@ public class ConditionEvaluatorTest {
test(null, Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, null);
}
-
@Test
@UseDataProvider("unsupportedMetricTypes")
public void fail_when_condition_is_on_unsupported_metric(Metric.ValueType metricType) {
@@ -107,22 +105,9 @@ public class ConditionEvaluatorTest {
};
}
- private void test(@Nullable QualityGateEvaluator.Measure measure, Condition.Operator operator, String errorThreshold, EvaluatedCondition.EvaluationStatus expectedStatus, @Nullable String expectedValue) {
- Condition condition = new Condition("foo", operator, errorThreshold);
-
- EvaluatedCondition result = ConditionEvaluator.evaluate(condition, new FakeMeasures(measure));
-
- assertThat(result.getStatus()).isEqualTo(expectedStatus);
- if (expectedValue == null) {
- assertThat(result.getValue()).isNotPresent();
- } else {
- assertThat(result.getValue()).hasValue(expectedValue);
- }
- }
-
- private void testOnLeak(QualityGateEvaluator.Measure measure, Condition.Operator operator, String errorThreshold, EvaluatedCondition.EvaluationStatus expectedStatus,
+ private void test(@Nullable QualityGateEvaluator.Measure measure, Condition.Operator operator, String errorThreshold, EvaluatedCondition.EvaluationStatus expectedStatus,
@Nullable String expectedValue) {
- Condition condition = new Condition("new_foo", operator, errorThreshold);
+ Condition condition = new Condition("foo", operator, errorThreshold);
EvaluatedCondition result = ConditionEvaluator.evaluate(condition, new FakeMeasures(measure));
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java
index 55df7dc93ce..9514f5a5146 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java
@@ -25,7 +25,6 @@ import javax.annotation.Nullable;
import org.sonar.api.measures.Metric;
public class FakeMeasure implements QualityGateEvaluator.Measure {
- private Double leakValue;
private Double value;
private Metric.ValueType valueType;
@@ -47,13 +46,6 @@ public class FakeMeasure implements QualityGateEvaluator.Measure {
this.valueType = Metric.ValueType.INT;
}
- public static FakeMeasure newMeasureOnLeak(@Nullable Integer value) {
- FakeMeasure measure = new FakeMeasure();
- measure.leakValue = value == null ? null : value.doubleValue();
- measure.valueType = Metric.ValueType.INT;
- return measure;
- }
-
@Override
public Metric.ValueType getType() {
return valueType;
@@ -68,9 +60,4 @@ public class FakeMeasure implements QualityGateEvaluator.Measure {
public Optional<String> getStringValue() {
return Optional.empty();
}
-
- @Override
- public OptionalDouble getNewMetricValue() {
- return leakValue == null ? OptionalDouble.empty() : OptionalDouble.of(leakValue);
- }
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateEvaluatorImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateEvaluatorImplTest.java
index b4e074ab097..b5a696d8bdd 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateEvaluatorImplTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateEvaluatorImplTest.java
@@ -39,7 +39,6 @@ import static org.mockito.Mockito.when;
import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY;
-import static org.sonar.server.qualitygate.FakeMeasure.newMeasureOnLeak;
public class QualityGateEvaluatorImplTest {
private final MapSettings settings = new MapSettings();
@@ -97,7 +96,7 @@ public class QualityGateEvaluatorImplTest {
QualityGate gate = mock(QualityGate.class);
when(gate.getConditions()).thenReturn(singleton(condition));
- QualityGateEvaluator.Measures measures = key -> Optional.of(newMeasureOnLeak(1));
+ QualityGateEvaluator.Measures measures = key -> Optional.of(new FakeMeasure(1));
assertThat(underTest.evaluate(gate, measures, configuration).getStatus()).isEqualTo(Metric.Level.ERROR);
}
@@ -107,12 +106,12 @@ public class QualityGateEvaluatorImplTest {
Condition condition = new Condition(NEW_DUPLICATED_LINES_KEY, Condition.Operator.GREATER_THAN, "0");
Map<String, QualityGateEvaluator.Measure> notSmallChange = new HashMap<>();
- notSmallChange.put(NEW_DUPLICATED_LINES_KEY, newMeasureOnLeak(1));
- notSmallChange.put(NEW_LINES_KEY, newMeasureOnLeak(1000));
+ notSmallChange.put(NEW_DUPLICATED_LINES_KEY, new FakeMeasure(1));
+ notSmallChange.put(NEW_LINES_KEY, new FakeMeasure(1000));
Map<String, QualityGateEvaluator.Measure> smallChange = new HashMap<>();
- smallChange.put(NEW_DUPLICATED_LINES_KEY, newMeasureOnLeak(1));
- smallChange.put(NEW_LINES_KEY, newMeasureOnLeak(10));
+ smallChange.put(NEW_DUPLICATED_LINES_KEY, new FakeMeasure(1));
+ smallChange.put(NEW_LINES_KEY, new FakeMeasure(10));
QualityGate gate = mock(QualityGate.class);
when(gate.getConditions()).thenReturn(singleton(condition));
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java
index ff8cb14dcc3..45c46995da4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImpl.java
@@ -158,7 +158,7 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater {
*/
@Override
public long getChildrenHotspotsReviewed() {
- return getChildrenHotspotsReviewed(LiveMeasureDto::getValue, SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY, SECURITY_HOTSPOTS_REVIEWED_KEY, SECURITY_HOTSPOTS_KEY);
+ return getChildrenHotspotsReviewed(SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY, SECURITY_HOTSPOTS_REVIEWED_KEY, SECURITY_HOTSPOTS_KEY);
}
/**
@@ -175,7 +175,7 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater {
@Override
public long getChildrenNewHotspotsReviewed() {
- return getChildrenHotspotsReviewed(LiveMeasureDto::getVariation, NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, NEW_SECURITY_HOTSPOTS_KEY);
+ return getChildrenHotspotsReviewed(NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS_KEY, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, NEW_SECURITY_HOTSPOTS_KEY);
}
/**
@@ -186,39 +186,32 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater {
return componentIndex.getChildren(currentComponent)
.stream()
.map(c -> matrix.getMeasure(c, NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS_KEY).or(() -> matrix.getMeasure(c, NEW_SECURITY_HOTSPOTS_KEY)))
- .mapToLong(lmOpt -> lmOpt.flatMap(lm -> Optional.ofNullable(lm.getVariation())).orElse(0D).longValue())
+ .mapToLong(lmOpt -> lmOpt.flatMap(lm -> Optional.ofNullable(lm.getValue())).orElse(0D).longValue())
.sum();
}
- private long getChildrenHotspotsReviewed(Function<LiveMeasureDto, Double> valueFunc, String metricKey, String percMetricKey, String hotspotsMetricKey) {
+ private long getChildrenHotspotsReviewed(String metricKey, String percMetricKey, String hotspotsMetricKey) {
return componentIndex.getChildren(currentComponent)
.stream()
- .mapToLong(c -> getHotspotsReviewed(c, valueFunc, metricKey, percMetricKey, hotspotsMetricKey))
+ .mapToLong(c -> getHotspotsReviewed(c, metricKey, percMetricKey, hotspotsMetricKey))
.sum();
}
- private long getHotspotsReviewed(ComponentDto c, Function<LiveMeasureDto, Double> valueFunc, String metricKey, String percMetricKey, String hotspotsMetricKey) {
+ private long getHotspotsReviewed(ComponentDto c, String metricKey, String percMetricKey, String hotspotsMetricKey) {
Optional<LiveMeasureDto> measure = matrix.getMeasure(c, metricKey);
- return measure.map(lm -> Optional.ofNullable(valueFunc.apply(lm)).orElse(0D).longValue())
+ return measure.map(lm -> Optional.ofNullable(lm.getValue()).orElse(0D).longValue())
.orElseGet(() -> matrix.getMeasure(c, percMetricKey)
.flatMap(percentage -> matrix.getMeasure(c, hotspotsMetricKey)
.map(hotspots -> {
- double perc = Optional.ofNullable(valueFunc.apply(percentage)).orElse(0D) / 100D;
- double toReview = Optional.ofNullable(valueFunc.apply(hotspots)).orElse(0D);
+ double perc = Optional.ofNullable(percentage.getValue()).orElse(0D) / 100D;
+ double toReview = Optional.ofNullable(hotspots.getValue()).orElse(0D);
double reviewed = (toReview * perc) / (1D - perc);
return Math.round(reviewed);
}))
.orElse(0L));
}
- public List<Double> getChildrenLeakValues() {
- List<ComponentDto> children = componentIndex.getChildren(currentComponent);
- return children.stream()
- .flatMap(c -> matrix.getMeasure(c, currentFormula.getMetric().getKey()).stream())
- .map(LiveMeasureDto::getVariation)
- .filter(Objects::nonNull)
- .collect(Collectors.toList());
- }
+
@Override
public ComponentDto getComponent() {
@@ -243,37 +236,15 @@ public class LiveMeasureTreeUpdaterImpl implements LiveMeasureTreeUpdater {
}
@Override
- public Optional<Double> getLeakValue(Metric metric) {
- Optional<LiveMeasureDto> measure = matrix.getMeasure(currentComponent, metric.getKey());
- return measure.map(LiveMeasureDto::getVariation);
- }
-
- @Override
public void setValue(double value) {
String metricKey = currentFormula.getMetric().getKey();
- checkState(!currentFormula.isOnLeak(), "Formula of metric %s accepts only leak values", metricKey);
matrix.setValue(currentComponent, metricKey, value);
}
@Override
- public void setLeakValue(double value) {
- String metricKey = currentFormula.getMetric().getKey();
- checkState(currentFormula.isOnLeak(), "Formula of metric %s does not accept leak values", metricKey);
- matrix.setLeakValue(currentComponent, metricKey, value);
- }
-
- @Override
public void setValue(Rating value) {
String metricKey = currentFormula.getMetric().getKey();
- checkState(!currentFormula.isOnLeak(), "Formula of metric %s accepts only leak values", metricKey);
matrix.setValue(currentComponent, metricKey, value);
}
-
- @Override
- public void setLeakValue(Rating value) {
- String metricKey = currentFormula.getMetric().getKey();
- checkState(currentFormula.isOnLeak(), "Formula of metric %s does not accept leak values", metricKey);
- matrix.setLeakValue(currentComponent, metricKey, value);
- }
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
index 4e8a8c44398..a60c302c1f2 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
@@ -135,13 +135,5 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer {
public Optional<String> getStringValue() {
return Optional.ofNullable(dto.getTextValue());
}
-
- @Override
- public OptionalDouble getNewMetricValue() {
- if (dto.getVariation() == null) {
- return OptionalDouble.empty();
- }
- return OptionalDouble.of(dto.getVariation());
- }
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java
index 88ddbdbc186..05c1a355942 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java
@@ -102,14 +102,6 @@ class MeasureMatrix {
changeCell(component, metricKey, m -> m.setData(data));
}
- void setLeakValue(ComponentDto component, String metricKey, double variation) {
- changeCell(component, metricKey, c -> c.setVariation(scale(metricsByKeys.get(metricKey), variation)));
- }
-
- void setLeakValue(ComponentDto component, String metricKey, Rating variation) {
- setLeakValue(component, metricKey, variation.getIndex());
- }
-
Stream<LiveMeasureDto> getChanged() {
return table.values().stream()
.filter(Objects::nonNull)
@@ -144,7 +136,6 @@ class MeasureMatrix {
private static class MeasureCell {
private final LiveMeasureDto measure;
- private final Double initialVariation;
private final Double initialValue;
private final byte[] initialData;
private final String initialTextValue;
@@ -152,7 +143,6 @@ class MeasureMatrix {
private MeasureCell(LiveMeasureDto measure) {
this.measure = measure;
this.initialValue = measure.getValue();
- this.initialVariation = measure.getVariation();
this.initialData = measure.getData();
this.initialTextValue = measure.getTextValue();
}
@@ -162,8 +152,7 @@ class MeasureMatrix {
}
public boolean isChanged() {
- return !Objects.equals(initialValue, measure.getValue()) || !Objects.equals(initialVariation, measure.getVariation())
- || !Arrays.equals(initialData, measure.getData()) || !Objects.equals(initialTextValue, measure.getTextValue());
+ return !Objects.equals(initialValue, measure.getValue()) || !Arrays.equals(initialData, measure.getData()) || !Objects.equals(initialTextValue, measure.getTextValue());
}
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormula.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormula.java
index 143f397e6cd..dcaad991e9a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormula.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormula.java
@@ -88,8 +88,6 @@ class MeasureUpdateFormula {
long getChildrenNewHotspotsToReview();
- List<Double> getChildrenLeakValues();
-
ComponentDto getComponent();
DebtRatingGrid getDebtRatingGrid();
@@ -104,14 +102,8 @@ class MeasureUpdateFormula {
Optional<String> getText(Metric metrc);
- Optional<Double> getLeakValue(Metric metric);
-
void setValue(double value);
void setValue(Rating value);
-
- void setLeakValue(double value);
-
- void setLeakValue(Rating value);
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java
index 21f4e843b27..5b6e514302b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImpl.java
@@ -145,89 +145,89 @@ public class MeasureUpdateFormulaFactoryImpl implements MeasureUpdateFormulaFact
}),
new MeasureUpdateFormula(CoreMetrics.NEW_CODE_SMELLS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedByType(RuleType.CODE_SMELL, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedByType(RuleType.CODE_SMELL, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_BUGS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedByType(RuleType.BUG, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedByType(RuleType.BUG, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_VULNERABILITIES, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedByType(RuleType.VULNERABILITY, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedByType(RuleType.VULNERABILITY, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_SECURITY_HOTSPOTS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedByType(RuleType.SECURITY_HOTSPOT, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedByType(RuleType.SECURITY_HOTSPOT, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_VIOLATIONS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolved(true))),
+ (context, issues) -> context.setValue(issues.countUnresolved(true))),
new MeasureUpdateFormula(CoreMetrics.NEW_BLOCKER_VIOLATIONS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedBySeverity(Severity.BLOCKER, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedBySeverity(Severity.BLOCKER, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_CRITICAL_VIOLATIONS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedBySeverity(Severity.CRITICAL, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedBySeverity(Severity.CRITICAL, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_MAJOR_VIOLATIONS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedBySeverity(Severity.MAJOR, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedBySeverity(Severity.MAJOR, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_MINOR_VIOLATIONS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedBySeverity(Severity.MINOR, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedBySeverity(Severity.MINOR, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_INFO_VIOLATIONS, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.countUnresolvedBySeverity(Severity.INFO, true))),
+ (context, issues) -> context.setValue(issues.countUnresolvedBySeverity(Severity.INFO, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_TECHNICAL_DEBT, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.sumEffortOfUnresolved(RuleType.CODE_SMELL, true))),
+ (context, issues) -> context.setValue(issues.sumEffortOfUnresolved(RuleType.CODE_SMELL, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_RELIABILITY_REMEDIATION_EFFORT, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.sumEffortOfUnresolved(RuleType.BUG, true))),
+ (context, issues) -> context.setValue(issues.sumEffortOfUnresolved(RuleType.BUG, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_SECURITY_REMEDIATION_EFFORT, true, new AddChildren(),
- (context, issues) -> context.setLeakValue(issues.sumEffortOfUnresolved(RuleType.VULNERABILITY, true))),
+ (context, issues) -> context.setValue(issues.sumEffortOfUnresolved(RuleType.VULNERABILITY, true))),
new MeasureUpdateFormula(CoreMetrics.NEW_RELIABILITY_RATING, true, new MaxRatingChildren(),
(context, issues) -> {
String highestSeverity = issues.getHighestSeverityOfUnresolved(RuleType.BUG, true).orElse(Severity.INFO);
- context.setLeakValue(RATING_BY_SEVERITY.get(highestSeverity));
+ context.setValue(RATING_BY_SEVERITY.get(highestSeverity));
}),
new MeasureUpdateFormula(CoreMetrics.NEW_SECURITY_RATING, true, new MaxRatingChildren(),
(context, issues) -> {
String highestSeverity = issues.getHighestSeverityOfUnresolved(RuleType.VULNERABILITY, true).orElse(Severity.INFO);
- context.setLeakValue(RATING_BY_SEVERITY.get(highestSeverity));
+ context.setValue(RATING_BY_SEVERITY.get(highestSeverity));
}),
new MeasureUpdateFormula(NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS, true,
- (context, formula) -> context.setLeakValue(context.getLeakValue(NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS).orElse(0D) + context.getChildrenNewHotspotsReviewed()),
- (context, issues) -> context.setLeakValue(issues.countHotspotsByStatus(Issue.STATUS_REVIEWED, true))),
+ (context, formula) -> context.setValue(context.getValue(NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS).orElse(0D) + context.getChildrenNewHotspotsReviewed()),
+ (context, issues) -> context.setValue(issues.countHotspotsByStatus(Issue.STATUS_REVIEWED, true))),
new MeasureUpdateFormula(NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS, true,
- (context, formula) -> context.setLeakValue(context.getLeakValue(NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS).orElse(0D) + context.getChildrenNewHotspotsToReview()),
- (context, issues) -> context.setLeakValue(issues.countHotspotsByStatus(Issue.STATUS_TO_REVIEW, true))),
+ (context, formula) -> context.setValue(context.getValue(NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS).orElse(0D) + context.getChildrenNewHotspotsToReview()),
+ (context, issues) -> context.setValue(issues.countHotspotsByStatus(Issue.STATUS_TO_REVIEW, true))),
new MeasureUpdateFormula(NEW_SECURITY_HOTSPOTS_REVIEWED, true,
(context, formula) -> {
Optional<Double> percent = computePercent(
- context.getLeakValue(NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS).orElse(0D).longValue(),
- context.getLeakValue(NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS).orElse(0D).longValue());
- percent.ifPresent(context::setLeakValue);
+ context.getValue(NEW_SECURITY_HOTSPOTS_TO_REVIEW_STATUS).orElse(0D).longValue(),
+ context.getValue(NEW_SECURITY_HOTSPOTS_REVIEWED_STATUS).orElse(0D).longValue());
+ percent.ifPresent(context::setValue);
},
(context, issues) -> computePercent(issues.countHotspotsByStatus(Issue.STATUS_TO_REVIEW, true), issues.countHotspotsByStatus(Issue.STATUS_REVIEWED, true))
- .ifPresent(context::setLeakValue)),
+ .ifPresent(context::setValue)),
new MeasureUpdateFormula(CoreMetrics.NEW_SECURITY_REVIEW_RATING, true,
- (context, formula) -> context.setLeakValue(computeRating(context.getLeakValue(NEW_SECURITY_HOTSPOTS_REVIEWED).orElse(null))),
+ (context, formula) -> context.setValue(computeRating(context.getValue(NEW_SECURITY_HOTSPOTS_REVIEWED).orElse(null))),
(context, issues) -> {
Optional<Double> percent = computePercent(issues.countHotspotsByStatus(Issue.STATUS_TO_REVIEW, true), issues.countHotspotsByStatus(Issue.STATUS_REVIEWED, true));
- context.setLeakValue(computeRating(percent.orElse(null)));
+ context.setValue(computeRating(percent.orElse(null)));
}),
new MeasureUpdateFormula(CoreMetrics.NEW_SQALE_DEBT_RATIO, true,
- (context, formula) -> context.setLeakValue(100.0D * newDebtDensity(context)),
- (context, issues) -> context.setLeakValue(100.0D * newDebtDensity(context)),
+ (context, formula) -> context.setValue(100.0D * newDebtDensity(context)),
+ (context, issues) -> context.setValue(100.0D * newDebtDensity(context)),
asList(CoreMetrics.NEW_TECHNICAL_DEBT, CoreMetrics.NEW_DEVELOPMENT_COST)),
new MeasureUpdateFormula(CoreMetrics.NEW_MAINTAINABILITY_RATING, true,
- (context, formula) -> context.setLeakValue(context.getDebtRatingGrid().getRatingForDensity(newDebtDensity(context))),
- (context, issues) -> context.setLeakValue(context.getDebtRatingGrid().getRatingForDensity(newDebtDensity(context))),
+ (context, formula) -> context.setValue(context.getDebtRatingGrid().getRatingForDensity(newDebtDensity(context))),
+ (context, issues) -> context.setValue(context.getDebtRatingGrid().getRatingForDensity(newDebtDensity(context))),
asList(CoreMetrics.NEW_TECHNICAL_DEBT, CoreMetrics.NEW_DEVELOPMENT_COST)));
private static final Set<Metric> FORMULA_METRICS = MeasureUpdateFormulaFactory.extractMetrics(FORMULAS);
@@ -242,8 +242,8 @@ public class MeasureUpdateFormulaFactoryImpl implements MeasureUpdateFormulaFact
}
private static double newDebtDensity(MeasureUpdateFormula.Context context) {
- double debt = Math.max(context.getLeakValue(CoreMetrics.NEW_TECHNICAL_DEBT).orElse(0.0D), 0.0D);
- Optional<Double> devCost = context.getLeakValue(CoreMetrics.NEW_DEVELOPMENT_COST);
+ double debt = Math.max(context.getValue(CoreMetrics.NEW_TECHNICAL_DEBT).orElse(0.0D), 0.0D);
+ Optional<Double> devCost = context.getValue(CoreMetrics.NEW_DEVELOPMENT_COST);
if (devCost.isPresent() && Double.doubleToRawLongBits(devCost.get()) > 0L) {
return debt / devCost.get();
}
@@ -260,33 +260,18 @@ public class MeasureUpdateFormulaFactoryImpl implements MeasureUpdateFormulaFact
static class AddChildren implements BiConsumer<MeasureUpdateFormula.Context, MeasureUpdateFormula> {
@Override
public void accept(MeasureUpdateFormula.Context context, MeasureUpdateFormula formula) {
- double sum;
- if (formula.isOnLeak()) {
- sum = context.getChildrenLeakValues().stream().mapToDouble(x -> x).sum();
- context.setLeakValue(context.getLeakValue(formula.getMetric()).orElse(0D) + sum);
- } else {
- sum = context.getChildrenValues().stream().mapToDouble(x -> x).sum();
- context.setValue(context.getValue(formula.getMetric()).orElse(0D) + sum);
- }
+ double sum = context.getChildrenValues().stream().mapToDouble(x -> x).sum();
+ context.setValue(context.getValue(formula.getMetric()).orElse(0D) + sum);
}
}
private static class MaxRatingChildren implements BiConsumer<MeasureUpdateFormula.Context, MeasureUpdateFormula> {
@Override
public void accept(MeasureUpdateFormula.Context context, MeasureUpdateFormula formula) {
- OptionalInt max;
- if (formula.isOnLeak()) {
- max = context.getChildrenLeakValues().stream().mapToInt(Double::intValue).max();
- if (max.isPresent()) {
- int currentRating = context.getLeakValue(formula.getMetric()).map(Double::intValue).orElse(Rating.A.getIndex());
- context.setLeakValue(Rating.valueOf(Math.max(currentRating, max.getAsInt())));
- }
- } else {
- max = context.getChildrenValues().stream().mapToInt(Double::intValue).max();
- if (max.isPresent()) {
- int currentRating = context.getValue(formula.getMetric()).map(Double::intValue).orElse(Rating.A.getIndex());
- context.setValue(Rating.valueOf(Math.max(currentRating, max.getAsInt())));
- }
+ OptionalInt max = context.getChildrenValues().stream().mapToInt(Double::intValue).max();
+ if (max.isPresent()) {
+ int currentRating = context.getValue(formula.getMetric()).map(Double::intValue).orElse(Rating.A.getIndex());
+ context.setValue(Rating.valueOf(Math.max(currentRating, max.getAsInt())));
}
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
index 3c2d531f2ee..ad7823344eb 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
@@ -394,7 +394,8 @@ public class ComponentTreeAction implements MeasuresWsAction {
Measures.Measure.Builder measureBuilder = Measures.Measure.newBuilder();
for (Map.Entry<MetricDto, ComponentTreeData.Measure> entry : measures.entrySet()) {
ComponentTreeData.Measure measure = entry.getValue();
- updateMeasureBuilder(measureBuilder, entry.getKey(), measure.getValue(), measure.getData(), measure.getVariation());
+ boolean onNewCode = entry.getKey().getKey().startsWith("new_");
+ updateMeasureBuilder(measureBuilder, entry.getKey(), measure.getValue(), measure.getData(), onNewCode);
wsComponent.addMeasures(measureBuilder);
measureBuilder.clear();
}
@@ -588,7 +589,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
return components
.stream()
- .filter(new HasMeasure(measuresByComponentUuidAndMetric, metricToSort.get(), wsRequest.getMetricPeriodSort()))
+ .filter(new HasMeasure(measuresByComponentUuidAndMetric, metricToSort.get()))
.collect(MoreCollectors.toList(components.size()));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java
index 83141c2f6b7..75b0734e561 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java
@@ -157,16 +157,14 @@ class ComponentTreeData {
static class Measure {
private double value;
private String data;
- private double variation;
- public Measure(@Nullable String data, @Nullable Double value, @Nullable Double variation) {
+ public Measure(@Nullable String data, @Nullable Double value) {
this.data = data;
this.value = toPrimitive(value);
- this.variation = toPrimitive(variation);
}
private Measure(LiveMeasureDto measureDto) {
- this(measureDto.getDataAsString(), measureDto.getValue(), measureDto.getVariation());
+ this(measureDto.getDataAsString(), measureDto.getValue());
}
public double getValue() {
@@ -182,14 +180,6 @@ class ComponentTreeData {
return data;
}
- public double getVariation() {
- return variation;
- }
-
- public boolean isVariationSet() {
- return !isNaN(variation);
- }
-
static Measure createFromMeasureDto(LiveMeasureDto measureDto) {
return new Measure(measureDto);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java
index 8de533c3503..120b0be0d43 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java
@@ -237,10 +237,10 @@ public class ComponentTreeSort {
@Override
public Double apply(@Nonnull ComponentDto input) {
ComponentTreeData.Measure measure = measuresByComponentUuidAndMetric.get(input.uuid(), metric);
- if (measure == null || !measure.isVariationSet()) {
+ if (measure == null || !metric.getKey().startsWith("new_")) {
return null;
}
- return measure.getVariation();
+ return measure.getValue();
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/HasMeasure.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/HasMeasure.java
index a1c6bb149fc..b67913202a2 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/HasMeasure.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/HasMeasure.java
@@ -22,7 +22,6 @@ package org.sonar.server.measure.ws;
import com.google.common.collect.Table;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.metric.MetricDto;
@@ -31,10 +30,8 @@ import static org.sonar.server.measure.ws.ComponentTreeData.Measure;
class HasMeasure implements Predicate<ComponentDto> {
private final Predicate<ComponentDto> predicate;
- HasMeasure(Table<String, MetricDto, ComponentTreeData.Measure> table, MetricDto metric, @Nullable Integer metricPeriodSort) {
- this.predicate = metricPeriodSort == null
- ? new HasAbsoluteValue(table, metric)
- : new HasValueOnPeriod(table, metric);
+ HasMeasure(Table<String, MetricDto, ComponentTreeData.Measure> table, MetricDto metric) {
+ this.predicate = new HasValue(table, metric);
}
@Override
@@ -42,11 +39,11 @@ class HasMeasure implements Predicate<ComponentDto> {
return predicate.test(input);
}
- private static class HasAbsoluteValue implements Predicate<ComponentDto> {
+ private static class HasValue implements Predicate<ComponentDto> {
private final Table<String, MetricDto, ComponentTreeData.Measure> table;
private final MetricDto metric;
- private HasAbsoluteValue(Table<String, MetricDto, ComponentTreeData.Measure> table, MetricDto metric) {
+ private HasValue(Table<String, MetricDto, ComponentTreeData.Measure> table, MetricDto metric) {
this.table = table;
this.metric = metric;
}
@@ -57,21 +54,4 @@ class HasMeasure implements Predicate<ComponentDto> {
return measure != null && (measure.isValueSet() || measure.getData() != null);
}
}
-
- private static class HasValueOnPeriod implements Predicate<ComponentDto> {
- private final Table<String, MetricDto, ComponentTreeData.Measure> table;
- private final MetricDto metric;
-
- private HasValueOnPeriod(Table<String, MetricDto, ComponentTreeData.Measure> table, MetricDto metric) {
- this.table = table;
- this.metric = metric;
- }
-
- @Override
- public boolean test(@Nonnull ComponentDto input) {
- Measure measure = table.get(input.uuid(), metric);
- return measure != null && measure.isVariationSet();
- }
- }
-
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
index c2241838984..ca1e1515911 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
@@ -29,7 +29,6 @@ import org.sonarqube.ws.Measures.Measure;
import static java.lang.Double.compare;
import static java.util.Optional.ofNullable;
import static org.sonar.server.measure.ws.MeasureValueFormatter.formatMeasureValue;
-import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue;
class MeasureDtoToWsMeasure {
@@ -38,37 +37,38 @@ class MeasureDtoToWsMeasure {
}
static void updateMeasureBuilder(Measure.Builder measureBuilder, MetricDto metricDto, MeasureDto measureDto) {
- Double value = measureDto.getValue();
- Double variation = measureDto.getVariation();
- updateMeasureBuilder(measureBuilder, metricDto, value == null ? Double.NaN : value, measureDto.getData(), variation == null ? Double.NaN : variation);
+ double value = measureDto.getValue() == null ? Double.NaN : measureDto.getValue();
+ boolean onNewCode = metricDto.getKey().startsWith("new_");
+ updateMeasureBuilder(measureBuilder, metricDto, value, measureDto.getData(), onNewCode);
}
static void updateMeasureBuilder(Measure.Builder measureBuilder, MetricDto metricDto, LiveMeasureDto measureDto) {
- Double value = measureDto.getValue();
- Double variation = measureDto.getVariation();
- updateMeasureBuilder(measureBuilder, metricDto, value == null ? Double.NaN : value, measureDto.getDataAsString(), variation == null ? Double.NaN : variation);
+ double value = measureDto.getValue() == null ? Double.NaN : measureDto.getValue();
+ boolean onNewCode = metricDto.getKey().startsWith("new_");
+ updateMeasureBuilder(measureBuilder, metricDto, value, measureDto.getDataAsString(), onNewCode);
}
- static void updateMeasureBuilder(Measure.Builder measureBuilder, MetricDto metric, double doubleValue, @Nullable String stringValue, double variation) {
+ static void updateMeasureBuilder(Measure.Builder measureBuilder, MetricDto metric, double doubleValue, @Nullable String stringValue, boolean onNewCode) {
measureBuilder.setMetric(metric.getKey());
Double bestValue = metric.getBestValue();
- // a measure value can be null, new_violations metric for example
- if (!Double.isNaN(doubleValue) || stringValue != null) {
- measureBuilder.setValue(formatMeasureValue(doubleValue, stringValue, metric));
- ofNullable(bestValue).ifPresent(v -> measureBuilder.setBestValue(compare(doubleValue, v) == 0));
- }
- Measures.PeriodValue.Builder periodBuilder = Measures.PeriodValue.newBuilder();
- if (Double.isNaN(variation)) {
+ if (Double.isNaN(doubleValue) && stringValue == null) {
return;
}
- Measures.PeriodValue.Builder builderForValue = periodBuilder
- .clear()
- .setIndex(1)
- .setValue(formatNumericalValue(variation, metric));
- ofNullable(bestValue).ifPresent(v -> builderForValue.setBestValue(compare(variation, v) == 0));
- //deprecated since 8.1
- measureBuilder.getPeriodsBuilder().addPeriodsValue(builderForValue);
- measureBuilder.setPeriod(builderForValue);
+
+ if (!onNewCode) {
+ measureBuilder.setValue(formatMeasureValue(doubleValue, stringValue, metric));
+ ofNullable(bestValue).ifPresent(v -> measureBuilder.setBestValue(compare(doubleValue, v) == 0));
+ } else {
+ Measures.PeriodValue.Builder periodBuilder = Measures.PeriodValue.newBuilder();
+ Measures.PeriodValue.Builder builderForValue = periodBuilder
+ .clear()
+ .setIndex(1)
+ .setValue(formatMeasureValue(doubleValue, stringValue, metric));
+ ofNullable(bestValue).ifPresent(v -> builderForValue.setBestValue(compare(doubleValue, v) == 0));
+ //deprecated since 8.1
+ measureBuilder.getPeriodsBuilder().addPeriodsValue(builderForValue);
+ measureBuilder.setPeriod(builderForValue);
+ }
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
index 41a7e2bb02d..37fcb4a6eed 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
@@ -20,7 +20,6 @@
package org.sonar.server.measure.ws;
import com.google.common.collect.ImmutableSortedSet;
-import java.util.Locale;
import java.util.Set;
import java.util.function.Predicate;
import org.sonar.api.resources.Qualifiers;
@@ -29,7 +28,6 @@ import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
public class MetricDtoWithBestValue {
- private static final String LOWER_CASE_NEW_METRIC_PREFIX = "new_";
private static final Set<String> QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE = ImmutableSortedSet.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE);
private final MetricDto metric;
@@ -38,13 +36,7 @@ public class MetricDtoWithBestValue {
MetricDtoWithBestValue(MetricDto metric) {
this.metric = metric;
LiveMeasureDto measure = new LiveMeasureDto().setMetricUuid(metric.getUuid());
- boolean isNewTypeMetric = metric.getKey().toLowerCase(Locale.ENGLISH).startsWith(LOWER_CASE_NEW_METRIC_PREFIX);
- if (isNewTypeMetric) {
- measure.setVariation(metric.getBestValue());
- } else {
- measure.setValue(metric.getBestValue());
- }
-
+ measure.setValue(metric.getBestValue());
this.bestValue = measure;
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java
index 2fc7308cf1b..43b60e01d58 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java
@@ -121,7 +121,7 @@ class PrMeasureFix {
String originalKey = METRICS.inverse().get(metric.getKey());
if (originalKey != null && requestedMetricKeys.contains(originalKey)) {
for (Map.Entry<String, ComponentTreeData.Measure> e : measuresByComponentUuidAndMetric.column(metric).entrySet()) {
- newEntries.put(e.getKey(), copyMeasureToVariation(e.getValue()));
+ newEntries.put(e.getKey(), e.getValue());
}
MetricDto originalMetric = metricByKey.get(originalKey);
@@ -142,7 +142,7 @@ class PrMeasureFix {
if (originalKey != null && requestedMetricKeys.contains(originalKey)) {
MetricDto metricDto = metricByKey.get(originalKey);
- newEntries.put(metricDto, copyMeasureToVariation(e.getValue(), metricDto.getUuid()));
+ newEntries.put(metricDto, copyMeasure(e.getValue(), metricDto.getUuid()));
}
}
@@ -150,13 +150,9 @@ class PrMeasureFix {
measuresByMetric.putAll(newEntries);
}
- private static ComponentTreeData.Measure copyMeasureToVariation(ComponentTreeData.Measure measure) {
- return new ComponentTreeData.Measure(null, null, measure.getValue());
- }
-
- private static LiveMeasureDto copyMeasureToVariation(LiveMeasureDto dto, String metricUuid) {
+ private static LiveMeasureDto copyMeasure(LiveMeasureDto dto, String metricUuid) {
LiveMeasureDto copy = new LiveMeasureDto();
- copy.setVariation(dto.getValue());
+ copy.setValue(dto.getValue());
copy.setProjectUuid(dto.getProjectUuid());
copy.setComponentUuid(dto.getComponentUuid());
copy.setMetricUuid(metricUuid);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
index 239bb3405bd..e5e741f3b2f 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
@@ -35,7 +35,6 @@ import org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryValue;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.server.measure.ws.MeasureValueFormatter.formatMeasureValue;
-import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue;
class SearchHistoryResponseFactory {
private final SearchHistoryResult result;
@@ -105,9 +104,7 @@ class SearchHistoryResponseFactory {
private SnapshotDto addValue(SnapshotDto analysis, MetricDto dbMetric, @Nullable MeasureDto dbMeasure) {
if (dbMeasure != null) {
- String measureValue = dbMetric.getKey().startsWith("new_")
- ? formatNumericalValue(dbMeasure.getVariation(), dbMetric)
- : formatMeasureValue(dbMeasure, dbMetric);
+ String measureValue = formatMeasureValue(dbMeasure, dbMetric);
if (measureValue != null) {
value.setValue(measureValue);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
index 3849db9fdcf..187cc8c4cc6 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
@@ -129,17 +129,10 @@ public class SearchHistoryResult {
}
private static MeasureDto toBestValue(MetricDto metric, SnapshotDto analysis) {
- MeasureDto measure = new MeasureDto()
+ return new MeasureDto()
.setMetricUuid(metric.getUuid())
- .setAnalysisUuid(analysis.getUuid());
-
- if (metric.getKey().startsWith("new_")) {
- measure.setVariation(metric.getBestValue());
- } else {
- measure.setValue(metric.getBestValue());
- }
-
- return measure;
+ .setAnalysisUuid(analysis.getUuid())
+ .setValue(metric.getBestValue());
}
Common.Paging getPaging() {
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json
index 60299412502..02403212db3 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json
@@ -8,11 +8,7 @@
"measures": [
{
"metric": "complexity",
- "value": "12",
- "period": {
- "value": "2",
- "bestValue": false
- }
+ "value": "12"
},
{
"metric": "new_violations",
@@ -23,11 +19,7 @@
},
{
"metric": "ncloc",
- "value": "114",
- "period": {
- "value": "3",
- "bestValue": false
- }
+ "value": "114"
}
]
},
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
index f87909519e9..72d1c1669f8 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
@@ -78,17 +78,11 @@
},
{
"metric": "complexity",
- "value": "35",
- "period": {
- "value": "0"
- }
+ "value": "35"
},
{
"metric": "ncloc",
- "value": "217",
- "period": {
- "value": "0"
- }
+ "value": "217"
}
]
}
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/search-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/search-example.json
index 2ee709129e6..4b88de945e8 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/search-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/search-example.json
@@ -8,12 +8,6 @@
{
"metric": "complexity",
"value": "35",
- "periods": [
- {
- "index": 1,
- "value": "0"
- }
- ],
"component": "MY_PROJECT_2"
},
{
@@ -29,12 +23,6 @@
{
"metric": "ncloc",
"value": "217",
- "periods": [
- {
- "index": 1,
- "value": "0"
- }
- ],
"component": "MY_PROJECT_2"
},
{
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
index 03bbabbe88f..9188315bce1 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
@@ -389,9 +389,9 @@ public class SearchProjectsActionTest {
public void filter_projects_by_new_rating(String newMetricKey) {
userSession.logIn();
MetricDto ratingMetric = db.measures().insertMetric(c -> c.setKey(newMetricKey).setValueType(INT.name()));
- insertProject(new Measure(ratingMetric, c -> c.setVariation(1d)));
- ComponentDto project2 = insertProject(new Measure(ratingMetric, c -> c.setVariation(2d)));
- insertProject(new Measure(ratingMetric, c -> c.setVariation(3d)));
+ insertProject(new Measure(ratingMetric, c -> c.setValue(1d)));
+ ComponentDto project2 = insertProject(new Measure(ratingMetric, c -> c.setValue(2d)));
+ insertProject(new Measure(ratingMetric, c -> c.setValue(3d)));
index();
SearchProjectsWsResponse result = call(request.setFilter(newMetricKey + " = 2"));
@@ -430,9 +430,9 @@ public class SearchProjectsActionTest {
public void filter_projects_by_new_coverage() {
userSession.logIn();
MetricDto coverage = db.measures().insertMetric(c -> c.setKey(NEW_COVERAGE).setValueType("PERCENT"));
- ComponentDto project1 = insertProject(new Measure(coverage, c -> c.setVariation(80d)));
- ComponentDto project2 = insertProject(new Measure(coverage, c -> c.setVariation(85d)));
- ComponentDto project3 = insertProject(new Measure(coverage, c -> c.setVariation(10d)));
+ ComponentDto project1 = insertProject(new Measure(coverage, c -> c.setValue(80d)));
+ ComponentDto project2 = insertProject(new Measure(coverage, c -> c.setValue(85d)));
+ ComponentDto project3 = insertProject(new Measure(coverage, c -> c.setValue(10d)));
index();
SearchProjectsWsResponse result = call(request.setFilter("new_coverage <= 80"));
@@ -486,9 +486,9 @@ public class SearchProjectsActionTest {
public void filter_projects_by_new_duplications() {
userSession.logIn();
MetricDto newDuplications = db.measures().insertMetric(c -> c.setKey(NEW_DUPLICATED_LINES_DENSITY_KEY).setValueType("PERCENT"));
- ComponentDto project1 = insertProject(new Measure(newDuplications, c -> c.setVariation(80d)));
- ComponentDto project2 = insertProject(new Measure(newDuplications, c -> c.setVariation(85d)));
- ComponentDto project3 = insertProject(new Measure(newDuplications, c -> c.setVariation(10d)));
+ ComponentDto project1 = insertProject(new Measure(newDuplications, c -> c.setValue(80d)));
+ ComponentDto project2 = insertProject(new Measure(newDuplications, c -> c.setValue(85d)));
+ ComponentDto project3 = insertProject(new Measure(newDuplications, c -> c.setValue(10d)));
index();
SearchProjectsWsResponse result = call(request.setFilter("new_duplicated_lines_density <= 80"));
@@ -514,9 +514,9 @@ public class SearchProjectsActionTest {
public void filter_projects_by_new_lines() {
userSession.logIn();
MetricDto newLines = db.measures().insertMetric(c -> c.setKey(NEW_LINES_KEY).setValueType(INT.name()));
- ComponentDto project1 = insertProject(new Measure(newLines, c -> c.setVariation(80d)));
- ComponentDto project2 = insertProject(new Measure(newLines, c -> c.setVariation(85d)));
- ComponentDto project3 = insertProject(new Measure(newLines, c -> c.setVariation(10d)));
+ ComponentDto project1 = insertProject(new Measure(newLines, c -> c.setValue(80d)));
+ ComponentDto project2 = insertProject(new Measure(newLines, c -> c.setValue(85d)));
+ ComponentDto project3 = insertProject(new Measure(newLines, c -> c.setValue(10d)));
index();
SearchProjectsWsResponse result = call(request.setFilter("new_lines <= 80"));
@@ -755,9 +755,9 @@ public class SearchProjectsActionTest {
public void return_new_lines_facet() {
userSession.logIn();
MetricDto coverage = db.measures().insertMetric(c -> c.setKey(NEW_LINES_KEY).setValueType(INT.name()));
- insertProject(new Measure(coverage, c -> c.setVariation(100d)));
- insertProject(new Measure(coverage, c -> c.setVariation(15_000d)));
- insertProject(new Measure(coverage, c -> c.setVariation(50_000d)));
+ insertProject(new Measure(coverage, c -> c.setValue(100d)));
+ insertProject(new Measure(coverage, c -> c.setValue(15_000d)));
+ insertProject(new Measure(coverage, c -> c.setValue(50_000d)));
index();
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_LINES_KEY)));
@@ -949,10 +949,10 @@ public class SearchProjectsActionTest {
public void return_new_rating_facet(String newRatingMetricKey) {
userSession.logIn();
MetricDto newRatingMetric = db.measures().insertMetric(c -> c.setKey(newRatingMetricKey).setValueType("RATING"));
- insertProject(new Measure(newRatingMetric, c -> c.setVariation(1d)));
- insertProject(new Measure(newRatingMetric, c -> c.setVariation(1d)));
- insertProject(new Measure(newRatingMetric, c -> c.setVariation(3d)));
- insertProject(new Measure(newRatingMetric, c -> c.setVariation(5d)));
+ insertProject(new Measure(newRatingMetric, c -> c.setValue(1d)));
+ insertProject(new Measure(newRatingMetric, c -> c.setValue(1d)));
+ insertProject(new Measure(newRatingMetric, c -> c.setValue(3d)));
+ insertProject(new Measure(newRatingMetric, c -> c.setValue(5d)));
index();
SearchProjectsWsResponse result = call(request.setFacets(singletonList(newRatingMetricKey)));
@@ -1001,9 +1001,9 @@ public class SearchProjectsActionTest {
userSession.logIn();
MetricDto coverage = db.measures().insertMetric(c -> c.setKey(NEW_COVERAGE).setValueType("PERCENT"));
insertProject();
- insertProject(new Measure(coverage, c -> c.setVariation(80d)));
- insertProject(new Measure(coverage, c -> c.setVariation(85d)));
- insertProject(new Measure(coverage, c -> c.setVariation(10d)));
+ insertProject(new Measure(coverage, c -> c.setValue(80d)));
+ insertProject(new Measure(coverage, c -> c.setValue(85d)));
+ insertProject(new Measure(coverage, c -> c.setValue(10d)));
index();
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_COVERAGE)));
@@ -1053,9 +1053,9 @@ public class SearchProjectsActionTest {
userSession.logIn();
MetricDto coverage = db.measures().insertMetric(c -> c.setKey(NEW_DUPLICATED_LINES_DENSITY_KEY).setValueType("PERCENT"));
insertProject();
- insertProject(new Measure(coverage, c -> c.setVariation(10d)));
- insertProject(new Measure(coverage, c -> c.setVariation(15d)));
- insertProject(new Measure(coverage, c -> c.setVariation(5d)));
+ insertProject(new Measure(coverage, c -> c.setValue(10d)));
+ insertProject(new Measure(coverage, c -> c.setValue(15d)));
+ insertProject(new Measure(coverage, c -> c.setValue(5d)));
index();
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_DUPLICATED_LINES_DENSITY_KEY)));
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImplTest.java
index ab72d88b161..1f40ee06968 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureTreeUpdaterImplTest.java
@@ -170,7 +170,7 @@ public class LiveMeasureTreeUpdaterImplTest {
componentIndex.load(db.getSession(), List.of(file1));
treeUpdater.update(db.getSession(), snapshot, config, componentIndex, branch, matrix);
- assertThat(matrix.getMeasure(file1, metric.getKey()).get().getVariation()).isEqualTo(1d);
+ assertThat(matrix.getMeasure(file1, metric.getKey()).get().getValue()).isEqualTo(1d);
}
@Test
@@ -185,7 +185,7 @@ public class LiveMeasureTreeUpdaterImplTest {
componentIndex.load(db.getSession(), List.of(file1));
treeUpdater.update(db.getSession(), snapshot, config, componentIndex, branch, matrix);
- assertThat(matrix.getMeasure(file1, metric.getKey()).get().getVariation()).isEqualTo(2d);
+ assertThat(matrix.getMeasure(file1, metric.getKey()).get().getValue()).isEqualTo(2d);
}
@Test
@@ -215,11 +215,11 @@ public class LiveMeasureTreeUpdaterImplTest {
matrix = new MeasureMatrix(List.of(project, dir, file1, file2), metrics, List.of());
LiveMeasureTreeUpdaterImpl.FormulaContextImpl context = new LiveMeasureTreeUpdaterImpl.FormulaContextImpl(matrix, componentIndex, null);
- matrix.setLeakValue(file1, NEW_SECURITY_HOTSPOTS_KEY, 4d);
- matrix.setLeakValue(file1, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, 33d);
+ matrix.setValue(file1, NEW_SECURITY_HOTSPOTS_KEY, 4d);
+ matrix.setValue(file1, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, 33d);
- matrix.setLeakValue(file2, NEW_SECURITY_HOTSPOTS_KEY, 2d);
- matrix.setLeakValue(file2, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, 50d);
+ matrix.setValue(file2, NEW_SECURITY_HOTSPOTS_KEY, 2d);
+ matrix.setValue(file2, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, 50d);
context.change(dir, null);
assertThat(context.getChildrenNewHotspotsToReview()).isEqualTo(6);
@@ -262,18 +262,6 @@ public class LiveMeasureTreeUpdaterImplTest {
}
}
- private class NoOpFormula implements MeasureUpdateFormulaFactory {
-
- @Override
- public List<MeasureUpdateFormula> getFormulas() {
- return emptyList();
- }
-
- @Override public Set<Metric> getFormulaMetrics() {
- return emptySet();
- }
- }
-
private class SetValuesFormula implements MeasureUpdateFormulaFactory {
@Override
public List<MeasureUpdateFormula> getFormulas() {
@@ -291,7 +279,7 @@ public class LiveMeasureTreeUpdaterImplTest {
@Override
public List<MeasureUpdateFormula> getFormulas() {
return List.of(new MeasureUpdateFormula(metric, true, (c, m) -> {
- }, (c, i) -> c.setLeakValue(i.countUnresolved(true))));
+ }, (c, i) -> c.setValue(i.countUnresolved(true))));
}
@Override
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java
index b740a2235ce..afb3bf17ce8 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java
@@ -56,8 +56,6 @@ import static org.assertj.core.groups.Tuple.tuple;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
public class LiveQualityGateComputerImplTest {
-
-
@Rule
public DbTester db = DbTester.create();
@@ -151,8 +149,8 @@ public class LiveQualityGateComputerImplTest {
MetricDto statusMetric = newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY);
MetricDto detailsMetric = newMetricDto().setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
QualityGate gate = new QualityGate("1", "foo", Collections.emptySet());
- LiveMeasureDto numericMeasure = new LiveMeasureDto().setMetricUuid(numericMetric.getUuid()).setValue(1.23).setVariation(4.56).setComponentUuid(project.uuid());
- LiveMeasureDto numericNewMeasure = new LiveMeasureDto().setMetricUuid(numericNewMetric.getUuid()).setValue(7.8).setVariation(8.9).setComponentUuid(project.uuid());
+ LiveMeasureDto numericMeasure = new LiveMeasureDto().setMetricUuid(numericMetric.getUuid()).setValue(1.23).setComponentUuid(project.uuid());
+ LiveMeasureDto numericNewMeasure = new LiveMeasureDto().setMetricUuid(numericNewMetric.getUuid()).setValue(8.9).setComponentUuid(project.uuid());
LiveMeasureDto stringMeasure = new LiveMeasureDto().setMetricUuid(stringMetric.getUuid()).setData("bar").setComponentUuid(project.uuid());
MeasureMatrix matrix = new MeasureMatrix(singleton(project), asList(statusMetric, detailsMetric, numericMetric, numericNewMetric, stringMetric),
asList(numericMeasure, numericNewMeasure, stringMeasure));
@@ -173,7 +171,7 @@ public class LiveQualityGateComputerImplTest {
QualityGateEvaluator.Measure loadedNumericNewMeasure = measures.get(numericNewMetric.getKey()).get();
assertThat(loadedNumericNewMeasure.getStringValue()).isEmpty();
- assertThat(loadedNumericNewMeasure.getNewMetricValue()).hasValue(8.9);
+ assertThat(loadedNumericNewMeasure.getValue()).hasValue(8.9);
assertThat(loadedNumericNewMeasure.getType()).isEqualTo(Metric.ValueType.FLOAT);
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java
index e5869c20a74..5c28f9178f4 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java
@@ -92,7 +92,6 @@ public class MeasureMatrixTest {
underTest.setValue(PROJECT, metric.getKey(), 3.148);
verifyValue(underTest, PROJECT, metric, 3.15);
- verifyVariation(underTest, PROJECT, metric, null);
}
private void verifyValue(MeasureMatrix underTest, ComponentDto component, MetricDto metric, @Nullable Double expectedValue) {
@@ -101,10 +100,6 @@ public class MeasureMatrixTest {
assertThat(measure.get().getValue()).isEqualTo(expectedValue);
}
- private void verifyVariation(MeasureMatrix underTest, ComponentDto component, MetricDto metric, @Nullable Double expectedVariation) {
- assertThat(underTest.getMeasure(component, metric.getKey()).get().getVariation()).isEqualTo(expectedVariation);
- }
-
@Test
public void setValue_double_does_nothing_if_value_is_unchanged() {
MetricDto metric = newMetricDto().setDecimalScale(2);
@@ -118,33 +113,6 @@ public class MeasureMatrixTest {
}
@Test
- public void setValue_double_updates_variation() {
- MetricDto metric = newMetricDto().setDecimalScale(2);
- LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(3.14).setVariation(1.14);
- MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
-
- underTest.setValue(PROJECT, metric.getKey(), 3.56);
-
- assertThat(underTest.getChanged()).hasSize(1);
- verifyValue(underTest, PROJECT, metric, 3.56);
- verifyVariation(underTest, PROJECT, metric, 1.14);
- }
-
- @Test
- public void setValue_double_rounds_up_variation() {
- MetricDto metric = newMetricDto().setDecimalScale(2);
- LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(3.14).setVariation(1.14);
- MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
-
- underTest.setValue(PROJECT, metric.getKey(), 3.569);
- underTest.setLeakValue(PROJECT, metric.getKey(), 3.569);
-
- assertThat(underTest.getChanged()).hasSize(1);
- verifyValue(underTest, PROJECT, metric, 3.57);
- verifyVariation(underTest, PROJECT, metric, 3.57);
- }
-
- @Test
public void setValue_String_does_nothing_if_value_is_not_changed() {
LiveMeasureDto measure = newMeasure(METRIC_1, PROJECT).setData("foo");
MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT, FILE), asList(METRIC_1), asList(measure));
@@ -166,35 +134,6 @@ public class MeasureMatrixTest {
assertThat(underTest.getChanged()).extracting(LiveMeasureDto::getDataAsString).containsExactly("bar");
}
- @Test
- public void setLeakValue_rounds_up_and_updates_value() {
- MetricDto metric = newMetricDto().setDecimalScale(2);
- LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(null);
- MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
-
- underTest.setLeakValue(PROJECT, metric.getKey(), 3.14159);
- verifyVariation(underTest, PROJECT, metric, 3.14);
- // do not update value
- verifyValue(underTest, PROJECT, metric, null);
-
- underTest.setLeakValue(PROJECT, metric.getKey(), 3.148);
- verifyVariation(underTest, PROJECT, metric, 3.15);
- // do not update value
- verifyValue(underTest, PROJECT, metric, null);
- }
-
- @Test
- public void setLeakValue_double_does_nothing_if_value_is_unchanged() {
- MetricDto metric = newMetricDto().setDecimalScale(2);
- LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(null).setVariation(3.14);
- MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
-
- underTest.setLeakValue(PROJECT, metric.getKey(), 3.14159);
-
- assertThat(underTest.getChanged()).isEmpty();
- verifyVariation(underTest, PROJECT, metric, 3.14);
- }
-
private LiveMeasureDto newMeasure(MetricDto metric, ComponentDto component) {
return new LiveMeasureDto().setMetricUuid(metric.getUuid()).setData("foo").setComponentUuid(component.uuid());
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java
index c68cc2c8813..72834d2f025 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java
@@ -565,7 +565,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
@Test
public void test_new_security_hotspots() {
- withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_SECURITY_HOTSPOTS, 0.0);
+ withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_SECURITY_HOTSPOTS, 0);
with(
newGroup(RuleType.SECURITY_HOTSPOT).setInLeak(false).setSeverity(Severity.MAJOR).setCount(3),
@@ -816,66 +816,66 @@ public class MeasureUpdateFormulaFactoryImplTest {
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
// technical_debt not computed
- withLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 0)
+ with(CoreMetrics.NEW_DEVELOPMENT_COST, 0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
- withLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 20)
+ with(CoreMetrics.NEW_DEVELOPMENT_COST, 20)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
// development_cost not computed
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 0)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, 0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 20)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, 20)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
// input measures are available
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 20.0)
- .andLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 0.0)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, 20.0)
+ .and(CoreMetrics.NEW_DEVELOPMENT_COST, 0.0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0.0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 20.0)
- .andLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 160.0)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, 20.0)
+ .and(CoreMetrics.NEW_DEVELOPMENT_COST, 160.0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 12.5)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.C);
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 20.0)
- .andLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 10.0D)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, 20.0)
+ .and(CoreMetrics.NEW_DEVELOPMENT_COST, 10.0D)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 200.0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.E);
// A is 5% --> min debt is exactly 200*0.05=10
- withLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 200.0)
- .andLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 10.0)
+ with(CoreMetrics.NEW_DEVELOPMENT_COST, 200.0)
+ .and(CoreMetrics.NEW_TECHNICAL_DEBT, 10.0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 5.0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 0.0)
- .andLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 0.0)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, 0.0)
+ .and(CoreMetrics.NEW_DEVELOPMENT_COST, 0.0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0.0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 0.0)
- .andLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 80.0)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, 0.0)
+ .and(CoreMetrics.NEW_DEVELOPMENT_COST, 80.0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0.0);
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, -20.0)
- .andLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 0.0)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, -20.0)
+ .and(CoreMetrics.NEW_DEVELOPMENT_COST, 0.0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0.0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
// bug, debt can't be negative
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, -20.0)
- .andLeak(CoreMetrics.NEW_DEVELOPMENT_COST, 80.0)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, -20.0)
+ .and(CoreMetrics.NEW_DEVELOPMENT_COST, 80.0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0.0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
// bug, cost can't be negative
- withLeak(CoreMetrics.NEW_TECHNICAL_DEBT, 20.0)
- .andLeak(CoreMetrics.NEW_DEVELOPMENT_COST, -80.0)
+ with(CoreMetrics.NEW_TECHNICAL_DEBT, 20.0)
+ .and(CoreMetrics.NEW_DEVELOPMENT_COST, -80.0)
.assertThatLeakValueIs(CoreMetrics.NEW_SQALE_DEBT_RATIO, 0.0)
.assertThatLeakValueIs(CoreMetrics.NEW_MAINTAINABILITY_RATING, Rating.A);
}
@@ -896,10 +896,6 @@ public class MeasureUpdateFormulaFactoryImplTest {
return new Verifier(new IssueGroupDto[0]).andText(metric, value);
}
- private Verifier withLeak(Metric metric, double leakValue) {
- return new Verifier(new IssueGroupDto[0]).andLeak(metric, leakValue);
- }
-
private class Verifier {
private final IssueGroupDto[] groups;
private final InitialValues initialValues = new InitialValues();
@@ -913,11 +909,6 @@ public class MeasureUpdateFormulaFactoryImplTest {
return this;
}
- Verifier andLeak(Metric metric, double value) {
- this.initialValues.leakValues.put(metric, value);
- return this;
- }
-
Verifier andText(Metric metric, String value) {
this.initialValues.text.put(metric, value);
return this;
@@ -931,19 +922,19 @@ public class MeasureUpdateFormulaFactoryImplTest {
Verifier assertThatLeakValueIs(Metric metric, double expectedValue) {
TestContext context = run(metric, true);
- assertThat(context.doubleLeakValue).isNotNull().isEqualTo(expectedValue);
+ assertThat(context.doubleValue).isNotNull().isEqualTo(expectedValue);
return this;
}
Verifier assertThatLeakValueIs(Metric metric, Rating expectedRating) {
TestContext context = run(metric, true);
- assertThat(context.ratingLeakValue).isNotNull().isEqualTo(expectedRating);
+ assertThat(context.ratingValue).isNotNull().isEqualTo(expectedRating);
return this;
}
Verifier assertNoLeakValue(Metric metric) {
TestContext context = run(metric, true);
- assertThat(context.ratingLeakValue).isNull();
+ assertThat(context.ratingValue).isNull();
return this;
}
@@ -1004,8 +995,6 @@ public class MeasureUpdateFormulaFactoryImplTest {
private final InitialValues initialValues;
private Double doubleValue;
private Rating ratingValue;
- private Double doubleLeakValue;
- private Rating ratingLeakValue;
private TestContext(Collection<Metric> dependentMetrics, InitialValues initialValues) {
this.dependentMetrics = new HashSet<>(dependentMetrics);
@@ -1038,11 +1027,6 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Override
- public List<Double> getChildrenLeakValues() {
- return initialValues.childrenLeakValues;
- }
-
- @Override
public ComponentDto getComponent() {
throw new UnsupportedOperationException();
}
@@ -1072,17 +1056,6 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
@Override
- public Optional<Double> getLeakValue(Metric metric) {
- if (!dependentMetrics.contains(metric)) {
- throw new IllegalStateException("Metric " + metric.getKey() + " is not declared as a dependency");
- }
- if (initialValues.leakValues.containsKey(metric)) {
- return Optional.of(initialValues.leakValues.get(metric));
- }
- return Optional.empty();
- }
-
- @Override
public void setValue(double value) {
this.doubleValue = value;
}
@@ -1091,23 +1064,11 @@ public class MeasureUpdateFormulaFactoryImplTest {
public void setValue(Rating value) {
this.ratingValue = value;
}
-
- @Override
- public void setLeakValue(double value) {
- this.doubleLeakValue = value;
- }
-
- @Override
- public void setLeakValue(Rating value) {
- this.ratingLeakValue = value;
- }
}
private class InitialValues {
private final Map<Metric, Double> values = new HashMap<>();
- private final Map<Metric, Double> leakValues = new HashMap<>();
private final List<Double> childrenValues = new ArrayList<>();
- private final List<Double> childrenLeakValues = new ArrayList<>();
private final Map<Metric, String> text = new HashMap<>();
private long childrenHotspotsReviewed = 0;
private long childrenNewHotspotsReviewed = 0;
@@ -1128,11 +1089,7 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
public HierarchyTester withValue(Metric metric, Double value) {
- if (formula.isOnLeak()) {
- this.initialValues.leakValues.put(metric, value);
- } else {
- this.initialValues.values.put(metric, value);
- }
+ this.initialValues.values.put(metric, value);
return this;
}
@@ -1150,31 +1107,19 @@ public class MeasureUpdateFormulaFactoryImplTest {
}
public HierarchyTester withChildrenValues(Double... values) {
- if (formula.isOnLeak()) {
- this.initialValues.childrenLeakValues.addAll(asList(values));
- } else {
- this.initialValues.childrenValues.addAll(asList(values));
- }
+ this.initialValues.childrenValues.addAll(asList(values));
return this;
}
public HierarchyTester expectedResult(@Nullable Double expected) {
TestContext ctx = run();
- if (formula.isOnLeak()) {
- assertThat(ctx.doubleLeakValue).isEqualTo(expected);
- } else {
- assertThat(ctx.doubleValue).isEqualTo(expected);
- }
+ assertThat(ctx.doubleValue).isEqualTo(expected);
return this;
}
public HierarchyTester expectedRating(@Nullable Rating rating) {
TestContext ctx = run();
- if (formula.isOnLeak()) {
- assertThat(ctx.ratingLeakValue).isEqualTo(rating);
- } else {
- assertThat(ctx.ratingValue).isEqualTo(rating);
- }
+ assertThat(ctx.ratingValue).isEqualTo(rating);
return this;
}
@@ -1182,7 +1127,6 @@ public class MeasureUpdateFormulaFactoryImplTest {
List<Metric> deps = new LinkedList<>(formula.getDependentMetrics());
deps.add(formula.getMetric());
deps.addAll(initialValues.values.keySet());
- deps.addAll(initialValues.leakValues.keySet());
deps.addAll(initialValues.text.keySet());
TestContext context = new TestContext(deps, initialValues);
formula.computeHierarchy(context);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
index 08cae5ea7ea..79f75484be3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
@@ -124,7 +124,7 @@ public class ComponentActionTest {
db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
MetricDto complexity = db.measures().insertMetric(m1 -> m1.setKey("complexity").setValueType("INT"));
- LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d).setVariation(2.0d));
+ LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
@@ -164,7 +164,7 @@ public class ComponentActionTest {
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
MetricDto complexity = db.measures().insertMetric(m1 -> m1.setKey("complexity").setValueType("INT"));
- LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d).setVariation(2.0d));
+ LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
@@ -190,9 +190,9 @@ public class ComponentActionTest {
MetricDto newBugs = db.measures().insertMetric(m1 -> m1.setKey("new_bugs").setValueType("INT"));
MetricDto violations = db.measures().insertMetric(m1 -> m1.setKey("violations").setValueType("INT"));
MetricDto newViolations = db.measures().insertMetric(m1 -> m1.setKey("new_violations").setValueType("INT"));
- LiveMeasureDto bugMeasure = db.measures().insertLiveMeasure(file, bugs, m -> m.setValue(12.0d).setVariation(null));
- LiveMeasureDto newBugMeasure = db.measures().insertLiveMeasure(file, newBugs, m -> m.setVariation(1d).setValue(null));
- LiveMeasureDto violationMeasure = db.measures().insertLiveMeasure(file, violations, m -> m.setValue(20.0d).setVariation(null));
+ LiveMeasureDto bugMeasure = db.measures().insertLiveMeasure(file, bugs, m -> m.setValue(12.0d));
+ LiveMeasureDto newBugMeasure = db.measures().insertLiveMeasure(file, newBugs, m -> m.setValue(1d));
+ LiveMeasureDto violationMeasure = db.measures().insertLiveMeasure(file, violations, m -> m.setValue(20.0d));
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
@@ -419,7 +419,6 @@ public class ComponentActionTest {
.setHidden(false));
db.measures().insertLiveMeasure(file, complexity,
m -> m.setValue(12.0d)
- .setVariation(2.0d)
.setData((String) null));
MetricDto ncloc = db.measures().insertMetric(m1 -> m1.setKey("ncloc")
@@ -432,7 +431,6 @@ public class ComponentActionTest {
.setHidden(false));
db.measures().insertLiveMeasure(file, ncloc,
m -> m.setValue(114.0d)
- .setVariation(3.0d)
.setData((String) null));
MetricDto newViolations = db.measures().insertMetric(m -> m.setKey("new_violations")
@@ -444,8 +442,7 @@ public class ComponentActionTest {
.setQualitative(true)
.setHidden(false));
db.measures().insertLiveMeasure(file, newViolations,
- m -> m.setVariation(25.0d)
- .setValue(null)
+ m -> m.setValue(25.0d)
.setData((String) null));
String response = ws.newRequest()
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
index 241edc67f81..2ee59711b6c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
@@ -144,18 +144,18 @@ public class ComponentTreeActionTest {
MetricDto complexity = insertComplexityMetric();
db.measures().insertLiveMeasure(file1, complexity, m -> m.setValue(12.0d));
- db.measures().insertLiveMeasure(dir, complexity, m -> m.setValue(35.0d).setVariation(0.0d));
+ db.measures().insertLiveMeasure(dir, complexity, m -> m.setValue(35.0d));
db.measures().insertLiveMeasure(project, complexity, m -> m.setValue(42.0d));
MetricDto ncloc = insertNclocMetric();
db.measures().insertLiveMeasure(file1, ncloc, m -> m.setValue(114.0d));
- db.measures().insertLiveMeasure(dir, ncloc, m -> m.setValue(217.0d).setVariation(0.0d));
+ db.measures().insertLiveMeasure(dir, ncloc, m -> m.setValue(217.0d));
db.measures().insertLiveMeasure(project, ncloc, m -> m.setValue(1984.0d));
MetricDto newViolations = insertNewViolationsMetric();
- db.measures().insertLiveMeasure(file1, newViolations, m -> m.setVariation(25.0d));
- db.measures().insertLiveMeasure(dir, newViolations, m -> m.setVariation(25.0d));
- db.measures().insertLiveMeasure(project, newViolations, m -> m.setVariation(255.0d));
+ db.measures().insertLiveMeasure(file1, newViolations, m -> m.setValue(25.0d));
+ db.measures().insertLiveMeasure(dir, newViolations, m -> m.setValue(25.0d));
+ db.measures().insertLiveMeasure(project, newViolations, m -> m.setValue(255.0d));
db.commit();
@@ -202,7 +202,7 @@ public class ComponentTreeActionTest {
MetricDto ncloc = insertNclocMetric();
MetricDto coverage = insertCoverageMetric();
db.commit();
- db.measures().insertLiveMeasure(file, ncloc, m -> m.setValue(5.0d).setVariation(4.0d));
+ db.measures().insertLiveMeasure(file, ncloc, m -> m.setValue(5.0d));
db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(15.5d));
db.measures().insertLiveMeasure(directory, coverage, m -> m.setValue(15.5d));
@@ -287,9 +287,9 @@ public class ComponentTreeActionTest {
.setKey("new_violations")
.setValueType(INT.name())
.setBestValue(null));
- db.measures().insertLiveMeasure(file, matchingBestValue, m -> m.setValue(null).setData((String) null).setVariation(100d));
- db.measures().insertLiveMeasure(file, doesNotMatchBestValue, m -> m.setValue(null).setData((String) null).setVariation(10d));
- db.measures().insertLiveMeasure(file, noBestValue, m -> m.setValue(null).setData((String) null).setVariation(42.0d));
+ db.measures().insertLiveMeasure(file, matchingBestValue, m -> m.setData((String) null).setValue(100d));
+ db.measures().insertLiveMeasure(file, doesNotMatchBestValue, m -> m.setData((String) null).setValue(10d));
+ db.measures().insertLiveMeasure(file, noBestValue, m -> m.setData((String) null).setValue(42.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, project.getKey())
@@ -333,7 +333,7 @@ public class ComponentTreeActionTest {
.setBestValue(1d)
.setValueType(RATING.name()));
db.commit();
- db.measures().insertLiveMeasure(directory, metric, m -> m.setVariation(2d));
+ db.measures().insertLiveMeasure(directory, metric, m -> m.setValue(2d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, project.getKey())
@@ -434,11 +434,9 @@ public class ComponentTreeActionTest {
db.components().insertComponent(file4);
MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
- db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(1.0d).setVariation(null));
- db.measures().insertLiveMeasure(file2, ncloc, m -> m.setData((String) null).setValue(2.0d).setVariation(null));
- db.measures().insertLiveMeasure(file3, ncloc, m -> m.setData((String) null).setValue(3.0d).setVariation(null));
- // measure on period 1
- db.measures().insertLiveMeasure(file4, ncloc, m -> m.setData((String) null).setValue(null).setVariation(4.0d));
+ db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(1.0d));
+ db.measures().insertLiveMeasure(file2, ncloc, m -> m.setData((String) null).setValue(2.0d));
+ db.measures().insertLiveMeasure(file3, ncloc, m -> m.setData((String) null).setValue(3.0d));
db.commit();
ComponentTreeWsResponse response = ws.newRequest()
@@ -466,9 +464,9 @@ public class ComponentTreeActionTest {
MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
db.commit();
- db.measures().insertLiveMeasure(file1, ncloc, m -> m.setVariation(1.0d));
- db.measures().insertLiveMeasure(file2, ncloc, m -> m.setVariation(2.0d));
- db.measures().insertLiveMeasure(file3, ncloc, m -> m.setVariation(3.0d));
+ db.measures().insertLiveMeasure(file1, ncloc, m -> m.setValue(1.0d));
+ db.measures().insertLiveMeasure(file2, ncloc, m -> m.setValue(2.0d));
+ db.measures().insertLiveMeasure(file3, ncloc, m -> m.setValue(3.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, project.getKey())
@@ -492,11 +490,9 @@ public class ComponentTreeActionTest {
ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setKey("file-1-key"));
MetricDto ncloc = newMetricDto().setKey("new_ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
- db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(null).setVariation(1.0d));
- db.measures().insertLiveMeasure(file2, ncloc, m -> m.setData((String) null).setValue(null).setVariation(2.0d));
- db.measures().insertLiveMeasure(file3, ncloc, m -> m.setData((String) null).setValue(null).setVariation(3.0d));
- // file 4 measure is on absolute value
- db.measures().insertLiveMeasure(file4, ncloc, m -> m.setData((String) null).setValue(4.0d).setVariation(null));
+ db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(1.0d));
+ db.measures().insertLiveMeasure(file2, ncloc, m -> m.setData((String) null).setValue(2.0d));
+ db.measures().insertLiveMeasure(file3, ncloc, m -> m.setData((String) null).setValue(3.0d));
db.commit();
ComponentTreeWsResponse response = ws.newRequest()
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java
index 3501d67b2b3..fb12f872b09 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java
@@ -46,6 +46,7 @@ import static org.sonar.server.measure.ws.ComponentTreeData.Measure.createFromMe
public class ComponentTreeSortTest {
private static final String NUM_METRIC_KEY = "violations";
+ private static final String NEW_METRIC_KEY = "new_violations";
private static final String TEXT_METRIC_KEY = "sqale_index";
private List<MetricDto> metrics;
@@ -68,18 +69,21 @@ public class ComponentTreeSortTest {
MetricDto violationsMetric = newMetricDto()
.setKey(NUM_METRIC_KEY)
.setValueType(ValueType.INT.name());
+ MetricDto newViolationsMetric = newMetricDto()
+ .setKey(NEW_METRIC_KEY)
+ .setValueType(ValueType.INT.name());
MetricDto sqaleIndexMetric = newMetricDto()
.setKey(TEXT_METRIC_KEY)
.setValueType(ValueType.STRING.name());
- metrics = newArrayList(violationsMetric, sqaleIndexMetric);
+ metrics = newArrayList(violationsMetric, sqaleIndexMetric, newViolationsMetric);
measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), 2);
// same number than path field
double currentValue = 9;
for (ComponentDto component : components) {
- measuresByComponentUuidAndMetric.put(component.uuid(), violationsMetric, createFromMeasureDto(new LiveMeasureDto().setValue(currentValue)
- .setVariation(-currentValue)));
+ measuresByComponentUuidAndMetric.put(component.uuid(), violationsMetric, createFromMeasureDto(new LiveMeasureDto().setValue(currentValue)));
+ measuresByComponentUuidAndMetric.put(component.uuid(), newViolationsMetric, createFromMeasureDto(new LiveMeasureDto().setValue(currentValue)));
measuresByComponentUuidAndMetric.put(component.uuid(), sqaleIndexMetric, createFromMeasureDto(new LiveMeasureDto().setData(String.valueOf(currentValue))));
currentValue--;
}
@@ -177,9 +181,9 @@ public class ComponentTreeSortTest {
}
@Test
- public void sort_by_numerical_metric_period_1_key_ascending() {
+ public void sort_by_numerical_metric_period_1_key_descending() {
components.add(newComponentWithoutSnapshotId("name-without-measure", "qualifier-without-measure", "path-without-measure"));
- ComponentTreeRequest wsRequest = newRequest(singletonList(METRIC_PERIOD_SORT), true, NUM_METRIC_KEY).setMetricPeriodSort(1);
+ ComponentTreeRequest wsRequest = newRequest(singletonList(METRIC_PERIOD_SORT), false, NEW_METRIC_KEY).setMetricPeriodSort(1);
List<ComponentDto> result = sortComponents(wsRequest);
@@ -188,9 +192,9 @@ public class ComponentTreeSortTest {
}
@Test
- public void sort_by_numerical_metric_period_1_key_descending() {
+ public void sort_by_numerical_metric_period_1_key_ascending() {
components.add(newComponentWithoutSnapshotId("name-without-measure", "qualifier-without-measure", "path-without-measure"));
- ComponentTreeRequest wsRequest = newRequest(singletonList(METRIC_PERIOD_SORT), false, NUM_METRIC_KEY).setMetricPeriodSort(1);
+ ComponentTreeRequest wsRequest = newRequest(singletonList(METRIC_PERIOD_SORT), true, NEW_METRIC_KEY).setMetricPeriodSort(1);
List<ComponentDto> result = sortComponents(wsRequest);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java
index daeeaee2439..b01ba1597df 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java
@@ -80,18 +80,18 @@ public class SearchActionTest {
MetricDto complexity = db.measures().insertMetric(m -> m.setKey("complexity").setValueType(INT.name()));
db.measures().insertLiveMeasure(project1, complexity, m -> m.setValue(12.0d));
- db.measures().insertLiveMeasure(project2, complexity, m -> m.setValue(35.0d).setVariation(0.0d));
+ db.measures().insertLiveMeasure(project2, complexity, m -> m.setValue(35.0d));
db.measures().insertLiveMeasure(project3, complexity, m -> m.setValue(42.0d));
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.name()));
db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(114.0d));
- db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(217.0d).setVariation(0.0d));
+ db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(217.0d));
db.measures().insertLiveMeasure(project3, ncloc, m -> m.setValue(1984.0d));
MetricDto newViolations = db.measures().insertMetric(m -> m.setKey("new_violations").setValueType(INT.name()));
- db.measures().insertLiveMeasure(project1, newViolations, m -> m.setVariation(25.0d));
- db.measures().insertLiveMeasure(project2, newViolations, m -> m.setVariation(25.0d));
- db.measures().insertLiveMeasure(project3, newViolations, m -> m.setVariation(255.0d));
+ db.measures().insertLiveMeasure(project1, newViolations, m -> m.setValue(25.0d));
+ db.measures().insertLiveMeasure(project2, newViolations, m -> m.setValue(25.0d));
+ db.measures().insertLiveMeasure(project3, newViolations, m -> m.setValue(255.0d));
List<String> projectKeys = Arrays.asList(project1.getKey(), project2.getKey(), project3.getKey());
@@ -147,8 +147,8 @@ public class SearchActionTest {
public void return_measures_on_new_code_period() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
- MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
- db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d).setVariation(10d));
+ MetricDto coverage = db.measures().insertMetric(m -> m.setKey("new_metric").setValueType(FLOAT.name()));
+ db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(10d));
SearchWsResponse result = call(singletonList(project.getKey()), singletonList(coverage.getKey()));
@@ -156,7 +156,7 @@ public class SearchActionTest {
assertThat(measures).hasSize(1);
Measure measure = measures.get(0);
assertThat(measure.getMetric()).isEqualTo(coverage.getKey());
- assertThat(measure.getValue()).isEqualTo("15.5");
+ assertThat(measure.getValue()).isEmpty();
assertThat(measure.getPeriods().getPeriodsValueList())
.extracting(Measures.PeriodValue::getIndex, Measures.PeriodValue::getValue)
.containsOnly(tuple(1, "10.0"));
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
index 84a1c91f8a5..f1c9e1479fd 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
@@ -167,8 +167,8 @@ public class SearchHistoryActionTest {
newMeasureDto(complexityMetric, project, laterAnalysis).setValue(100d),
newMeasureDto(complexityMetric, file, analysis).setValue(42d),
newMeasureDto(nclocMetric, project, analysis).setValue(201d),
- newMeasureDto(newViolationMetric, project, analysis).setVariation(5d),
- newMeasureDto(newViolationMetric, project, laterAnalysis).setVariation(10d));
+ newMeasureDto(newViolationMetric, project, analysis).setValue(5d),
+ newMeasureDto(newViolationMetric, project, laterAnalysis).setValue(10d));
db.commit();
SearchHistoryRequest request = SearchHistoryRequest.builder()
@@ -450,7 +450,7 @@ public class SearchHistoryActionTest {
.mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(now + i * 24 * 1_000 * 60 * 60)))
.forEach(analysis -> dbClient.measureDao().insert(dbSession,
newMeasureDto(complexityMetric, project, analysis).setValue(45d),
- newMeasureDto(newViolationMetric, project, analysis).setVariation(46d),
+ newMeasureDto(newViolationMetric, project, analysis).setValue(46d),
newMeasureDto(nclocMetric, project, analysis).setValue(47d)));
db.commit();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java
index 9d02fa1fe5c..12361a42434 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java
@@ -72,10 +72,10 @@ public class prMeasureFixTest {
List<MetricDto> metricList = Arrays.asList(bugsMetric, newBugsMetric, violationsMetric, newViolationsMetric);
- LiveMeasureDto bugs = createLiveMeasure(bugsMetric.getUuid(), 10.0, null);
- LiveMeasureDto newBugs = createLiveMeasure(newBugsMetric.getUuid(), null, 5.0);
- LiveMeasureDto violations = createLiveMeasure(violationsMetric.getUuid(), 20.0, null);
- LiveMeasureDto newViolations = createLiveMeasure(newViolationsMetric.getUuid(), null, 3.0);
+ LiveMeasureDto bugs = createLiveMeasure(bugsMetric.getUuid(), 10.0);
+ LiveMeasureDto newBugs = createLiveMeasure(newBugsMetric.getUuid(), 5.0);
+ LiveMeasureDto violations = createLiveMeasure(violationsMetric.getUuid(), 20.0);
+ LiveMeasureDto newViolations = createLiveMeasure(newViolationsMetric.getUuid(), 3.0);
Map<MetricDto, LiveMeasureDto> measureByMetric = new HashMap<>();
measureByMetric.put(bugsMetric, bugs);
@@ -84,13 +84,13 @@ public class prMeasureFixTest {
measureByMetric.put(newViolationsMetric, newViolations);
PrMeasureFix.createReplacementMeasures(metricList, measureByMetric, requestedKeys);
- assertThat(measureByMetric.entrySet()).extracting(e -> e.getKey().getKey(), e -> e.getValue().getValue(), e -> e.getValue().getVariation())
- .containsOnly(tuple(NEW_BUGS_KEY, null, 10.0),
- tuple(MINOR_VIOLATIONS_KEY, 20.0, null),
- tuple(NEW_MINOR_VIOLATIONS_KEY, null, 20.0));
+ assertThat(measureByMetric.entrySet()).extracting(e -> e.getKey().getKey(), e -> e.getValue().getValue())
+ .containsOnly(tuple(NEW_BUGS_KEY, 10.0),
+ tuple(MINOR_VIOLATIONS_KEY, 20.0),
+ tuple(NEW_MINOR_VIOLATIONS_KEY, 20.0));
}
- private static LiveMeasureDto createLiveMeasure(String metricUuid, @Nullable Double value, @Nullable Double variation) {
- return new LiveMeasureDto().setMetricUuid(metricUuid).setVariation(variation).setValue(value);
+ private static LiveMeasureDto createLiveMeasure(String metricUuid, @Nullable Double value) {
+ return new LiveMeasureDto().setMetricUuid(metricUuid).setValue(value);
}
}