diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-14 19:15:56 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-14 19:15:56 +0100 |
commit | e5ee5b9ca0c582bb282e3174e4fc8590a9d2737c (patch) | |
tree | 153918e4e4149f3ee93666f2c6971d43487bcd35 /sonar-batch | |
parent | 5d39faf6f9ed9b2951044060ecd1602cd8931eec (diff) | |
download | sonarqube-e5ee5b9ca0c582bb282e3174e4fc8590a9d2737c.tar.gz sonarqube-e5ee5b9ca0c582bb282e3174e4fc8590a9d2737c.zip |
SONAR-4069 Fix issue with ProjectBuilder extension
* ProjectBuilder is now a TaskExtension but with a @RequiresProject to be loaded only when
task is executed on a project
Diffstat (limited to 'sonar-batch')
7 files changed, 25 insertions, 15 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java index 651d24ef9b9..de66cbbf39a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java @@ -64,9 +64,11 @@ public abstract class AbstractTaskModule extends Module { private static final Logger LOG = LoggerFactory.getLogger(AbstractTaskModule.class); private TaskDefinition task; + private boolean projectPresent; - public AbstractTaskModule(TaskDefinition task) { + public AbstractTaskModule(TaskDefinition task, boolean projectPresent) { this.task = task; + this.projectPresent = projectPresent; } @Override @@ -130,7 +132,7 @@ public abstract class AbstractTaskModule extends Module { private void registerTaskExtensions() { ExtensionInstaller installer = container.getComponentByType(ExtensionInstaller.class); - installer.installTaskExtensions(container); + installer.installTaskExtensions(container, projectPresent); } private void logSettings() { diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java index 068a2b69730..396a60841d3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java @@ -98,37 +98,38 @@ public class ExtensionInstaller implements BatchComponent { return installed; } - public void installTaskExtensions(ComponentContainer container) { + public void installTaskExtensions(ComponentContainer container, boolean projectPresent) { for (Map.Entry<PluginMetadata, Plugin> entry : pluginRepository.getPluginsByMetadata().entrySet()) { PluginMetadata metadata = entry.getKey(); Plugin plugin = entry.getValue(); container.addExtension(metadata, plugin); for (Object extension : plugin.getExtensions()) { - installTaskExtension(container, metadata, extension); + installTaskExtension(container, metadata, extension, projectPresent); } } List<ExtensionProvider> providers = container.getComponentsByType(ExtensionProvider.class); for (ExtensionProvider provider : providers) { - executeTaskExtensionProvider(container, provider); + executeTaskExtensionProvider(container, provider, projectPresent); } } - private void executeTaskExtensionProvider(ComponentContainer container, ExtensionProvider provider) { + private void executeTaskExtensionProvider(ComponentContainer container, ExtensionProvider provider, boolean projectPresent) { Object obj = provider.provide(); if (obj instanceof Iterable) { for (Object extension : (Iterable) obj) { - installTaskExtension(container, null, extension); + installTaskExtension(container, null, extension, projectPresent); } } else { - installTaskExtension(container, null, obj); + installTaskExtension(container, null, obj, projectPresent); } } - boolean installTaskExtension(ComponentContainer container, @Nullable PluginMetadata plugin, Object extension) { + boolean installTaskExtension(ComponentContainer container, @Nullable PluginMetadata plugin, Object extension, boolean projectPresent) { boolean installed; if (ExtensionUtils.isTaskExtension(extension) && + (projectPresent || !ExtensionUtils.requireProject(extension)) && ExtensionUtils.supportsEnvironment(extension, environment)) { if (plugin != null) { LOG.debug("Installing task extension {} from plugin {}", extension.toString(), plugin.getKey()); 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 fd6a1ba2252..40fa0286aca 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.api.batch.RequiresProject; + import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchExtension; import org.sonar.api.Extension; @@ -73,6 +75,10 @@ final class ExtensionUtils { return AnnotationUtils.getAnnotation(extension, DryRunIncompatible.class) == null; } + static boolean requireProject(Object extension) { + return AnnotationUtils.getAnnotation(extension, RequiresProject.class) == null; + } + static boolean isMavenExtensionOnly(Object extension) { SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class); return env != null && env.value().length == 1 && StringUtils.equalsIgnoreCase("maven", env.value()[0]); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java index e2c9c53db01..4cd50965e29 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java @@ -23,8 +23,8 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.api.BatchComponent; import org.sonar.api.CoreProperties; +import org.sonar.api.TaskComponent; import org.sonar.api.batch.bootstrap.ProjectBuilder; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; @@ -35,7 +35,7 @@ import org.sonar.api.config.Settings; * * @since 2.12 */ -public class ProjectExclusions implements BatchComponent { +public class ProjectExclusions implements TaskComponent { private static final Logger LOG = LoggerFactory.getLogger(ProjectExclusions.class); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskModule.java index 75f932deeb1..603a39fa185 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectLessTaskModule.java @@ -24,7 +24,7 @@ import org.sonar.api.batch.TaskDefinition; public class ProjectLessTaskModule extends AbstractTaskModule { public ProjectLessTaskModule(TaskDefinition task) { - super(task); + super(task, false); } @Override 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 index a7c7d3b97ee..124ac8b70bd 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTaskModule.java @@ -28,7 +28,7 @@ import org.sonar.batch.index.DefaultIndex; public class ProjectTaskModule extends AbstractTaskModule { public ProjectTaskModule(TaskDefinition task) { - super(task); + super(task, true); } @Override 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 5c98364162f..f25bc762354 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 @@ -61,11 +61,12 @@ public class TaskBootstrapModule extends Module { } private void executeTask(TaskDefinition task) { - if (task.getTaskDescriptor().isRequiresProject() && container.getComponentByType(ProjectReactor.class) == null) { + 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"); } Module childModule; - if (task.getTaskDescriptor().isRequiresProject()) { + if (projectPresent) { childModule = new ProjectTaskModule(task); } else { |