use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class CheckFactoryTest method checks_as_objects.
/**
* SONAR-2900
*/
@Test
public void checks_as_objects() {
RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithStringProperty");
NewActiveRule rule = new NewActiveRule.Builder().setRuleKey(ruleKey).setParam("pattern", "foo").build();
builder.addRule(rule);
CheckFactory checkFactory = new CheckFactory(builder.build());
CheckWithStringProperty check = new CheckWithStringProperty();
Checks checks = checkFactory.create("squid").addAnnotatedChecks(check);
Object createdCheck = checks.of(ruleKey);
assertThat(createdCheck).isSameAs(check);
assertThat(((CheckWithStringProperty) createdCheck).getPattern()).isEqualTo("foo");
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class CheckFactoryTest method param_as_string_field.
@Test
public void param_as_string_field() {
RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithStringProperty");
NewActiveRule rule = new NewActiveRule.Builder().setRuleKey(ruleKey).setParam("pattern", "foo").build();
builder.addRule(rule);
CheckFactory checkFactory = new CheckFactory(builder.build());
Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithStringProperty.class);
Object check = checks.of(ruleKey);
assertThat(check).isInstanceOf(CheckWithStringProperty.class);
assertThat(((CheckWithStringProperty) check).getPattern()).isEqualTo("foo");
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class CheckFactoryTest method override_field_key.
@Test
public void override_field_key() {
RuleKey ruleKey = RuleKey.of("squid", "org.sonar.api.batch.rule.CheckWithOverriddenPropertyKey");
NewActiveRule rule = new NewActiveRule.Builder().setRuleKey(ruleKey).setParam("maximum", "300").build();
builder.addRule(rule);
CheckFactory checkFactory = new CheckFactory(builder.build());
Checks checks = checkFactory.create("squid").addAnnotatedChecks(CheckWithOverriddenPropertyKey.class);
Object check = checks.of(ruleKey);
assertThat(check).isInstanceOf(CheckWithOverriddenPropertyKey.class);
assertThat(((CheckWithOverriddenPropertyKey) check).getMax()).isEqualTo(300);
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarqube by SonarSource.
the class ActiveRulesProvider method transform.
private static ActiveRules transform(Collection<LoadedActiveRule> loadedRules) {
ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (LoadedActiveRule activeRule : loadedRules) {
NewActiveRule newActiveRule = builder.create(activeRule.getRuleKey());
newActiveRule.setName(activeRule.getName());
newActiveRule.setSeverity(activeRule.getSeverity());
newActiveRule.setCreatedAt(activeRule.getCreatedAt());
newActiveRule.setLanguage(activeRule.getLanguage());
newActiveRule.setInternalKey(activeRule.getInternalKey());
newActiveRule.setTemplateRuleKey(activeRule.getTemplateRuleKey());
// load parameters
if (activeRule.getParams() != null) {
for (Map.Entry<String, String> params : activeRule.getParams().entrySet()) {
newActiveRule.setParam(params.getKey(), params.getValue());
}
}
newActiveRule.activate();
}
return builder.build();
}
use of org.sonar.api.batch.rule.internal.NewActiveRule in project sonarlint-core by SonarSource.
the class StandaloneActiveRulesProvider method createActiveRules.
private ActiveRules createActiveRules() {
ActiveRulesBuilder builder = new ActiveRulesBuilder();
ListMultimap<String, RulesProfile> profilesByLanguage = profilesByLanguage(profileDefinitions);
for (String language : profilesByLanguage.keySet()) {
List<RulesProfile> defs = profilesByLanguage.get(language);
registerProfilesForLanguage(builder, language, defs);
}
for (Repository repo : ruleDefsLoader.getContext().repositories()) {
for (Rule rule : repo.rules()) {
if (rule.activatedByDefault()) {
NewActiveRule newAr = builder.create(RuleKey.of(repo.key(), rule.key())).setLanguage(repo.language()).setName(rule.name()).setSeverity(rule.severity()).setInternalKey(rule.internalKey());
for (Param param : rule.params()) {
newAr.setParam(param.key(), param.defaultValue());
}
newAr.activate();
}
}
}
return builder.build();
}
Aggregations