Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* SonarLint Core - Implementation
* Copyright (C) 2016-2021 SonarSource SA
* mailto:info 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.sonarsource.sonarlint.core.analyzer.sensor;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.sonar.api.batch.DependedUpon;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.batch.Phase;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.api.utils.dag.DirectAcyclicGraph;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonarsource.sonarlint.core.util.ProgressWrapper;
import org.sonarsource.sonarlint.core.util.StringUtils;
import static java.util.Arrays.asList;
/**
* Execute Sensors.
*/
public class SensorsExecutor {
private static final Logger LOG = Loggers.get(SensorsExecutor.class);
private final SensorOptimizer sensorOptimizer;
private final ProgressWrapper progress;
private final Sensor[] sensors;
private final DefaultSensorContext context;
public SensorsExecutor(DefaultSensorContext context, SensorOptimizer sensorOptimizer, ProgressWrapper progress) {
this(context, sensorOptimizer, progress, new Sensor[0]);
}
public SensorsExecutor(DefaultSensorContext context, SensorOptimizer sensorOptimizer, ProgressWrapper progress, Sensor[] sensors) {
this.context = context;
this.sensors = sensors;
this.sensorOptimizer = sensorOptimizer;
this.progress = progress;
}
public void execute() {
for (Sensor sensor : sort(asList(sensors))) {
progress.checkCancel();
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
sensor.describe(descriptor);
if (sensorOptimizer.shouldExecute(descriptor)) {
executeSensor(context, sensor, descriptor);
}
}
}
private static void executeSensor(SensorContext context, Sensor sensor, DefaultSensorDescriptor descriptor) {
if (LOG.isDebugEnabled()) {
LOG.debug("Execute Sensor: {}", descriptor.name() != null ? descriptor.name() : StringUtils.describe(sensor));
}
sensor.execute(context);
}
private static Collection sort(Collection extensions) {
DirectAcyclicGraph dag = new DirectAcyclicGraph();
for (T extension : extensions) {
dag.add(extension);
for (Object dependency : getDependencies(extension)) {
dag.add(extension, dependency);
}
for (Object generates : getDependents(extension)) {
dag.add(generates, extension);
}
completePhaseDependencies(dag, extension);
}
List sortedList = dag.sort();
return (Collection) sortedList.stream()
.filter(extensions::contains)
.collect(Collectors.toList());
}
/**
* Extension dependencies
*/
private static List