diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-07-27 18:02:43 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-08-02 20:21:35 +0200 |
commit | 92fb3dc68dff7aa937f005bbda644a2dc27f62d6 (patch) | |
tree | eb90ae958ba3b81649ffab61b3e8e2fc53295076 /server/sonar-ce-task | |
parent | 4c03a7686dfc417db0376be571e2a3bf3fb04637 (diff) | |
download | sonarqube-92fb3dc68dff7aa937f005bbda644a2dc27f62d6.tar.gz sonarqube-92fb3dc68dff7aa937f005bbda644a2dc27f62d6.zip |
SONAR-11077 add statistics to CE PersistIssuesStep
Diffstat (limited to 'server/sonar-ce-task')
3 files changed, 8 insertions, 5 deletions
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<String, Object> 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<String, Object> getAll() { |