use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class CheckFactoryTest method param_as_inherited_field.
/**
* SONAR-3164
*/
@Test
public void param_as_inherited_field() {
RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithPrimitiveProperties");
NewActiveRule rule = new NewActiveRule.Builder().setRuleKey(ruleKey).setParam("max", "300").build();
builder.addRule(rule);
CheckFactory checkFactory = new CheckFactory(builder.build());
Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithPrimitiveProperties.class);
Object check = checks.of(ruleKey);
assertThat(check).isInstanceOf(CheckWithPrimitiveProperties.class);
assertThat(((CheckWithPrimitiveProperties) check).getMax()).isEqualTo(300);
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class CheckFactoryTest method param_as_primitive_fields.
@Test
public void param_as_primitive_fields() {
RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithPrimitiveProperties");
NewActiveRule rule = new NewActiveRule.Builder().setRuleKey(ruleKey).setParam("max", "300").setParam("ignore", "true").build();
builder.addRule(rule);
CheckFactory checkFactory = new CheckFactory(builder.build());
Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithPrimitiveProperties.class);
Object check = checks.of(ruleKey);
assertThat(check).isInstanceOf(CheckWithPrimitiveProperties.class);
assertThat(((CheckWithPrimitiveProperties) check).getMax()).isEqualTo(300);
assertThat(((CheckWithPrimitiveProperties) check).isIgnore()).isTrue();
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class CheckFactoryTest method use_template_rule_key.
@Test
public void use_template_rule_key() {
RuleKey ruleKey = RuleKey.of("squid", "S0001_123");
NewActiveRule rule = new NewActiveRule.Builder().setRuleKey(ruleKey).setTemplateRuleKey("S0001").build();
builder.addRule(rule);
CheckFactory checkFactory = new CheckFactory(builder.build());
Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithKey.class);
Object check = checks.of(ruleKey);
assertThat(check).isInstanceOf(CheckWithKey.class);
assertThat(checks.of(ruleKey)).isSameAs(check);
assertThat(checks.ruleKey(check)).isEqualTo(ruleKey);
assertThat(checks.all()).containsOnly(check);
}
use of org.sonar.api.batch.rule.internal.NewActiveRule 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