Search in sources :

Example 1 with ValidationMessages

use of org.sonar.api.utils.ValidationMessages in project sonarqube by SonarSource.

the class FakeRule method shouldParseOnlyWantedProfile.

@Test
public void shouldParseOnlyWantedProfile() {
    RuleFinder ruleFinder = mock(RuleFinder.class);
    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {

        public Rule answer(InvocationOnMock iom) throws Throwable {
            return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
        }
    });
    ValidationMessages messages = ValidationMessages.create();
    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
    assertThat(profile.getActiveRule("squid", "fake")).isNotNull();
    assertThat(profile.getActiveRule("squid", "other")).isNull();
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Rule(org.sonar.api.rules.Rule) Matchers.anyString(org.mockito.Matchers.anyString) RuleFinder(org.sonar.api.rules.RuleFinder) ValidationMessages(org.sonar.api.utils.ValidationMessages) Test(org.junit.Test)

Example 2 with ValidationMessages

use of org.sonar.api.utils.ValidationMessages in project sonarqube by SonarSource.

the class FakeRule method shouldParseAnnotatedClasses.

@Test
public void shouldParseAnnotatedClasses() {
    RuleFinder ruleFinder = mock(RuleFinder.class);
    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {

        public Rule answer(InvocationOnMock iom) throws Throwable {
            return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
        }
    });
    ValidationMessages messages = ValidationMessages.create();
    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages);
    assertThat(profile.getName()).isEqualTo("Foo way");
    assertThat(profile.getLanguage()).isEqualTo("java");
    assertThat(profile.getActiveRule("squid", "fake").getSeverity()).isEqualTo(RulePriority.BLOCKER);
    assertThat(messages.hasErrors()).isFalse();
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Rule(org.sonar.api.rules.Rule) Matchers.anyString(org.mockito.Matchers.anyString) RuleFinder(org.sonar.api.rules.RuleFinder) ValidationMessages(org.sonar.api.utils.ValidationMessages) Test(org.junit.Test)

Example 3 with ValidationMessages

use of org.sonar.api.utils.ValidationMessages in project sonarqube by SonarSource.

the class DeprecatedRulesDefinitionLoader method loadRuleDebtsFromXml.

public List<RuleDebt> loadRuleDebtsFromXml(String pluginKey) {
    Reader xmlFileReader = null;
    try {
        xmlFileReader = languageModelFinder.createReaderForXMLFile(pluginKey);
        ValidationMessages validationMessages = ValidationMessages.create();
        List<RuleDebt> rules = importer.importXML(xmlFileReader, validationMessages);
        validationMessages.log(LOG);
        return rules;
    } finally {
        IOUtils.closeQuietly(xmlFileReader);
    }
}
Also used : Reader(java.io.Reader) RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt) ValidationMessages(org.sonar.api.utils.ValidationMessages)

Example 4 with ValidationMessages

use of org.sonar.api.utils.ValidationMessages in project sonarqube by SonarSource.

the class RegisterQualityProfiles method profilesByLanguage.

/**
   * @return profiles by language
   */
private ListMultimap<String, RulesProfile> profilesByLanguage() {
    ListMultimap<String, RulesProfile> byLang = ArrayListMultimap.create();
    for (ProfileDefinition definition : definitions) {
        ValidationMessages validation = ValidationMessages.create();
        RulesProfile profile = definition.createProfile(validation);
        validation.log(LOGGER);
        if (profile != null && !validation.hasErrors()) {
            byLang.put(StringUtils.lowerCase(profile.getLanguage()), profile);
        }
    }
    return byLang;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ProfileDefinition(org.sonar.api.profiles.ProfileDefinition) ValidationMessages(org.sonar.api.utils.ValidationMessages)

Example 5 with ValidationMessages

use of org.sonar.api.utils.ValidationMessages in project sonarlint-core by SonarSource.

the class StandaloneActiveRulesProvider method profilesByLanguage.

private static ListMultimap<String, RulesProfile> profilesByLanguage(ProfileDefinition[] profileDefinitions) {
    ListMultimap<String, RulesProfile> byLang = ArrayListMultimap.create();
    for (ProfileDefinition definition : profileDefinitions) {
        ValidationMessages validation = ValidationMessages.create();
        RulesProfile profile = definition.createProfile(validation);
        if (profile != null && !validation.hasErrors()) {
            byLang.put(StringUtils.lowerCase(profile.getLanguage()), profile);
        }
    }
    return byLang;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ProfileDefinition(org.sonar.api.profiles.ProfileDefinition) ValidationMessages(org.sonar.api.utils.ValidationMessages)

Aggregations

ValidationMessages (org.sonar.api.utils.ValidationMessages)16 Test (org.junit.Test)8 RulesProfile (org.sonar.api.profiles.RulesProfile)7 ProfileDefinition (org.sonar.api.profiles.ProfileDefinition)3 ProfileImporter (org.sonar.api.profiles.ProfileImporter)3 Reader (java.io.Reader)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ActiveRule (org.sonar.api.rules.ActiveRule)2 Rule (org.sonar.api.rules.Rule)2 RuleFinder (org.sonar.api.rules.RuleFinder)2 BuiltInQualityProfilesDefinition (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition)2 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1 RuleDebt (org.sonar.server.debt.DebtModelXMLExporter.RuleDebt)1