diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-07-27 17:08:07 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-08-02 20:21:35 +0200 |
commit | 4c03a7686dfc417db0376be571e2a3bf3fb04637 (patch) | |
tree | 80d5d6667bd23efe92af855f1b5961504b6b10ab /server | |
parent | 40fcc3b5a45a441fd9a08ed84fd53d6209e056e2 (diff) | |
download | sonarqube-4c03a7686dfc417db0376be571e2a3bf3fb04637.tar.gz sonarqube-4c03a7686dfc417db0376be571e2a3bf3fb04637.zip |
SONAR-11077 ability to log statistics from CE task steps
Diffstat (limited to 'server')
120 files changed, 762 insertions, 486 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java index e757af1b60b..a07a0032a0d 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java @@ -94,7 +94,7 @@ public class FileMoveDetectionStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { // do nothing if no files in db (first analysis) if (analysisMetadataHolder.isFirstAnalysis()) { LOG.debug("First analysis. Do nothing."); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java index f541b277a44..4c882c23f17 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStep.java @@ -60,10 +60,10 @@ public class PostMeasuresComputationChecksStep implements ComputationStep { } @Override - public void execute() { - PostMeasuresComputationCheck.Context context = new ContextImpl(); + public void execute(ComputationStep.Context context) { + PostMeasuresComputationCheck.Context extensionContext = new ContextImpl(); for (PostMeasuresComputationCheck extension : extensions) { - extension.onCheck(context); + extension.onCheck(extensionContext); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/PurgeDatastoresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/PurgeDatastoresStep.java index 464d99bbc3b..e6909e22642 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/PurgeDatastoresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/PurgeDatastoresStep.java @@ -56,7 +56,7 @@ public class PurgeDatastoresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new DepthTraversalTypeAwareCrawler( new TypeAwareVisitorAdapter(reportMaxDepth(PROJECT).withViewsMaxDepth(VIEW), PRE_ORDER) { @Override diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java index de462b9ac8a..6d8174954bc 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java @@ -62,7 +62,7 @@ public class BuildComponentTreeStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { ScannerReport.Component reportProject = reportReader.readComponent(analysisMetadataHolder.getRootComponentRef()); ComponentKeyGenerator keyGenerator = loadKeyGenerator(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java index bbb427e4a85..7d95e27677e 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java @@ -67,7 +67,7 @@ public class CommentMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new PathAwareCrawler<>( FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository).buildFor(formulas)) .visit(treeRootHolder.getRoot()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComplexityMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComplexityMeasuresStep.java index cfd4a240e4d..723ffa71539 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComplexityMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComplexityMeasuresStep.java @@ -82,7 +82,7 @@ public class ComplexityMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new PathAwareCrawler<>( FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository).buildFor(FORMULAS)) .visit(treeRootHolder.getRoot()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java index 8b94a1fdc36..c05f75916e2 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeMeasureVariationsStep.java @@ -79,7 +79,7 @@ public class ComputeMeasureVariationsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { List<Metric> metrics = StreamSupport.stream(metricRepository.getAll().spliterator(), false).filter(isNumeric()).collect(MoreCollectors.toList()); new DepthTraversalTypeAwareCrawler(new VariationMeasuresVisitor(dbSession, metrics)) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeQProfileMeasureStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeQProfileMeasureStep.java index 5e9fbd930cf..40cbc8882d6 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeQProfileMeasureStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComputeQProfileMeasureStep.java @@ -57,7 +57,7 @@ public class ComputeQProfileMeasureStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { Metric qProfilesMetric = metricRepository.getByKey(CoreMetrics.QUALITY_PROFILES_KEY); new PathAwareCrawler<>(new QProfileAggregationComponentVisitor(qProfilesMetric)) .visit(treeRootHolder.getRoot()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CoverageMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CoverageMeasuresStep.java index d71f253ac4d..e2a41566bb8 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CoverageMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CoverageMeasuresStep.java @@ -65,7 +65,7 @@ public class CoverageMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new PathAwareCrawler<>( FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository).buildFor(COVERAGE_FORMULAS)) .visit(treeRootHolder.getRoot()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java index 384f7768b7f..33e236f5aef 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java @@ -53,7 +53,7 @@ public class CustomMeasuresCopyStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession session = dbClient.openSession(false)) { CrawlerDepthLimit depthLimit = new CrawlerDepthLimit.Builder(Component.Type.MODULE) .withViewsMaxDepth(Component.Type.PROJECT_VIEW); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DbMigrationsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DbMigrationsStep.java index 5c8d046ee28..be052b9a1e9 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DbMigrationsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DbMigrationsStep.java @@ -37,7 +37,7 @@ public class DbMigrationsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { dataChanges.getDataChanges().forEach(DbMigrationsStep::execute); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStep.java index 2519f093343..98e8a907702 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStep.java @@ -62,7 +62,7 @@ public class DuplicationDataMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new DepthTraversalTypeAwareCrawler(new DuplicationVisitor()) .visit(treeRootHolder.getRoot()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationMeasuresStep.java index 1f4c8077c59..915f218d4cc 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationMeasuresStep.java @@ -41,7 +41,7 @@ public class DuplicationMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { defaultDuplicationMeasures.execute(); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStep.java index 25ea4fa86f1..b570dd9748f 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStep.java @@ -39,7 +39,7 @@ public class EnableAnalysisStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { Component project = treeRootHolder.getRoot(); dbClient.snapshotDao().switchIsLastFlagAndSetProcessedStatus(dbSession, project.getUuid(), analysisMetadataHolder.getUuid()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStep.java index c854d394fde..e92052ec05a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStep.java @@ -46,7 +46,7 @@ public class ExecuteVisitorsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { VisitorsCrawler visitorsCrawler = new VisitorsCrawler(visitors, LOGGER.isDebugEnabled()); visitorsCrawler.visit(treeRootHolder.getRoot()); logVisitorExecutionDurations(visitors, visitorsCrawler); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStep.java index 3ea69a18b20..27ac1d80195 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStep.java @@ -54,7 +54,7 @@ public class ExtractReportStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { Optional<CeTaskInputDao.DataStream> opt = dbClient.ceTaskInputDao().selectData(dbSession, task.getUuid()); if (opt.isPresent()) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/GenerateAnalysisUuid.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/GenerateAnalysisUuid.java index c52167f8905..2acdcc06906 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/GenerateAnalysisUuid.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/GenerateAnalysisUuid.java @@ -34,7 +34,7 @@ public class GenerateAnalysisUuid implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { analysisMetadataHolder.setUuid(uuidFactory.create()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/IndexAnalysisStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/IndexAnalysisStep.java index 7139d68755c..96cda313bd7 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/IndexAnalysisStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/IndexAnalysisStep.java @@ -38,7 +38,7 @@ public class IndexAnalysisStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { String branchUuid = treeRootHolder.getRoot().getUuid(); for (ProjectIndexer indexer : indexers) { LOGGER.debug("Call {}", indexer); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java index 81b0bb7c595..80a9e2c0a71 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java @@ -68,7 +68,7 @@ public class LanguageDistributionMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new PathAwareCrawler<>(FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository).buildFor(FORMULAS)) .visit(treeRootHolder.getRoot()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java index 9fac502e6d9..a6867957d8c 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java @@ -77,7 +77,7 @@ public class LoadCrossProjectDuplicationsRepositoryStep implements ComputationSt } @Override - public void execute() { + public void execute(ComputationStep.Context context) { if (crossProjectDuplicationStatusHolder.isEnabled()) { new DepthTraversalTypeAwareCrawler(new CrossProjectDuplicationVisitor()).visit(treeRootHolder.getRoot()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadDuplicationsFromReportStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadDuplicationsFromReportStep.java index 13921b17ffe..d5df8cebbf5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadDuplicationsFromReportStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadDuplicationsFromReportStep.java @@ -62,7 +62,7 @@ public class LoadDuplicationsFromReportStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new DepthTraversalTypeAwareCrawler( new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, ComponentVisitor.Order.POST_ORDER) { @Override diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadMeasureComputersStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadMeasureComputersStep.java index d82c3ca07d3..023437975bf 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadMeasureComputersStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadMeasureComputersStep.java @@ -84,7 +84,7 @@ public class LoadMeasureComputersStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { List<MeasureComputerWrapper> wrappers = from(Arrays.asList(measureComputers)).transform(ToMeasureWrapper.INSTANCE).toList(); validateMetrics(wrappers); measureComputersHolder.setMeasureComputers(sortComputers(wrappers)); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStep.java index 2a308af44d3..a64e45b3678 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStep.java @@ -64,7 +64,7 @@ public class LoadPeriodsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new DepthTraversalTypeAwareCrawler( new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, ComponentVisitor.Order.PRE_ORDER) { @Override diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java index 7e0c7521ef2..634d087e86a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java @@ -52,7 +52,7 @@ public class LoadQualityGateStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { Optional<QualityGate> qualityGate = getShortLivingBranchQualityGate(); if (!qualityGate.isPresent()) { // Not on a short living branch, let's retrieve the QG of the project diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityProfilesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityProfilesStep.java index e07a9035bb1..ce02c122ead 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityProfilesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityProfilesStep.java @@ -48,7 +48,7 @@ public class LoadQualityProfilesStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { List<ActiveRule> activeRules = new ArrayList<>(); try (CloseableIterator<ScannerReport.ActiveRule> batchActiveRules = batchReportReader.readActiveRules()) { while (batchActiveRules.hasNext()) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java index cdf158d8b09..5b09d232bdd 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java @@ -82,7 +82,7 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { ScannerReport.Metadata reportMetadata = reportReader.readMetadata(); loadMetadata(reportMetadata); 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 21b8e702307..6048a183f24 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 @@ -101,7 +101,7 @@ public class NewCoverageMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new PathAwareCrawler<>( FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository) .withVariationSupport(periodHolder) 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 278a0815d04..c4abc14afd9 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 @@ -78,7 +78,7 @@ public class NewSizeMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new PathAwareCrawler<>( FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository) .withVariationSupport(periodHolder) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java index 00049703d70..ca4dd145d3d 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java @@ -53,7 +53,7 @@ public class PersistAnalysisPropertiesStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { final List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>(); reportReader.readContextProperties().forEachRemaining( contextProperty -> { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisStep.java index 696707b188f..05b899b3abb 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisStep.java @@ -54,7 +54,7 @@ public class PersistAnalysisStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { new DepthTraversalTypeAwareCrawler( new PersistSnapshotsPathAwareVisitor(dbSession, analysisMetadataHolder.getAnalysisDate())) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java index 7abaece8c43..639b6110fa0 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java @@ -92,7 +92,7 @@ public class PersistComponentsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { branchPersister.persist(dbSession); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java index 2c0da8b5351..f5b2bd3f280 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStep.java @@ -58,7 +58,7 @@ public class PersistCrossProjectDuplicationIndexStep implements ComputationStep } @Override - public void execute() { + public void execute(ComputationStep.Context context) { if (!crossProjectDuplicationStatusHolder.isEnabled()) { return; } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStep.java index 4107d1cebaa..3e7c0641dff 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStep.java @@ -58,7 +58,7 @@ public class PersistEventsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { long analysisDate = analysisMetadataHolder.getAnalysisDate(); new DepthTraversalTypeAwareCrawler(new PersistEventComponentVisitor(dbSession, analysisDate)) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java index 3ebc3be6a49..67baee66f5c 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java @@ -35,8 +35,7 @@ public class PersistExternalRulesStep implements ComputationStep { } @Override - public void execute() { - + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { ruleRepository.persistNewExternalRules(dbSession); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStep.java index e743dc9516b..ca933bd5a7a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStep.java @@ -86,7 +86,7 @@ public class PersistFileSourcesStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { // Don't use batch insert for file_sources since keeping all data in memory can produce OOM for big files try (DbSession dbSession = dbClient.openSession(false)) { new DepthTraversalTypeAwareCrawler(new FileSourceVisitor(dbSession)) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java index 29ceb0278f9..2c49f92d78e 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java @@ -53,7 +53,7 @@ public class PersistIssuesStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(true); CloseableIterator<DefaultIssue> issues = issueCache.traverse()) { 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 f8dd0c70bb0..536cd39183f 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 @@ -83,7 +83,7 @@ public class PersistLiveMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { String marker = Uuids.create(); Component root = treeRootHolder.getRoot(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java index a65030af84b..c303dfef113 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java @@ -77,7 +77,7 @@ public class PersistMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(true)) { new DepthTraversalTypeAwareCrawler(new MeasureVisitor(dbSession)).visit(treeRootHolder.getRoot()); dbSession.commit(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStep.java index 6bd943aac3b..ea568608905 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStep.java @@ -63,7 +63,7 @@ public class PersistProjectLinksStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { if (!analysisMetadataHolder.getBranch().isMain()) { return; } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStep.java index 37a22511cf4..d207e9fd6b0 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStep.java @@ -45,7 +45,7 @@ public class PersistScannerContextStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (CloseableIterator<String> logsIterator = reportReader.readScannerLogs()) { if (logsIterator.hasNext()) { try (DbSession dbSession = dbClient.openSession(false)) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStep.java index 0135404606b..41ba395ace2 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStep.java @@ -70,7 +70,7 @@ public class PersistTestsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(true)) { TestDepthTraversalTypeAwareVisitor visitor = new TestDepthTraversalTypeAwareVisitor(dbSession); new DepthTraversalTypeAwareCrawler(visitor).visit(treeRootHolder.getRoot()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PublishTaskResultStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PublishTaskResultStep.java index 0e22976da0a..e91d06d9084 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PublishTaskResultStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PublishTaskResultStep.java @@ -41,7 +41,7 @@ public class PublishTaskResultStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { taskResultHolder.setResult(new CeTaskResultImpl(analysisMetadataHolder.getUuid())); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java index deed07a778b..907f2bc790c 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java @@ -68,7 +68,7 @@ public class QualityGateEventsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { // no notification on short living branch and pull request as there is no real Quality Gate on those if (analysisMetadataHolder.isShortLivingBranch() || analysisMetadataHolder.isPullRequest()) { return; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java index a3e0e9ead5f..6791b2af52d 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java @@ -99,7 +99,7 @@ public class QualityGateMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new DepthTraversalTypeAwareCrawler( new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, PRE_ORDER) { @Override diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java index 7571450714a..e6d979361e6 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java @@ -70,7 +70,7 @@ public class QualityProfileEventsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new DepthTraversalTypeAwareCrawler( new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, POST_ORDER) { @Override diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java index 214cdc3f825..92cee140446 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java @@ -96,7 +96,7 @@ public class SendIssueNotificationsStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { Component project = treeRootHolder.getRoot(); if (service.hasProjectSubscribersForTypes(project.getUuid(), NOTIF_TYPES)) { doExecute(project); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java index f8beb8f1c0e..906923b66f2 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java @@ -73,7 +73,7 @@ public class SizeMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new PathAwareCrawler<>(new FileAndDirectoryMeasureVisitor( metricRepository.getByKey(DIRECTORIES_KEY), metricRepository.getByKey(FILES_KEY), diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/TriggerViewRefreshStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/TriggerViewRefreshStep.java index 3cf6db44b28..b8f22b27a18 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/TriggerViewRefreshStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/TriggerViewRefreshStep.java @@ -20,7 +20,7 @@ package org.sonar.ce.task.projectanalysis.step; -import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; import org.sonar.ce.task.projectanalysis.view.TriggerViewRefreshDelegate; import org.sonar.ce.task.step.ComputationStep; @@ -30,7 +30,7 @@ import org.sonar.ce.task.step.ComputationStep; */ public class TriggerViewRefreshStep implements ComputationStep { - @CheckForNull + @Nullable private final TriggerViewRefreshDelegate triggerViewRefreshDelegate; private final AnalysisMetadataHolder analysisMetadata; @@ -45,7 +45,7 @@ public class TriggerViewRefreshStep implements ComputationStep { /** * Constructor used by Pico when an implementation of {@link TriggerViewRefreshDelegate} is available */ - public TriggerViewRefreshStep(AnalysisMetadataHolder analysisMetadata, TriggerViewRefreshDelegate triggerViewRefreshDelegate) { + public TriggerViewRefreshStep(AnalysisMetadataHolder analysisMetadata, @Nullable TriggerViewRefreshDelegate triggerViewRefreshDelegate) { this.analysisMetadata = analysisMetadata; this.triggerViewRefreshDelegate = triggerViewRefreshDelegate; } @@ -56,7 +56,7 @@ public class TriggerViewRefreshStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { if (triggerViewRefreshDelegate != null) { triggerViewRefreshDelegate.accept(analysisMetadata.getProject()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java index fc9854c4e90..9cf89f9c5f7 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java @@ -63,7 +63,7 @@ public class UnitTestMeasuresStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { new PathAwareCrawler<>( FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository).buildFor(FORMULAS)) .visit(treeRootHolder.getRoot()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java index c9fc9d294c5..1bacce8bc59 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java @@ -59,7 +59,7 @@ public class UpdateQualityProfilesLastUsedDateStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(true)) { Component root = treeRootHolder.getRoot(); Metric metric = metricRepository.getByKey(QUALITY_PROFILES_KEY); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java index 287c7fe3b00..4dbe0f0253e 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java @@ -73,7 +73,7 @@ public class ValidateProjectStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { Component root = treeRootHolder.getRoot(); List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java index 0080f7c8c3b..e68695dd48b 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStep.java @@ -40,7 +40,7 @@ public class VerifyBillingStep implements ComputationStep { } @Override - public void execute() { + public void execute(ComputationStep.Context context) { try { Organization organization = analysisMetadata.getOrganization(); BillingValidations.Organization billingOrganization = new BillingValidations.Organization(organization.getKey(), organization.getUuid()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java index f56c14a0f59..c3ad9ef07d6 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java @@ -40,6 +40,7 @@ import org.sonar.ce.task.projectanalysis.component.FileAttributes; import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepository; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.hash.SourceLineHashesComputer; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; @@ -243,7 +244,7 @@ public class FileMoveDetectionStepTest { public void execute_detects_no_move_if_baseProjectSnapshot_is_null() { analysisMetadataHolder.setBaseAnalysis(null); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); } @@ -252,7 +253,7 @@ public class FileMoveDetectionStepTest { public void execute_detects_no_move_if_baseSnapshot_has_no_file_and_report_has_no_file() { analysisMetadataHolder.setBaseAnalysis(ANALYSIS); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); } @@ -264,7 +265,7 @@ public class FileMoveDetectionStepTest { Component file2 = fileComponent(FILE_2_REF, null); setFilesInReport(file1, file2); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); } @@ -275,7 +276,7 @@ public class FileMoveDetectionStepTest { insertFiles( /* no components */); setFilesInReport(); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); } @@ -288,7 +289,7 @@ public class FileMoveDetectionStepTest { insertFiles(file1.getKey(), file2.getKey()); setFilesInReport(file2, file1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); } @@ -302,7 +303,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).containsExactly(file2); MovedFilesRepository.OriginalFile originalFile = movedFilesRepository.getOriginalFile(file2).get(); @@ -320,7 +321,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()) @@ -337,7 +338,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file1.getKey(), CONTENT_EMPTY); setFilesInReport(file2); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isZero(); @@ -352,7 +353,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix).isNull(); @@ -367,7 +368,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isZero(); @@ -383,7 +384,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2, file3); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isEqualTo(100); @@ -400,7 +401,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file2.getKey(), CONTENT1); setFilesInReport(file3); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isEqualTo(100); @@ -415,7 +416,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file1.getKey(), null); insertContentOfFileInDb(file2.getKey(), null); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix).isNull(); @@ -442,7 +443,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file5.getKey(), CONTENT2); setFilesInReport(file3, file4, file6); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).containsOnly(file3, file6); MovedFilesRepository.OriginalFile originalFile2 = movedFilesRepository.getOriginalFile(file3).get(); @@ -468,7 +469,7 @@ public class FileMoveDetectionStepTest { insertContentOfFileInDb(file2.getKey(), arrayOf(30)); setFilesInReport(file3, file4); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isZero(); @@ -508,7 +509,7 @@ public class FileMoveDetectionStepTest { setFilesInReport(comps.values().toArray(new Component[0])); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Component makeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex = comps.get("MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndex.java"); Component migrationRb1238 = comps.get("1238_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb"); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStepTest.java index 3a8a22e8b73..c7bd59039df 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationChecksStepTest.java @@ -29,6 +29,7 @@ import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.PostMeasuresComputationCheck.Context; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.server.project.Project; import static org.assertj.core.api.Assertions.assertThat; @@ -60,7 +61,7 @@ public class PostMeasuresComputationChecksStepTest { PostMeasuresComputationCheck check1 = mock(PostMeasuresComputationCheck.class); PostMeasuresComputationCheck check2 = mock(PostMeasuresComputationCheck.class); - newStep(check1, check2).execute(); + newStep(check1, check2).execute(new TestComputationStepContext()); InOrder inOrder = inOrder(check1, check2); inOrder.verify(check1).onCheck(any(Context.class)); @@ -72,7 +73,7 @@ public class PostMeasuresComputationChecksStepTest { analysisMetadataHolder.setProject(new Project("project_uuid", "project_key", "project_name")); PostMeasuresComputationCheck check = mock(PostMeasuresComputationCheck.class); - newStep(check).execute(); + newStep(check).execute(new TestComputationStepContext()); ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class); verify(check).onCheck(contextArgumentCaptor.capture()); @@ -84,7 +85,7 @@ public class PostMeasuresComputationChecksStepTest { PostMeasuresComputationCheck check = mock(PostMeasuresComputationCheck.class); measureRepository.addRawMeasure(DUMB_PROJECT.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(10)); - newStep(check).execute(); + newStep(check).execute(new TestComputationStepContext()); ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class); verify(check).onCheck(contextArgumentCaptor.capture()); @@ -95,7 +96,7 @@ public class PostMeasuresComputationChecksStepTest { public void ncloc_is_zero_in_context_when_not_available() { PostMeasuresComputationCheck check = mock(PostMeasuresComputationCheck.class); - newStep(check).execute(); + newStep(check).execute(new TestComputationStepContext()); ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class); verify(check).onCheck(contextArgumentCaptor.capture()); @@ -105,7 +106,7 @@ public class PostMeasuresComputationChecksStepTest { @Test public void do_nothing_if_no_extensions() { // no failure - newStep().execute(); + newStep().execute(new TestComputationStepContext()); } @Test @@ -116,7 +117,7 @@ public class PostMeasuresComputationChecksStepTest { PostMeasuresComputationCheck check3 = mock(PostMeasuresComputationCheck.class); try { - newStep(check1, check2, check3).execute(); + newStep(check1, check2, check3).execute(new TestComputationStepContext()); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage("BOOM"); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/purge/PurgeDatastoresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/purge/PurgeDatastoresStepTest.java index c26b334075f..a5bb2db502f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/purge/PurgeDatastoresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/purge/PurgeDatastoresStepTest.java @@ -39,6 +39,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.component.ViewsComponent; import org.sonar.ce.task.projectanalysis.step.BaseStepTest; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.purge.IdUuidPair; import org.sonar.server.util.WrapInSingleElementArray; @@ -124,7 +125,7 @@ public class PurgeDatastoresStepTest extends BaseStepTest { private void verify_do_not_call_purge_method_of_the_purge_task(Component component) { treeRootHolder.setRoot(component); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyNoMoreInteractions(projectCleaner); } @@ -134,7 +135,7 @@ public class PurgeDatastoresStepTest extends BaseStepTest { when(settingsRepository.getConfiguration()).thenReturn(new MapSettings().asConfig()); dbIdsRepository.setComponentId(project, PROJECT_ID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); ArgumentCaptor<IdUuidPair> argumentCaptor = ArgumentCaptor.forClass(IdUuidPair.class); verify(projectCleaner).purge(any(), argumentCaptor.capture(), any(), any()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java index 34dc809356e..f5b0b78d707 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java @@ -35,6 +35,7 @@ import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule; import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl; import org.sonar.ce.task.projectanalysis.component.MutableTreeRootHolderRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -105,7 +106,7 @@ public class BuildComponentTreeStepTest { public void fails_if_root_component_does_not_exist_in_reportReader() { setAnalysisMetadataHolder(); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @DataProvider @@ -126,7 +127,7 @@ public class BuildComponentTreeStepTest { int componentRef = 1; reportReader.putComponent(component(componentRef, componentType)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Component root = treeRootHolder.getRoot(); assertThat(root).isNotNull(); @@ -146,7 +147,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(component(DIR_REF_2, DIRECTORY, FILE_3_REF)); reportReader.putComponent(component(FILE_3_REF, FILE)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Component root = treeRootHolder.getRoot(); assertThat(root).isNotNull(); @@ -170,7 +171,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF)); reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, REPORT_PROJECT_KEY); verifyComponent(MODULE_REF, REPORT_MODULE_KEY); @@ -193,7 +194,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF)); reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, REPORT_PROJECT_KEY, "ABCD"); verifyComponent(MODULE_REF, REPORT_MODULE_KEY, "BCDE"); @@ -218,7 +219,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF)); reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, "generated", REPORT_PROJECT_KEY, null); verifyComponent(MODULE_REF, "generated", REPORT_MODULE_KEY, null); @@ -242,7 +243,7 @@ public class BuildComponentTreeStepTest { BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder); reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, branchDto.getKey())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, branchDto.getDbKey(), branchDto.getKey(), branchDto.uuid()); } @@ -260,7 +261,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF)); reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, REPORT_PROJECT_KEY, REPORT_PROJECT_KEY, null); verifyComponent(MODULE_REF, REPORT_MODULE_KEY, REPORT_MODULE_KEY, null); @@ -280,7 +281,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF)); reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, REPORT_PROJECT_KEY + ":origin/feature", null); verifyComponent(MODULE_REF, REPORT_MODULE_KEY + ":origin/feature", null); @@ -298,7 +299,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(componentWithPath(DIR_REF_2, DIRECTORY, REPORT_DIR_KEY_2, FILE_2_REF)); reportReader.putComponent(componentWithPath(FILE_2_REF, FILE, REPORT_FILE_KEY_2)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, REPORT_PROJECT_KEY); verifyComponent(MODULE_REF, REPORT_MODULE_KEY); @@ -317,7 +318,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF)); reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, REPORT_PROJECT_KEY); verifyComponent(MODULE_REF, REPORT_MODULE_KEY); @@ -340,7 +341,7 @@ public class BuildComponentTreeStepTest { reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF)); reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyComponent(ROOT_REF, REPORT_PROJECT_KEY, "ABCD"); @@ -354,7 +355,7 @@ public class BuildComponentTreeStepTest { public void set_no_base_project_snapshot_when_no_snapshot() { setAnalysisMetadataHolder(); reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(analysisMetadataHolder.isFirstAnalysis()).isTrue(); } @@ -367,7 +368,7 @@ public class BuildComponentTreeStepTest { insertSnapshot(newAnalysis(project).setLast(false)); reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(analysisMetadataHolder.isFirstAnalysis()).isTrue(); } @@ -380,7 +381,7 @@ public class BuildComponentTreeStepTest { insertSnapshot(newAnalysis(project).setLast(true)); reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(analysisMetadataHolder.isFirstAnalysis()).isFalse(); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ComputeQProfileMeasureStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ComputeQProfileMeasureStepTest.java index 49c57cdd570..c04157a7ba5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ComputeQProfileMeasureStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ComputeQProfileMeasureStepTest.java @@ -33,6 +33,7 @@ import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.server.qualityprofile.QPMeasureData; import org.sonar.server.qualityprofile.QualityProfile; @@ -107,7 +108,7 @@ public class ComputeQProfileMeasureStepTest { QualityProfile qpPhp = createQProfile(QP_NAME_2, LANGUAGE_KEY_2); analysisMetadataHolder.setQProfilesByLanguage(ImmutableMap.of(LANGUAGE_KEY_1, qpJava, LANGUAGE_KEY_2, qpPhp)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasures(PROJECT_REF).get(QUALITY_PROFILES_KEY)) .extracting("data").containsOnly(toJson(qpJava, qpPhp)); @@ -118,7 +119,7 @@ public class ComputeQProfileMeasureStepTest { ReportComponent project = ReportComponent.builder(PROJECT, PROJECT_REF).build(); treeRootHolder.setRoot(project); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasures(PROJECT_REF)).isEmpty(); } @@ -130,7 +131,7 @@ public class ComputeQProfileMeasureStepTest { analysisMetadataHolder.setQProfilesByLanguage(ImmutableMap.of(LANGUAGE_KEY_1, qpJava)); try { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); fail("Expected exception"); } catch (Exception e) { assertThat(e).hasCause(new IllegalStateException("Report contains a file with language 'php' but no matching quality profile")); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java index b742dfd6d44..813c0c8039a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java @@ -32,6 +32,7 @@ import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.Metric; import org.sonar.ce.task.projectanalysis.metric.MetricImpl; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.measure.custom.CustomMeasureDto; @@ -127,7 +128,7 @@ public class CustomMeasuresCopyStepTest { ReportComponent.builder(MODULE, MODULE2_REF).setUuid(MODULE2_UUID).build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasureValue(FILE1_REF); assertNoRawMeasureValue(FILE2_REF); @@ -152,7 +153,7 @@ public class CustomMeasuresCopyStepTest { ViewsComponent.builder(PROJECT_VIEW, PROJECT_VIEW_REF).setUuid("PROJECT_VIEW").build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasureValue(PROJECT_VIEW_REF); assertRawMeasureValue(SUBVIEW_REF, FLOAT_METRIC.getKey(), 3.1d); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DbMigrationsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DbMigrationsStepTest.java index b2dc9150130..78250395dd4 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DbMigrationsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DbMigrationsStepTest.java @@ -29,6 +29,7 @@ import org.mockito.InOrder; import org.mockito.Mockito; import org.sonar.ce.task.projectanalysis.dbmigration.ProjectAnalysisDataChange; import org.sonar.ce.task.projectanalysis.dbmigration.ProjectAnalysisDataChanges; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -43,7 +44,7 @@ public class DbMigrationsStepTest { @Test public void execute_has_no_effect_if_there_is_no_DataChange() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -54,7 +55,7 @@ public class DbMigrationsStepTest { InOrder inOrder = Mockito.inOrder((Object[]) dataChanges); when(projectAnalysisDataChanges.getDataChanges()).thenReturn(Arrays.asList(dataChanges)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Arrays.stream(dataChanges).forEach(t -> { try { @@ -83,7 +84,7 @@ public class DbMigrationsStepTest { okMock1, okMock2, failingMock1, okMock3, failingMock2, okMock4)); try { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); fail("A IllegalStateException should have been thrown"); } catch (IllegalStateException e) { assertThat(e) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java index 3a4089cd9aa..d71c604ac97 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStepTest.java @@ -27,6 +27,7 @@ import org.sonar.ce.task.projectanalysis.duplication.TextBlock; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -77,7 +78,7 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest { @Test public void nothing_to_do_when_no_duplication() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, DUPLICATIONS_DATA_KEY)).isAbsent(); @@ -87,7 +88,7 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest { public void compute_duplications_on_same_file() { duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 5), new TextBlock(6, 10)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY)).isPresent(); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY).get().getData()).isEqualTo( @@ -99,7 +100,7 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest { public void compute_duplications_on_different_files() { duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 5), FILE_2_REF, new TextBlock(6, 10)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY)).isPresent(); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY).get().getData()).isEqualTo( @@ -112,7 +113,7 @@ public class DuplicationDataMeasuresStepTest extends BaseStepTest { String fileKeyFromOtherProject = "PROJECT2_KEY:file2"; duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 5), fileKeyFromOtherProject, new TextBlock(6, 10)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY)).isPresent(); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, DUPLICATIONS_DATA_KEY).get().getData()).isEqualTo( diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationMeasuresStepTest.java index 5c24ce6a795..54e8be9aa35 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/DuplicationMeasuresStepTest.java @@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.step; import org.junit.Test; import org.sonar.ce.task.projectanalysis.duplication.DuplicationMeasures; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -33,7 +34,8 @@ public class DuplicationMeasuresStepTest extends BaseStepTest { @Test public void full_analysis_mode() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); + verify(defaultDuplicationMeasures).execute(); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepTest.java index 9616f98edc8..ee9c3271ac7 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepTest.java @@ -27,6 +27,7 @@ import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolderR import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; @@ -64,7 +65,7 @@ public class EnableAnalysisStepTest { treeRootHolder.setRoot(REPORT_PROJECT); analysisMetadataHolder.setUuid(CURRENT_ANALYSIS_UUID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyAnalysis(PREVIOUS_ANALYSIS_UUID, SnapshotDto.STATUS_PROCESSED, false); verifyAnalysis(CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_PROCESSED, true); @@ -79,7 +80,7 @@ public class EnableAnalysisStepTest { treeRootHolder.setRoot(REPORT_PROJECT); analysisMetadataHolder.setUuid(CURRENT_ANALYSIS_UUID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyAnalysis(CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_PROCESSED, true); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java index af80de32ec5..c583c014d3f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java @@ -36,6 +36,7 @@ import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.Metric; import org.sonar.ce.task.projectanalysis.metric.MetricImpl; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; +import org.sonar.ce.task.step.TestComputationStepContext; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; @@ -96,7 +97,7 @@ public class ExecuteVisitorsStepTest { measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(3)); measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(3)); - underStep.execute(); + underStep.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(2); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(3); @@ -107,12 +108,12 @@ public class ExecuteVisitorsStepTest { @Test public void execute_with_path_aware_visitor() { - ExecuteVisitorsStep underStep = new ExecuteVisitorsStep(treeRootHolder, singletonList(new TestPathAwareVisitor())); + ExecuteVisitorsStep underTest = new ExecuteVisitorsStep(treeRootHolder, singletonList(new TestPathAwareVisitor())); measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(1)); measureRepository.addRawMeasure(FILE_2_REF, NCLOC_KEY, newMeasureBuilder().create(1)); - underStep.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(1); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(1); @@ -127,11 +128,11 @@ public class ExecuteVisitorsStepTest { ChangeLogLevel step1 = new ChangeLogLevel(VisitorA.class, LoggerLevel.DEBUG); ChangeLogLevel step2 = new ChangeLogLevel(VisitorB.class, LoggerLevel.DEBUG); ChangeLogLevel step3 = new ChangeLogLevel(VisitorB.class, LoggerLevel.DEBUG)) { - ExecuteVisitorsStep underStep = new ExecuteVisitorsStep( + ExecuteVisitorsStep underTest = new ExecuteVisitorsStep( treeRootHolder, asList(new VisitorA(), new VisitorB(), new VisitorC())); - underStep.execute(); + underTest.execute(new TestComputationStepContext()); List<String> logs = logTester.logs(LoggerLevel.DEBUG); assertThat(logs).hasSize(4); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest.java index 7dd21097f5d..715753e1753 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest.java @@ -35,6 +35,7 @@ import org.sonar.api.utils.log.LoggerLevel; import org.sonar.ce.task.CeTask; import org.sonar.ce.task.projectanalysis.batch.BatchReportDirectoryHolderImpl; import org.sonar.ce.task.projectanalysis.batch.MutableBatchReportDirectoryHolder; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbTester; import org.sonar.db.ce.CeTaskTypes; @@ -70,7 +71,7 @@ public class ExtractReportStepTest { expectedException.expect(MessageException.class); expectedException.expectMessage("Analysis report 1 is missing in database"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -82,7 +83,7 @@ public class ExtractReportStepTest { dbTester.getSession().commit(); dbTester.getSession().close(); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // directory contains the uncompressed report (which contains only metadata.pb in this test) File unzippedDir = reportDirectoryHolder.getDirectory(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/IndexAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/IndexAnalysisStepTest.java index 8a19d093f62..469561735a9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/IndexAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/IndexAnalysisStepTest.java @@ -27,6 +27,7 @@ import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.component.ViewsComponent; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.server.es.ProjectIndexer; import static org.mockito.Mockito.mock; @@ -52,7 +53,7 @@ public class IndexAnalysisStepTest extends BaseStepTest { Component project = ReportComponent.builder(PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).build(); treeRootHolder.setRoot(project); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(componentIndexer).indexOnAnalysis(PROJECT_UUID); } @@ -62,7 +63,7 @@ public class IndexAnalysisStepTest extends BaseStepTest { Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid(PROJECT_UUID).build(); treeRootHolder.setRoot(view); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(componentIndexer).indexOnAnalysis(PROJECT_UUID); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java index 29d66394a89..8ac7a666505 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java @@ -40,6 +40,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolder; import org.sonar.ce.task.projectanalysis.duplication.IntegrateCrossProjectDuplications; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -146,7 +147,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .build(); batchReportReader.putDuplicationBlocks(FILE_REF, asList(originBlock)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(integrateCrossProjectDuplications).computeCpd(CURRENT_FILE, asList( @@ -211,7 +212,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { dbClient.duplicationDao().insert(dbSession, duplicate2); dbSession.commit(); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Class<ArrayList<Block>> listClass = (Class<ArrayList<Block>>) (Class) ArrayList.class; ArgumentCaptor<ArrayList<Block>> originBlocks = ArgumentCaptor.forClass(listClass); @@ -284,7 +285,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .build(); batchReportReader.putDuplicationBlocks(FILE_REF, asList(originBlock)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyZeroInteractions(integrateCrossProjectDuplications); } @@ -296,7 +297,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { batchReportReader.putDuplicationBlocks(FILE_REF, Collections.emptyList()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyZeroInteractions(integrateCrossProjectDuplications); } @@ -315,7 +316,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .build(); batchReportReader.putDuplicationBlocks(FILE_REF, asList(originBlock)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyZeroInteractions(integrateCrossProjectDuplications); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadDuplicationsFromReportStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadDuplicationsFromReportStepTest.java index a993b89d68c..0f6cc3cca50 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadDuplicationsFromReportStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadDuplicationsFromReportStepTest.java @@ -34,6 +34,7 @@ import org.sonar.ce.task.projectanalysis.duplication.DuplicationRepositoryRule; import org.sonar.ce.task.projectanalysis.duplication.InProjectDuplicate; import org.sonar.ce.task.projectanalysis.duplication.InnerDuplicate; import org.sonar.ce.task.projectanalysis.duplication.TextBlock; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.scanner.protocol.output.ScannerReport; import static org.assertj.core.api.Assertions.assertThat; @@ -74,7 +75,7 @@ public class LoadDuplicationsFromReportStepTest { public void loads_duplication_without_otherFileRef_as_inner_duplication() { reportReader.putDuplications(FILE_2_REF, createDuplication(singleLineTextRange(LINE), createInnerDuplicate(LINE + 1))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoDuplication(FILE_1_REF); assertDuplications(FILE_2_REF, singleLineDetailedTextBlock(1, LINE), new InnerDuplicate(singleLineTextBlock(LINE + 1))); @@ -84,7 +85,7 @@ public class LoadDuplicationsFromReportStepTest { public void loads_duplication_with_otherFileRef_as_inProject_duplication() { reportReader.putDuplications(FILE_1_REF, createDuplication(singleLineTextRange(LINE), createInProjectDuplicate(FILE_2_REF, LINE + 1))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertDuplications(FILE_1_REF, singleLineDetailedTextBlock(1, LINE), new InProjectDuplicate(treeRootHolder.getComponentByRef(FILE_2_REF), singleLineTextBlock(LINE + 1))); assertNoDuplication(FILE_2_REF); @@ -104,7 +105,7 @@ public class LoadDuplicationsFromReportStepTest { singleLineTextRange(OTHER_LINE + 80), createInnerDuplicate(LINE), createInnerDuplicate(LINE + 10))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Component file1Component = treeRootHolder.getComponentByRef(FILE_1_REF); assertThat(duplicationRepository.getDuplications(FILE_2_REF)).containsOnly( @@ -131,7 +132,7 @@ public class LoadDuplicationsFromReportStepTest { singleLineTextRange(LINE), createInnerDuplicate(LINE + 2), createInnerDuplicate(LINE + 3), createInProjectDuplicate(FILE_1_REF, LINE + 2))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Component file1Component = treeRootHolder.getComponentByRef(FILE_1_REF); assertThat(duplicationRepository.getDuplications(FILE_2_REF)).containsOnly( @@ -153,7 +154,7 @@ public class LoadDuplicationsFromReportStepTest { expectedException.expect(VisitException.class); expectedException.expectCause(hasType(IllegalArgumentException.class).andMessage("Component with ref '666' can't be found")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -164,7 +165,7 @@ public class LoadDuplicationsFromReportStepTest { expectedException.expect(VisitException.class); expectedException.expectCause(hasType(IllegalArgumentException.class).andMessage("file and otherFile references can not be the same")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } private void assertDuplications(int fileRef, TextBlock original, Duplicate... duplicates) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadMeasureComputersStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadMeasureComputersStepTest.java index 3b38127268d..1ef5adda7e9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadMeasureComputersStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadMeasureComputersStepTest.java @@ -33,6 +33,7 @@ import org.sonar.api.measures.Metrics; import org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper; import org.sonar.ce.task.projectanalysis.measure.MeasureComputersHolderImpl; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; @@ -60,7 +61,7 @@ public class LoadMeasureComputersStepTest { public void support_core_metrics_as_input_metrics() { MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1))}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(holder.getMeasureComputers()).hasSize(1); } @@ -69,7 +70,7 @@ public class LoadMeasureComputersStepTest { public void support_plugin_metrics_as_input_metrics() { MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2))}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(holder.getMeasureComputers()).hasSize(1); } @@ -85,7 +86,7 @@ public class LoadMeasureComputersStepTest { MeasureComputer[] computers = new MeasureComputer[] {measureComputer1, measureComputer2, measureComputer3}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers()); assertThat(result).hasSize(3); @@ -105,7 +106,7 @@ public class LoadMeasureComputersStepTest { MeasureComputer[] computers = new MeasureComputer[] {measureComputer1, measureComputer2, measureComputer3}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers()); assertThat(result).hasSize(3); @@ -121,7 +122,7 @@ public class LoadMeasureComputersStepTest { MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array("unknown"), array(NEW_METRIC_4))}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -131,7 +132,7 @@ public class LoadMeasureComputersStepTest { MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_4), array("unknown"))}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -141,14 +142,14 @@ public class LoadMeasureComputersStepTest { MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_4), array(NCLOC_KEY))}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test public void not_fail_if_input_metrics_are_same_as_output_metrics() { MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_1))}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(holder.getMeasureComputers()).hasSize(1); } @@ -156,7 +157,7 @@ public class LoadMeasureComputersStepTest { @Test public void return_empty_list_when_no_measure_computers() { ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(holder.getMeasureComputers()).isEmpty(); } @@ -164,7 +165,7 @@ public class LoadMeasureComputersStepTest { @Test public void return_empty_list_when_no_metrics_neither_measure_computers() { ComputationStep underTest = new LoadMeasureComputersStep(holder); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(holder.getMeasureComputers()).isEmpty(); } @@ -176,7 +177,7 @@ public class LoadMeasureComputersStepTest { MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1))}; ComputationStep underTest = new LoadMeasureComputersStep(holder, computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -186,7 +187,7 @@ public class LoadMeasureComputersStepTest { MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1)), newMeasureComputer(array(CLASSES_KEY), array(NEW_METRIC_1))}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -220,7 +221,7 @@ public class LoadMeasureComputersStepTest { MeasureComputer[] computers = new MeasureComputer[] {measureComputer}; ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } private static MeasureComputer newMeasureComputer(final String[] inputMetrics, final String[] outputMetrics) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java index b370fc0f7c6..92f8768d7c5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java @@ -38,6 +38,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.period.Period; import org.sonar.ce.task.projectanalysis.period.PeriodHolderImpl; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -93,7 +94,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setKey("ROOT_KEY").setVersion("1.1").build()); // No project, no snapshot - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(periodsHolder.getPeriod()).isNull(); } @@ -107,7 +108,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { String textDate = "2008-11-22"; settings.setProperty("sonar.leak.period", textDate); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Period period = periodsHolder.getPeriod(); assertThat(period).isNotNull(); @@ -125,7 +126,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project); settings.setProperty("sonar.leak.period", "UNKNWOWN VERSION"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(periodsHolder.getPeriod()).isNull(); } @@ -138,7 +139,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project); settings.setProperty("sonar.leak.period", ""); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(periodsHolder.getPeriod()).isNull(); } @@ -151,7 +152,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project); settings.setProperty("sonar.leak.period", "100"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(periodsHolder.getPeriod()).isNull(); } @@ -169,7 +170,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { String textDate = "2008-11-22"; settings.setProperty("sonar.leak.period", textDate); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // Return analysis from given date 2008-11-22 Period period = periodsHolder.getPeriod(); @@ -196,7 +197,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { String date = "2008-11-13"; settings.setProperty("sonar.leak.period", date); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // Analysis form 2008-11-20 Period period = periodsHolder.getPeriod(); @@ -216,7 +217,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { // No analysis at and after this date settings.setProperty("sonar.leak.period", "2008-11-30"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(periodsHolder.getPeriod()).isNull(); } @@ -233,7 +234,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project); settings.setProperty("sonar.leak.period", "10"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // return analysis from 2008-11-20 Period period = periodsHolder.getPeriod(); @@ -254,7 +255,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project); settings.setProperty("sonar.leak.period", "0"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(periodsHolder.getPeriod()).isNull(); } @@ -274,7 +275,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project, "1.1"); settings.setProperty("sonar.leak.period", "previous_version"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // Analysis form 2008-11-12 Period period = periodsHolder.getPeriod(); @@ -301,7 +302,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project, "1.1"); settings.setProperty("sonar.leak.period", "previous_version"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // Analysis form 2008-11-11 Period period = periodsHolder.getPeriod(); @@ -319,7 +320,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project); settings.setProperty("sonar.leak.period", "previous_version"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(periodsHolder.getPeriod()).isNull(); } @@ -334,7 +335,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project, "1.1"); settings.setProperty("sonar.leak.period", "previous_version"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Period period = periodsHolder.getPeriod(); assertThat(period).isNotNull(); @@ -352,7 +353,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project, "1.1"); settings.setProperty("sonar.leak.period", "previous_version"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Period period = periodsHolder.getPeriod(); assertThat(period).isNotNull(); @@ -377,7 +378,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project, "1.1"); settings.setProperty("sonar.leak.period", "1.0"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // Analysis form 2008-11-11 Period period = periodsHolder.getPeriod(); @@ -398,7 +399,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { setupRoot(project); settings.setProperty("sonar.leak.period", "0.8"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(periodsHolder.getPeriod()).isNull(); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java index 2b188f94607..c64f81d2244 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java @@ -30,6 +30,7 @@ import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository; import org.sonar.ce.task.projectanalysis.qualitygate.MutableQualityGateHolderRule; import org.sonar.ce.task.projectanalysis.qualitygate.QualityGate; import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateService; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.server.qualitygate.ShortLivingBranchQualityGate; import static java.util.Collections.emptyList; @@ -62,7 +63,7 @@ public class LoadQualityGateStepTest { QualityGate qualityGate = mock(QualityGate.class); when(qualityGateService.findById(ShortLivingBranchQualityGate.ID)).thenReturn(Optional.of(qualityGate)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(mutableQualityGateHolder.getQualityGate().get()).isSameAs(qualityGate); } @@ -73,7 +74,7 @@ public class LoadQualityGateStepTest { QualityGate qualityGate = mock(QualityGate.class); when(qualityGateService.findById(ShortLivingBranchQualityGate.ID)).thenReturn(Optional.of(qualityGate)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(mutableQualityGateHolder.getQualityGate().get()).isSameAs(qualityGate); } @@ -84,7 +85,7 @@ public class LoadQualityGateStepTest { QualityGate defaultGate = mock(QualityGate.class); when(qualityGateService.findDefaultQualityGate(any())).thenReturn(defaultGate); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(mutableQualityGateHolder.getQualityGate().get()).isSameAs(defaultGate); } @@ -96,7 +97,7 @@ public class LoadQualityGateStepTest { when(settingsRepository.getConfiguration()).thenReturn(new MapSettings().setProperty("sonar.qualitygate", "10 sds").asConfig()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -106,7 +107,7 @@ public class LoadQualityGateStepTest { when(settingsRepository.getConfiguration()).thenReturn(new MapSettings().setProperty("sonar.qualitygate", 10).asConfig()); when(qualityGateService.findById(10)).thenReturn(Optional.of(qualityGate)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(mutableQualityGateHolder.getQualityGate().get()).isSameAs(qualityGate); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityProfilesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityProfilesStepTest.java index cc6aa5da43a..ac9959b9acf 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityProfilesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityProfilesStepTest.java @@ -30,6 +30,7 @@ import org.sonar.ce.task.projectanalysis.issue.DumbRule; import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryRule; import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule; import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRulesHolderImpl; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.scanner.protocol.Constants; import org.sonar.scanner.protocol.output.ScannerReport; @@ -65,7 +66,7 @@ public class LoadQualityProfilesStepTest { .setRuleRepository(XOO_X2.repository()).setRuleKey(XOO_X2.rule()).setSeverity(Constants.Severity.MAJOR); batchReportReader.putActiveRules(asList(batch1.build(), batch2.build())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(activeRulesHolder.getAll()).hasSize(2); @@ -89,7 +90,7 @@ public class LoadQualityProfilesStepTest { .setSeverity(Constants.Severity.BLOCKER); batchReportReader.putActiveRules(asList(batch1.build())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(activeRulesHolder.getAll()).isEmpty(); } @@ -101,7 +102,7 @@ public class LoadQualityProfilesStepTest { .setSeverity(Constants.Severity.BLOCKER); batchReportReader.putActiveRules(asList(batch1.build())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(activeRulesHolder.getAll()).isEmpty(); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java index 5f7bf561297..41e3a4f8b73 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java @@ -41,6 +41,7 @@ import org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin; import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule; import org.sonar.ce.task.projectanalysis.component.BranchLoader; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginRepository; import org.sonar.db.DbClient; @@ -96,7 +97,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { .setRootComponentRef(1) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(analysisMetadataHolder.getRootComponentRef()).isEqualTo(1); } @@ -108,7 +109,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { .setAnalysisDate(ANALYSIS_DATE) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(analysisMetadataHolder.getAnalysisDate()).isEqualTo(ANALYSIS_DATE); } @@ -120,7 +121,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { .setRootComponentRef(1) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Project project = analysisMetadataHolder.getProject(); assertThat(project.getUuid()).isEqualTo(this.project.uuid()); @@ -136,7 +137,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { .setCrossProjectDuplicationActivated(true) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isEqualTo(true); } @@ -148,7 +149,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { .setCrossProjectDuplicationActivated(false) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isEqualTo(false); } @@ -159,7 +160,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { newBatchReportBuilder() .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isEqualTo(false); } @@ -176,7 +177,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { expectedException.expect(MessageException.class); expectedException.expectMessage("Compute Engine task component key is null. Project with UUID prj_uuid must have been deleted since report was uploaded. Can not proceed."); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -192,7 +193,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { expectedException .expectMessage("ProjectKey in report (" + otherProject.getDbKey() + ") is not consistent with projectKey under which the report has been submitted (" + PROJECT_KEY + ")"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -205,7 +206,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { .build()); try { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } catch (MessageException e) { assertThat(analysisMetadataHolder.getBranch()).isNotNull(); } @@ -222,7 +223,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { .build()); try { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } catch (MessageException e) { assertThat(analysisMetadataHolder.getAnalysisDate()).isEqualTo(ANALYSIS_DATE); } @@ -241,7 +242,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { expectedException.expectMessage("Report does not specify an OrganizationKey but it has been submitted to another organization (" + nonDefaultOrganizationDto.getKey() + ") than the default one (" + db.getDefaultOrganization().getKey() + ")"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -250,7 +251,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { newBatchReportBuilder() .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Organization organization = analysisMetadataHolder.getOrganization(); OrganizationDto defaultOrganization = db.getDefaultOrganization(); @@ -268,7 +269,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { .build()); when(organizationFlags.isEnabled(any())).thenReturn(organizationEnabled); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Organization organization = analysisMetadataHolder.getOrganization(); OrganizationDto defaultOrganization = db.getDefaultOrganization(); @@ -292,7 +293,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { ComputationStep underTest = createStep(createCeTask(project.getDbKey(), nonDefaultOrganizationDto.getUuid())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Organization organization = analysisMetadataHolder.getOrganization(); assertThat(organization.getUuid()).isEqualTo(nonDefaultOrganizationDto.getUuid()); @@ -325,7 +326,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { ComputationStep underTest = createStep(createCeTask(project.getDbKey(), organization.getUuid())); // no errors - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -349,7 +350,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { expectedException.expect(MessageException.class); expectedException.expectMessage("Quality profiles with following keys don't exist in organization [" + organization1.getKey() + "]: phpInOrg2"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -365,7 +366,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { ComputationStep underTest = createStep(createCeTask(project.getDbKey(), organization.getUuid())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -384,7 +385,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { metadataBuilder.putPluginsByKey("uninstalled", ScannerReport.Metadata.Plugin.newBuilder().setKey("uninstalled").setUpdatedAt(40L).build()); reportReader.setMetadata(metadataBuilder.build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Assertions.assertThat(analysisMetadataHolder.getScannerPluginsByKey().values()).extracting(ScannerPlugin::getKey, ScannerPlugin::getBasePluginKey, ScannerPlugin::getUpdatedAt) .containsExactlyInAnyOrder( 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 14f57395662..2b983b6c1a4 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 @@ -32,6 +32,7 @@ import org.sonar.ce.task.projectanalysis.period.Period; import org.sonar.ce.task.projectanalysis.period.PeriodHolderRule; import org.sonar.ce.task.projectanalysis.scm.Changeset; import org.sonar.ce.task.projectanalysis.scm.ScmInfoRepositoryRule; +import org.sonar.ce.task.step.TestComputationStepContext; import static com.google.common.base.Preconditions.checkArgument; import static org.assertj.core.api.Assertions.assertThat; @@ -118,7 +119,7 @@ public class NewSizeMeasuresStepTest { public void compute_new_lines() { setChangesets(FILE_1_REF, FILE_2_REF, FILE_4_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_LINES_KEY, 11); assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_LINES_KEY, 11); @@ -136,7 +137,7 @@ public class NewSizeMeasuresStepTest { public void compute_new_lines_with_only_some_lines_having_changesets() { setChangesetsForFirstThreeLines(FILE_1_REF, FILE_2_REF, FILE_4_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_LINES_KEY, 2); assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_LINES_KEY, 2); @@ -152,7 +153,7 @@ public class NewSizeMeasuresStepTest { @Test public void does_not_compute_new_lines_when_no_changeset() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasures(NEW_LINES_KEY); } @@ -162,7 +163,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 1), new TextBlock(2, 2)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); } @@ -173,7 +174,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, original, FILE_2_REF, new TextBlock(2, 2)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d); } @@ -184,7 +185,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, original, SOME_FILE_KEY, new TextBlock(2, 2)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d); } @@ -195,7 +196,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(10, 11)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 6d); } @@ -207,7 +208,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(2, 2), new TextBlock(4, 4)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 11d); } @@ -222,7 +223,7 @@ public class NewSizeMeasuresStepTest { setChangesets(FILE_3_REF); setChangesets(FILE_4_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0d); @@ -247,7 +248,7 @@ public class NewSizeMeasuresStepTest { setChangesetsForFirstThreeLines(FILE_3_REF); setChangesetsForFirstThreeLines(FILE_4_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0d); @@ -268,7 +269,7 @@ public class NewSizeMeasuresStepTest { setChangesets(FILE_3_REF); setChangesets(FILE_4_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertComputedAndAggregatedToZeroInt(NEW_DUPLICATED_LINES_KEY); } @@ -279,7 +280,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(2, 2), new TextBlock(4, 4), new TextBlock(3, 4)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4); } @@ -290,7 +291,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(2, 2), new TextBlock(4, 4)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4); } @@ -300,7 +301,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 1), FILE_2_REF, new TextBlock(2, 2)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1); } @@ -310,7 +311,7 @@ public class NewSizeMeasuresStepTest { duplicationRepository.addDuplication(FILE_1_REF, new TextBlock(1, 1), SOME_FILE_KEY, new TextBlock(2, 2)); setChangesets(FILE_1_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1); } @@ -322,7 +323,7 @@ public class NewSizeMeasuresStepTest { addDuplicatedBlock(FILE_4_REF, 7); setChangesets(FILE_1_REF, FILE_2_REF, FILE_3_REF, FILE_4_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 10); assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_BLOCKS_DUPLICATED_KEY, 2); @@ -339,7 +340,7 @@ public class NewSizeMeasuresStepTest { public void compute_and_aggregate_duplicated_blocks_to_zero_when_no_duplication() { setChangesets(FILE_1_REF, FILE_2_REF, FILE_3_REF, FILE_4_REF); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertComputedAndAggregatedToZeroInt(NEW_BLOCKS_DUPLICATED_KEY); } @@ -351,7 +352,7 @@ public class NewSizeMeasuresStepTest { addDuplicatedBlock(FILE_3_REF, 10); addDuplicatedBlock(FILE_4_REF, 12); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 18.2d); assertRawMeasureValue(FILE_2_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 0d); @@ -367,7 +368,7 @@ public class NewSizeMeasuresStepTest { @Test public void compute_no_new_duplicated_lines_density_when_no_lines() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasures(NEW_DUPLICATED_LINES_DENSITY_KEY); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java index cc247b35dbf..3b257fb16d5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java @@ -27,6 +27,7 @@ import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.util.CloseableIterator; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbTester; @@ -73,7 +74,7 @@ public class PersistAnalysisPropertiesStepTest { when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.from(PROPERTIES.iterator())); when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(8); List<AnalysisPropertyDto> propertyDtos = dbTester.getDbClient() @@ -103,7 +104,7 @@ public class PersistAnalysisPropertiesStepTest { newContextProperty("sonar.pullREQUEST.doo", "doh")).iterator())); when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(0); } @@ -113,7 +114,8 @@ public class PersistAnalysisPropertiesStepTest { when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.emptyCloseableIterator()); when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); + assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(0); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java index 7a6134db3ef..1ed10710631 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java @@ -29,6 +29,7 @@ import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.component.MutableDbIdsRepository; import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder; import org.sonar.ce.task.projectanalysis.component.TreeRootHolder; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDao; @@ -68,6 +69,6 @@ public class PersistComponentsStepTest { System2.INSTANCE, mock(MutableDisabledComponentsHolder.class), mock(AnalysisMetadataHolder.class), - mock(BranchPersister.class)).execute(); + mock(BranchPersister.class)).execute(new TestComputationStepContext()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java index f66e15a1dcd..19f343fc1dc 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java @@ -35,6 +35,7 @@ import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolder; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.scanner.protocol.output.ScannerReport; @@ -95,7 +96,7 @@ public class PersistCrossProjectDuplicationIndexStepTest { when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true); reportReader.putDuplicationBlocks(FILE_1_REF, singletonList(CPD_TEXT_BLOCK)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Map<String, Object> dto = dbTester.selectFirst("select HASH, START_LINE, END_LINE, INDEX_IN_FILE, COMPONENT_UUID, ANALYSIS_UUID from duplications_index"); assertThat(dto.get("HASH")).isEqualTo(CPD_TEXT_BLOCK.getHash()); @@ -117,7 +118,7 @@ public class PersistCrossProjectDuplicationIndexStepTest { .setEndLine(15) .build())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); List<Map<String, Object>> dtos = dbTester.select("select HASH, START_LINE, END_LINE, INDEX_IN_FILE, COMPONENT_UUID, ANALYSIS_UUID from duplications_index"); assertThat(dtos).extracting("HASH").containsOnly(CPD_TEXT_BLOCK.getHash(), "b1234353e96320ff"); @@ -133,7 +134,7 @@ public class PersistCrossProjectDuplicationIndexStepTest { when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true); reportReader.putDuplicationBlocks(FILE_1_REF, Collections.emptyList()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("duplications_index")).isEqualTo(0); } @@ -143,7 +144,7 @@ public class PersistCrossProjectDuplicationIndexStepTest { when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(false); reportReader.putDuplicationBlocks(FILE_1_REF, singletonList(CPD_TEXT_BLOCK)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("duplications_index")).isEqualTo(0); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java index 28cb70b8c4e..f9ce412ed8a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java @@ -33,6 +33,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.event.Event; import org.sonar.ce.task.projectanalysis.event.EventRepository; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.util.UuidFactory; import org.sonar.core.util.UuidFactoryImpl; import org.sonar.db.DbTester; @@ -100,7 +101,7 @@ public class PersistEventsStepTest extends BaseStepTest { treeRootHolder.setRoot(ROOT); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); dbTester.assertDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml", new String[] {"uuid"}, "events"); } @@ -114,7 +115,7 @@ public class PersistEventsStepTest extends BaseStepTest { when(eventRepository.getEvents(ROOT)).thenReturn(ImmutableList.of(Event.createAlert("Red (was Orange)", null, "Open issues > 0"))); treeRootHolder.setRoot(ROOT); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); dbTester.assertDbUnit(getClass(), "persist_report_events_with_component_children-result.xml", new String[] {"uuid"}, "events"); } @@ -141,7 +142,7 @@ public class PersistEventsStepTest extends BaseStepTest { .build(); treeRootHolder.setRoot(project); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); dbTester.assertDbUnit(getClass(), "add_version_event-result.xml", new String[] {"uuid"}, "events"); } @@ -168,7 +169,7 @@ public class PersistEventsStepTest extends BaseStepTest { .build(); treeRootHolder.setRoot(project); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); dbTester.assertDbUnit(getClass(), "keep_one_event_by_version-result.xml", new String[] {"uuid"}, "events"); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java index a5abc7708ca..87d44ddb343 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java @@ -28,6 +28,7 @@ import org.sonar.api.utils.System2; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryImpl; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.rule.RuleDao; @@ -81,7 +82,7 @@ public class PersistExternalRulesStepTest extends BaseStepTest { .setName("eslint:no-cond-assign") .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); RuleDao ruleDao = dbClient.ruleDao(); Optional<RuleDefinitionDto> ruleDefinitionDtoOptional = ruleDao.selectDefinitionByKey(dbClient.openSession(false), ruleKey); @@ -109,7 +110,7 @@ public class PersistExternalRulesStepTest extends BaseStepTest { .setPluginKey("eslint") .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); RuleDao ruleDao = dbClient.ruleDao(); assertThat(ruleDao.selectAllDefinitions(dbClient.openSession(false))).hasSize(1); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStepTest.java index 180fd48977b..245602dcb3f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStepTest.java @@ -43,6 +43,7 @@ import org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepository; import org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl; import org.sonar.ce.task.projectanalysis.source.SourceLinesRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -110,7 +111,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { public void persist_sources() { initBasicReport(2); when(lineHashesComputer.getResult()).thenReturn(Lists.newArrayList("137f72c3708c6bd0de00a0e5a69c699b", "e6251bcf1a7dc3ba5e7933e325bbe605")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -135,7 +136,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { public void persist_source_hashes() { initBasicReport(2); when(lineHashesComputer.getResult()).thenReturn(Lists.newArrayList("137f72c3708c6bd0de00a0e5a69c699b", "e6251bcf1a7dc3ba5e7933e325bbe605")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -154,7 +155,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { .setCoveredConditions(2) .build())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -176,7 +177,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { .setRevision("rev-1") .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -204,7 +205,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { .setDate(223456789L) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -241,7 +242,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { .setType(HighlightingType.ANNOTATION) .build())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -266,7 +267,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { .build()) .build())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -287,7 +288,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { FILE1_REF, new Duplication(new TextBlock(1, 2), Arrays.asList(new InnerDuplicate(new TextBlock(3, 4))))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -307,7 +308,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { .setRevision("rev-1") .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getRevision()).isEqualTo("rev-1"); @@ -317,7 +318,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { public void not_save_revision() { initBasicReport(1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getRevision()).isNull(); @@ -351,7 +352,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { // Sources from the report initBasicReport(1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -392,7 +393,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { .setRevision("rev-1") .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -424,7 +425,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { initBasicReport(1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -463,7 +464,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { initBasicReport(1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); @@ -496,7 +497,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { initBasicReport(1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(session, FILE1_UUID); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java index d8e2470046a..d2f758013f6 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java @@ -37,6 +37,7 @@ import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryImpl; import org.sonar.ce.task.projectanalysis.issue.UpdateConflictResolver; import org.sonar.ce.task.projectanalysis.util.cache.DiskCache; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.FieldDiffs; @@ -81,13 +82,13 @@ public class PersistIssuesStepTest extends BaseStepTest { private DbSession session = db.getSession(); private DbClient dbClient = db.getDbClient(); private IssueCache issueCache; - private ComputationStep step; + private ComputationStep underTest; private ExternalRuleCreator externalRuleCreator = mock(ExternalRuleCreator.class); @Override protected ComputationStep step() { - return step; + return underTest; } @Before @@ -97,7 +98,7 @@ public class PersistIssuesStepTest extends BaseStepTest { when(system2.now()).thenReturn(NOW); reportReader.setMetadata(ScannerReport.Metadata.getDefaultInstance()); - step = new PersistIssuesStep(dbClient, system2, new UpdateConflictResolver(), new RuleRepositoryImpl(externalRuleCreator, dbClient, analysisMetadataHolder), issueCache, new IssueStorage()); + underTest = new PersistIssuesStep(dbClient, system2, new UpdateConflictResolver(), new RuleRepositoryImpl(externalRuleCreator, dbClient, analysisMetadataHolder), issueCache, new IssueStorage()); } @After @@ -142,7 +143,7 @@ public class PersistIssuesStepTest extends BaseStepTest { .setCreationDate(new Date(NOW)))) .close(); - step.execute(); + underTest.execute(new TestComputationStepContext()); IssueDto result = dbClient.issueDao().selectOrFailByKey(session, "ISSUE"); assertThat(result.getKey()).isEqualTo("ISSUE"); @@ -192,7 +193,7 @@ public class PersistIssuesStepTest extends BaseStepTest { .setDiff("technicalDebt", null, 1L) .setCreationDate(new Date(NOW)))) .close(); - step.execute(); + underTest.execute(new TestComputationStepContext()); IssueDto result = dbClient.issueDao().selectOrFailByKey(session, "ISSUE"); assertThat(result.getKey()).isEqualTo("ISSUE"); @@ -229,7 +230,7 @@ public class PersistIssuesStepTest extends BaseStepTest { .setNew(true) .setType(RuleType.BUG)).close(); - step.execute(); + underTest.execute(new TestComputationStepContext()); IssueDto result = dbClient.issueDao().selectOrFailByKey(session, "ISSUE"); assertThat(result.getKey()).isEqualTo("ISSUE"); @@ -261,7 +262,7 @@ public class PersistIssuesStepTest extends BaseStepTest { .setNew(false) .setChanged(true)) .close(); - step.execute(); + underTest.execute(new TestComputationStepContext()); IssueDto issueReloaded = db.getDbClient().issueDao().selectByKey(db.getSession(), issue.getKey()).get(); assertThat(issueReloaded.getStatus()).isEqualTo(STATUS_CLOSED); @@ -295,7 +296,7 @@ public class PersistIssuesStepTest extends BaseStepTest { .setCreatedAt(new Date(NOW)) .setNew(true))) .close(); - step.execute(); + underTest.execute(new TestComputationStepContext()); IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0); assertThat(issueChangeDto) @@ -329,7 +330,7 @@ public class PersistIssuesStepTest extends BaseStepTest { .setDiff("technicalDebt", null, 1L) .setCreationDate(new Date(NOW)))) .close(); - step.execute(); + underTest.execute(new TestComputationStepContext()); IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0); assertThat(issueChangeDto) 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 f78c86e1b72..6d709263662 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 @@ -34,6 +34,7 @@ import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.measure.MeasureToMeasureDto; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -100,7 +101,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { measureRepository.addRawMeasure(REF_3, STRING_METRIC.getKey(), newMeasureBuilder().create("dir-value")); measureRepository.addRawMeasure(REF_4, STRING_METRIC.getKey(), newMeasureBuilder().create("file-value")); - step().execute(); + step().execute(new TestComputationStepContext()); // all measures are persisted, from project to file assertThat(db.countRowsOfTable("live_measures")).isEqualTo(4); @@ -116,7 +117,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { measureRepository.addRawMeasure(REF_1, STRING_METRIC.getKey(), newMeasureBuilder().createNoValue()); measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().createNoValue()); - step().execute(); + step().execute(new TestComputationStepContext()); assertThatMeasureIsNotPersisted("project-uuid", STRING_METRIC); assertThatMeasureIsNotPersisted("project-uuid", INT_METRIC); @@ -127,7 +128,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { prepareProject(); measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().setVariation(42.0).createNoValue()); - step().execute(); + step().execute(new TestComputationStepContext()); LiveMeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get(); assertThat(persistedMeasure.getValue()).isNull(); @@ -149,7 +150,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { measureRepository.addRawMeasure(REF_4, INT_METRIC.getKey(), newMeasureBuilder().create(42)); - step().execute(); + step().execute(new TestComputationStepContext()); assertThatMeasureHasValue(measureOnFileInProject, 42); assertThatMeasureDoesNotExist(measureOnDeletedFileInProject); @@ -169,7 +170,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { // file measure with metric best value -> do not persist measureRepository.addRawMeasure(REF_4, METRIC_WITH_BEST_VALUE.getKey(), newMeasureBuilder().create(0)); - step().execute(); + step().execute(new TestComputationStepContext()); assertThatMeasureDoesNotExist(oldMeasure); assertThatMeasureHasValue("project-uuid", METRIC_WITH_BEST_VALUE, 0); @@ -184,7 +185,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { measureRepository.addRawMeasure(REF_2, STRING_METRIC.getKey(), newMeasureBuilder().create("subview-value")); measureRepository.addRawMeasure(REF_3, STRING_METRIC.getKey(), newMeasureBuilder().create("project-value")); - step().execute(); + step().execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("live_measures")).isEqualTo(3); assertThat(selectMeasure("view-uuid", STRING_METRIC).get().getDataAsString()).isEqualTo("view-value"); 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 c710d08fc35..fd19e2974c2 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 @@ -34,6 +34,7 @@ import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.measure.MeasureToMeasureDto; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -217,7 +218,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { private void execute(boolean persistDirectories) { new PersistMeasuresStep(dbClient, metricRepository, new MeasureToMeasureDto(analysisMetadataHolder, treeRootHolder), treeRootHolder, measureRepository, persistDirectories) - .execute(); + .execute(new TestComputationStepContext()); } private Optional<MeasureDto> selectMeasure(String componentUuid, Metric metric) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepTest.java index 052cc1052b5..1edab8b6ee0 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepTest.java @@ -33,6 +33,7 @@ import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolder; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.util.UuidFactory; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; @@ -65,11 +66,11 @@ public class PersistProjectLinksStepTest extends BaseStepTest { @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); - PersistProjectLinksStep step = new PersistProjectLinksStep(analysisMetadataHolder, db.getDbClient(), treeRootHolder, reportReader, UuidFactoryFast.getInstance()); + private PersistProjectLinksStep underTest = new PersistProjectLinksStep(analysisMetadataHolder, db.getDbClient(), treeRootHolder, reportReader, UuidFactoryFast.getInstance()); @Override protected ComputationStep step() { - return step; + return underTest; } @Test @@ -81,7 +82,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { mockBranch(false); PersistProjectLinksStep underTest = new PersistProjectLinksStep(analysisMetadataHolder, dbClient, treeRootHolder, reportReader, uuidFactory); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyZeroInteractions(uuidFactory, reportReader, treeRootHolder, dbClient); } @@ -104,7 +105,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { .addLink(ScannerReport.ComponentLink.newBuilder().setType(CI).setHref("http://bamboo.ci.codehaus.org/browse/SONAR").build()) .build()); - step.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.getDbClient().projectLinkDao().selectByProjectUuid(db.getSession(), "ABCD")) .extracting(ProjectLinkDto::getType, ProjectLinkDto::getHref, ProjectLinkDto::getName) @@ -129,7 +130,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { .addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()) .build()); - step.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.getDbClient().projectLinkDao().selectByProjectUuid(db.getSession(), "ABCD")) .extracting(ProjectLinkDto::getType, ProjectLinkDto::getHref) @@ -153,7 +154,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { .addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()) .build()); - step.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("project_links")).isZero(); } @@ -176,7 +177,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { .addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()) .build()); - step.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("project_links")).isZero(); } @@ -195,7 +196,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { .addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()) .build()); - step.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.getDbClient().projectLinkDao().selectByProjectUuid(db.getSession(), "ABCD")) .extracting(ProjectLinkDto::getType, ProjectLinkDto::getHref) @@ -215,7 +216,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { .setType(ComponentType.PROJECT) .build()); - step.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("project_links")).isZero(); } @@ -233,7 +234,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { .setType(ComponentType.PROJECT) .build()); - step.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("project_links")).isEqualTo(1); } @@ -253,7 +254,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Link of type 'homepage' has already been declared on component 'ABCD'"); - step.execute(); + underTest.execute(new TestComputationStepContext()); } private void mockBranch(boolean isMain) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepTest.java index 6fad5e539fe..2c12960df10 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepTest.java @@ -27,6 +27,7 @@ import org.sonar.api.utils.System2; import org.sonar.ce.task.CeTask; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.util.CloseableIterator; import org.sonar.db.DbClient; import org.sonar.db.DbTester; @@ -64,7 +65,7 @@ public class PersistScannerContextStepTest { when(ceTask.getUuid()).thenReturn(taskUuid); reportReader.setScannerLogs(asList("log1", "log2")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), taskUuid)) .contains("log1" + '\n' + "log2"); @@ -74,14 +75,14 @@ public class PersistScannerContextStepTest { public void executes_persist_does_not_persist_any_scanner_context_if_iterator_is_empty() { reportReader.setScannerLogs(emptyList()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID)) .isEmpty(); } /** - * @see SONAR-8306 + * SONAR-8306 */ @Test public void execute_does_not_fail_if_scanner_context_has_already_been_persisted() { @@ -90,7 +91,7 @@ public class PersistScannerContextStepTest { reportReader.setScannerLogs(asList("1", "2", "3")); when(ceTask.getUuid()).thenReturn(ANALYSIS_UUID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID)) .contains("1" + '\n' + "2" + '\n' + "3"); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStepTest.java index eda6f5a3865..2f177976ef9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStepTest.java @@ -33,6 +33,7 @@ import org.sonar.ce.task.projectanalysis.component.FileAttributes; import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.protobuf.DbFileSources; @@ -102,7 +103,7 @@ public class PersistTestsStepTest extends BaseStepTest { @Test public void no_test_in_database_and_batch_report() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbClient.fileSourceDao().selectTestByFileUuid(db.getSession(), TEST_FILE_UUID_1)).isNull(); assertThat(log.logs()).isEmpty(); @@ -117,7 +118,7 @@ public class PersistTestsStepTest extends BaseStepTest { newCoverageDetail(1, MAIN_FILE_REF_1)); reportReader.putCoverageDetails(TEST_FILE_REF_1, coverageDetails); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("file_sources")).isEqualTo(1); @@ -140,7 +141,7 @@ public class PersistTestsStepTest extends BaseStepTest { reportReader.putTests(TEST_FILE_REF_1, Arrays.asList(newTest(1))); reportReader.putCoverageDetails(TEST_FILE_REF_1, Arrays.asList(newCoverageDetail(1, MAIN_FILE_REF_1))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); FileSourceDto dto = dbClient.fileSourceDao().selectTestByFileUuid(db.getSession(), TEST_FILE_UUID_1); assertThat(dto.getCreatedAt()).isEqualTo(now); @@ -166,7 +167,7 @@ public class PersistTestsStepTest extends BaseStepTest { List<ScannerReport.Test> batchTests = Arrays.asList(newTest(1)); reportReader.putTests(TEST_FILE_REF_1, batchTests); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); FileSourceDto dto = dbClient.fileSourceDao().selectTestByFileUuid(db.getSession(), TEST_FILE_UUID_1); assertThat(dto.getFileUuid()).isEqualTo(TEST_FILE_UUID_1); @@ -184,7 +185,7 @@ public class PersistTestsStepTest extends BaseStepTest { reportReader.putCoverageDetails(TEST_FILE_REF_1, coverageDetails); reportReader.putCoverageDetails(TEST_FILE_REF_2, coverageDetails); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(log.logs(LoggerLevel.WARN)).hasSize(1); assertThat(log.logs(LoggerLevel.WARN).get(0)).isEqualTo("Some coverage tests are not taken into account during analysis of project 'PROJECT_KEY'"); @@ -201,7 +202,7 @@ public class PersistTestsStepTest extends BaseStepTest { newCoverageDetailWithLines(1, MAIN_FILE_REF_1, 1, 3), newCoverageDetailWithLines(1, MAIN_FILE_REF_1, 2, 4))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); FileSourceDto dto = dbClient.fileSourceDao().selectTestByFileUuid(db.getSession(), TEST_FILE_UUID_1); List<Integer> coveredLines = dto.getTestData().get(0).getCoveredFile(0).getCoveredLineList(); @@ -234,7 +235,7 @@ public class PersistTestsStepTest extends BaseStepTest { reportReader.putCoverageDetails(TEST_FILE_REF_1, Arrays.asList(newCoverageDetail)); // ACT - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // ASSERT FileSourceDto dto = dbClient.fileSourceDao().selectTestByFileUuid(db.getSession(), TEST_FILE_UUID_1); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PublishTaskResultStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PublishTaskResultStepTest.java index 1ec445635c8..ae32f0a6983 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PublishTaskResultStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PublishTaskResultStepTest.java @@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.step; import org.junit.Rule; import org.junit.Test; import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolderRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.ce.task.taskprocessor.MutableTaskResultHolder; import org.sonar.ce.task.taskprocessor.MutableTaskResultHolderImpl; @@ -47,7 +48,7 @@ public class PublishTaskResultStepTest { public void execute_populate_TaskResultHolder_with_a_TaskResult_with_snapshot_id_of_the_root_taken_from_DbIdsRepository() { analysisMetadataHolder.setUuid(AN_ANALYSIS_UUID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(taskResultHolder.getResult().getAnalysisUuid().get()).isEqualTo(AN_ANALYSIS_UUID); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java index daef3366005..32caea964ba 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java @@ -39,6 +39,7 @@ import org.sonar.ce.task.projectanalysis.measure.MeasureRepository; import org.sonar.ce.task.projectanalysis.measure.QualityGateStatus; import org.sonar.ce.task.projectanalysis.metric.Metric; import org.sonar.ce.task.projectanalysis.metric.MetricRepository; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.component.BranchType; import org.sonar.server.notification.NotificationService; import org.sonar.server.project.Project; @@ -96,7 +97,7 @@ public class QualityGateEventsStepTest { public void no_event_if_no_raw_ALERT_STATUS_measure() { when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(Optional.absent()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric); verifyNoMoreInteractions(measureRepository, eventRepository); @@ -106,7 +107,7 @@ public class QualityGateEventsStepTest { public void no_event_created_if_raw_ALERT_STATUS_measure_is_null() { when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().createNoValue())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric); verifyNoMoreInteractions(measureRepository, eventRepository); @@ -120,7 +121,7 @@ public class QualityGateEventsStepTest { public void no_event_created_if_raw_ALERT_STATUS_measure_is_unsupported_value() { when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().create(INVALID_ALERT_STATUS))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric); verifyNoMoreInteractions(measureRepository, eventRepository); @@ -133,7 +134,7 @@ public class QualityGateEventsStepTest { when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(someQGStatus).createNoValue())); when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().createNoValue())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric); verify(measureRepository).getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric); @@ -176,7 +177,7 @@ public class QualityGateEventsStepTest { when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(someQGStatus).createNoValue())); when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().createNoValue())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric); verify(measureRepository).getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric); @@ -207,7 +208,7 @@ public class QualityGateEventsStepTest { when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)) .thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(OK_QUALITY_GATE_STATUS).createNoValue())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric); verify(measureRepository).getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric); @@ -231,7 +232,7 @@ public class QualityGateEventsStepTest { when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn( of(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(previousAlertStatus)).createNoValue())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric); verify(measureRepository).getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric); @@ -272,7 +273,7 @@ public class QualityGateEventsStepTest { when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn( of(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(ERROR)).createNoValue())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService).deliver(notificationArgumentCaptor.capture()); Notification notification = notificationArgumentCaptor.getValue(); @@ -294,7 +295,7 @@ public class QualityGateEventsStepTest { when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn( of(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(ERROR)).createNoValue())); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService).deliver(notificationArgumentCaptor.capture()); Notification notification = notificationArgumentCaptor.getValue(); @@ -321,7 +322,7 @@ public class QualityGateEventsStepTest { QualityGateEventsStep underTest = new QualityGateEventsStep(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService, analysisMetadataHolder); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyZeroInteractions(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService); } @@ -340,7 +341,7 @@ public class QualityGateEventsStepTest { QualityGateEventsStep underTest = new QualityGateEventsStep(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService, analysisMetadataHolder); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyZeroInteractions(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService); } 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 15178ad7406..8f0fe48d65e 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 @@ -51,6 +51,7 @@ import org.sonar.ce.task.projectanalysis.qualitygate.QualityGate; import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateHolderRule; import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatus; import org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatusHolder; +import org.sonar.ce.task.step.TestComputationStepContext; import static com.google.common.collect.ImmutableList.of; import static org.mockito.ArgumentMatchers.any; @@ -121,7 +122,7 @@ public class QualityGateMeasuresStepTest { treeRootHolder.setRoot(notAProjectComponent); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); measureRepository.getAddedRawMeasures(1).isEmpty(); } @@ -130,7 +131,7 @@ public class QualityGateMeasuresStepTest { public void no_measure_if_there_is_no_qualitygate() { qualityGateHolder.setQualityGate(null); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); measureRepository.getAddedRawMeasures(PROJECT_COMPONENT).isEmpty(); } @@ -139,7 +140,7 @@ public class QualityGateMeasuresStepTest { public void mutableQualityGateStatusHolder_is_not_populated_if_there_is_no_qualitygate() { qualityGateHolder.setQualityGate(null); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Quality gate status has not been set yet"); @@ -152,7 +153,7 @@ public class QualityGateMeasuresStepTest { Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", null); qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Optional<Measure> addedRawMeasure = measureRepository.getAddedRawMeasure(PROJECT_COMPONENT, INT_METRIC_1_KEY); @@ -178,7 +179,7 @@ public class QualityGateMeasuresStepTest { qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition))); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Optional<Measure> addedRawMeasure = measureRepository.getAddedRawMeasure(PROJECT_COMPONENT, INT_METRIC_1_KEY); @@ -208,7 +209,7 @@ public class QualityGateMeasuresStepTest { measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY); Optional<Measure> rawMeasure2 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_2_KEY); @@ -246,7 +247,7 @@ public class QualityGateMeasuresStepTest { measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY); Optional<Measure> rawMeasure2 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_2_KEY); @@ -283,7 +284,7 @@ public class QualityGateMeasuresStepTest { Measure measure = newMeasureBuilder().create(rawValue, null); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, measure); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY); assertThat(rawMeasure1.get()) @@ -303,7 +304,7 @@ public class QualityGateMeasuresStepTest { .create(rawValue, null); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, measure); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY); assertThat(rawMeasure1.get()) @@ -323,7 +324,7 @@ public class QualityGateMeasuresStepTest { .create(rawValue, null); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, measure); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY); assertThat(rawMeasure1.get()) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java index 9ae358912ab..acfd6d4423e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStepTest.java @@ -46,6 +46,7 @@ import org.sonar.ce.task.projectanalysis.measure.Measure; import org.sonar.ce.task.projectanalysis.measure.MeasureRepository; import org.sonar.ce.task.projectanalysis.metric.Metric; import org.sonar.ce.task.projectanalysis.metric.MetricRepository; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.util.UtcDateUtils; import org.sonar.server.qualityprofile.QPMeasureData; import org.sonar.server.qualityprofile.QualityProfile; @@ -92,7 +93,7 @@ public class QualityProfileEventsStepTest { public void no_event_if_no_base_measure() { when(measureRepository.getBaseMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.absent()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyNoMoreInteractions(eventRepository); } @@ -102,7 +103,7 @@ public class QualityProfileEventsStepTest { when(measureRepository.getBaseMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.of(newMeasure())); when(measureRepository.getRawMeasure(treeRootHolder.getRoot(), qualityProfileMetric)).thenReturn(Optional.absent()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyNoMoreInteractions(eventRepository); } @@ -111,7 +112,7 @@ public class QualityProfileEventsStepTest { public void no_event_if_no_base_and_quality_profile_measure_is_empty() { mockMeasures(treeRootHolder.getRoot(), null, null); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyNoMoreInteractions(eventRepository); } @@ -123,7 +124,7 @@ public class QualityProfileEventsStepTest { Language language = mockLanguageInRepository(LANGUAGE_KEY_1); mockMeasures(treeRootHolder.getRoot(), null, arrayOf(qp)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture()); verifyNoMoreInteractions(eventRepository); @@ -137,7 +138,7 @@ public class QualityProfileEventsStepTest { mockLanguageNotInRepository(LANGUAGE_KEY_1); mockMeasures(treeRootHolder.getRoot(), null, arrayOf(qp)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture()); verifyNoMoreInteractions(eventRepository); @@ -151,7 +152,7 @@ public class QualityProfileEventsStepTest { mockMeasures(treeRootHolder.getRoot(), arrayOf(qp), null); Language language = mockLanguageInRepository(LANGUAGE_KEY_1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture()); verifyNoMoreInteractions(eventRepository); @@ -165,7 +166,7 @@ public class QualityProfileEventsStepTest { mockMeasures(treeRootHolder.getRoot(), arrayOf(qp), null); mockLanguageNotInRepository(LANGUAGE_KEY_1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture()); verifyNoMoreInteractions(eventRepository); @@ -178,7 +179,7 @@ public class QualityProfileEventsStepTest { mockMeasures(treeRootHolder.getRoot(), arrayOf(qp), arrayOf(qp)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(eventRepository, never()).add(any(Component.class), any(Event.class)); } @@ -191,7 +192,7 @@ public class QualityProfileEventsStepTest { mockMeasures(treeRootHolder.getRoot(), arrayOf(qp1), arrayOf(qp2)); Language language = mockLanguageInRepository(LANGUAGE_KEY_1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture()); verifyNoMoreInteractions(eventRepository); @@ -223,7 +224,7 @@ public class QualityProfileEventsStepTest { qp(QP_NAME_2, LANGUAGE_KEY_3))); mockNoLanguageInRepository(); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(events).extracting("name").containsOnly( "Stop using '" + QP_NAME_2 + "' (" + LANGUAGE_KEY_1 + ")", diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java index 87b0bb3b0da..ee72a91fad5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCommentMeasuresStepTest.java @@ -26,6 +26,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -101,7 +102,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, COMMENTED_OUT_CODE_LINES_KEY, newMeasureBuilder().create(100)); measureRepository.addRawMeasure(FILE_2_REF, COMMENTED_OUT_CODE_LINES_KEY, newMeasureBuilder().create(400)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENTED_OUT_CODE_LINES_KEY)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENTED_OUT_CODE_LINES_KEY)).isAbsent(); @@ -116,7 +117,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, COMMENT_LINES_KEY, newMeasureBuilder().create(100)); measureRepository.addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, newMeasureBuilder().create(400)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENT_LINES_KEY)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENT_LINES_KEY)).isAbsent(); @@ -138,7 +139,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(300)); measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(300)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(60d); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(20d); @@ -160,7 +161,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(300)); measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(300)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d); @@ -182,7 +183,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(0)); measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(0)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoNewMeasures(COMMENT_LINES_DENSITY_KEY); } @@ -192,7 +193,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, COMMENT_LINES_KEY, newMeasureBuilder().create(150)); measureRepository.addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, newMeasureBuilder().create(50)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoNewMeasures(COMMENT_LINES_DENSITY_KEY); } @@ -206,7 +207,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(200)); measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(200)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoNewMeasures(COMMENT_LINES_DENSITY_KEY); } @@ -216,7 +217,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, PUBLIC_API_KEY, newMeasureBuilder().create(100)); measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_API_KEY, newMeasureBuilder().create(400)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_API_KEY)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_API_KEY)).isAbsent(); @@ -231,7 +232,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, PUBLIC_UNDOCUMENTED_API_KEY, newMeasureBuilder().create(100)); measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, newMeasureBuilder().create(400)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_UNDOCUMENTED_API_KEY)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY)).isAbsent(); @@ -250,7 +251,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_API_KEY, newMeasureBuilder().create(400)); measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, newMeasureBuilder().create(100)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(50d); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(75d); @@ -265,7 +266,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, PUBLIC_UNDOCUMENTED_API_KEY, newMeasureBuilder().create(50)); measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, newMeasureBuilder().create(100)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoNewMeasures(PUBLIC_DOCUMENTED_API_DENSITY_KEY); } @@ -275,7 +276,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, PUBLIC_API_KEY, newMeasureBuilder().create(50)); measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_API_KEY, newMeasureBuilder().create(100)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoNewMeasures(PUBLIC_DOCUMENTED_API_DENSITY_KEY); } @@ -288,7 +289,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_API_KEY, newMeasureBuilder().create(0)); measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, newMeasureBuilder().create(100)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoNewMeasures(PUBLIC_DOCUMENTED_API_DENSITY_KEY); } @@ -301,7 +302,7 @@ public class ReportCommentMeasuresStepTest { measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_API_KEY, newMeasureBuilder().create(400)); measureRepository.addRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, newMeasureBuilder().create(0)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d); @@ -313,7 +314,7 @@ public class ReportCommentMeasuresStepTest { @Test public void compute_nothing_when_no_data() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasures(FILE_1_REF)).isEmpty(); assertThat(measureRepository.getAddedRawMeasures(FILE_2_REF)).isEmpty(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java index edbd84ecd1c..ca2bfb009b7 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComplexityMeasuresStepTest.java @@ -26,6 +26,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -136,7 +137,7 @@ public class ReportComplexityMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, metricKey, newMeasureBuilder().create(10)); measureRepository.addRawMeasure(FILE_2_REF, metricKey, newMeasureBuilder().create(40)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isAbsent(); @@ -167,7 +168,7 @@ public class ReportComplexityMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, metricKey, newMeasureBuilder().create("0.5=3;3.5=5;6.5=9")); measureRepository.addRawMeasure(FILE_2_REF, metricKey, newMeasureBuilder().create("0.5=0;3.5=2;6.5=1")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isAbsent(); @@ -201,7 +202,7 @@ public class ReportComplexityMeasuresStepTest { measureRepository.addRawMeasure(FILE_2_REF, mainMetric, newMeasureBuilder().create(1)); measureRepository.addRawMeasure(FILE_2_REF, byMetric, newMeasureBuilder().create(1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(2.5, 1))); assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(1d, 1))); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComputeMeasureVariationsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComputeMeasureVariationsStepTest.java index 91d0a6a7f99..015dfdcb0e5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComputeMeasureVariationsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportComputeMeasureVariationsStepTest.java @@ -35,6 +35,7 @@ import org.sonar.ce.task.projectanalysis.metric.MetricImpl; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.projectanalysis.period.Period; import org.sonar.ce.task.projectanalysis.period.PeriodHolderRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -100,7 +101,7 @@ public class ReportComputeMeasureVariationsStepTest { treeRootHolder.setRoot(PROJECT); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasures(PROJECT).keys()).isEmpty(); } @@ -111,7 +112,7 @@ public class ReportComputeMeasureVariationsStepTest { treeRootHolder.setRoot(project); periodsHolder.setPeriod(null); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasures(project).keys()).isEmpty(); } @@ -138,7 +139,7 @@ public class ReportComputeMeasureVariationsStepTest { addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(80, null)); addRawMeasure(directory, ISSUES_METRIC, newMeasureBuilder().create(20, null)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(20d); assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(10d); @@ -166,7 +167,7 @@ public class ReportComputeMeasureVariationsStepTest { addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(60, null)); addRawMeasure(directory, ISSUES_METRIC, newMeasureBuilder().create(10, null)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(0d); assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(0d); @@ -193,7 +194,7 @@ public class ReportComputeMeasureVariationsStepTest { addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(90, null)); addRawMeasure(directory, ISSUES_METRIC, newMeasureBuilder().create(10, null)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(30d); // Variation should be the raw value @@ -220,7 +221,7 @@ public class ReportComputeMeasureVariationsStepTest { addRawMeasure(PROJECT, FILE_COMPLEXITY_METRIC, newMeasureBuilder().create(3d, 1, null)); addRawMeasure(PROJECT, BUILD_BREAKER_METRIC, newMeasureBuilder().create(false, null)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(4); @@ -245,7 +246,7 @@ public class ReportComputeMeasureVariationsStepTest { DumbDeveloper developer = new DumbDeveloper("a"); measureRepository.addRawMeasure(PROJECT_REF, ISSUES_METRIC.getKey(), newMeasureBuilder().forDeveloper(developer).create(80, null)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(1); @@ -263,7 +264,7 @@ public class ReportComputeMeasureVariationsStepTest { addRawMeasure(PROJECT, NEW_DEBT, newMeasureBuilder().setVariation(10d).createNoValue()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // As the measure has already variations it has been ignored, then variations will be the same assertThat(measureRepository.getRawMeasure(PROJECT, NEW_DEBT).get().getVariation()).isEqualTo(10d); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCoverageMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCoverageMeasuresStepTest.java index 318de5d8c15..dad85b0f194 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCoverageMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportCoverageMeasuresStepTest.java @@ -29,6 +29,7 @@ import org.sonar.ce.task.projectanalysis.formula.coverage.LinesAndConditionsWith 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.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY; @@ -106,7 +107,7 @@ public class ReportCoverageMeasuresStepTest { .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), newMeasureBuilder().create(200)) .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), newMeasureBuilder().create(16)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); MeasureRepoEntry[] nonFileRepoEntries = { entryOf(metricKeys.getLines(), newMeasureBuilder().create(5000)), @@ -145,7 +146,7 @@ public class ReportCoverageMeasuresStepTest { .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), newMeasureBuilder().create(200)) .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), newMeasureBuilder().create(16)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).contains( entryOf(codeCoverageKey, newMeasureBuilder().create(98.8d, 1)), diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java index 668129ab181..189a496e32a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportLanguageDistributionMeasuresStepTest.java @@ -27,6 +27,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -96,7 +97,7 @@ public class ReportLanguageDistributionMeasuresStepTest { measureRepository.addRawMeasure(FILE_3_REF, NCLOC_KEY, newMeasureBuilder().create(6)); measureRepository.addRawMeasure(FILE_4_REF, NCLOC_KEY, newMeasureBuilder().create(2)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY).get().getStringValue()).isEqualTo("xoo=10"); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY).get().getStringValue()).isEqualTo("xoo=8"); @@ -111,7 +112,7 @@ public class ReportLanguageDistributionMeasuresStepTest { @Test public void do_not_compute_ncloc_language_distribution_when_no_ncloc() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isAbsent(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java index 73dc6f83d47..6fe3ec3571c 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java @@ -36,6 +36,7 @@ import org.sonar.ce.task.projectanalysis.period.Period; import org.sonar.ce.task.projectanalysis.period.PeriodHolderRule; import org.sonar.ce.task.projectanalysis.scm.Changeset; import org.sonar.ce.task.projectanalysis.scm.ScmInfoRepositoryRule; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -121,7 +122,7 @@ public class ReportNewCoverageMeasuresStepTest { public void no_measure_for_PROJECT_component() { treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, ROOT_REF).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.isEmpty()).isTrue(); } @@ -130,7 +131,7 @@ public class ReportNewCoverageMeasuresStepTest { public void no_measure_for_MODULE_component() { treeRootHolder.setRoot(ReportComponent.builder(Component.Type.MODULE, MODULE_REF).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.isEmpty()).isTrue(); } @@ -139,7 +140,7 @@ public class ReportNewCoverageMeasuresStepTest { public void no_measure_for_DIRECTORY_component() { treeRootHolder.setRoot(ReportComponent.builder(Component.Type.DIRECTORY, DIRECTORY_1_REF).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.isEmpty()).isTrue(); } @@ -148,7 +149,7 @@ public class ReportNewCoverageMeasuresStepTest { public void no_measure_for_unit_test_FILE_component() { treeRootHolder.setRoot(ReportComponent.builder(Component.Type.FILE, FILE_1_REF).setFileAttributes(new FileAttributes(true, null, 1)).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.isEmpty()).isTrue(); } @@ -157,7 +158,7 @@ public class ReportNewCoverageMeasuresStepTest { public void no_measures_for_FILE_component_without_code() { treeRootHolder.setRoot(ReportComponent.builder(Component.Type.FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, null, 1)).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.isEmpty()).isTrue(); } @@ -176,7 +177,7 @@ public class ReportNewCoverageMeasuresStepTest { measureRepository.addRawMeasure(FILE_COMPONENT.getReportAttributes().getRef(), CONDITIONS_BY_LINE_KEY, newMeasureBuilder().create("2=1")); measureRepository.addRawMeasure(FILE_COMPONENT.getReportAttributes().getRef(), COVERED_CONDITIONS_BY_LINE_KEY, newMeasureBuilder().create("2=1")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify_only_zero_measures_on_new_lines_and_conditions_measures(FILE_COMPONENT); } @@ -188,7 +189,7 @@ public class ReportNewCoverageMeasuresStepTest { Changeset.newChangesetBuilder().setDate(parseDate("2008-05-18").getTime()).setRevision("rev-1").build(), Changeset.newChangesetBuilder().setDate(parseDate("2008-05-18").getTime()).setRevision("rev-1").build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify_only_zero_measures_on_new_lines_and_conditions_measures(FILE_COMPONENT); } @@ -216,7 +217,7 @@ public class ReportNewCoverageMeasuresStepTest { measureRepository.addRawMeasure(FILE_COMPONENT.getReportAttributes().getRef(), coverageLineHitsData, newMeasureBuilder().create("2=0;3=2;4=3")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_COMPONENT.getReportAttributes().getRef()))).contains( entryOf(newLinesToCover, createMeasure(2d)), @@ -257,7 +258,7 @@ public class ReportNewCoverageMeasuresStepTest { defineChangeSetsAndMeasures(FILE_2_REF, metricKeys, new MeasureValues(0, 14, 6), new MeasureValues(0, 13, 7)); defineChangeSetsAndMeasures(FILE_3_REF, metricKeys, new MeasureValues(3, 4, 1), new MeasureValues(1, 13, 7)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // files assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).contains( @@ -323,7 +324,7 @@ public class ReportNewCoverageMeasuresStepTest { .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d)) .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).containsOnly( entryOf(codeCoverageKey, createMeasure(98.8d)), @@ -417,7 +418,7 @@ public class ReportNewCoverageMeasuresStepTest { treeRootHolder.setRoot(FILE_COMPONENT); defineChangeSetsAndMeasures(FILE_COMPONENT.getReportAttributes().getRef(), metricKeys, new MeasureValues(3, 4, 1), new MeasureValues(0, 3, 2)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_COMPONENT.getReportAttributes().getRef()))).contains( entryOf(metricKeys.newLinesToCover, createMeasure(5d)), diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java index ae55c80742a..4ce74afaa5a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java @@ -33,6 +33,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.period.Period; import org.sonar.ce.task.projectanalysis.period.PeriodHolderRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -115,7 +116,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { dbIdsRepository.setComponentId(directory, directoryDto.getId()); dbIdsRepository.setComponentId(file, fileDto.getId()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); @@ -147,7 +148,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { treeRootHolder.setRoot(project); dbIdsRepository.setComponentId(project, projectDto.getId()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(projectSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_DATE); @@ -187,7 +188,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { dbIdsRepository.setComponentId(directory, directoryDto.getId()); dbIdsRepository.setComponentId(file, fileDto.getId()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(newProjectSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_PREVIOUS_VERSION); @@ -205,7 +206,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { treeRootHolder.setRoot(project); dbIdsRepository.setComponentId(project, projectDto.getId()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(projectSnapshot.getPeriodMode()).isNull(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java index 8ff4bab7717..454d6f910e4 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java @@ -41,6 +41,7 @@ import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHold import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.component.ComponentKeys; import org.sonar.db.DbClient; import org.sonar.db.DbTester; @@ -128,7 +129,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build(); treeRootHolder.setRoot(treeRoot); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("projects")).isEqualTo(4); @@ -208,7 +209,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build(); treeRootHolder.setRoot(treeRoot); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("projects")).isEqualTo(4); @@ -279,7 +280,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); ComponentDto directory = dbClient.componentDao().selectByKey(db.getSession(), projectDto.getDbKey() + ":/").get(); assertThat(directory.name()).isEqualTo("/"); @@ -306,7 +307,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/test/java/dir/FooTest.java").get(); assertThat(file.name()).isEqualTo("FooTest.java"); @@ -340,7 +341,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("projects")).isEqualTo(4); @@ -400,7 +401,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("projects")).isEqualTo(5); @@ -440,7 +441,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("projects")).isEqualTo(4); @@ -491,7 +492,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("projects")).isEqualTo(4); assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().getId()).isEqualTo(project.getId()); @@ -559,7 +560,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // functional transaction not finished, "A-fields" are not updated yet assertNameAndDescription(project.getDbKey(), "Project", "Project description"); @@ -594,7 +595,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get().path()).isEqualTo("path"); @@ -640,7 +641,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // commit the functional transaction dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid()); @@ -690,7 +691,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Optional<ComponentDto> projectReloaded = dbClient.componentDao().selectByUuid(db.getSession(), project.uuid()); assertThat(projectReloaded.get().getCreatedAt()).isNotEqualTo(now); @@ -733,7 +734,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("projects")).isEqualTo(4); assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().getId()).isEqualTo(project.getId()); @@ -827,7 +828,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // commit the functional transaction dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid()); @@ -858,7 +859,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { ComponentDto dir = db.components().insertComponent(newDirectory(module, "DEFG", "Directory").setDbKey("DIR").setPrivate(true)); treeRootHolder.setRoot(createSampleProjectComponentTree(project)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Stream.of(project.uuid(), module.uuid(), dir.uuid()) .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(db.getSession(), uuid).get().isPrivate()) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportSizeMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportSizeMeasuresStepTest.java index 0c16ff772ec..fb2aa33469a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportSizeMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportSizeMeasuresStepTest.java @@ -28,6 +28,7 @@ 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.step.TestComputationStepContext; import static com.google.common.base.Predicates.notNull; import static com.google.common.collect.FluentIterable.from; @@ -110,7 +111,7 @@ public class ReportSizeMeasuresStepTest { @Test public void verify_LINES_and_FILE_and_DIRECTORY_computation_and_aggregation() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyMeasuresOnFile(FILE_1_REF, 1, 1); verifyMeasuresOnFile(FILE_2_REF, 2, 1); @@ -140,7 +141,7 @@ public class ReportSizeMeasuresStepTest { measureRepository.addRawMeasure(FILE_2_REF, metricKey, newMeasureBuilder().create(6)); measureRepository.addRawMeasure(UNIT_TEST_1_REF, metricKey, newMeasureBuilder().create(3)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyMeasuresOnFile(FILE_1_REF, 1, 1); verifyMeasuresOnFile(FILE_2_REF, 2, 1); @@ -164,7 +165,7 @@ public class ReportSizeMeasuresStepTest { // UNIT_TEST_1_REF has no metric1 measureRepository.addRawMeasure(UNIT_TEST_1_REF, metric2Key, newMeasureBuilder().create(90)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyMeasuresOnFile(FILE_1_REF, 1, 1); verifyMeasuresOnFile(FILE_2_REF, 2, 1); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java index b10ca89a135..0b4b6ea07fe 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportUnitTestMeasuresStepTest.java @@ -27,6 +27,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -128,7 +129,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(4)); measureRepository.addRawMeasure(FILE_2_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).contains(entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(40d, 1))); assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).contains(entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(70d, 1))); @@ -149,7 +150,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(4)); measureRepository.addRawMeasure(FILE_2_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(60d); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(95d); @@ -170,7 +171,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(0)); measureRepository.addRawMeasure(FILE_2_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(0)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(80d); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(75d); @@ -191,7 +192,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(0)); measureRepository.addRawMeasure(FILE_2_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(0)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d); @@ -212,7 +213,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(2)); measureRepository.addRawMeasure(FILE_2_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(5)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d); @@ -230,7 +231,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(4)); measureRepository.addRawMeasure(FILE_2_REF, TEST_FAILURES_KEY, newMeasureBuilder().create(1)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent(); @@ -248,7 +249,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, TEST_ERRORS_KEY, newMeasureBuilder().create(0)); measureRepository.addRawMeasure(FILE_2_REF, TEST_ERRORS_KEY, newMeasureBuilder().create(0)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY)).isAbsent(); @@ -273,7 +274,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(DIRECTORY_REF, SKIPPED_TESTS_KEY, newMeasureBuilder().create(5)); measureRepository.addRawMeasure(DIRECTORY_REF, TEST_EXECUTION_TIME_KEY, newMeasureBuilder().create(100L)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).containsOnly( entryOf(TESTS_KEY, newMeasureBuilder().create(10)), @@ -300,7 +301,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(ROOT_REF, SKIPPED_TESTS_KEY, newMeasureBuilder().create(5)); measureRepository.addRawMeasure(ROOT_REF, TEST_EXECUTION_TIME_KEY, newMeasureBuilder().create(100L)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).containsOnly( entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(70d, 1))); @@ -310,7 +311,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, metricKey, newMeasureBuilder().create(file1Value)); measureRepository.addRawMeasure(FILE_2_REF, metricKey, newMeasureBuilder().create(file2Value)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isAbsent(); @@ -324,7 +325,7 @@ public class ReportUnitTestMeasuresStepTest { measureRepository.addRawMeasure(FILE_1_REF, metricKey, newMeasureBuilder().create(file1Value)); measureRepository.addRawMeasure(FILE_2_REF, metricKey, newMeasureBuilder().create(file2Value)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isAbsent(); assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isAbsent(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java index f1730c9142b..fb005599d3e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java @@ -46,6 +46,7 @@ import org.sonar.ce.task.projectanalysis.issue.IssueCache; import org.sonar.ce.task.projectanalysis.issue.RuleRepositoryRule; import org.sonar.ce.task.projectanalysis.util.cache.DiskCache; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.core.issue.DefaultIssue; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -138,7 +139,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { public void do_not_send_notifications_if_no_subscribers() { when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(false); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService, never()).deliver(any(Notification.class)); } @@ -151,7 +152,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { .close(); when(notificationService.hasProjectSubscribersForTypes(eq(PROJECT.getUuid()), any())).thenReturn(true); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService).deliver(newIssuesNotificationMock); verify(newIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getName(), null, null); @@ -178,7 +179,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { issues.forEach(issueCache::append); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService).deliver(newIssuesNotificationMock); ArgumentCaptor<NewIssuesStatistics.Stats> statsCaptor = forClass(NewIssuesStatistics.Stats.class); @@ -201,7 +202,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { .close(); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService, never()).deliver(any(Notification.class)); } @@ -214,7 +215,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true); analysisMetadataHolder.setBranch(newBranch()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService).deliver(newIssuesNotificationMock); verify(newIssuesNotificationMock).setProject(branch.getKey(), branch.longName(), BRANCH_NAME, null); @@ -232,7 +233,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { analysisMetadataHolder.setBranch(newPullRequest()); analysisMetadataHolder.setPullRequestKey(PULL_REQUEST_ID); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService).deliver(newIssuesNotificationMock); verify(newIssuesNotificationMock).setProject(branch.getKey(), branch.longName(), null, PULL_REQUEST_ID); @@ -249,7 +250,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true); analysisMetadataHolder.setBranch(newBranch()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService, never()).deliver(any(Notification.class)); } @@ -265,7 +266,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { .close(); when(notificationService.hasProjectSubscribersForTypes(eq(PROJECT.getUuid()), any())).thenReturn(true); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService).deliver(newIssuesNotificationMock); verify(notificationService).deliver(myNewIssuesNotificationMock); @@ -311,7 +312,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { when(newIssuesNotificationFactory.newMyNewIssuesNotification()).thenReturn(myNewIssuesNotificationMock1).thenReturn(myNewIssuesNotificationMock2); new SendIssueNotificationsStep(issueCache, ruleRepository, treeRootHolder, notificationService, analysisMetadataHolder, newIssuesNotificationFactory, db.getDbClient()) - .execute(); + .execute(new TestComputationStepContext()); verify(notificationService).deliver(myNewIssuesNotificationMock1); Map<String, MyNewIssuesNotification> myNewIssuesNotificationMocksByUsersName = new HashMap<>(); @@ -359,7 +360,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { issues.forEach(issueCache::append); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService).deliver(newIssuesNotificationMock); verify(notificationService).deliver(myNewIssuesNotificationMock); @@ -385,7 +386,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { .close(); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService, never()).deliver(any(Notification.class)); } @@ -403,7 +404,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { RuleDefinitionDto ruleDefinitionDto = newRule(); DefaultIssue issue = prepareIssue(ANALYSE_DATE, user, project, file, ruleDefinitionDto, RuleType.SECURITY_HOTSPOT); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(notificationService, never()).deliver(any(IssueChangeNotification.class)); } @@ -421,7 +422,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = prepareIssue(issueCreatedAt, user, project, file, ruleDefinitionDto, randomTypeExceptHotspot); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); ArgumentCaptor<IssueChangeNotification> issueChangeNotificationCaptor = forClass(IssueChangeNotification.class); verify(notificationService).deliver(issueChangeNotificationCaptor.capture()); @@ -473,7 +474,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true); analysisMetadataHolder.setBranch(newBranch()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); ArgumentCaptor<IssueChangeNotification> issueChangeNotificationCaptor = forClass(IssueChangeNotification.class); verify(notificationService).deliver(issueChangeNotificationCaptor.capture()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/TriggerViewRefreshStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/TriggerViewRefreshStepTest.java index 64aeaa724c3..3229eaae4fe 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/TriggerViewRefreshStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/TriggerViewRefreshStepTest.java @@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.step; import org.junit.Test; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; import org.sonar.ce.task.projectanalysis.view.TriggerViewRefreshDelegate; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.server.project.Project; import static org.mockito.Mockito.mock; @@ -36,7 +37,7 @@ public class TriggerViewRefreshStepTest { public void execute_has_no_effect_if_constructor_without_delegate() { TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyZeroInteractions(analysisMetadataHolder); } @@ -45,7 +46,7 @@ public class TriggerViewRefreshStepTest { public void execute_has_no_effect_if_constructor_with_null_delegate() { TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder, null); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyZeroInteractions(analysisMetadataHolder); } @@ -57,7 +58,7 @@ public class TriggerViewRefreshStepTest { when(analysisMetadataHolder.getProject()).thenReturn(project); TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder, delegate); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verify(analysisMetadataHolder).getProject(); verify(delegate).accept(project); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java index 09fec177391..55229db2ba8 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java @@ -34,6 +34,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.Measure; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -84,7 +85,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest { public void doest_not_update_profiles_when_no_measure() { qualityProfileDb.insert(sonarWayJava, sonarWayPhp, myQualityProfile); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertQualityProfileIsTheSame(sonarWayJava); assertQualityProfileIsTheSame(sonarWayPhp); @@ -98,7 +99,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest { measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create( toJson(sonarWayJava.getKee(), myQualityProfile.getKee()))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertQualityProfileIsTheSame(sonarWayPhp); assertQualityProfileIsUpdated(sonarWayJava); @@ -118,7 +119,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest { measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKee()))); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertQualityProfileIsUpdated(rootProfile); assertQualityProfileIsUpdated(parentProfile); @@ -134,7 +135,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest { measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKee()))); expectedException.expect(RowNotFoundException.class); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java index bf584f8a919..306278d6c87 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java @@ -33,6 +33,7 @@ import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl; import org.sonar.ce.task.projectanalysis.component.ReportComponent; import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -98,7 +99,7 @@ public class ValidateProjectStepTest { "If you really want to stop directly analysing project \"" + MODULE_KEY + "\", please first delete it from SonarQube and then relaunch the analysis of project \"" + PROJECT_KEY + "\"."); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -132,7 +133,7 @@ public class ValidateProjectStepTest { thrown.expectMessage("Validation of project failed:\n" + " o Module \"" + MODULE_KEY + "\" is already part of project \"" + anotherProjectKey + "\""); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -151,7 +152,7 @@ public class ValidateProjectStepTest { treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -177,7 +178,7 @@ public class ValidateProjectStepTest { thrown.expectMessage("Date of analysis cannot be older than the date of the last known analysis on this project. Value: "); thrown.expectMessage("Latest analysis: "); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java index 975b31edb02..be68d14f81e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/VerifyBillingStepTest.java @@ -26,6 +26,7 @@ import org.mockito.ArgumentCaptor; import org.sonar.api.utils.MessageException; import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolderRule; import org.sonar.ce.task.projectanalysis.analysis.Organization; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.organization.OrganizationDto; import org.sonar.server.organization.BillingValidations; import org.sonar.server.organization.BillingValidations.BillingValidationsException; @@ -61,16 +62,16 @@ public class VerifyBillingStepTest { expectedException.expect(MessageException.class); expectedException.expectMessage("This organization cannot execute project analysis"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test public void execute_does_no_fail_when_organization_is_allowed_to_execute_analysis() { ArgumentCaptor<BillingValidations.Organization> orgCaptor = ArgumentCaptor.forClass(BillingValidations.Organization.class); - VerifyBillingStep underTest = new VerifyBillingStep(analysisMetadata, validations); - underTest.execute(); + + underTest.execute(new TestComputationStepContext()); verify(validations).checkBeforeProjectAnalysis(orgCaptor.capture()); BillingValidations.Organization calledOrg = orgCaptor.getValue(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java index 858e3582cfd..670b048ae57 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCommentMeasuresStepTest.java @@ -26,6 +26,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -99,7 +100,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_2_REF, COMMENTED_OUT_CODE_LINES_KEY, 400); addRawMeasure(PROJECTVIEW_3_REF, COMMENTED_OUT_CODE_LINES_KEY, 500); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertRawMeasureValue(SUB_MODULE_REF, COMMENTED_OUT_CODE_LINES_KEY, 500); @@ -113,7 +114,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_2_REF, COMMENT_LINES_KEY, 400); addRawMeasure(PROJECTVIEW_3_REF, COMMENT_LINES_KEY, 500); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertRawMeasureValue(SUB_MODULE_REF, COMMENT_LINES_KEY, 500); @@ -134,7 +135,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(MODULE_REF, NCLOC_KEY, 300); addRawMeasure(ROOT_REF, NCLOC_KEY, 300); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertRawMeasureValue(SUB_MODULE_REF, COMMENT_LINES_DENSITY_KEY, 40d); @@ -153,7 +154,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(MODULE_REF, NCLOC_KEY, 300); addRawMeasure(ROOT_REF, NCLOC_KEY, 300); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertRawMeasureValue(SUB_MODULE_REF, COMMENT_LINES_DENSITY_KEY, 0d); @@ -172,7 +173,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(MODULE_REF, NCLOC_KEY, 0); addRawMeasure(ROOT_REF, NCLOC_KEY, 0); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertNoRawMeasures(COMMENT_LINES_DENSITY_KEY); @@ -183,7 +184,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_1_REF, COMMENT_LINES_KEY, 150); addRawMeasure(PROJECTVIEW_2_REF, COMMENT_LINES_KEY, 50); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasures(COMMENT_LINES_DENSITY_KEY); } @@ -196,7 +197,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(MODULE_REF, NCLOC_KEY, 200); addRawMeasure(ROOT_REF, NCLOC_KEY, 200); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasures(COMMENT_LINES_DENSITY_KEY); } @@ -206,7 +207,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_1_REF, PUBLIC_API_KEY, 100); addRawMeasure(PROJECTVIEW_2_REF, PUBLIC_API_KEY, 400); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertRawMeasureValue(SUB_MODULE_REF, PUBLIC_API_KEY, 500); @@ -219,7 +220,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_1_REF, PUBLIC_UNDOCUMENTED_API_KEY, 100); addRawMeasure(PROJECTVIEW_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, 400); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertRawMeasureValue(SUB_MODULE_REF, PUBLIC_UNDOCUMENTED_API_KEY, 500); @@ -239,7 +240,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_3_REF, PUBLIC_API_KEY, 300); addRawMeasure(PROJECTVIEW_3_REF, PUBLIC_UNDOCUMENTED_API_KEY, 200); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertRawMeasureValue(SUB_MODULE_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY, 70d); @@ -252,7 +253,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_1_REF, PUBLIC_UNDOCUMENTED_API_KEY, 50); addRawMeasure(PROJECTVIEW_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, 100); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasures(PUBLIC_DOCUMENTED_API_DENSITY_KEY); } @@ -262,7 +263,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_1_REF, PUBLIC_API_KEY, 50); addRawMeasure(PROJECTVIEW_2_REF, PUBLIC_API_KEY, 100); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasures(PUBLIC_DOCUMENTED_API_DENSITY_KEY); } @@ -275,7 +276,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_2_REF, PUBLIC_API_KEY, 0); addRawMeasure(PROJECTVIEW_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, 100); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoRawMeasures(PUBLIC_DOCUMENTED_API_DENSITY_KEY); } @@ -288,7 +289,7 @@ public class ViewsCommentMeasuresStepTest { addRawMeasure(PROJECTVIEW_2_REF, PUBLIC_API_KEY, 400); addRawMeasure(PROJECTVIEW_2_REF, PUBLIC_UNDOCUMENTED_API_KEY, 0); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertRawMeasureValue(SUB_MODULE_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY, 100d); @@ -298,7 +299,7 @@ public class ViewsCommentMeasuresStepTest { @Test public void compute_nothing_when_no_data() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertProjectViewsHasNoNewRawMeasure(); assertThat(measureRepository.getAddedRawMeasures(SUB_MODULE_REF)).isEmpty(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsComplexityMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsComplexityMeasuresStepTest.java index 4a1aa869367..361cc5023d5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsComplexityMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsComplexityMeasuresStepTest.java @@ -26,6 +26,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -136,7 +137,7 @@ public class ViewsComplexityMeasuresStepTest { addRawMeasureValue(PROJECT_VIEW_2_REF, metricKey, 40); addRawMeasureValue(PROJECT_VIEW_3_REF, metricKey, 20); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasures(SUB_SUBVIEW_1_REF, metricKey, 50); @@ -165,7 +166,7 @@ public class ViewsComplexityMeasuresStepTest { addRawMeasure(PROJECT_VIEW_2_REF, metricKey, "0.5=0;3.5=2;6.5=1"); addRawMeasure(PROJECT_VIEW_3_REF, metricKey, "0.5=1;3.5=1;6.5=0"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasures(SUB_SUBVIEW_1_REF, metricKey, "0.5=3;3.5=7;6.5=10"); @@ -199,7 +200,7 @@ public class ViewsComplexityMeasuresStepTest { addRawMeasureValue(PROJECT_VIEW_3_REF, mainMetric, 6); addRawMeasureValue(PROJECT_VIEW_3_REF, byMetric, 8); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasures(SUB_SUBVIEW_1_REF, metricKey, 2d); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsComputeMeasureVariationsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsComputeMeasureVariationsStepTest.java index b25aff4ca97..4cea1ab40cd 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsComputeMeasureVariationsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsComputeMeasureVariationsStepTest.java @@ -34,6 +34,7 @@ import org.sonar.ce.task.projectanalysis.metric.MetricImpl; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.projectanalysis.period.Period; import org.sonar.ce.task.projectanalysis.period.PeriodHolderRule; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -100,7 +101,7 @@ public class ViewsComputeMeasureVariationsStepTest { treeRootHolder.setRoot(VIEW); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasures(VIEW).keys()).isEmpty(); } @@ -111,7 +112,7 @@ public class ViewsComputeMeasureVariationsStepTest { treeRootHolder.setRoot(view); periodsHolder.setPeriod(null); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasures(view).keys()).isEmpty(); } @@ -138,7 +139,7 @@ public class ViewsComputeMeasureVariationsStepTest { addRawMeasure(view, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null)); addRawMeasure(subview, ISSUES_METRIC, Measure.newMeasureBuilder().create(20, null)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasure(view, ISSUES_METRIC).get().getVariation()).isEqualTo(20d); assertThat(measureRepository.getRawMeasure(subview, ISSUES_METRIC).get().getVariation()).isEqualTo(10d); @@ -164,7 +165,7 @@ public class ViewsComputeMeasureVariationsStepTest { addRawMeasure(VIEW, FILE_COMPLEXITY_METRIC, Measure.newMeasureBuilder().create(3d, 1)); addRawMeasure(VIEW, BUILD_BREAKER_METRIC, Measure.newMeasureBuilder().create(false, null)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(measureRepository.getRawMeasures(VIEW).keys()).hasSize(4); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCoverageMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCoverageMeasuresStepTest.java index 4e3721db562..59808dbe984 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCoverageMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsCoverageMeasuresStepTest.java @@ -28,6 +28,7 @@ import org.sonar.ce.task.projectanalysis.formula.coverage.LinesAndConditionsWith 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.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW; @@ -105,7 +106,7 @@ public class ViewsCoverageMeasuresStepTest { .addRawMeasure(PROJECTVIEW_3_REF, metricKeys.getUncoveredLines(), newMeasureBuilder().create(300)) .addRawMeasure(PROJECTVIEW_3_REF, metricKeys.getUncoveredConditions(), newMeasureBuilder().create(19)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); MeasureRepoEntry[] subViewRepoEntries = { entryOf(metricKeys.getLines(), newMeasureBuilder().create(5000)), @@ -152,7 +153,7 @@ public class ViewsCoverageMeasuresStepTest { .addRawMeasure(PROJECTVIEW_3_REF, metricKeys.getUncoveredLines(), newMeasureBuilder().create(300)) .addRawMeasure(PROJECTVIEW_3_REF, metricKeys.getUncoveredConditions(), newMeasureBuilder().create(19)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(toEntries(measureRepository.getAddedRawMeasures(PROJECTVIEW_1_REF))).isEmpty(); assertThat(toEntries(measureRepository.getAddedRawMeasures(PROJECTVIEW_2_REF))).isEmpty(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsLanguageDistributionMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsLanguageDistributionMeasuresStepTest.java index 5287c71237c..89a1ec22ea0 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsLanguageDistributionMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsLanguageDistributionMeasuresStepTest.java @@ -25,6 +25,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -85,7 +86,7 @@ public class ViewsLanguageDistributionMeasuresStepTest { // no raw measure on PROJECT_VIEW_4_REF addRawMeasure(PROJECT_VIEW_5_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY, "<null>=3;foo=10"); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasure(SUB_SUBVIEW_1_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY, "java=16;xoo=15"); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java index 72b7ae29d99..0e93781e7c7 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java @@ -31,6 +31,7 @@ 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.ce.task.projectanalysis.period.PeriodHolderRule; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -122,7 +123,7 @@ public class ViewsNewCoverageMeasuresStepTest { measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newConditionsToCover, createMeasure(24d)); measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newUncoveredConditions, createMeasure(60d)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertNoAddedRawMeasures(SUB_SUBVIEW_1_REF); @@ -169,7 +170,7 @@ public class ViewsNewCoverageMeasuresStepTest { .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getUncoveredLines(), createMeasure(100d)) .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getUncoveredConditions(), createMeasure(6d)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java index e4fb3374a77..d41c5c78e4d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java @@ -32,6 +32,7 @@ import org.sonar.ce.task.projectanalysis.component.ViewsComponent; import org.sonar.ce.task.projectanalysis.period.Period; import org.sonar.ce.task.projectanalysis.period.PeriodHolderRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -103,7 +104,7 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { Component view = ViewsComponent.builder(VIEW, "KEY_VIEW").setUuid("UUID_VIEW").addChildren(subView).build(); treeRootHolder.setRoot(view); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); @@ -130,7 +131,7 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_DATE, "2015-01-01", analysisDate, "u1")); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid()); assertThat(viewSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_DATE); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java index 5246f8c021a..531e02d3d8a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java @@ -42,6 +42,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.component.ViewAttributes; import org.sonar.ce.task.projectanalysis.component.ViewsComponent; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDbTester; @@ -115,7 +116,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { public void persist_empty_view() { treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(1); @@ -130,7 +131,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(1); @@ -147,7 +148,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .addChildren(createProjectView1Builder(project, null).build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(3); @@ -168,7 +169,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .addChildren(createProjectView1Builder(project, null).build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(3); @@ -187,7 +188,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { createSubView1Builder(null).build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(2); @@ -206,7 +207,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { createSubView1Builder("ORIGINAL_UUID").build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(2); @@ -226,7 +227,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { createSubView1Builder(null).build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(2); @@ -244,7 +245,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { createSubView1Builder(null).build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(2); @@ -266,7 +267,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertRowsCountInTableProjects(4); @@ -285,7 +286,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // commit functional transaction -> copies B-fields to A-fields dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), viewDto.uuid()); @@ -314,7 +315,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .addChildren(createProjectView1Builder(project, null).build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // commit functional transaction -> copies B-fields to A-fields dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid()); @@ -345,7 +346,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .addChildren(createProjectView1Builder(project2, null).build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // commit functional transaction -> copies B-fields to A-fields dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid()); @@ -369,7 +370,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { createSubView1Builder("NEW_COPY").build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); // commit functional transaction -> copies B-fields to A-fields dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid()); @@ -391,7 +392,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID) .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate()).isFalse()); @@ -413,7 +414,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID) .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate()) @@ -440,7 +441,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .build()) .build()); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID, subView.uuid(), "DEFG") .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate()) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsSizeMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsSizeMeasuresStepTest.java index 94ae2928140..e3678cac5d1 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsSizeMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsSizeMeasuresStepTest.java @@ -26,6 +26,7 @@ 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.step.TestComputationStepContext; import static com.google.common.base.Predicates.notNull; import static com.google.common.collect.FluentIterable.from; @@ -128,7 +129,7 @@ public class ViewsSizeMeasuresStepTest { @Test public void verify_FILE_and_DIRECTORY_computation_and_aggregation() { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyNoMeasure(PROJECTVIEW_1_REF); verifyNoMeasure(PROJECTVIEW_2_REF); @@ -159,7 +160,7 @@ public class ViewsSizeMeasuresStepTest { measureRepository.addRawMeasure(PROJECTVIEW_4_REF, metricKey, newMeasureBuilder().create(3)); measureRepository.addRawMeasure(PROJECTVIEW_5_REF, metricKey, newMeasureBuilder().create(7)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyNoMeasure(PROJECTVIEW_1_REF); verifyNoMeasure(PROJECTVIEW_2_REF); @@ -185,7 +186,7 @@ public class ViewsSizeMeasuresStepTest { measureRepository.addRawMeasure(PROJECTVIEW_5_REF, metric1Key, newMeasureBuilder().create(3)); measureRepository.addRawMeasure(PROJECTVIEW_5_REF, metric2Key, newMeasureBuilder().create(7)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); verifyNoMeasure(PROJECTVIEW_1_REF); verifyNoMeasure(PROJECTVIEW_2_REF); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java index 8bb4b85d011..bf83094d7e6 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsUnitTestMeasuresStepTest.java @@ -25,6 +25,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.ce.task.step.TestComputationStepContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.guava.api.Assertions.assertThat; @@ -121,7 +122,7 @@ public class ViewsUnitTestMeasuresStepTest { addedRawMeasure(PROJECT_VIEW_1_REF, TEST_FAILURES_KEY, 4); addedRawMeasure(PROJECT_VIEW_2_REF, TEST_FAILURES_KEY, 1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasureValue(SUB_SUBVIEW_1_REF, TEST_SUCCESS_DENSITY_KEY, 60d); @@ -140,7 +141,7 @@ public class ViewsUnitTestMeasuresStepTest { addedRawMeasure(PROJECT_VIEW_1_REF, TEST_FAILURES_KEY, 4); addedRawMeasure(PROJECT_VIEW_2_REF, TEST_FAILURES_KEY, 1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasureValue(SUB_SUBVIEW_1_REF, TEST_SUCCESS_DENSITY_KEY, 83.3d); @@ -160,7 +161,7 @@ public class ViewsUnitTestMeasuresStepTest { addedRawMeasure(PROJECT_VIEW_1_REF, TEST_FAILURES_KEY, 0); addedRawMeasure(PROJECT_VIEW_2_REF, TEST_FAILURES_KEY, 0); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasureValue(SUB_SUBVIEW_1_REF, TEST_SUCCESS_DENSITY_KEY, 76.7d); @@ -180,7 +181,7 @@ public class ViewsUnitTestMeasuresStepTest { addedRawMeasure(PROJECT_VIEW_1_REF, TEST_FAILURES_KEY, 0); addedRawMeasure(PROJECT_VIEW_2_REF, TEST_FAILURES_KEY, 0); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasureValue(SUB_SUBVIEW_1_REF, TEST_SUCCESS_DENSITY_KEY, 100d); @@ -203,7 +204,7 @@ public class ViewsUnitTestMeasuresStepTest { addedRawMeasure(PROJECT_VIEW_1_REF, TEST_FAILURES_KEY, 2); addedRawMeasure(PROJECT_VIEW_2_REF, TEST_FAILURES_KEY, 5); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasureValue(SUB_SUBVIEW_1_REF, TEST_SUCCESS_DENSITY_KEY, 0d); @@ -220,7 +221,7 @@ public class ViewsUnitTestMeasuresStepTest { addedRawMeasure(PROJECT_VIEW_1_REF, TEST_FAILURES_KEY, 4); addedRawMeasure(PROJECT_VIEW_2_REF, TEST_FAILURES_KEY, 1); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertNoAddedRawMeasure(SUB_SUBVIEW_1_REF, TEST_SUCCESS_DENSITY_KEY); @@ -236,7 +237,7 @@ public class ViewsUnitTestMeasuresStepTest { addedRawMeasure(PROJECT_VIEW_1_REF, TEST_ERRORS_KEY, 0); addedRawMeasure(PROJECT_VIEW_2_REF, TEST_ERRORS_KEY, 0); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertNoAddedRawMeasure(SUB_SUBVIEW_1_REF, TEST_SUCCESS_DENSITY_KEY); @@ -248,7 +249,7 @@ public class ViewsUnitTestMeasuresStepTest { addedRawMeasure(PROJECT_VIEW_1_REF, metricKey, file1Value); addedRawMeasure(PROJECT_VIEW_2_REF, metricKey, file2Value); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasureValue(SUB_SUBVIEW_1_REF, metricKey, expectedValue); @@ -261,7 +262,7 @@ public class ViewsUnitTestMeasuresStepTest { measureRepository.addRawMeasure(PROJECT_VIEW_1_REF, metricKey, newMeasureBuilder().create(file1Value)); measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, metricKey, newMeasureBuilder().create(file2Value)); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); assertNoAddedRawMeasureOnProjectViews(); assertAddedRawMeasureValue(SUB_SUBVIEW_1_REF, metricKey, expectedValue); diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ComputationStep.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ComputationStep.java index 3766ecd826f..1d9f67e2e9d 100644 --- a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ComputationStep.java +++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ComputationStep.java @@ -20,12 +20,43 @@ package org.sonar.ce.task.step; /** - * A way of splitting the processing of a task into smaller items which can be executed sequencially + * A way of splitting the processing of a task into smaller items which can be executed sequentially * by {@link ComputationStepExecutor}. */ public interface ComputationStep { - void execute(); + /** + * Statistics are displayed in the step ending log. They help + * understanding the runtime context and potential performance hotspots. + * + * <p/> + * Example: + * <code> + * statistics.add("inserts", 200); + * statistics.add("updates", 50); + * </code> + * adds two parameters to the log: + * <code> + * 2018.07.26 10:22:58 DEBUG ce[AWTVrwb-KZf9YbDx-laU][o.s.s.c.t.s.ComputationStepExecutor] Persist issues | inserts=200 | updates=50 | time=30ms + * </code> + * + * <p/> + * Statistics are logged in the order of insertion. + */ + interface Statistics { + /** + * @throws NullPointerException if key or value is null + * @throws IllegalArgumentException if key has already been set + * @throws IllegalArgumentException if key is "time", to avoid conflict with the profiler field with same name + */ + void add(String key, Object value); + } + + interface Context { + Statistics getStatistics(); + } + + void execute(Context context); String getDescription(); } diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ComputationStepExecutor.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ComputationStepExecutor.java index 9fa8eea74dd..d706b8914fa 100644 --- a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ComputationStepExecutor.java +++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ComputationStepExecutor.java @@ -25,6 +25,9 @@ import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.core.util.logs.Profiler; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; + public final class ComputationStepExecutor { private static final Logger LOGGER = Loggers.get(ComputationStepExecutor.class); @@ -46,7 +49,7 @@ public final class ComputationStepExecutor { } public void execute() { - Profiler stepProfiler = Profiler.create(LOGGER); + Profiler stepProfiler = Profiler.create(LOGGER).logTimeLast(true); boolean allStepsExecuted = false; try { executeSteps(stepProfiler); @@ -59,9 +62,11 @@ public final class ComputationStepExecutor { } private void executeSteps(Profiler stepProfiler) { + StepStatisticsImpl statistics = new StepStatisticsImpl(stepProfiler); + ComputationStep.Context context = new StepContextImpl(statistics); for (ComputationStep step : steps.instances()) { stepProfiler.start(); - step.execute(); + step.execute(context); stepProfiler.stopInfo(step.getDescription()); } } @@ -80,4 +85,34 @@ public final class ComputationStepExecutor { public interface Listener { void finished(boolean allStepsExecuted); } + + private static class StepStatisticsImpl implements ComputationStep.Statistics { + private final Profiler profiler; + + private StepStatisticsImpl(Profiler profiler) { + this.profiler = profiler; + } + + @Override + public void add(String key, Object value) { + requireNonNull(key, "Statistic has null key"); + requireNonNull(value, () -> String.format("Statistic with key [%s] has null value", key)); + checkArgument(!key.equalsIgnoreCase("time"), "Statistic with key [time] is not accepted"); + checkArgument(!profiler.hasContext(key), "Statistic with key [%s] is already present", key); + profiler.addContext(key, value); + } + } + + private static class StepContextImpl implements ComputationStep.Context { + private final ComputationStep.Statistics statistics; + + private StepContextImpl(ComputationStep.Statistics statistics) { + this.statistics = statistics; + } + + @Override + public ComputationStep.Statistics getStatistics() { + return statistics; + } + } } diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ExecuteStatelessInitExtensionsStep.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ExecuteStatelessInitExtensionsStep.java index 6508d1d5e0b..8b7c2040f99 100644 --- a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ExecuteStatelessInitExtensionsStep.java +++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/step/ExecuteStatelessInitExtensionsStep.java @@ -43,7 +43,7 @@ public class ExecuteStatelessInitExtensionsStep implements ComputationStep { } @Override - public void execute() { + public void execute(Context context) { for (StatelessInitExtension extension : extensions) { extension.onInit(); } diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ComputationStepExecutorTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ComputationStepExecutorTest.java index e8ae8735f05..8e7acad22f5 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ComputationStepExecutorTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ComputationStepExecutorTest.java @@ -31,6 +31,7 @@ import org.sonar.ce.task.ChangeLogLevel; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; @@ -56,11 +57,11 @@ public class ComputationStepExecutorTest { .execute(); InOrder inOrder = inOrder(computationStep1, computationStep2, computationStep3); - inOrder.verify(computationStep1).execute(); + inOrder.verify(computationStep1).execute(any()); inOrder.verify(computationStep1).getDescription(); - inOrder.verify(computationStep2).execute(); + inOrder.verify(computationStep2).execute(any()); inOrder.verify(computationStep2).getDescription(); - inOrder.verify(computationStep3).execute(); + inOrder.verify(computationStep3).execute(any()); inOrder.verify(computationStep3).getDescription(); inOrder.verifyNoMoreInteractions(); } @@ -72,7 +73,7 @@ public class ComputationStepExecutorTest { ComputationStep computationStep = mockComputationStep("step1"); doThrow(new RuntimeException(message)) .when(computationStep) - .execute(); + .execute(any()); ComputationStepExecutor computationStepExecutor = new ComputationStepExecutor(mockComputationSteps(computationStep)); @@ -83,17 +84,70 @@ public class ComputationStepExecutorTest { } @Test - public void execute_logs_end_timing_for_each_ComputationStep_in_INFO_level() { + public void execute_logs_end_timing_and_statistics_for_each_ComputationStep_in_INFO_level() { + ComputationStep step1 = new StepWithStatistics("Step One", "foo", "100", "bar", "20"); + ComputationStep step2 = new StepWithStatistics("Step Two", "foo", "50", "baz", "10"); + ComputationStep step3 = new StepWithStatistics("Step Three"); + try (ChangeLogLevel executor = new ChangeLogLevel(ComputationStepExecutor.class, LoggerLevel.INFO); - ChangeLogLevel step1 = new ChangeLogLevel(computationStep1.getClass(), LoggerLevel.INFO); - ChangeLogLevel step2 = new ChangeLogLevel(computationStep2.getClass(), LoggerLevel.INFO)) { - new ComputationStepExecutor(mockComputationSteps(computationStep1, computationStep2)) - .execute(); + ChangeLogLevel logLevel1 = new ChangeLogLevel(step1.getClass(), LoggerLevel.INFO); + ChangeLogLevel logLevel2 = new ChangeLogLevel(step1.getClass(), LoggerLevel.INFO); + ChangeLogLevel logLevel3 = new ChangeLogLevel(step2.getClass(), LoggerLevel.INFO)) { + new ComputationStepExecutor(mockComputationSteps(step1, step2, step3)).execute(); List<String> infoLogs = logTester.logs(LoggerLevel.INFO); - assertThat(infoLogs).hasSize(2); - assertThat(infoLogs.get(0)).contains("step1 | time="); - assertThat(infoLogs.get(1)).contains("step2 | time="); + assertThat(infoLogs).hasSize(3); + assertThat(infoLogs.get(0)).contains("Step One | foo=100 | bar=20 | time="); + assertThat(infoLogs.get(1)).contains("Step Two | foo=50 | baz=10 | time="); + assertThat(infoLogs.get(2)).contains("Step Three | time="); + } + } + + @Test + public void execute_throws_IAE_if_step_adds_time_statistic() { + ComputationStep step = new StepWithStatistics("A Step", "foo", "100", "time", "20"); + + try (ChangeLogLevel executor = new ChangeLogLevel(ComputationStepExecutor.class, LoggerLevel.INFO)) { + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Statistic with key [time] is not accepted"); + + new ComputationStepExecutor(mockComputationSteps(step)).execute(); + } + } + + @Test + public void execute_throws_IAE_if_step_adds_statistic_multiple_times() { + ComputationStep step = new StepWithStatistics("A Step", "foo", "100", "foo", "20"); + + try (ChangeLogLevel executor = new ChangeLogLevel(ComputationStepExecutor.class, LoggerLevel.INFO)) { + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Statistic with key [foo] is already present"); + + new ComputationStepExecutor(mockComputationSteps(step)).execute(); + } + } + + @Test + public void execute_throws_NPE_if_step_adds_statistic_with_null_key() { + ComputationStep step = new StepWithStatistics("A Step", "foo", "100", null, "bar"); + + try (ChangeLogLevel executor = new ChangeLogLevel(ComputationStepExecutor.class, LoggerLevel.INFO)) { + expectedException.expect(NullPointerException.class); + expectedException.expectMessage("Statistic has null key"); + + new ComputationStepExecutor(mockComputationSteps(step)).execute(); + } + } + + @Test + public void execute_throws_NPE_if_step_adds_statistic_with_null_value() { + ComputationStep step = new StepWithStatistics("A Step", "foo", "100", "bar", null); + + try (ChangeLogLevel executor = new ChangeLogLevel(ComputationStepExecutor.class, LoggerLevel.INFO)) { + expectedException.expect(NullPointerException.class); + expectedException.expectMessage("Statistic with key [bar] has null value"); + + new ComputationStepExecutor(mockComputationSteps(step)).execute(); } } @@ -111,7 +165,7 @@ public class ComputationStepExecutorTest { RuntimeException toBeThrown = new RuntimeException("simulating failing execute Step method"); doThrow(toBeThrown) .when(computationStep1) - .execute(); + .execute(any()); try { new ComputationStepExecutor(mockComputationSteps(computationStep1, computationStep2), listener) @@ -145,4 +199,26 @@ public class ComputationStepExecutorTest { when(mock.getDescription()).thenReturn(desc); return mock; } + + private static class StepWithStatistics implements ComputationStep { + private final String description; + private final String[] statistics; + + private StepWithStatistics(String description, String... statistics) { + this.description = description; + this.statistics = statistics; + } + + @Override + public void execute(Context context) { + for (int i = 0; i < statistics.length; i += 2) { + context.getStatistics().add(statistics[i], statistics[i + 1]); + } + } + + @Override + public String getDescription() { + return description; + } + } } diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ExecuteStatelessInitExtensionsStepTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ExecuteStatelessInitExtensionsStepTest.java index 15d0664f2ba..030b4d6fed3 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ExecuteStatelessInitExtensionsStepTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/ExecuteStatelessInitExtensionsStepTest.java @@ -49,7 +49,7 @@ public class ExecuteStatelessInitExtensionsStepTest { ExecuteStatelessInitExtensionsStep underTest = new ExecuteStatelessInitExtensionsStep(); // no failure - underTest.execute(); + underTest.execute(new TestComputationStepContext()); } @Test @@ -59,7 +59,7 @@ public class ExecuteStatelessInitExtensionsStepTest { ExecuteStatelessInitExtensionsStep underTest = new ExecuteStatelessInitExtensionsStep( new StatelessInitExtension[] {ext1, ext2}); - underTest.execute(); + underTest.execute(new TestComputationStepContext()); InOrder inOrder = inOrder(ext1, ext2); inOrder.verify(ext1).onInit(); @@ -77,7 +77,7 @@ public class ExecuteStatelessInitExtensionsStepTest { new StatelessInitExtension[] {ext1, ext2, ext3}); try { - underTest.execute(); + underTest.execute(new TestComputationStepContext()); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage("BOOM"); diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/TestComputationStepContext.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/TestComputationStepContext.java new file mode 100644 index 00000000000..dc560ed8aaa --- /dev/null +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/step/TestComputationStepContext.java @@ -0,0 +1,71 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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.step; + +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Implementation of {@link ComputationStep.Context} for unit tests. + */ +public class TestComputationStepContext implements ComputationStep.Context { + + private final ComputationStep.Statistics statistics = new TestStatistics(); + + @Override + public ComputationStep.Statistics getStatistics() { + return statistics; + } + + public static class TestStatistics implements ComputationStep.Statistics { + private final Map<String, Object> map = new HashMap<>(); + + @Override + public void add(String key, Object value) { + requireNonNull(key, "Statistic has null key"); + requireNonNull(value, () -> String.format("Statistic with key [%s] has null value", key)); + checkArgument(!key.equalsIgnoreCase("time"), "Statistic with key [time] is not accepted"); + checkArgument(!map.containsKey(key), "Statistic with key [%s] is already present", key); + map.put(key, value); + } + + public Map<String, Object> getAll() { + return map; + } + + public Object get(String key) { + return requireNonNull(map.get(key)); + } + + public TestStatistics assertValue(String key, @Nullable Object expectedValue) { + if (expectedValue == null) { + assertThat(map.get(key)).as(key).isNull(); + } else { + assertThat(map.get(key)).as(key).isEqualTo(expectedValue); + } + return this; + } + } +} |