Search in sources :

Example 1 with LoadedActiveRule

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;
}
Also used : LoadedActiveRule(org.sonar.api.batch.rule.LoadedActiveRule)

Example 2 with LoadedActiveRule

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();
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) RuleKey(org.sonar.api.rule.RuleKey) LoadedActiveRule(org.sonar.api.batch.rule.LoadedActiveRule) HashSet(java.util.HashSet)

Example 3 with LoadedActiveRule

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;
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) LoadedActiveRule(org.sonar.api.batch.rule.LoadedActiveRule) LinkedList(java.util.LinkedList) SearchResponse(org.sonarqube.ws.Rules.SearchResponse)

Example 4 with LoadedActiveRule

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);
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) LoadedActiveRule(org.sonar.api.batch.rule.LoadedActiveRule) Test(org.junit.Test)

Example 5 with LoadedActiveRule

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;
}
Also used : LoadedActiveRule(org.sonar.api.batch.rule.LoadedActiveRule)

Aggregations

LoadedActiveRule (org.sonar.api.batch.rule.LoadedActiveRule)9 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)2 RuleKey (org.sonar.api.rule.RuleKey)2 HashSet (java.util.HashSet)1 ActiveRules (org.sonar.api.batch.rule.ActiveRules)1 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)1 Active (org.sonarqube.ws.Rules.Active)1 Param (org.sonarqube.ws.Rules.Active.Param)1 ActiveList (org.sonarqube.ws.Rules.ActiveList)1 Rule (org.sonarqube.ws.Rules.Rule)1 SearchResponse (org.sonarqube.ws.Rules.SearchResponse)1 GetRequest (org.sonarqube.ws.client.GetRequest)1