use of org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor in project sonarlint-core by SonarSource.
the class SensorOptimizerTests method should_optimize_on_language.
@Test
void should_optimize_on_language() {
var descriptor = new DefaultSensorDescriptor().onlyOnLanguages("java", "php");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
inputFileCache.doAdd(new TestInputFileBuilder("src/Foo.java").setLanguage(Language.JAVA).build());
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
use of org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor in project sonarlint-core by SonarSource.
the class SensorOptimizerTests method should_optimize_on_settings.
@Test
void should_optimize_on_settings() {
var descriptor = new DefaultSensorDescriptor().onlyWhenConfiguration(c -> c.hasKey("sonar.foo.reportPath"));
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
settings = new MapSettings(Map.of("sonar.foo.reportPath", "foo"));
optimizer = new SensorOptimizer(fs, mock(ActiveRules.class), settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
use of org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor in project sonarlint-core by SonarSource.
the class SensorOptimizerTests method should_optimize_on_repository.
@Test
void should_optimize_on_repository() {
var descriptor = new DefaultSensorDescriptor().createIssuesForRuleRepositories("squid");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
var ruleAnotherRepo = mock(ActiveRuleAdapter.class);
when(ruleAnotherRepo.ruleKey()).thenReturn(RuleKey.of("repo1", "foo"));
ActiveRules activeRules = new ActiveRulesAdapter(List.of(ruleAnotherRepo));
optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
var ruleSquid = mock(ActiveRuleAdapter.class);
when(ruleSquid.ruleKey()).thenReturn(RuleKey.of("squid", "rule"));
activeRules = new ActiveRulesAdapter(asList(ruleSquid, ruleAnotherRepo));
optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
use of org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor in project sonarlint-core by SonarSource.
the class SensorsExecutor method execute.
public void execute() {
for (Sensor sensor : sort(asList(sensors))) {
progress.checkCancel();
var descriptor = new DefaultSensorDescriptor();
sensor.describe(descriptor);
if (sensorOptimizer.shouldExecute(descriptor)) {
executeSensor(context, sensor, descriptor);
}
}
}
use of org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor in project sonarlint-core by SonarSource.
the class SensorOptimizerTests method should_optimize_on_type.
@Test
void should_optimize_on_type() {
var descriptor = new DefaultSensorDescriptor().onlyOnFileType(InputFile.Type.MAIN);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
inputFileCache.doAdd(new TestInputFileBuilder("tests/FooTest.java").setType(InputFile.Type.TEST).build());
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
inputFileCache.doAdd(new TestInputFileBuilder("src/Foo.java").setType(InputFile.Type.MAIN).build());
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
Aggregations