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