Search in sources :

Example 1 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonar-web by SonarSource.

the class WebSensorTest method setUp.

@Before
public void setUp() throws Exception {
    WebRulesDefinition rulesDefinition = new WebRulesDefinition();
    RulesDefinition.Context context = new RulesDefinition.Context();
    rulesDefinition.define(context);
    RulesDefinition.Repository repository = context.repository(WebRulesDefinition.REPOSITORY_KEY);
    List<NewActiveRule> ar = new ArrayList<>();
    for (RulesDefinition.Rule rule : repository.rules()) {
        ar.add(new ActiveRulesBuilder().create(RuleKey.of(WebRulesDefinition.REPOSITORY_KEY, rule.key())));
    }
    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));
    sensor = new WebSensor(new NoSonarFilter(), fileLinesContextFactory, checkFactory);
    tester = SensorContextTester.create(TEST_DIR);
}
Also used : FileLinesContext(org.sonar.api.measures.FileLinesContext) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) 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) WebRulesDefinition(org.sonar.plugins.web.rules.WebRulesDefinition) 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) WebRulesDefinition(org.sonar.plugins.web.rules.WebRulesDefinition) FileLinesContext(org.sonar.api.measures.FileLinesContext) Before(org.junit.Before)

Example 2 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules 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 3 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules 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 4 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules 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 5 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.

the class ActiveRulesProvider method provide.

@Bean("ActiveRules")
public DefaultActiveRules provide(ActiveRulesLoader loader, QualityProfiles qProfiles) {
    Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
    DefaultActiveRules activeRules = load(loader, qProfiles);
    profiler.stopInfo();
    return activeRules;
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) Profiler(org.sonar.api.utils.log.Profiler) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)18 Test (org.junit.Test)15 CheckFactory (org.sonar.api.batch.rule.CheckFactory)5 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)5 RuleKey (org.sonar.api.rule.RuleKey)5 IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)5 SonarRuntime (org.sonar.api.SonarRuntime)4 ActiveRules (org.sonar.api.batch.rule.ActiveRules)3 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)3 WildcardPattern (org.sonar.api.utils.WildcardPattern)3 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 InputFile (org.sonar.api.batch.fs.InputFile)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)2 File (java.io.File)1 LoadedActiveRule (org.sonar.api.batch.rule.LoadedActiveRule)1