Search in sources :

Example 1 with NewBuiltInActiveRule

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]");
}
Also used : BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) 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 2 with NewBuiltInActiveRule

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());
    }
}
Also used : BelongsToProfile(org.sonar.check.BelongsToProfile) NewBuiltInActiveRule(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule)

Aggregations

NewBuiltInActiveRule (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule)2 Map (java.util.Map)1 Test (org.junit.Test)1 BuiltInQualityProfile (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile)1 NewBuiltInQualityProfile (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile)1 BelongsToProfile (org.sonar.check.BelongsToProfile)1