--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.qualityprofile.ws;
+
+import org.sonar.api.profiles.ProfileExporter;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService.NewController;
+import org.sonar.api.utils.text.JsonWriter;
+
+public class QProfileExportersAction implements BaseQProfileWsAction {
+
+ private ProfileExporter[] exporters;
+
+ public QProfileExportersAction(ProfileExporter[] exporters) {
+ this.exporters = exporters;
+ }
+
+ public QProfileExportersAction() {
+ this(new ProfileExporter[0]);
+ }
+
+ @Override
+ public void define(NewController context) {
+ context.createAction("exporters")
+ .setDescription("Lists available profile export formats.")
+ .setHandler(this)
+ .setInternal(true)
+ .setResponseExample(getClass().getResource("example-exporters.json"))
+ .setSince("5.2");
+ }
+
+ @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();
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.qualityprofile.ws;
+
+import org.junit.Test;
+import org.sonar.api.profiles.ProfileExporter;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.server.ws.WsTester;
+
+import java.io.Writer;
+
+import static org.mockito.Mockito.mock;
+
+public class QProfileExportersActionTest {
+
+ @Test
+ public void importers_nominal() throws Exception {
+ WsTester wsTester = new WsTester(new QProfilesWs(
+ mock(RuleActivationActions.class), mock(BulkRuleActivationActions.class), mock(ProjectAssociationActions.class),
+ new QProfileExportersAction(createExporters())));
+
+ wsTester.newGetRequest("api/qualityprofiles", "exporters").execute().assertJson(getClass(), "exporters.json");
+ }
+
+ private ProfileExporter[] createExporters() {
+ class NoopImporter extends ProfileExporter {
+ private NoopImporter(String key, String name, String... languages) {
+ super(key, name);
+ setSupportedLanguages(languages);
+ }
+
+ @Override
+ public void exportProfile(RulesProfile profile, Writer writer) {
+ // Nothing
+ }
+
+ }
+ return new ProfileExporter[] {
+ new NoopImporter("findbugs", "FindBugs", "java"),
+ new NoopImporter("jslint", "JS Lint", "js"),
+ new NoopImporter("vaadin", "Vaadin", "java", "js")
+ };
+ }
+}
--- /dev/null
+{
+ "exporters": [
+ {"key": "findbugs", "name": "FindBugs", "languages": ["java"]},
+ {"key": "jslint", "name": "JS Lint", "languages": ["js"]},
+ {"key": "vaadin", "name": "Vaadin", "languages": ["java", "js"]}
+ ]
+}