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.projectanalysis.taskprocessor;
22 import java.util.Collections;
24 import javax.annotation.CheckForNull;
25 import org.sonar.ce.queue.CeTask;
26 import org.sonar.ce.queue.CeTaskResult;
27 import org.sonar.ce.settings.SettingsLoader;
28 import org.sonar.ce.settings.ThreadLocalSettings;
29 import org.sonar.ce.taskprocessor.CeTaskProcessor;
30 import org.sonar.core.platform.ComponentContainer;
31 import org.sonar.db.ce.CeTaskTypes;
32 import org.sonar.plugin.ce.ReportAnalysisComponentProvider;
33 import org.sonar.server.computation.task.container.TaskContainer;
34 import org.sonar.server.computation.task.projectanalysis.container.ContainerFactory;
35 import org.sonar.server.computation.task.step.ComputationStepExecutor;
36 import org.sonar.server.computation.taskprocessor.TaskResultHolder;
38 public class ReportTaskProcessor implements CeTaskProcessor {
40 private static final Set<String> HANDLED_TYPES = Collections.singleton(CeTaskTypes.REPORT);
42 private final ContainerFactory containerFactory;
43 private final ComponentContainer serverContainer;
45 private final ReportAnalysisComponentProvider[] componentProviders;
48 * Used when at least one Privileged plugin is installed
50 public ReportTaskProcessor(ContainerFactory containerFactory, ComponentContainer serverContainer, ReportAnalysisComponentProvider[] componentProviders) {
51 this.containerFactory = containerFactory;
52 this.serverContainer = serverContainer;
53 this.componentProviders = componentProviders;
57 * Used when no privileged plugin is installed
59 public ReportTaskProcessor(ContainerFactory containerFactory, ComponentContainer serverContainer) {
60 this.containerFactory = containerFactory;
61 this.serverContainer = serverContainer;
62 this.componentProviders = null;
66 public Set<String> getHandledCeTaskTypes() {
71 public CeTaskResult process(CeTask task) {
72 TaskContainer ceContainer = containerFactory.create(serverContainer, task, componentProviders);
75 ceContainer.getComponentByType(ComputationStepExecutor.class).execute();
76 return ceContainer.getComponentByType(TaskResultHolder.class).getResult();
78 ensureThreadLocalIsClean(ceContainer);
80 ceContainer.cleanup();
84 /** safety call to clear ThreadLocal even if Pico container fails to call {@link SettingsLoader#stop()}) */
85 private static void ensureThreadLocalIsClean(TaskContainer ceContainer) {
86 ceContainer.getComponentByType(ThreadLocalSettings.class).unload();