diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-18 15:40:58 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-18 15:43:09 +0100 |
commit | 8133a2c491d5d59c35af8a7d55dba506ade3c8fa (patch) | |
tree | 690cf0ee617614579848576c154b19620afaf4db /sonar-batch | |
parent | 5ab69aedad1e97e6339bb313e1e50bbfb6f872c7 (diff) | |
download | sonarqube-8133a2c491d5d59c35af8a7d55dba506ade3c8fa.tar.gz sonarqube-8133a2c491d5d59c35af8a7d55dba506ade3c8fa.zip |
SONAR-4069 Refactoring of Task extension
* @RequiresProject is no more in API
* Simplify TaskModule
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java | 3 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskModule.java | 59 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java | 8 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskModule.java (renamed from sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java) | 29 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/tasks/InspectionTask.java | 1 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/tasks/RequiresProject.java (renamed from sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskModule.java) | 28 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskModuleTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/bootstrap/AbstractTaskModuleTest.java) | 6 |
7 files changed, 48 insertions, 86 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java index 12c104f03bb..5ad891af55f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.bootstrap; +import org.sonar.batch.tasks.RequiresProject; + import org.sonar.api.task.TaskDefinitionExtension; import org.sonar.api.task.TaskExtension; @@ -27,7 +29,6 @@ import org.sonar.api.BatchExtension; import org.sonar.api.Extension; 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; diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskModule.java deleted file mode 100644 index ae540020ce6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskModule.java +++ /dev/null @@ -1,59 +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.bootstrap; - -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.InspectionTask; - -public class ProjectTaskModule extends AbstractTaskModule { - - public ProjectTaskModule(TaskDefinition task) { - super(task, true); - } - - @Override - protected void configure() { - super.configure(); - registerCoreComponentsRequiringProject(); - registerCoreTasksRequiringProject(); - } - - private void registerCoreComponentsRequiringProject() { - container.addSingleton(ProjectExclusions.class); - container.addSingleton(ProjectReactorReady.class); - container.addSingleton(ProjectTree.class); - container.addSingleton(ProjectConfigurator.class); - container.addSingleton(DefaultIndex.class); - container.addSingleton(DefaultFileLinesContextFactory.class); - container.addSingleton(ProjectLock.class); - - container.addSingleton(DryRunDatabase.class); - } - - private void registerCoreTasksRequiringProject() { - container.addSingleton(InspectionTask.class); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java index de57549c961..052d9a07931 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskBootstrapModule.java @@ -65,13 +65,7 @@ public class TaskBootstrapModule extends Module { 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(taskDefinition); - } - else { - childModule = new ProjectLessTaskModule(taskDefinition); - } + Module childModule = new TaskModule(taskDefinition, projectPresent); try { installChild(childModule); childModule.start(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskModule.java index c433bb84f2d..1193b23b4fc 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskModule.java @@ -26,7 +26,10 @@ 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.DefaultFileLinesContextFactory; import org.sonar.batch.DefaultResourceCreationLock; +import org.sonar.batch.ProjectConfigurator; +import org.sonar.batch.ProjectTree; import org.sonar.batch.components.PastMeasuresLoader; import org.sonar.batch.components.PastSnapshotFinder; import org.sonar.batch.components.PastSnapshotFinderByDate; @@ -34,6 +37,7 @@ import org.sonar.batch.components.PastSnapshotFinderByDays; import org.sonar.batch.components.PastSnapshotFinderByPreviousAnalysis; import org.sonar.batch.components.PastSnapshotFinderByPreviousVersion; import org.sonar.batch.components.PastSnapshotFinderByVersion; +import org.sonar.batch.index.DefaultIndex; import org.sonar.batch.index.DefaultPersistenceManager; import org.sonar.batch.index.DefaultResourcePersister; import org.sonar.batch.index.DependencyPersister; @@ -42,6 +46,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.InspectionTask; import org.sonar.batch.tasks.ListTasksTask; import org.sonar.core.i18n.I18nManager; import org.sonar.core.i18n.RuleI18nManager; @@ -61,14 +66,14 @@ import org.sonar.jpa.session.JpaDatabaseSession; /** * Level-3 components. Task-level components that don't depends on project. */ -public abstract class AbstractTaskModule extends Module { +public class TaskModule extends Module { - private static final Logger LOG = LoggerFactory.getLogger(AbstractTaskModule.class); + private static final Logger LOG = LoggerFactory.getLogger(TaskModule.class); private TaskDefinition taskDefinition; private boolean projectPresent; - public AbstractTaskModule(TaskDefinition task, boolean projectPresent) { + public TaskModule(TaskDefinition task, boolean projectPresent) { this.taskDefinition = task; this.projectPresent = projectPresent; } @@ -80,6 +85,9 @@ public abstract class AbstractTaskModule extends Module { registerDatabaseComponents(); registerTaskExtensions(); registerCoreTasks(); + if (projectPresent) { + registerCoreComponentsRequiringProject(); + } } private void registerCoreComponents() { @@ -133,6 +141,9 @@ public abstract class AbstractTaskModule extends Module { private void registerCoreTasks() { container.addSingleton(ListTasksTask.class); + if (projectPresent) { + container.addSingleton(InspectionTask.class); + } } private void registerTaskExtensions() { @@ -140,6 +151,18 @@ public abstract class AbstractTaskModule extends Module { installer.installTaskExtensions(container, projectPresent); } + private void registerCoreComponentsRequiringProject() { + container.addSingleton(ProjectExclusions.class); + container.addSingleton(ProjectReactorReady.class); + container.addSingleton(ProjectTree.class); + container.addSingleton(ProjectConfigurator.class); + container.addSingleton(DefaultIndex.class); + container.addSingleton(DefaultFileLinesContextFactory.class); + container.addSingleton(ProjectLock.class); + + container.addSingleton(DryRunDatabase.class); + } + private void logSettings() { LOG.info("------------- Executing {}", taskDefinition.getName()); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/InspectionTask.java b/sonar-batch/src/main/java/org/sonar/batch/tasks/InspectionTask.java index 05ead3d88c8..a98a960a50b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/tasks/InspectionTask.java +++ b/sonar-batch/src/main/java/org/sonar/batch/tasks/InspectionTask.java @@ -23,7 +23,6 @@ import org.sonar.batch.bootstrap.InspectionModule; 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; diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskModule.java b/sonar-batch/src/main/java/org/sonar/batch/tasks/RequiresProject.java index 49c95063e77..430a53d4cbd 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/tasks/RequiresProject.java @@ -17,19 +17,23 @@ * 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; +package org.sonar.batch.tasks; -import org.sonar.api.task.TaskDefinition; +import com.google.common.annotations.Beta; -public class ProjectLessTaskModule extends AbstractTaskModule { - - public ProjectLessTaskModule(TaskDefinition task) { - super(task, false); - } - - @Override - protected void configure() { - super.configure(); - } +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +/** + * The presence of this annotation on a task extension class indicates that the extension + * will be disabled when there is no project available. + * + * @since 3.5 + */ +@Beta +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface RequiresProject { } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/AbstractTaskModuleTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskModuleTest.java index 4963c9cd0c8..e5b7f49b035 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/AbstractTaskModuleTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TaskModuleTest.java @@ -28,7 +28,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -public class AbstractTaskModuleTest { +public class TaskModuleTest { @Test public void should_register_task_extensions_when_project_present() { final ExtensionInstaller extensionInstaller = mock(ExtensionInstaller.class); @@ -40,7 +40,7 @@ public class AbstractTaskModuleTest { } }; bootstrapModule.init(); - ProjectTaskModule module = new ProjectTaskModule(TaskDefinition.create()); + TaskModule module = new TaskModule(TaskDefinition.create(), true); bootstrapModule.installChild(module); verify(extensionInstaller).installTaskExtensions(any(ComponentContainer.class), eq(true)); @@ -57,7 +57,7 @@ public class AbstractTaskModuleTest { } }; bootstrapModule.init(); - ProjectLessTaskModule module = new ProjectLessTaskModule(TaskDefinition.create()); + TaskModule module = new TaskModule(TaskDefinition.create(), false); bootstrapModule.installChild(module); verify(extensionInstaller).installTaskExtensions(any(ComponentContainer.class), eq(false)); |