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());
}
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();
}
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");
}
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);
}
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");
}
Aggregations