Search in sources :

Example 1 with Checks

use of org.sonar.api.batch.rule.Checks in project sonar-go by SonarSource.

the class GoSensorTest method getSensor.

private GoSensor getSensor(String... activeRuleArray) {
    Set<String> activeRuleSet = new HashSet<>(Arrays.asList(activeRuleArray));
    List<Class> ruleClasses = GoChecks.getChecks();
    List<String> allKeys = ruleClasses.stream().map(ruleClass -> ((org.sonar.check.Rule) ruleClass.getAnnotations()[0]).key()).collect(Collectors.toList());
    ActiveRulesBuilder rulesBuilder = new ActiveRulesBuilder();
    allKeys.forEach(key -> {
        NewActiveRule newActiveRule = rulesBuilder.create(RuleKey.of(GoRulesDefinition.REPOSITORY_KEY, key));
        if (activeRuleSet.contains(key)) {
            newActiveRule.activate();
        }
    });
    ActiveRules activeRules = rulesBuilder.build();
    CheckFactory checkFactory = new CheckFactory(activeRules);
    Checks<Check> checks = checkFactory.create(GoRulesDefinition.REPOSITORY_KEY);
    checks.addAnnotatedChecks((Iterable) ruleClasses);
    return new GoSensor(checkFactory, fileLinesContextFactory);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) InputFile(org.sonar.api.batch.fs.InputFile) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) HashMap(java.util.HashMap) ActiveRules(org.sonar.api.batch.rule.ActiveRules) Mockito.spy(org.mockito.Mockito.spy) HashSet(java.util.HashSet) FileLinesContext(org.sonar.api.measures.FileLinesContext) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) CheckFactory(org.sonar.api.batch.rule.CheckFactory) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Map(java.util.Map) Checks(org.sonar.api.batch.rule.Checks) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) Check(org.sonar.commonruleengine.checks.Check) Awaitility.await(org.awaitility.Awaitility.await) Files(java.nio.file.Files) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) Set(java.util.Set) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) CoreMetrics(org.sonar.api.measures.CoreMetrics) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) TypeOfText(org.sonar.api.batch.sensor.highlighting.TypeOfText) Test(org.junit.jupiter.api.Test) List(java.util.List) RuleKey(org.sonar.api.rule.RuleKey) Mockito.any(org.mockito.Mockito.any) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Mockito.mock(org.mockito.Mockito.mock) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) Check(org.sonar.commonruleengine.checks.Check) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ActiveRules(org.sonar.api.batch.rule.ActiveRules) CheckFactory(org.sonar.api.batch.rule.CheckFactory) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Awaitility.await (org.awaitility.Awaitility.await)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)1 Mockito.any (org.mockito.Mockito.any)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.spy (org.mockito.Mockito.spy)1