Search in sources :

Example 6 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 7 with ValidationMessages

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

the class CreateActionTest method createImporters.

private ProfileImporter[] createImporters() {
    class DefaultProfileImporter extends ProfileImporter {

        private DefaultProfileImporter() {
            super("xoo_lint", "Xoo Lint");
            setSupportedLanguages(XOO_LANGUAGE);
        }

        @Override
        public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
            RulesProfile rulesProfile = RulesProfile.create();
            rulesProfile.activateRule(org.sonar.api.rules.Rule.create(RULE.getRepositoryKey(), RULE.getRuleKey()), RulePriority.BLOCKER);
            return rulesProfile;
        }
    }
    class ProfileImporterGeneratingMessages extends ProfileImporter {

        private ProfileImporterGeneratingMessages() {
            super("with_messages", "With messages");
            setSupportedLanguages(XOO_LANGUAGE);
        }

        @Override
        public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
            RulesProfile rulesProfile = RulesProfile.create();
            messages.addWarningText("a warning");
            messages.addInfoText("an info");
            return rulesProfile;
        }
    }
    class ProfileImporterGeneratingErrors extends ProfileImporter {

        private ProfileImporterGeneratingErrors() {
            super("with_errors", "With errors");
            setSupportedLanguages(XOO_LANGUAGE);
        }

        @Override
        public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
            RulesProfile rulesProfile = RulesProfile.create();
            messages.addErrorText("error!");
            return rulesProfile;
        }
    }
    return new ProfileImporter[] { new DefaultProfileImporter(), new ProfileImporterGeneratingMessages(), new ProfileImporterGeneratingErrors() };
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ProfileImporter(org.sonar.api.profiles.ProfileImporter) Reader(java.io.Reader) ValidationMessages(org.sonar.api.utils.ValidationMessages)

Example 8 with ValidationMessages

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

the class SonarWayProfileTest method test.

@Test
public void test() {
    ValidationMessages validationMessages = ValidationMessages.create();
    RulesProfile profile = new SonarWayProfile(ruleFinder()).createProfile(validationMessages);
    Assertions.assertThat(profile.getName()).isEqualTo("Sonar way");
    Assertions.assertThat(profile.getLanguage()).isEqualTo(WebConstants.LANGUAGE_KEY);
    Assertions.assertThat(profile.getActiveRules()).onProperty("repositoryKey").containsOnly(WebRulesDefinition.REPOSITORY_KEY);
    Assertions.assertThat(profile.getActiveRules().size()).isGreaterThan(10);
    assertThat(validationMessages.hasErrors(), is(false));
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ValidationMessages(org.sonar.api.utils.ValidationMessages) Test(org.junit.Test)

Example 9 with ValidationMessages

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

the class QProfileReset method loadDefinitionsGroupedByName.

private ListMultimap<QProfileName, RulesProfile> loadDefinitionsGroupedByName(String language) {
    ListMultimap<QProfileName, RulesProfile> profilesByName = ArrayListMultimap.create();
    for (ProfileDefinition definition : definitions) {
        ValidationMessages validation = ValidationMessages.create();
        RulesProfile profile = definition.createProfile(validation);
        if (language.equals(profile.getLanguage())) {
            processValidationMessages(validation);
            profilesByName.put(new QProfileName(profile.getLanguage(), profile.getName()), profile);
        }
    }
    return profilesByName;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ProfileDefinition(org.sonar.api.profiles.ProfileDefinition) ValidationMessages(org.sonar.api.utils.ValidationMessages)

Example 10 with ValidationMessages

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

the class QProfileExporters method importXml.

private QProfileResult importXml(QualityProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) {
    QProfileResult result = new QProfileResult();
    ValidationMessages messages = ValidationMessages.create();
    ProfileImporter importer = getProfileImporter(importerKey);
    RulesProfile rulesProfile = importer.importProfile(xml, messages);
    List<ActiveRuleChange> changes = importProfile(profileDto, rulesProfile, dbSession);
    result.addChanges(changes);
    processValidationMessages(messages, result);
    return result;
}
Also used : RulesProfile(org.sonar.api.profiles.RulesProfile) ProfileImporter(org.sonar.api.profiles.ProfileImporter) ValidationMessages(org.sonar.api.utils.ValidationMessages)

Aggregations

ValidationMessages (org.sonar.api.utils.ValidationMessages)12 Test (org.junit.Test)7 RulesProfile (org.sonar.api.profiles.RulesProfile)5 Reader (java.io.Reader)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ProfileDefinition (org.sonar.api.profiles.ProfileDefinition)2 ProfileImporter (org.sonar.api.profiles.ProfileImporter)2 ActiveRule (org.sonar.api.rules.ActiveRule)2 Rule (org.sonar.api.rules.Rule)2 RuleFinder (org.sonar.api.rules.RuleFinder)2 RuleDebt (org.sonar.server.debt.DebtModelXMLExporter.RuleDebt)1