Search in sources :

Example 6 with DefaultSensorDescriptor

use of org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor in project sonarqube by SonarSource.

the class ModuleSensorOptimizerTest method should_optimize_on_both_type_and_language.

@Test
public void should_optimize_on_both_type_and_language() {
    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor().onlyOnLanguages("java", "php").onlyOnFileType(InputFile.Type.MAIN);
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    fs.add(new TestInputFileBuilder("foo", "tests/FooTest.java").setLanguage("java").setType(InputFile.Type.TEST).build());
    fs.add(new TestInputFileBuilder("foo", "src/Foo.cbl").setLanguage("cobol").setType(InputFile.Type.MAIN).build());
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    fs.add(new TestInputFileBuilder("foo", "src/Foo.java").setLanguage("java").setType(InputFile.Type.MAIN).build());
    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) Test(org.junit.Test)

Example 7 with DefaultSensorDescriptor

use of org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor in project sonarqube by SonarSource.

the class ModuleSensorOptimizerTest method should_optimize_on_settings.

@Test
public void should_optimize_on_settings() {
    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
    descriptor.onlyWhenConfiguration(c -> c.hasKey("sonar.foo.reportPath"));
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    settings.setProperty("sonar.foo.reportPath", "foo");
    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
Also used : DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) Test(org.junit.Test)

Example 8 with DefaultSensorDescriptor

use of org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor in project sonar-web by SonarSource.

the class HtmlSensorTest method test_descriptor_sonarqube_9_3_reflection_failure.

@Test
public void test_descriptor_sonarqube_9_3_reflection_failure() {
    DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor();
    SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 3), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
    new HtmlSensor(sonarRuntime, null, null, new CheckFactory(new DefaultActiveRules(Collections.emptyList()))).describe(sensorDescriptor);
    assertThat(sensorDescriptor.name()).isEqualTo("HTML");
    assertThat(sensorDescriptor.languages()).isEmpty();
    assertTrue(logTester.logs().contains("Could not call SensorDescriptor.processesFilesIndependently() method"));
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) SonarRuntime(org.sonar.api.SonarRuntime) CheckFactory(org.sonar.api.batch.rule.CheckFactory) Test(org.junit.Test)

Example 9 with DefaultSensorDescriptor

use of org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor in project sonar-web by SonarSource.

the class HtmlSensorTest method test_descriptor_sonarlint.

@Test
public void test_descriptor_sonarlint() {
    DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor();
    SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarLint(Version.create(6, 5));
    new HtmlSensor(sonarRuntime, null, null, new CheckFactory(new DefaultActiveRules(Collections.emptyList()))).describe(sensorDescriptor);
    assertThat(sensorDescriptor.name()).isEqualTo("HTML");
    assertThat(sensorDescriptor.languages()).isEmpty();
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) SonarRuntime(org.sonar.api.SonarRuntime) CheckFactory(org.sonar.api.batch.rule.CheckFactory) Test(org.junit.Test)

Example 10 with DefaultSensorDescriptor

use of org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor in project sonarqube by SonarSource.

the class SensorOptimizerTest method should_optimize_on_settings.

@Test
public void should_optimize_on_settings() {
    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor().requireProperty("sonar.foo.reportPath");
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    settings.setProperty("sonar.foo.reportPath", "foo");
    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
Also used : DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) Test(org.junit.Test)

Aggregations

DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)28 Test (org.junit.Test)26 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)10 SonarRuntime (org.sonar.api.SonarRuntime)3 ActiveRules (org.sonar.api.batch.rule.ActiveRules)3 CheckFactory (org.sonar.api.batch.rule.CheckFactory)3 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)3 DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)3 Test (org.junit.jupiter.api.Test)1 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)1 Sensor (org.sonar.api.batch.sensor.Sensor)1 MapSettings (org.sonar.api.config.internal.MapSettings)1