Search in sources :

Example 1 with DefaultSensorDescriptor

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();
}
Also used : TestInputFileBuilder(testutils.TestInputFileBuilder) DefaultSensorDescriptor(org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultSensorDescriptor

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();
}
Also used : MapSettings(org.sonarsource.sonarlint.core.analysis.sonarapi.MapSettings) DefaultSensorDescriptor(org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultSensorDescriptor

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();
}
Also used : DefaultSensorDescriptor(org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor) ActiveRules(org.sonar.api.batch.rule.ActiveRules) ActiveRulesAdapter(org.sonarsource.sonarlint.core.analysis.sonarapi.ActiveRulesAdapter) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultSensorDescriptor

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);
        }
    }
}
Also used : DefaultSensorDescriptor(org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor) Sensor(org.sonar.api.batch.sensor.Sensor)

Example 5 with DefaultSensorDescriptor

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();
}
Also used : TestInputFileBuilder(testutils.TestInputFileBuilder) DefaultSensorDescriptor(org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultSensorDescriptor (org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor)5 Test (org.junit.jupiter.api.Test)4 TestInputFileBuilder (testutils.TestInputFileBuilder)2 ActiveRules (org.sonar.api.batch.rule.ActiveRules)1 Sensor (org.sonar.api.batch.sensor.Sensor)1 ActiveRulesAdapter (org.sonarsource.sonarlint.core.analysis.sonarapi.ActiveRulesAdapter)1 MapSettings (org.sonarsource.sonarlint.core.analysis.sonarapi.MapSettings)1