From 92fb3dc68dff7aa937f005bbda644a2dc27f62d6 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 27 Jul 2018 18:02:43 +0200 Subject: SONAR-11077 add statistics to CE PersistIssuesStep --- .../src/main/java/org/sonar/ce/task/step/ComputationStep.java | 3 ++- .../main/java/org/sonar/ce/task/step/ComputationStepExecutor.java | 3 ++- .../java/org/sonar/ce/task/step/TestComputationStepContext.java | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'server/sonar-ce-task') 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 1d9f67e2e9d..28eb3cfc05e 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 @@ -45,11 +45,12 @@ public interface ComputationStep { */ interface Statistics { /** + * @return this * @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); + Statistics add(String key, Object value); } interface Context { 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 d706b8914fa..381a824cc32 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 @@ -94,12 +94,13 @@ public final class ComputationStepExecutor { } @Override - public void add(String key, Object value) { + public ComputationStep.Statistics 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); + return this; } } 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 index dc560ed8aaa..33edcdc16fd 100644 --- 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 @@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class TestComputationStepContext implements ComputationStep.Context { - private final ComputationStep.Statistics statistics = new TestStatistics(); + private final TestStatistics statistics = new TestStatistics(); @Override - public ComputationStep.Statistics getStatistics() { + public TestStatistics getStatistics() { return statistics; } @@ -43,12 +43,13 @@ public class TestComputationStepContext implements ComputationStep.Context { private final Map map = new HashMap<>(); @Override - public void add(String key, Object value) { + public ComputationStep.Statistics 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); + return this; } public Map getAll() { -- cgit v1.2.3