Search in sources :

Example 11 with SonarRuntime

use of org.sonar.api.SonarRuntime 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 12 with SonarRuntime

use of org.sonar.api.SonarRuntime in project sonar-web by SonarSource.

the class HtmlSensorTest method setUp.

@Before
public void setUp() {
    HtmlRulesDefinition rulesDefinition = new HtmlRulesDefinition();
    RulesDefinition.Context context = new RulesDefinition.Context();
    rulesDefinition.define(context);
    RulesDefinition.Repository repository = context.repository(HtmlRulesDefinition.REPOSITORY_KEY);
    List<NewActiveRule> ar = new ArrayList<>();
    for (RulesDefinition.Rule rule : repository.rules()) {
        ar.add(new NewActiveRule.Builder().setRuleKey(RuleKey.of(HtmlRulesDefinition.REPOSITORY_KEY, rule.key())).build());
    }
    ActiveRules activeRules = new DefaultActiveRules(ar);
    CheckFactory checkFactory = new CheckFactory(activeRules);
    FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
    when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class));
    final SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(8, 9), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
    sensor = new HtmlSensor(sonarRuntime, new NoSonarFilter(), fileLinesContextFactory, checkFactory);
    tester = SensorContextTester.create(TEST_DIR).setRuntime(sonarRuntime);
}
Also used : FileLinesContext(org.sonar.api.measures.FileLinesContext) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) HtmlRulesDefinition(org.sonar.plugins.html.rules.HtmlRulesDefinition) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) ArrayList(java.util.ArrayList) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) RulesDefinition(org.sonar.api.server.rule.RulesDefinition) HtmlRulesDefinition(org.sonar.plugins.html.rules.HtmlRulesDefinition) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) ActiveRules(org.sonar.api.batch.rule.ActiveRules) CheckFactory(org.sonar.api.batch.rule.CheckFactory) SonarRuntime(org.sonar.api.SonarRuntime) FileLinesContext(org.sonar.api.measures.FileLinesContext) Before(org.junit.Before)

Example 13 with SonarRuntime

use of org.sonar.api.SonarRuntime in project sonarqube by SonarSource.

the class XooPluginTest method provide_extensions_for_5_4.

@Test
public void provide_extensions_for_5_4() {
    SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4"));
    Plugin.Context context = new Plugin.Context(runtime);
    new XooPlugin().define(context);
    assertThat(context.getExtensions()).hasSize(44).doesNotContain(CpdTokenizerSensor.class);
}
Also used : SonarRuntime(org.sonar.api.SonarRuntime) Plugin(org.sonar.api.Plugin) Test(org.junit.Test)

Example 14 with SonarRuntime

use of org.sonar.api.SonarRuntime in project sonarlint-core by SonarSource.

the class DefaultServerTest method shouldLoadServerProperties.

@Test
public void shouldLoadServerProperties() {
    SonarRuntime runtime = mock(SonarRuntime.class);
    when(runtime.getApiVersion()).thenReturn(Version.create(2, 2));
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.SERVER_ID, "123");
    settings.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000");
    settings.setProperty(CoreProperties.PERMANENT_SERVER_ID, "abcde");
    DefaultServer metadata = new DefaultServer(settings, runtime);
    assertThat(metadata.getId()).isEqualTo("123");
    assertThat(metadata.getVersion()).isEqualTo("2.2");
    assertThat(metadata.getStartedAt()).isNotNull();
    assertThat(metadata.getURL()).isNull();
    assertThat(metadata.getPermanentServerId()).isEqualTo("abcde");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) SonarRuntime(org.sonar.api.SonarRuntime) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.Test)

Example 15 with SonarRuntime

use of org.sonar.api.SonarRuntime in project sonar-java by SonarSource.

the class JavaPluginTest method sonarqube_6_7_extensions.

@Test
public void sonarqube_6_7_extensions() {
    SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_6_7, SonarQubeSide.SERVER);
    Plugin.Context context = new Plugin.Context(runtime);
    javaPlugin.define(context);
    assertThat(context.getExtensions()).hasSize(24);
}
Also used : SonarRuntime(org.sonar.api.SonarRuntime) Plugin(org.sonar.api.Plugin) Test(org.junit.Test)

Aggregations

SonarRuntime (org.sonar.api.SonarRuntime)21 Test (org.junit.Test)18 Plugin (org.sonar.api.Plugin)7 CheckFactory (org.sonar.api.batch.rule.CheckFactory)4 DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)4 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)3 MapSettings (org.sonar.api.config.internal.MapSettings)3 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.jupiter.api.Test)1 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 ActiveRules (org.sonar.api.batch.rule.ActiveRules)1 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)1 Settings (org.sonar.api.config.Settings)1 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)1 FileLinesContext (org.sonar.api.measures.FileLinesContext)1 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)1 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)1 HtmlRulesDefinition (org.sonar.plugins.html.rules.HtmlRulesDefinition)1