
org.sonar.batch.bootstrap.BatchExtensionDictionnary Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonar-scanner-engine Show documentation
Show all versions of sonar-scanner-engine Show documentation
Open source platform for continuous inspection of code quality
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.batch.bootstrap;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.commons.lang.ClassUtils;
import org.sonar.api.batch.CheckProject;
import org.sonar.api.batch.DependedUpon;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.batch.Phase;
import org.sonar.api.batch.postjob.PostJob;
import org.sonar.api.batch.postjob.PostJobContext;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.api.utils.dag.DirectAcyclicGraph;
import org.sonar.batch.postjob.PostJobOptimizer;
import org.sonar.batch.postjob.PostJobWrapper;
import org.sonar.batch.sensor.DefaultSensorContext;
import org.sonar.batch.sensor.SensorOptimizer;
import org.sonar.batch.sensor.SensorWrapper;
import org.sonar.core.platform.ComponentContainer;
/**
* @since 2.6
*/
public class BatchExtensionDictionnary {
private final ComponentContainer componentContainer;
private final SensorContext sensorContext;
private final SensorOptimizer sensorOptimizer;
private final PostJobContext postJobContext;
private final PostJobOptimizer postJobOptimizer;
public BatchExtensionDictionnary(ComponentContainer componentContainer, DefaultSensorContext sensorContext, SensorOptimizer sensorOptimizer, PostJobContext postJobContext,
PostJobOptimizer postJobOptimizer) {
this.componentContainer = componentContainer;
this.sensorContext = sensorContext;
this.sensorOptimizer = sensorOptimizer;
this.postJobContext = postJobContext;
this.postJobOptimizer = postJobOptimizer;
}
public Collection select(Class type, @Nullable Project project, boolean sort, @Nullable ExtensionMatcher matcher) {
List result = getFilteredExtensions(type, project, matcher);
if (sort) {
return sort(result);
}
return result;
}
private static Phase.Name evaluatePhase(Object extension) {
Object extensionToEvaluate;
if (extension instanceof SensorWrapper) {
extensionToEvaluate = ((SensorWrapper) extension).wrappedSensor();
} else {
extensionToEvaluate = extension;
}
Phase phaseAnnotation = AnnotationUtils.getAnnotation(extensionToEvaluate, Phase.class);
if (phaseAnnotation != null) {
return phaseAnnotation.name();
}
return Phase.Name.DEFAULT;
}
private List getFilteredExtensions(Class type, @Nullable Project project, @Nullable ExtensionMatcher matcher) {
List result = Lists.newArrayList();
for (Object extension : getExtensions(type)) {
if (org.sonar.api.batch.Sensor.class.equals(type) && extension instanceof Sensor) {
extension = new SensorWrapper((Sensor) extension, sensorContext, sensorOptimizer);
}
if (shouldKeep(type, extension, project, matcher)) {
result.add((T) extension);
}
}
if (org.sonar.api.batch.Sensor.class.equals(type)) {
// Retrieve new Sensors and wrap then in SensorWrapper
for (Object extension : getExtensions(Sensor.class)) {
extension = new SensorWrapper((Sensor) extension, sensorContext, sensorOptimizer);
if (shouldKeep(type, extension, project, matcher)) {
result.add((T) extension);
}
}
}
if (org.sonar.api.batch.PostJob.class.equals(type)) {
// Retrieve new PostJob and wrap then in PostJobWrapper
for (Object extension : getExtensions(PostJob.class)) {
extension = new PostJobWrapper((PostJob) extension, postJobContext, postJobOptimizer);
if (shouldKeep(type, extension, project, matcher)) {
result.add((T) extension);
}
}
}
return result;
}
protected List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy