use of org.sonar.api.batch.rule.LoadedActiveRule in project sonarqube by SonarSource.
the class ScannerMediumTester method addActiveRule.
public ScannerMediumTester addActiveRule(String repositoryKey, String ruleKey, @Nullable String templateRuleKey, String name, @Nullable String severity, @Nullable String internalKey, @Nullable String language) {
LoadedActiveRule r = new LoadedActiveRule();
r.setInternalKey(internalKey);
r.setRuleKey(RuleKey.of(repositoryKey, ruleKey));
r.setName(name);
r.setTemplateRuleKey(templateRuleKey);
r.setLanguage(language);
r.setSeverity(severity);
r.setDeprecatedKeys(emptySet());
activeRules.addActiveRule(r);
return this;
}
use of org.sonar.api.batch.rule.LoadedActiveRule in project sonarqube by SonarSource.
the class ActiveRulesProvider method load.
private static DefaultActiveRules load(ActiveRulesLoader loader, QualityProfiles qProfiles) {
Collection<String> qProfileKeys = getKeys(qProfiles);
Set<RuleKey> loadedRulesKey = new HashSet<>();
ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (String qProfileKey : qProfileKeys) {
Collection<LoadedActiveRule> qProfileRules = load(loader, qProfileKey);
for (LoadedActiveRule r : qProfileRules) {
if (!loadedRulesKey.contains(r.getRuleKey())) {
loadedRulesKey.add(r.getRuleKey());
builder.addRule(transform(r, qProfileKey, r.getDeprecatedKeys()));
}
}
}
return builder.build();
}
use of org.sonar.api.batch.rule.LoadedActiveRule in project sonarqube by SonarSource.
the class DefaultActiveRulesLoader method load.
@Override
public List<LoadedActiveRule> load(String qualityProfileKey) {
List<LoadedActiveRule> ruleList = new LinkedList<>();
int page = 1;
int pageSize = 500;
long loaded = 0;
while (true) {
GetRequest getRequest = new GetRequest(getUrl(qualityProfileKey, page, pageSize));
SearchResponse response = loadFromStream(wsClient.call(getRequest).contentStream());
List<LoadedActiveRule> pageRules = readPage(response);
ruleList.addAll(pageRules);
loaded += response.getPs();
if (response.getTotal() <= loaded) {
break;
}
page++;
}
return ruleList;
}
use of org.sonar.api.batch.rule.LoadedActiveRule in project sonarqube by SonarSource.
the class ActiveRulesProviderTest method testCombinationOfRules.
@Test
public void testCombinationOfRules() {
LoadedActiveRule r1 = mockRule("rule1");
LoadedActiveRule r2 = mockRule("rule2");
LoadedActiveRule r3 = mockRule("rule3");
List<LoadedActiveRule> qp1Rules = ImmutableList.of(r1, r2);
List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3);
List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3);
when(loader.load("qp1")).thenReturn(qp1Rules);
when(loader.load("qp2")).thenReturn(qp2Rules);
when(loader.load("qp3")).thenReturn(qp3Rules);
QualityProfiles profiles = mockProfiles("qp1", "qp2", "qp3");
DefaultActiveRules activeRules = provider.provide(loader, profiles);
assertThat(activeRules.findAll()).hasSize(3);
assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly(RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3"));
verify(loader).load("qp1");
verify(loader).load("qp2");
verify(loader).load("qp3");
assertThat(activeRules.getDeprecatedRuleKeys(RuleKey.of("rule1", "rule1"))).containsOnly("rule1old:rule1old");
verifyNoMoreInteractions(loader);
}
use of org.sonar.api.batch.rule.LoadedActiveRule in project sonarqube by SonarSource.
the class ActiveRulesProviderTest method mockRule.
private static LoadedActiveRule mockRule(String name) {
LoadedActiveRule r = new LoadedActiveRule();
r.setName(name);
r.setRuleKey(RuleKey.of(name, name));
r.setDeprecatedKeys(ImmutableSet.of(RuleKey.of(name + "old", name + "old")));
return r;
}
Aggregations