use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule in project sonarqube by SonarSource.
the class BuiltInQualityProfilesDefinitionTest method sanityEqualCheck.
@Test
public void sanityEqualCheck() {
Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> {
NewBuiltInQualityProfile profile1 = c.createBuiltInQualityProfile("Foo1", "xoo");
NewBuiltInActiveRule rule = profile1.activateRule("repo", "rule");
profile1.done();
NewBuiltInQualityProfile profile2 = c.createBuiltInQualityProfile("Foo2", "xoo");
profile2.done();
NewBuiltInQualityProfile profile3 = c.createBuiltInQualityProfile("Foo1", "xoo2");
profile3.done();
assertThat(profile1).isNotNull();
assertThat(profile1).isNotEqualTo(profile2);
assertThat(profile1).isNotEqualTo(profile3);
assertThat(profile1.hashCode()).isNotEqualTo(profile2.hashCode());
assertThat(profile1.name()).isNotEqualTo("Foo");
assertThat(profile1.toString()).hasToString("NewBuiltInQualityProfile{name='Foo1', language='xoo', default='false'}");
assertThat(rule.toString()).hasToString("[repository=repo, key=rule]");
});
BuiltInQualityProfile profile1 = profiles.get("xoo").get("Foo1");
BuiltInQualityProfile profile2 = profiles.get("xoo").get("Foo2");
BuiltInQualityProfile profile3 = profiles.get("xoo2").get("Foo1");
assertThat(profile1).isNotNull().isNotEqualTo(profile2).isNotEqualTo(profile3);
assertThat(profile1.hashCode()).isNotEqualTo(profile2.hashCode());
assertThat(profile1.name()).isNotEqualTo("Foo");
assertThat(profile1.toString()).hasToString("BuiltInQualityProfile{name='Foo1', language='xoo', default='false'}");
assertThat(profile1.rule(RuleKey.of("repo", "rule")).toString()).hasToString("[repository=repo, key=rule]");
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule in project sonarqube by SonarSource.
the class BuiltInQualityProfileAnnotationLoader method loadActiveRule.
void loadActiveRule(BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile profile, String repositoryKey, Class<?> clazz) {
BelongsToProfile belongsToProfile = clazz.getAnnotation(BelongsToProfile.class);
if ((belongsToProfile != null) && StringUtils.equals(belongsToProfile.title(), profile.name())) {
String ruleKey = RuleAnnotationUtils.getRuleKey(clazz);
NewBuiltInActiveRule activeRule = profile.activateRule(repositoryKey, ruleKey);
activeRule.overrideSeverity(belongsToProfile.priority().name());
}
}
Aggregations