@@ -19,18 +19,19 @@ | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import com.google.common.collect.Lists; | |||
import org.apache.commons.lang.ClassUtils; | |||
import org.sonar.api.batch.CheckProject; | |||
import org.sonar.api.batch.Sensor; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import org.sonar.api.batch.fs.FileSystem; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.batch.scan.SensorWrapper; | |||
import javax.annotation.Nullable; | |||
import java.util.Collection; | |||
import java.util.List; | |||
@@ -48,7 +49,7 @@ public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensio | |||
this.context = context; | |||
} | |||
public <T> Collection<T> select(Class<T> type, Project project, boolean sort, ExtensionMatcher matcher) { | |||
public <T> Collection<T> select(Class<T> type, @Nullable Project project, boolean sort, @Nullable ExtensionMatcher matcher) { | |||
List<T> result = getFilteredExtensions(type, project, matcher); | |||
if (sort) { | |||
return sort(result); | |||
@@ -56,9 +57,9 @@ public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensio | |||
return result; | |||
} | |||
private <T> List<T> getFilteredExtensions(Class<T> type, Project project, ExtensionMatcher matcher) { | |||
private <T> List<T> getFilteredExtensions(Class<T> type, @Nullable Project project, @Nullable ExtensionMatcher matcher) { | |||
List<T> result = Lists.newArrayList(); | |||
for (Object extension : getExtensions()) { | |||
for (Object extension : getExtensions(type)) { | |||
if (type == Sensor.class && extension instanceof Analyzer) { | |||
extension = new SensorWrapper((Analyzer) extension, context, fs); | |||
} | |||
@@ -69,7 +70,7 @@ public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensio | |||
return result; | |||
} | |||
private boolean shouldKeep(Class type, Object extension, Project project, ExtensionMatcher matcher) { | |||
private boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) { | |||
boolean keep = (ClassUtils.isAssignable(extension.getClass(), type) | |||
|| (type == Sensor.class && ClassUtils.isAssignable(extension.getClass(), Analyzer.class))) | |||
&& (matcher == null || matcher.accept(extension)); |
@@ -25,7 +25,7 @@ import org.sonar.api.BatchComponent; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.batch.bootstrap.BatchExtensionDictionnary; | |||
import java.util.Collection; | |||
@@ -33,14 +33,14 @@ public class AnalyzersExecutor implements BatchComponent { | |||
private static final Logger LOG = LoggerFactory.getLogger(AnalyzersExecutor.class); | |||
private ComponentContainer container; | |||
private BatchExtensionDictionnary selector; | |||
public AnalyzersExecutor(ComponentContainer container) { | |||
this.container = container; | |||
public AnalyzersExecutor(BatchExtensionDictionnary selector) { | |||
this.selector = selector; | |||
} | |||
public void execute(AnalyzerContext context) { | |||
Collection<Analyzer> analyzers = container.getComponentsByType(Analyzer.class); | |||
Collection<Analyzer> analyzers = selector.select(Analyzer.class, null, true, null); | |||
for (Analyzer analyzer : analyzers) { | |||
@@ -33,6 +33,8 @@ import org.sonar.api.resources.Project; | |||
import org.sonar.api.utils.AnnotationUtils; | |||
import org.sonar.api.utils.dag.DirectAcyclicGraph; | |||
import javax.annotation.Nullable; | |||
import java.lang.annotation.Annotation; | |||
import java.lang.reflect.Array; | |||
import java.lang.reflect.Method; | |||
@@ -59,7 +61,7 @@ public class BatchExtensionDictionnary { | |||
return select(type, null, false); | |||
} | |||
public <T> Collection<T> select(Class<T> type, Project project, boolean sort) { | |||
public <T> Collection<T> select(Class<T> type, @Nullable Project project, boolean sort) { | |||
List<T> result = getFilteredExtensions(type, project); | |||
if (sort) { | |||
return sort(result); | |||
@@ -69,7 +71,7 @@ public class BatchExtensionDictionnary { | |||
public Collection<MavenPluginHandler> selectMavenPluginHandlers(Project project) { | |||
List<DependsUponMavenPlugin> selectedExtensions = Lists.newArrayList(); | |||
for (Object extension : getExtensions()) { | |||
for (Object extension : getExtensions(null)) { | |||
if (ClassUtils.isAssignable(extension.getClass(), DependsUponMavenPlugin.class)) { | |||
selectedExtensions.add((DependsUponMavenPlugin) extension); | |||
} | |||
@@ -91,22 +93,22 @@ public class BatchExtensionDictionnary { | |||
return handlers; | |||
} | |||
protected List<Object> getExtensions() { | |||
protected List<Object> getExtensions(@Nullable Class type) { | |||
List<Object> extensions = Lists.newArrayList(); | |||
completeBatchExtensions(componentContainer, extensions); | |||
completeBatchExtensions(componentContainer, extensions, type); | |||
return extensions; | |||
} | |||
private static void completeBatchExtensions(ComponentContainer container, List<Object> extensions) { | |||
private static void completeBatchExtensions(ComponentContainer container, List<Object> extensions, @Nullable Class type) { | |||
if (container != null) { | |||
extensions.addAll(container.getComponentsByType(BatchExtension.class)); | |||
completeBatchExtensions(container.getParent(), extensions); | |||
extensions.addAll(container.getComponentsByType(type != null ? type : BatchExtension.class)); | |||
completeBatchExtensions(container.getParent(), extensions, type); | |||
} | |||
} | |||
private <T> List<T> getFilteredExtensions(Class<T> type, Project project) { | |||
private <T> List<T> getFilteredExtensions(Class<T> type, @Nullable Project project) { | |||
List<T> result = Lists.newArrayList(); | |||
for (Object extension : getExtensions()) { | |||
for (Object extension : getExtensions(type)) { | |||
if (shouldKeep(type, extension, project)) { | |||
result.add((T) extension); | |||
} | |||
@@ -114,7 +116,7 @@ public class BatchExtensionDictionnary { | |||
return result; | |||
} | |||
private boolean shouldKeep(Class type, Object extension, Project project) { | |||
private boolean shouldKeep(Class type, Object extension, @Nullable Project project) { | |||
boolean keep = ClassUtils.isAssignable(extension.getClass(), type); | |||
if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) { | |||
keep = ((CheckProject) extension).shouldExecuteOnProject(project); |
@@ -29,10 +29,10 @@ import java.util.Collection; | |||
public class DefaultAnalyzerDescriptor implements AnalyzerDescriptor { | |||
private String name; | |||
private Metric<?>[] dependsOn; | |||
private Metric<?>[] provides; | |||
private String[] languages; | |||
private InputFile.Type[] types; | |||
private Metric<?>[] dependsOn = new Metric<?>[0]; | |||
private Metric<?>[] provides = new Metric<?>[0]; | |||
private String[] languages = new String[0]; | |||
private InputFile.Type[] types = new InputFile.Type[0]; | |||
public String name() { | |||
return name; |