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);
}
Aggregations