use of org.sonar.api.impl.server.RulesDefinitionContext in project sonarqube by SonarSource.
the class RuleDefinitionsLoader method load.
public RulesDefinition.Context load() {
RulesDefinition.Context context = new RulesDefinitionContext();
for (RulesDefinition pluginDefinition : pluginDefs) {
context.setCurrentPluginKey(serverPluginRepository.getPluginKey(pluginDefinition));
pluginDefinition.define(context);
}
context.setCurrentPluginKey(null);
coreCommonDefs.define(context);
return context;
}
use of org.sonar.api.impl.server.RulesDefinitionContext in project sonarqube by SonarSource.
the class ScannerMediumTester method addRules.
public ScannerMediumTester addRules(RulesDefinition rulesDefinition) {
RulesDefinition.Context context = new RulesDefinitionContext();
rulesDefinition.define(context);
List<Repository> repositories = context.repositories();
for (Repository repo : repositories) {
for (RulesDefinition.Rule rule : repo.rules()) {
this.addRule(rule.key(), rule.repository().key(), rule.internalKey(), rule.name());
}
}
return this;
}
use of org.sonar.api.impl.server.RulesDefinitionContext in project sonarqube by SonarSource.
the class RulesDefinitionAnnotationLoaderTest method override_annotation_programmatically.
@Test
public void override_annotation_programmatically() {
RulesDefinition.Context context = new RulesDefinitionContext();
RulesDefinition.NewRepository newRepository = context.createRepository("squid", "java");
NewRule newRule = annotationLoader.loadRule(newRepository, RuleWithProperty.class);
newRule.setName("Overridden name");
newRule.param("property").setDefaultValue("true");
newRule.param("property").setDescription("Overridden");
newRepository.done();
RulesDefinition.Repository repository = context.repository("squid");
assertThat(repository.rules()).hasSize(1);
RulesDefinition.Rule rule = repository.rules().get(0);
assertThat(rule.key()).isEqualTo("foo");
assertThat(rule.status()).isEqualTo(RuleStatus.BETA);
assertThat(rule.name()).isEqualTo("Overridden name");
assertThat(rule.htmlDescription()).isEqualTo("Foo Bar");
assertThat(rule.severity()).isEqualTo(Severity.BLOCKER);
assertThat(rule.params()).hasSize(1);
RulesDefinition.Param prop = rule.param("property");
assertThat(prop.key()).isEqualTo("property");
assertThat(prop.description()).isEqualTo("Overridden");
assertThat(prop.defaultValue()).isEqualTo("true");
assertThat(prop.type()).isEqualTo(RuleParamType.STRING);
}
use of org.sonar.api.impl.server.RulesDefinitionContext in project sonarqube by SonarSource.
the class RulesDefinitionXmlLoaderTest method load.
private RulesDefinition.Repository load(String xml) {
RulesDefinition.Context context = new RulesDefinitionContext();
RulesDefinition.NewRepository newRepository = context.createRepository("squid", "java");
underTest.load(newRepository, new StringReader(xml));
newRepository.done();
return context.repository("squid");
}
use of org.sonar.api.impl.server.RulesDefinitionContext in project sonarqube by SonarSource.
the class DefaultRepositoryTest method create_simple_repo.
@Test
public void create_simple_repo() {
RulesDefinitionContext ctx = mock(RulesDefinitionContext.class);
DefaultNewRepository newRepo = new DefaultNewRepository(ctx, "key", "lang", false);
newRepo.createRule("rule1").setName("rule1").setHtmlDescription("desc");
newRepo.setName("name");
DefaultRepository repo = new DefaultRepository(newRepo, null);
assertThat(repo.isExternal()).isFalse();
assertThat(repo.key()).isEqualTo("key");
assertThat(repo.language()).isEqualTo("lang");
assertThat(repo.isExternal()).isFalse();
assertThat(repo.name()).isEqualTo("name");
assertThat(repo.rules()).extracting(RulesDefinition.Rule::key).containsOnly("rule1");
}
Aggregations