3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.computation.task.step;
22 import javax.annotation.CheckForNull;
23 import javax.annotation.Nullable;
24 import org.sonar.api.utils.log.Logger;
25 import org.sonar.api.utils.log.Loggers;
26 import org.sonar.core.util.logs.Profiler;
28 public final class ComputationStepExecutor {
29 private static final Logger LOGGER = Loggers.get(ComputationStepExecutor.class);
31 private final ComputationSteps steps;
33 private final Listener listener;
36 * Used when no {@link ComputationStepExecutor.Listener} is available in pico
39 public ComputationStepExecutor(ComputationSteps steps) {
43 public ComputationStepExecutor(ComputationSteps steps, @Nullable Listener listener) {
45 this.listener = listener;
48 public void execute() {
49 Profiler stepProfiler = Profiler.create(LOGGER);
50 boolean allStepsExecuted = false;
52 executeSteps(stepProfiler);
53 allStepsExecuted = true;
55 if (listener != null) {
56 listener.finished(allStepsExecuted);
61 private void executeSteps(Profiler stepProfiler) {
62 for (ComputationStep step : steps.instances()) {
65 stepProfiler.stopDebug(step.getDescription());
70 public interface Listener {
71 void finished(boolean allStepsExecuted);