use of org.sonar.api.profiles.ProfileImporter in project sonarqube by SonarSource.
the class CreateAction method define.
@Override
public void define(WebService.NewController controller) {
NewAction create = controller.createAction(ACTION_CREATE).setSince("5.2").setDescription("Create a quality profile.<br/>" + "Require Administer Quality Profiles permission.").setPost(true).setResponseExample(getClass().getResource("example-create.json")).setHandler(this);
create.createParam(PARAM_PROFILE_NAME).setDescription("The name for the new quality profile. Since 6.1, this parameter has been renamed from '%s' to '%s'", DEPRECATED_PARAM_PROFILE_NAME, PARAM_PROFILE_NAME).setExampleValue("My Sonar way").setDeprecatedKey(DEPRECATED_PARAM_PROFILE_NAME, "6.3").setRequired(true);
create.createParam(PARAM_LANGUAGE).setDescription("The language for the quality profile.").setExampleValue("js").setPossibleValues(LanguageParamUtils.getLanguageKeys(languages)).setRequired(true);
for (ProfileImporter importer : importers) {
create.createParam(getBackupParamName(importer.getKey())).setDescription(String.format("A configuration file for %s.", importer.getName()));
}
}
use of org.sonar.api.profiles.ProfileImporter 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.profiles.ProfileImporter 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;
}
use of org.sonar.api.profiles.ProfileImporter in project sonarqube by SonarSource.
the class CreateAction method doHandle.
private CreateWsResponse doHandle(DbSession dbSession, CreateRequest createRequest, Request request) {
QProfileResult result = new QProfileResult();
QualityProfileDto profile = profileFactory.create(dbSession, QProfileName.createFor(createRequest.getLanguage(), createRequest.getProfileName()));
result.setProfile(profile);
for (ProfileImporter importer : importers) {
String importerKey = importer.getKey();
InputStream contentToImport = request.paramAsInputStream(getBackupParamName(importerKey));
if (contentToImport != null) {
result.add(exporters.importXml(profile, importerKey, contentToImport, dbSession));
}
}
dbSession.commit();
activeRuleIndexer.index(result.getChanges());
return buildResponse(result);
}
use of org.sonar.api.profiles.ProfileImporter in project sonarqube by SonarSource.
the class ImportersAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
JsonWriter json = response.newJsonWriter().beginObject().name("importers").beginArray();
for (ProfileImporter importer : importers) {
json.beginObject().prop("key", importer.getKey()).prop("name", importer.getName()).name("languages").beginArray();
for (String languageKey : importer.getSupportedLanguages()) {
json.value(languageKey);
}
json.endArray().endObject();
}
json.endArray().endObject().close();
}
Aggregations