diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-02-26 16:53:29 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-02-27 14:37:01 +0100 |
commit | b0fe2aae234489d21be964a9e8a1ffd699be4fbb (patch) | |
tree | 6e127ce10f3d1c4eb8724c43447cf29cbf849baf /sonar-plugin-api | |
parent | b71ab81e064d952eb398700dba3dbe6ee8261afd (diff) | |
download | sonarqube-b0fe2aae234489d21be964a9e8a1ffd699be4fbb.tar.gz sonarqube-b0fe2aae234489d21be964a9e8a1ffd699be4fbb.zip |
Refactor ioc containers to allow views to work as a task.
Signed-off-by: Julien Lancelot <julien.lancelot@gmail.com>
Diffstat (limited to 'sonar-plugin-api')
6 files changed, 33 insertions, 19 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java index ef295033bd3..4a68f84d1d6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java @@ -28,6 +28,7 @@ import org.sonar.api.batch.maven.DependsUponMavenPlugin; import org.sonar.api.batch.maven.MavenPluginHandler; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.resources.Project; +import org.sonar.api.task.TaskExtension; import org.sonar.api.utils.AnnotationUtils; import org.sonar.api.utils.dag.DirectAcyclicGraph; @@ -80,7 +81,7 @@ public class BatchExtensionDictionnary { return handlers; } - private List<BatchExtension> getExtensions() { + private List<BatchExtension> getBatchExtensions() { List<BatchExtension> extensions = Lists.newArrayList(); completeBatchExtensions(componentContainer, extensions); return extensions; @@ -93,9 +94,27 @@ public class BatchExtensionDictionnary { } } + private List<TaskExtension> getTaskExtensions() { + List<TaskExtension> extensions = Lists.newArrayList(); + completeTaskExtensions(componentContainer, extensions); + return extensions; + } + + private static void completeTaskExtensions(ComponentContainer container, List<TaskExtension> extensions) { + if (container != null) { + extensions.addAll(container.getComponentsByType(TaskExtension.class)); + completeTaskExtensions(container.getParent(), extensions); + } + } + private <T> List<T> getFilteredExtensions(Class<T> type, Project project) { List<T> result = Lists.newArrayList(); - for (BatchExtension extension : getExtensions()) { + for (BatchExtension extension : getBatchExtensions()) { + if (shouldKeep(type, extension, project)) { + result.add((T) extension); + } + } + for (TaskExtension extension : getTaskExtensions()) { if (shouldKeep(type, extension, project)) { result.add((T) extension); } @@ -155,7 +174,6 @@ public class BatchExtensionDictionnary { } } - protected List evaluateAnnotatedClasses(Object extension, Class<? extends Annotation> annotation) { List<Object> results = Lists.newArrayList(); Class aClass = extension.getClass(); @@ -203,7 +221,7 @@ public class BatchExtensionDictionnary { try { Object result = method.invoke(extension); if (result != null) { - //TODO add arrays/collections of objects/classes + // TODO add arrays/collections of objects/classes if (result instanceof Class<?>) { results.addAll(componentContainer.getComponentsByType((Class<?>) result)); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java index 1c96d1535e7..189cab40645 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java @@ -22,9 +22,8 @@ package org.sonar.api.measures; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.BatchExtension; import org.sonar.api.ServerExtension; -import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.task.TaskExtension; import javax.persistence.Column; import javax.persistence.Entity; @@ -42,8 +41,7 @@ import javax.persistence.Transient; */ @Table(name = "metrics") @Entity(name = "Metric") -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public class Metric implements ServerExtension, BatchExtension { +public class Metric implements ServerExtension, TaskExtension { /** * A metric bigger value means a degradation diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metrics.java index fe0170eac4e..7d000a2de1e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metrics.java @@ -19,16 +19,14 @@ */ package org.sonar.api.measures; -import org.sonar.api.BatchExtension; import org.sonar.api.ServerExtension; -import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.task.TaskExtension; import java.util.List; /** * @since 1.10 */ -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public interface Metrics extends BatchExtension, ServerExtension { +public interface Metrics extends TaskExtension, ServerExtension { List<Metric> getMetrics(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/ModelFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/ModelFinder.java index b6970c7beff..a7d05e777e8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/ModelFinder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/ModelFinder.java @@ -19,13 +19,13 @@ */ package org.sonar.api.qualitymodel; -import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; +import org.sonar.api.task.TaskComponent; /** * @since 2.3 */ -public interface ModelFinder extends BatchComponent, ServerComponent { +public interface ModelFinder extends TaskComponent, ServerComponent { /** * @return null if the name is not found diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java index 8a025a32108..8b41ff61f10 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java @@ -19,15 +19,15 @@ */ package org.sonar.api.resources; -import org.sonar.api.BatchExtension; import org.sonar.api.ServerExtension; +import org.sonar.api.task.TaskExtension; /** * The extension point to define a new language * * @since 1.10 */ -public interface Language extends BatchExtension, ServerExtension { +public interface Language extends TaskExtension, ServerExtension { /** * For example "java". Should not be more than 20 chars. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java index b6285f5a419..07a00f6a38c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java @@ -21,8 +21,8 @@ package org.sonar.api.resources; import com.google.common.collect.Maps; import org.apache.commons.lang.ArrayUtils; -import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; +import org.sonar.api.task.TaskComponent; import java.util.ArrayList; import java.util.Arrays; @@ -31,10 +31,10 @@ import java.util.Map; /** * A class to store the list of languages - * + * * @since 1.10 */ -public class Languages implements BatchComponent, ServerComponent { +public class Languages implements TaskComponent, ServerComponent { private final Map<String, Language> map = Maps.newHashMap(); |