From 8e7ffed1b130c47fe5ac394b4f5c78dd901bff1b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 14 Mar 2013 15:49:22 +0100 Subject: SONAR-4069 fix task extension point --- .../org/sonar/batch/bootstrap/TaskContainer.java | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java') diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java index 7afac65e0ed..bc50ede3ea2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.bootstrap; +import org.sonar.api.CoreProperties; +import org.sonar.api.config.Settings; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.resources.ResourceTypes; import org.sonar.api.task.Task; @@ -27,8 +29,6 @@ import org.sonar.api.task.TaskExtension; import org.sonar.api.utils.SonarException; import org.sonar.batch.tasks.Tasks; -import javax.annotation.Nullable; - public class TaskContainer extends ComponentContainer { public TaskContainer(ComponentContainer parent) { @@ -41,23 +41,24 @@ public class TaskContainer extends ComponentContainer { installComponentsUsingTaskExtensions(); } - public void executeTask(@Nullable String key) { + public void execute() { startComponents(); - TaskDefinition taskDef = get(Tasks.class).getTaskDefinition(key); - if (taskDef != null) { - Task task = get(taskDef.getTask()); - if (task != null) { - task.execute(); - } else { - throw new IllegalStateException("Command " + key + " is badly defined."); - } + // default value is declared in CorePlugin + String taskKey = get(Settings.class).getString(CoreProperties.TASK); + + TaskDefinition def = get(Tasks.class).definition(taskKey); + if (def == null) { + throw new SonarException("Task " + taskKey + " does not exist."); + } + Task task = get(def.taskClass()); + if (task != null) { + task.execute(); } else { - throw new SonarException("Command " + key + " does not exist."); + throw new IllegalStateException("Task " + taskKey + " is badly defined."); } } - private void installTaskExtensions() { get(ExtensionInstaller.class).install(this, new ExtensionInstaller.ComponentFilter() { public boolean accept(Object extension) { -- cgit v1.2.3