Search in sources :

Example 1 with BuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile in project sonarqube by SonarSource.

the class BuiltInQProfileRepositoryImpl method toQualityProfileBuilders.

/**
 * Creates {@link BuiltInQProfile.Builder} for each unique quality profile name for a given language.
 * Builders will have the following properties populated:
 * <ul>
 *   <li>{@link BuiltInQProfile.Builder#language language}: key of the method's parameter</li>
 *   <li>{@link BuiltInQProfile.Builder#name name}: {@link RulesProfile#getName()}</li>
 *   <li>{@link BuiltInQProfile.Builder#declaredDefault declaredDefault}: {@code true} if at least one RulesProfile
 *       with a given name has {@link RulesProfile#getDefaultProfile()} is {@code true}</li>
 *   <li>{@link BuiltInQProfile.Builder#activeRules activeRules}: the concatenate of the active rules of all
 *       RulesProfile with a given name</li>
 * </ul>
 */
private static List<BuiltInQProfile.Builder> toQualityProfileBuilders(Map.Entry<String, Map<String, BuiltInQualityProfile>> rulesProfilesByLanguageAndName, Map<RuleKey, RuleDefinitionDto> rulesByRuleKey) {
    String language = rulesProfilesByLanguageAndName.getKey();
    // use a LinkedHashMap to keep order of insertion of RulesProfiles
    Map<String, BuiltInQProfile.Builder> qualityProfileBuildersByName = new LinkedHashMap<>();
    for (BuiltInQualityProfile builtInProfile : rulesProfilesByLanguageAndName.getValue().values()) {
        qualityProfileBuildersByName.compute(builtInProfile.name(), (name, existingBuilder) -> updateOrCreateBuilder(language, existingBuilder, builtInProfile, rulesByRuleKey));
    }
    return ImmutableList.copyOf(qualityProfileBuildersByName.values());
}
Also used : BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with BuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile in project sonarqube by SonarSource.

the class BuiltInQualityProfilesDefinitionTest method createEmptyProfile.

@Test
public void createEmptyProfile() {
    Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> c.createBuiltInQualityProfile("Foo", "xoo").done());
    assertThat(profiles).containsOnlyKeys("xoo");
    assertThat(profiles.get("xoo")).containsOnlyKeys("Foo");
    BuiltInQualityProfile profile = profiles.get("xoo").get("Foo");
    assertThat(profile.name()).isEqualTo("Foo");
    assertThat(profile.language()).isEqualTo("xoo");
    assertThat(profile.isDefault()).isFalse();
}
Also used : BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Map(java.util.Map) Test(org.junit.Test)

Example 3 with BuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile in project sonarqube by SonarSource.

the class BuiltInQualityProfilesDefinitionTest method createProfileWithRules.

@Test
public void createProfileWithRules() {
    Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> {
        NewBuiltInQualityProfile profile = c.createBuiltInQualityProfile("Foo", "xoo");
        profile.activateRule("repo", "ruleWithoutParam");
        profile.activateRule("repo", "ruleWithSeverity").overrideSeverity("CRITICAL");
        profile.activateRule("repo", "ruleWithParam").overrideParam("param", "value");
        profile.done();
    });
    assertThat(profiles).containsOnlyKeys("xoo");
    assertThat(profiles.get("xoo")).containsOnlyKeys("Foo");
    BuiltInQualityProfile profile = profiles.get("xoo").get("Foo");
    assertThat(profile.name()).isEqualTo("Foo");
    assertThat(profile.language()).isEqualTo("xoo");
    assertThat(profile.isDefault()).isFalse();
    assertThat(profile.rules()).extracting(BuiltInQualityProfilesDefinition.BuiltInActiveRule::repoKey, BuiltInQualityProfilesDefinition.BuiltInActiveRule::ruleKey, BuiltInQualityProfilesDefinition.BuiltInActiveRule::overriddenSeverity, r -> r.overriddenParams().size()).containsOnly(tuple("repo", "ruleWithoutParam", null, 0), tuple("repo", "ruleWithSeverity", "CRITICAL", 0), tuple("repo", "ruleWithParam", null, 1));
    assertThat(profile.rule(RuleKey.of("repo", "ruleWithParam")).overriddenParam("param").key()).isEqualTo("param");
    assertThat(profile.rule(RuleKey.of("repo", "ruleWithParam")).overriddenParam("param").overriddenValue()).isEqualTo("value");
}
Also used : BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Consumer(java.util.function.Consumer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RuleKey(org.sonar.api.rule.RuleKey) BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) Test(org.junit.Test) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ExpectedException(org.junit.rules.ExpectedException) NewBuiltInActiveRule(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Map(java.util.Map) Test(org.junit.Test)

Example 4 with BuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile in project sonar-web by SonarSource.

the class SonarWayProfileTest method test.

@Test
public void test() {
    SonarWayProfile definition = new SonarWayProfile();
    Context context = new Context();
    definition.define(context);
    BuiltInQualityProfile profile = context.profile("web", "Sonar way");
    Assertions.assertThat(profile.name()).isEqualTo("Sonar way");
    Assertions.assertThat(profile.language()).isEqualTo(HtmlConstants.LANGUAGE_KEY);
    Assertions.assertThat(profile.rules().size()).isGreaterThan(10);
}
Also used : Context(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.Context) BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) Test(org.junit.Test)

Example 5 with BuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile in project sonarqube by SonarSource.

the class XooBuiltInQualityProfilesDefinitionTest method test_built_in_quality_profile.

@Test
public void test_built_in_quality_profile() {
    BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
    underTest.define(context);
    BuiltInQualityProfile profile = context.profile("xoo", "test BuiltInQualityProfilesDefinition");
    assertThat(profile.isDefault()).isFalse();
    assertThat(profile.name()).isEqualTo("test BuiltInQualityProfilesDefinition");
    assertThat(profile.language()).isEqualTo("xoo");
    assertThat(profile.rules()).hasSize(1);
    BuiltInQualityProfilesDefinition.BuiltInActiveRule activeRule = profile.rule(RuleKey.of("xoo", "HasTag"));
    assertThat(activeRule.overriddenSeverity()).isEqualTo("BLOCKER");
    assertThat(activeRule.overriddenParams()).hasSize(1);
    assertThat(activeRule.overriddenParam("tag").overriddenValue()).isEqualTo("TODO");
}
Also used : BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) Test(org.junit.Test)

Aggregations

BuiltInQualityProfile (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile)7 Test (org.junit.Test)6 Map (java.util.Map)4 NewBuiltInQualityProfile (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile)4 NewBuiltInActiveRule (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule)2 LinkedHashMap (java.util.LinkedHashMap)1 Consumer (java.util.function.Consumer)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)1 ExpectedException (org.junit.rules.ExpectedException)1 RuleKey (org.sonar.api.rule.RuleKey)1 BuiltInQualityProfilesDefinition (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition)1 Context (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.Context)1