* Simon feedback * Add additional JUnit teststags/3.5
@@ -21,10 +21,10 @@ package org.sonar.batch.bootstrap; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.api.batch.TaskDefinition; | |||
import org.sonar.api.batch.TaskExecutor; | |||
import org.sonar.api.config.EmailSettings; | |||
import org.sonar.api.resources.ResourceTypes; | |||
import org.sonar.api.task.Task; | |||
import org.sonar.api.task.TaskDefinition; | |||
import org.sonar.api.utils.SonarException; | |||
import org.sonar.batch.DefaultResourceCreationLock; | |||
import org.sonar.batch.components.PastMeasuresLoader; | |||
@@ -42,7 +42,7 @@ import org.sonar.batch.index.LinkPersister; | |||
import org.sonar.batch.index.MeasurePersister; | |||
import org.sonar.batch.index.MemoryOptimizer; | |||
import org.sonar.batch.index.SourcePersister; | |||
import org.sonar.batch.tasks.ListTaskExecutor; | |||
import org.sonar.batch.tasks.ListTasksTask; | |||
import org.sonar.core.i18n.I18nManager; | |||
import org.sonar.core.i18n.RuleI18nManager; | |||
import org.sonar.core.metric.CacheMetricFinder; | |||
@@ -65,11 +65,11 @@ public abstract class AbstractTaskModule extends Module { | |||
private static final Logger LOG = LoggerFactory.getLogger(AbstractTaskModule.class); | |||
private TaskDefinition task; | |||
private TaskDefinition taskDefinition; | |||
private boolean projectPresent; | |||
public AbstractTaskModule(TaskDefinition task, boolean projectPresent) { | |||
this.task = task; | |||
this.taskDefinition = task; | |||
this.projectPresent = projectPresent; | |||
} | |||
@@ -132,7 +132,7 @@ public abstract class AbstractTaskModule extends Module { | |||
} | |||
private void registerCoreTasks() { | |||
container.addSingleton(ListTaskExecutor.class); | |||
container.addSingleton(ListTasksTask.class); | |||
} | |||
private void registerTaskExtensions() { | |||
@@ -141,7 +141,7 @@ public abstract class AbstractTaskModule extends Module { | |||
} | |||
private void logSettings() { | |||
LOG.info("------------- Executing {}", task.getTaskDescriptor().getName()); | |||
LOG.info("------------- Executing {}", taskDefinition.getName()); | |||
} | |||
/** | |||
@@ -149,12 +149,12 @@ public abstract class AbstractTaskModule extends Module { | |||
*/ | |||
@Override | |||
protected void doStart() { | |||
TaskExecutor taskExecutor = container.getComponentByType(task.getExecutor()); | |||
if (taskExecutor != null) { | |||
taskExecutor.execute(); | |||
Task task = container.getComponentByType(taskDefinition.getTask()); | |||
if (task != null) { | |||
task.execute(); | |||
} | |||
else { | |||
throw new SonarException("Extension " + task.getExecutor() + " was not found in declared extensions."); | |||
throw new SonarException("Extension " + taskDefinition.getTask() + " was not found in declared extensions."); | |||
} | |||
} | |||
@@ -137,7 +137,7 @@ public class ExtensionInstaller implements BatchComponent { | |||
boolean installTaskExtension(ComponentContainer container, @Nullable PluginMetadata plugin, Object extension, boolean projectPresent) { | |||
boolean installed; | |||
if (ExtensionUtils.isTaskExtension(extension) && | |||
(projectPresent || !ExtensionUtils.requireProject(extension)) && | |||
(projectPresent || !ExtensionUtils.requiresProject(extension)) && | |||
ExtensionUtils.supportsEnvironment(extension, environment)) { | |||
if (plugin != null) { | |||
LOG.debug("Installing task extension {} from plugin {}", extension.toString(), plugin.getKey()); |
@@ -19,8 +19,6 @@ | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import org.sonar.api.batch.RequiresProject; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.BatchExtension; | |||
import org.sonar.api.Extension; | |||
@@ -28,6 +26,7 @@ import org.sonar.api.TaskDefinitionExtension; | |||
import org.sonar.api.TaskExtension; | |||
import org.sonar.api.batch.InstantiationStrategy; | |||
import org.sonar.api.batch.SupportedEnvironment; | |||
import org.sonar.api.task.RequiresProject; | |||
import org.sonar.api.utils.AnnotationUtils; | |||
import org.sonar.batch.bootstrapper.EnvironmentInformation; | |||
import org.sonar.core.DryRunIncompatible; | |||
@@ -75,8 +74,8 @@ final class ExtensionUtils { | |||
return AnnotationUtils.getAnnotation(extension, DryRunIncompatible.class) == null; | |||
} | |||
static boolean requireProject(Object extension) { | |||
return AnnotationUtils.getAnnotation(extension, RequiresProject.class) == null; | |||
static boolean requiresProject(Object extension) { | |||
return AnnotationUtils.getAnnotation(extension, RequiresProject.class) != null; | |||
} | |||
static boolean isMavenExtensionOnly(Object extension) { |
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import org.sonar.api.batch.TaskDefinition; | |||
import org.sonar.api.task.TaskDefinition; | |||
public class ProjectLessTaskModule extends AbstractTaskModule { | |||
@@ -19,12 +19,13 @@ | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import org.sonar.api.batch.TaskDefinition; | |||
import org.sonar.api.task.TaskDefinition; | |||
import org.sonar.batch.DefaultFileLinesContextFactory; | |||
import org.sonar.batch.ProjectConfigurator; | |||
import org.sonar.batch.ProjectTree; | |||
import org.sonar.batch.index.DefaultIndex; | |||
import org.sonar.batch.tasks.InspectionTaskExecutor; | |||
import org.sonar.batch.tasks.InspectionTask; | |||
public class ProjectTaskModule extends AbstractTaskModule { | |||
@@ -52,7 +53,7 @@ public class ProjectTaskModule extends AbstractTaskModule { | |||
} | |||
private void registerCoreTasksRequiringProject() { | |||
container.addSingleton(InspectionTaskExecutor.class); | |||
container.addSingleton(InspectionTask.class); | |||
} | |||
} |
@@ -19,13 +19,12 @@ | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.batch.TaskDefinition; | |||
import org.sonar.api.batch.bootstrap.ProjectReactor; | |||
import org.sonar.api.task.TaskDefinition; | |||
import org.sonar.api.utils.SonarException; | |||
import org.sonar.batch.tasks.InspectionTaskDefinition; | |||
import org.sonar.batch.tasks.ListTaskDefinition; | |||
import org.sonar.batch.tasks.TaskManager; | |||
import org.sonar.batch.tasks.InspectionTask; | |||
import org.sonar.batch.tasks.ListTasksTask; | |||
import org.sonar.batch.tasks.Tasks; | |||
/** | |||
* Level-2 components. Collect tasks definitions. | |||
@@ -42,12 +41,12 @@ public class TaskBootstrapModule extends Module { | |||
protected void configure() { | |||
registerCoreTaskDefinitions(); | |||
registerTaskDefinitionExtensions(); | |||
container.addSingleton(TaskManager.class); | |||
container.addSingleton(Tasks.class); | |||
} | |||
private void registerCoreTaskDefinitions() { | |||
container.addSingleton(InspectionTaskDefinition.class); | |||
container.addSingleton(ListTaskDefinition.class); | |||
container.addSingleton(InspectionTask.DEFINITION); | |||
container.addSingleton(ListTasksTask.DEFINITION); | |||
} | |||
private void registerTaskDefinitionExtensions() { | |||
@@ -57,22 +56,21 @@ public class TaskBootstrapModule extends Module { | |||
@Override | |||
protected void doStart() { | |||
String command = StringUtils.isNotBlank(taskCommand) ? taskCommand : InspectionTaskDefinition.COMMAND; | |||
TaskManager manager = container.getComponentByType(TaskManager.class); | |||
executeTask(manager.getTask(command)); | |||
Tasks tasks = container.getComponentByType(Tasks.class); | |||
executeTask(tasks.getTaskDefinition(taskCommand)); | |||
} | |||
private void executeTask(TaskDefinition task) { | |||
private void executeTask(TaskDefinition taskDefinition) { | |||
boolean projectPresent = container.getComponentByType(ProjectReactor.class) != null; | |||
if (task.getTaskDescriptor().isRequiresProject() && !projectPresent) { | |||
throw new SonarException("Task " + task.getTaskDescriptor().getName() + " requires to be run on a project"); | |||
if (ExtensionUtils.requiresProject(taskDefinition.getTask()) && !projectPresent) { | |||
throw new SonarException("Task " + taskDefinition.getName() + " requires to be run on a project"); | |||
} | |||
Module childModule; | |||
if (projectPresent) { | |||
childModule = new ProjectTaskModule(task); | |||
childModule = new ProjectTaskModule(taskDefinition); | |||
} | |||
else { | |||
childModule = new ProjectLessTaskModule(task); | |||
childModule = new ProjectLessTaskModule(taskDefinition); | |||
} | |||
try { | |||
installChild(childModule); |
@@ -19,19 +19,27 @@ | |||
*/ | |||
package org.sonar.batch.tasks; | |||
import org.sonar.api.batch.RequiresProject; | |||
import org.sonar.api.batch.TaskExecutor; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.task.RequiresProject; | |||
import org.sonar.api.task.Task; | |||
import org.sonar.api.task.TaskDefinition; | |||
import org.sonar.batch.ProjectTree; | |||
@RequiresProject | |||
public class InspectionTaskExecutor implements TaskExecutor { | |||
public class InspectionTask implements Task { | |||
public static final String COMMAND = "inspect"; | |||
public static final TaskDefinition DEFINITION = TaskDefinition.create() | |||
.setDescription("Start a Sonar inspection of a project") | |||
.setName("Sonar project inspection") | |||
.setCommand(COMMAND) | |||
.setTask(InspectionTask.class); | |||
private final ComponentContainer container; | |||
private final ProjectTree projectTree; | |||
public InspectionTaskExecutor(ProjectTree projectTree, ComponentContainer container) { | |||
public InspectionTask(ProjectTree projectTree, ComponentContainer container) { | |||
this.container = container; | |||
this.projectTree = projectTree; | |||
} |
@@ -1,42 +0,0 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2008-2012 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* Sonar is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.batch.tasks; | |||
import org.sonar.api.batch.TaskDefinition; | |||
import org.sonar.api.batch.TaskDescriptor; | |||
import org.sonar.api.batch.TaskExecutor; | |||
public class InspectionTaskDefinition implements TaskDefinition { | |||
public static final String COMMAND = "inspect"; | |||
public TaskDescriptor getTaskDescriptor() { | |||
return TaskDescriptor.create() | |||
.setDescription("Start a Sonar inspection of a project") | |||
.setName("Sonar project inspection") | |||
.setCommand(COMMAND) | |||
.setRequiresProject(true); | |||
} | |||
public Class<? extends TaskExecutor> getExecutor() { | |||
return InspectionTaskExecutor.class; | |||
} | |||
} |
@@ -1,42 +0,0 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2008-2012 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* Sonar is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.batch.tasks; | |||
import org.sonar.api.batch.TaskDefinition; | |||
import org.sonar.api.batch.TaskDescriptor; | |||
import org.sonar.api.batch.TaskExecutor; | |||
public class ListTaskDefinition implements TaskDefinition { | |||
public static final String COMMAND = "list-tasks"; | |||
public TaskDescriptor getTaskDescriptor() { | |||
return TaskDescriptor.create() | |||
.setDescription("List all available tasks on the Sonar server") | |||
.setName("List tasks") | |||
.setCommand(COMMAND) | |||
.setRequiresProject(false); | |||
} | |||
public Class<? extends TaskExecutor> getExecutor() { | |||
return ListTaskExecutor.class; | |||
} | |||
} |
@@ -19,22 +19,28 @@ | |||
*/ | |||
package org.sonar.batch.tasks; | |||
import org.sonar.api.batch.TaskDefinition; | |||
import org.sonar.api.batch.TaskDescriptor; | |||
import org.sonar.api.batch.TaskExecutor; | |||
import org.sonar.api.task.Task; | |||
import org.sonar.api.task.TaskDefinition; | |||
public class ListTaskExecutor implements TaskExecutor { | |||
public class ListTasksTask implements Task { | |||
private final TaskManager taskManager; | |||
public static final String COMMAND = "list-tasks"; | |||
public ListTaskExecutor(TaskManager taskManager) { | |||
public static final TaskDefinition DEFINITION = TaskDefinition.create() | |||
.setDescription("List all available tasks on the Sonar server") | |||
.setName("List tasks") | |||
.setCommand(COMMAND) | |||
.setTask(ListTasksTask.class); | |||
private final Tasks taskManager; | |||
public ListTasksTask(Tasks taskManager) { | |||
this.taskManager = taskManager; | |||
} | |||
public void execute() { | |||
for (TaskDefinition task : taskManager.getTasks()) { | |||
TaskDescriptor desc = task.getTaskDescriptor(); | |||
System.out.println(" " + desc.getCommand() + ": " + desc.getDescription()); | |||
for (TaskDefinition taskDef : taskManager.getTaskDefinitions()) { | |||
System.out.println(" " + taskDef.getCommand() + ": " + taskDef.getDescription()); | |||
} | |||
} | |||
@@ -1,46 +0,0 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2008-2012 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* Sonar is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.batch.tasks; | |||
import org.sonar.api.batch.TaskDefinition; | |||
import org.sonar.api.utils.SonarException; | |||
public class TaskManager { | |||
private final TaskDefinition[] tasks; | |||
public TaskManager(TaskDefinition[] tasks) { | |||
this.tasks = tasks; | |||
} | |||
public TaskDefinition getTask(String command) { | |||
for (TaskDefinition task : tasks) { | |||
if (command.equals(task.getTaskDescriptor().getCommand())) { | |||
return task; | |||
} | |||
} | |||
throw new SonarException("No task found for command: " + command); | |||
} | |||
public TaskDefinition[] getTasks() { | |||
return tasks; | |||
} | |||
} |
@@ -0,0 +1,58 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2008-2012 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* Sonar is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.batch.tasks; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.task.TaskDefinition; | |||
import org.sonar.api.utils.SonarException; | |||
public class Tasks { | |||
private final TaskDefinition[] taskDefinitions; | |||
private final Settings settings; | |||
public Tasks(Settings settings, TaskDefinition[] taskDefinitions) { | |||
this.settings = settings; | |||
this.taskDefinitions = taskDefinitions; | |||
} | |||
public TaskDefinition getTaskDefinition(String command) { | |||
String finalCommand = command; | |||
if (StringUtils.isBlank(finalCommand)) { | |||
// Try with a property | |||
finalCommand = settings.getString(CoreProperties.TASK); | |||
} | |||
// Default to inspection task | |||
finalCommand = StringUtils.isNotBlank(finalCommand) ? finalCommand : InspectionTask.COMMAND; | |||
for (TaskDefinition taskDef : taskDefinitions) { | |||
if (finalCommand.equals(taskDef.getCommand())) { | |||
return taskDef; | |||
} | |||
} | |||
throw new SonarException("No task found for command: " + finalCommand); | |||
} | |||
public TaskDefinition[] getTaskDefinitions() { | |||
return taskDefinitions; | |||
} | |||
} |
@@ -21,7 +21,7 @@ package org.sonar.batch.bootstrap; | |||
import org.junit.Test; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.batch.tasks.ListTaskDefinition; | |||
import org.sonar.api.task.TaskDefinition; | |||
import static org.mockito.Matchers.any; | |||
import static org.mockito.Matchers.eq; | |||
@@ -40,7 +40,7 @@ public class AbstractTaskModuleTest { | |||
} | |||
}; | |||
bootstrapModule.init(); | |||
ProjectTaskModule module = new ProjectTaskModule(new ListTaskDefinition()); | |||
ProjectTaskModule module = new ProjectTaskModule(TaskDefinition.create()); | |||
bootstrapModule.installChild(module); | |||
verify(extensionInstaller).installTaskExtensions(any(ComponentContainer.class), eq(true)); | |||
@@ -57,7 +57,7 @@ public class AbstractTaskModuleTest { | |||
} | |||
}; | |||
bootstrapModule.init(); | |||
ProjectLessTaskModule module = new ProjectLessTaskModule(new ListTaskDefinition()); | |||
ProjectLessTaskModule module = new ProjectLessTaskModule(TaskDefinition.create()); | |||
bootstrapModule.installChild(module); | |||
verify(extensionInstaller).installTaskExtensions(any(ComponentContainer.class), eq(false)); |
@@ -0,0 +1,56 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2008-2012 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* Sonar is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.utils.SonarException; | |||
import static org.mockito.Mockito.mock; | |||
public class TaskBootstrapModuleTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void should_throw_when_no_project_and_task_require_project() { | |||
final ExtensionInstaller extensionInstaller = mock(ExtensionInstaller.class); | |||
Module bootstrapModule = new Module() { | |||
@Override | |||
protected void configure() { | |||
// used to install project extensions | |||
container.addSingleton(extensionInstaller); | |||
container.addSingleton(Settings.class); | |||
} | |||
}; | |||
bootstrapModule.init(); | |||
TaskBootstrapModule module = new TaskBootstrapModule("inspect"); | |||
bootstrapModule.installChild(module); | |||
thrown.expect(SonarException.class); | |||
thrown.expectMessage("Task Sonar project inspection requires to be run on a project"); | |||
module.doStart(); | |||
} | |||
} |
@@ -0,0 +1,83 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2008-2012 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* Sonar is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.batch.tasks; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.task.TaskDefinition; | |||
import org.sonar.api.utils.SonarException; | |||
import static org.fest.assertions.Assertions.assertThat; | |||
public class TasksTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private Settings settings; | |||
@Before | |||
public void prepare() { | |||
settings = new Settings(); | |||
} | |||
@Test | |||
public void shouldReturnTaskDefinitions() { | |||
Tasks tasks = new Tasks(settings, new TaskDefinition[] {InspectionTask.DEFINITION, ListTasksTask.DEFINITION}); | |||
assertThat(tasks.getTaskDefinitions().length).isEqualTo(2); | |||
} | |||
@Test | |||
public void shouldReturnInspectionTask() { | |||
Tasks tasks = new Tasks(settings, new TaskDefinition[] {InspectionTask.DEFINITION, ListTasksTask.DEFINITION}); | |||
assertThat(tasks.getTaskDefinition(InspectionTask.COMMAND)).isEqualTo(InspectionTask.DEFINITION); | |||
} | |||
@Test | |||
public void shouldReturnInspectionTaskByDefault() { | |||
Tasks tasks = new Tasks(settings, new TaskDefinition[] {InspectionTask.DEFINITION, ListTasksTask.DEFINITION}); | |||
assertThat(tasks.getTaskDefinition(null)).isEqualTo(InspectionTask.DEFINITION); | |||
} | |||
@Test | |||
public void shouldReturnUsePropertyWhenNoCommand() { | |||
Tasks tasks = new Tasks(settings, new TaskDefinition[] {InspectionTask.DEFINITION, ListTasksTask.DEFINITION}); | |||
assertThat(tasks.getTaskDefinition(ListTasksTask.COMMAND)).isEqualTo(ListTasksTask.DEFINITION); | |||
assertThat(tasks.getTaskDefinition(null)).isEqualTo(InspectionTask.DEFINITION); | |||
settings.setProperty(CoreProperties.TASK, ListTasksTask.COMMAND); | |||
assertThat(tasks.getTaskDefinition(null)).isEqualTo(ListTasksTask.DEFINITION); | |||
assertThat(tasks.getTaskDefinition(InspectionTask.COMMAND)).isEqualTo(InspectionTask.DEFINITION); | |||
} | |||
@Test | |||
public void shouldThrowWhenCommandNotFound() { | |||
Tasks tasks = new Tasks(settings, new TaskDefinition[] {InspectionTask.DEFINITION, ListTasksTask.DEFINITION}); | |||
thrown.expect(SonarException.class); | |||
thrown.expectMessage("No task found for command: not-exists"); | |||
tasks.getTaskDefinition("not-exists"); | |||
} | |||
} |
@@ -161,7 +161,6 @@ public interface CoreProperties { | |||
String BATCH_INCLUDE_PLUGINS = "sonar.includePlugins"; | |||
String BATCH_EXCLUDE_PLUGINS = "sonar.excludePlugins"; | |||
/** | |||
* @since 3.4 | |||
*/ | |||
@@ -372,6 +371,11 @@ public interface CoreProperties { | |||
*/ | |||
String FORCE_ANALYSIS = "sonar.forceAnalysis"; | |||
/** | |||
* @since 3.5 | |||
*/ | |||
String TASK = "sonar.task"; | |||
/** | |||
* @deprecated replaced in v3.4 by properties specific to languages, for example sonar.java.coveragePlugin | |||
* See http://jira.codehaus.org/browse/SONARJAVA-39 for more details. |
@@ -1,34 +0,0 @@ | |||
/* | |||
* Sonar, open source software quality management tool. | |||
* Copyright (C) 2008-2012 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* Sonar is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* Sonar is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.api.batch; | |||
import org.sonar.api.TaskDefinitionExtension; | |||
/** | |||
* Implement this interface to provide a new task. | |||
* @since 3.5 | |||
*/ | |||
public interface TaskDefinition extends TaskDefinitionExtension { | |||
TaskDescriptor getTaskDescriptor(); | |||
Class<? extends TaskExecutor> getExecutor(); | |||
} |
@@ -17,7 +17,7 @@ | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.api.batch; | |||
package org.sonar.api.task; | |||
import java.lang.annotation.ElementType; | |||
import java.lang.annotation.Retention; |
@@ -17,7 +17,7 @@ | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.api.batch; | |||
package org.sonar.api.task; | |||
import org.sonar.api.TaskExtension; | |||
@@ -25,7 +25,7 @@ import org.sonar.api.TaskExtension; | |||
* Implement this interface to provide the behavior of a task. | |||
* @since 3.5 | |||
*/ | |||
public interface TaskExecutor extends TaskExtension { | |||
public interface Task extends TaskExtension { | |||
void execute(); | |||
@@ -17,32 +17,34 @@ | |||
* License along with Sonar; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | |||
*/ | |||
package org.sonar.api.batch; | |||
package org.sonar.api.task; | |||
import org.sonar.api.TaskDefinitionExtension; | |||
/** | |||
* Provide description of a task. | |||
* Implement this interface to provide a new task. | |||
* @since 3.5 | |||
*/ | |||
public class TaskDescriptor { | |||
public class TaskDefinition implements TaskDefinitionExtension { | |||
private String name; | |||
private String description; | |||
private String command; | |||
private boolean requiresProject = false; | |||
private Class<? extends Task> task; | |||
private TaskDescriptor() { | |||
private TaskDefinition() { | |||
} | |||
public static TaskDescriptor create() { | |||
return new TaskDescriptor(); | |||
public static TaskDefinition create() { | |||
return new TaskDefinition(); | |||
} | |||
public String getName() { | |||
return name; | |||
} | |||
public TaskDescriptor setName(String name) { | |||
public TaskDefinition setName(String name) { | |||
this.name = name; | |||
return this; | |||
} | |||
@@ -51,7 +53,7 @@ public class TaskDescriptor { | |||
return description; | |||
} | |||
public TaskDescriptor setDescription(String description) { | |||
public TaskDefinition setDescription(String description) { | |||
this.description = description; | |||
return this; | |||
} | |||
@@ -60,18 +62,23 @@ public class TaskDescriptor { | |||
return command; | |||
} | |||
public TaskDescriptor setCommand(String command) { | |||
public TaskDefinition setCommand(String command) { | |||
this.command = command; | |||
return this; | |||
} | |||
public boolean isRequiresProject() { | |||
return requiresProject; | |||
public Class<? extends Task> getTask() { | |||
return task; | |||
} | |||
public TaskDescriptor setRequiresProject(boolean requiresProject) { | |||
this.requiresProject = requiresProject; | |||
public TaskDefinition setTask(Class<? extends Task> task) { | |||
this.task = task; | |||
return this; | |||
} | |||
@Override | |||
public String toString() { | |||
return "Definition of task " + task + " with command " + command; | |||
} | |||
} |