diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-03-26 10:53:26 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-03-26 10:53:26 +0100 |
commit | e1629b0ed4ca8a6ed7065d1358df0c2e238e3660 (patch) | |
tree | a8bd1132ab0a5b939d7903ead1fb2a0408c2e3b7 /sonar-plugin-api/src/main | |
parent | c51ea2ec313b0fd4f9e4154bed5221009a03fbdf (diff) | |
download | sonarqube-e1629b0ed4ca8a6ed7065d1358df0c2e238e3660.tar.gz sonarqube-e1629b0ed4ca8a6ed7065d1358df0c2e238e3660.zip |
SONAR-4069 Allow to filter list of sensors that will be executed
Diffstat (limited to 'sonar-plugin-api/src/main')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java | 17 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/batch/ExtensionMatcher.java | 27 |
2 files changed, 37 insertions, 7 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..df5ddd263bf 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 @@ -54,7 +54,11 @@ public class BatchExtensionDictionnary { } public <T> Collection<T> select(Class<T> type, Project project, boolean sort) { - List<T> result = getFilteredExtensions(type, project); + return select(type, project, sort, null); + } + + public <T> Collection<T> select(Class<T> type, Project project, boolean sort, ExtensionMatcher matcher) { + List<T> result = getFilteredExtensions(type, project, matcher); if (sort) { return sort(result); } @@ -93,18 +97,18 @@ public class BatchExtensionDictionnary { } } - private <T> List<T> getFilteredExtensions(Class<T> type, Project project) { + private <T> List<T> getFilteredExtensions(Class<T> type, Project project, ExtensionMatcher matcher) { List<T> result = Lists.newArrayList(); for (BatchExtension extension : getExtensions()) { - if (shouldKeep(type, extension, project)) { + if (shouldKeep(type, extension, project, matcher)) { result.add((T) extension); } } return result; } - private boolean shouldKeep(Class type, Object extension, Project project) { - boolean keep = ClassUtils.isAssignable(extension.getClass(), type); + private boolean shouldKeep(Class type, Object extension, Project project, ExtensionMatcher matcher) { + boolean keep = ClassUtils.isAssignable(extension.getClass(), type) && (matcher == null || matcher.accept(extension)); if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) { keep = ((CheckProject) extension).shouldExecuteOnProject(project); } @@ -155,7 +159,6 @@ public class BatchExtensionDictionnary { } } - protected List evaluateAnnotatedClasses(Object extension, Class<? extends Annotation> annotation) { List<Object> results = Lists.newArrayList(); Class aClass = extension.getClass(); @@ -203,7 +206,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/batch/ExtensionMatcher.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/ExtensionMatcher.java new file mode 100644 index 00000000000..96d81ae587d --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/ExtensionMatcher.java @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * @since 3.6 + */ +public interface ExtensionMatcher { + boolean accept(Object extension); +} |