Search in sources :

Example 1 with ProfileExporter

use of org.sonar.api.profiles.ProfileExporter in project sonarqube by SonarSource.

the class ExportAction method define.

@Override
public void define(WebService.NewController controller) {
    NewAction action = controller.createAction("export").setSince("5.2").setDescription("Export a quality profile.").setResponseExample(getClass().getResource("export-example.xml")).setHandler(this);
    action.createParam(PARAM_PROFILE_NAME).setDescription("The name of the quality profile to export. If left empty, will export the default profile for the language.").setExampleValue("My Sonar way");
    action.createParam(PARAM_LANGUAGE).setDescription("The language for the quality profile.").setExampleValue(LanguageParamUtils.getExampleValue(languages)).setPossibleValues(LanguageParamUtils.getLanguageKeys(languages)).setRequired(true);
    Set<String> exporterKeys = Arrays.stream(languages.all()).map(language -> exporters.exportersForLanguage(language.getKey())).flatMap(Collection::stream).map(ProfileExporter::getKey).collect(Collectors.toSet());
    if (!exporterKeys.isEmpty()) {
        action.createParam(PARAM_FORMAT).setDescription("Output format. If left empty, the same format as api/qualityprofiles/backup is used. " + "Possible values are described by api/qualityprofiles/exporters.").setPossibleValues(exporterKeys).setDeprecatedKey("format", "6.3");
    }
}
Also used : Arrays(java.util.Arrays) QProfileExporters(org.sonar.server.qualityprofile.QProfileExporters) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) WsUtils.checkFound(org.sonar.server.ws.WsUtils.checkFound) Response(org.sonar.api.server.ws.Response) OutputStreamWriter(java.io.OutputStreamWriter) ProfileExporter(org.sonar.api.profiles.ProfileExporter) MediaTypes(org.sonarqube.ws.MediaTypes) Nullable(javax.annotation.Nullable) OutputStream(java.io.OutputStream) Collection(java.util.Collection) Stream(org.sonar.api.server.ws.Response.Stream) LanguageParamUtils(org.sonar.server.util.LanguageParamUtils) Set(java.util.Set) Collectors(org.sonar.core.util.stream.Collectors) IOException(java.io.IOException) NewAction(org.sonar.api.server.ws.WebService.NewAction) StandardCharsets(java.nio.charset.StandardCharsets) DbClient(org.sonar.db.DbClient) Writer(java.io.Writer) QProfileBackuper(org.sonar.server.qualityprofile.QProfileBackuper) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Collection(java.util.Collection) NewAction(org.sonar.api.server.ws.WebService.NewAction)

Example 2 with ProfileExporter

use of org.sonar.api.profiles.ProfileExporter in project sonarqube by SonarSource.

the class QProfileExporters method export.

public void export(QualityProfileDto profile, String exporterKey, Writer writer) {
    ProfileExporter exporter = findExporter(exporterKey);
    exporter.exportProfile(wrap(profile), writer);
}
Also used : ProfileExporter(org.sonar.api.profiles.ProfileExporter)

Example 3 with ProfileExporter

use of org.sonar.api.profiles.ProfileExporter in project sonarqube by SonarSource.

the class ExportersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    JsonWriter json = response.newJsonWriter().beginObject().name("exporters").beginArray();
    for (ProfileExporter exporter : exporters) {
        json.beginObject().prop("key", exporter.getKey()).prop("name", exporter.getName());
        json.name("languages").beginArray();
        for (String language : exporter.getSupportedLanguages()) {
            json.value(language);
        }
        json.endArray().endObject();
    }
    json.endArray().endObject().close();
}
Also used : ProfileExporter(org.sonar.api.profiles.ProfileExporter) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Aggregations

ProfileExporter (org.sonar.api.profiles.ProfileExporter)3 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 Languages (org.sonar.api.resources.Languages)1 Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 Stream (org.sonar.api.server.ws.Response.Stream)1 WebService (org.sonar.api.server.ws.WebService)1 NewAction (org.sonar.api.server.ws.WebService.NewAction)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 Collectors (org.sonar.core.util.stream.Collectors)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1