pico.addSingleton(QProfileBackupAction.class);
pico.addSingleton(QProfileRestoreAction.class);
pico.addSingleton(QProfileCreateAction.class);
+ pico.addSingleton(QProfileImportersAction.class);
pico.addSingleton(QProfilesWs.class);
pico.addSingleton(ProfilesWs.class);
pico.addSingleton(RuleActivationActions.class);
--- /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.ProfileImporter;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
+
+public class QProfileImportersAction implements BaseQProfileWsAction {
+
+ private final ProfileImporter[] importers;
+
+ public QProfileImportersAction(ProfileImporter[] importers) {
+ this.importers = importers;
+ }
+
+ public QProfileImportersAction() {
+ this(new ProfileImporter[0]);
+ }
+
+ @Override
+ public void define(WebService.NewController controller) {
+ controller.createAction("importers")
+ .setSince("5.2")
+ .setDescription("List supported importers.")
+ .setInternal(true)
+ .setResponseExample(getClass().getResource("example-importers.json"))
+ .setHandler(this);
+ }
+
+ @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();
+ }
+}
--- /dev/null
+{
+ "importers": [
+ {"key": "pmd", "name": "PMD", "languages": ["java"]},
+ {"key": "checkstyle", "name": "Checkstyle", "languages": ["java"]},
+ {"key": "js-lint", "name": "JS Lint", "languages": ["js"]},
+ {"key": "android-lint", "name": "Android Lint", "languages": ["xml", "java"]}
+ ]
+}
--- /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.ProfileImporter;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.utils.ValidationMessages;
+import org.sonar.server.ws.WsTester;
+
+import java.io.Reader;
+
+import static org.mockito.Mockito.mock;
+
+public class QProfileImportersActionTest {
+
+ @Test
+ public void importers_nominal() throws Exception {
+ WsTester wsTester = new WsTester(new QProfilesWs(
+ mock(RuleActivationActions.class), mock(BulkRuleActivationActions.class), mock(ProjectAssociationActions.class),
+ new QProfileImportersAction(createImporters())));
+
+ wsTester.newGetRequest("api/qualityprofiles", "importers").execute().assertJson(getClass(), "importers.json");
+ }
+
+ private ProfileImporter[] createImporters() {
+ class NoopImporter extends ProfileImporter {
+ private NoopImporter(String key, String name, String... languages) {
+ super(key, name);
+ setSupportedLanguages(languages);
+ }
+
+ @Override
+ public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
+ return RulesProfile.create();
+ }
+
+ }
+ return new ProfileImporter[] {
+ new NoopImporter("findbugs", "FindBugs", "java"),
+ new NoopImporter("jslint", "JS Lint", "js"),
+ new NoopImporter("vaadin", "Vaadin", "java", "js")
+ };
+ }
+}
new BulkRuleActivationActions(profileService, ruleService, i18n),
new ProjectAssociationActions(null, null, null, languages),
new QProfileCreateAction(null, null, null, languages, importers),
+ new QProfileImportersAction(importers),
new QProfileRestoreBuiltInAction(null),
new QProfileSearchAction(languages, null, null),
new QProfileSetDefaultAction(languages, null, null),
assertThat(controller).isNotNull();
assertThat(controller.path()).isEqualTo(QProfilesWs.API_ENDPOINT);
assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(13);
- assertThat(controller.actions()).hasSize(10);
+ assertThat(controller.actions()).hasSize(14);
}
@Test
assertThat(create.param("backup_" + xoo2Key)).isNotNull();
assertThat(create.param("backup_" + xoo2Key).isRequired()).isFalse();
}
+
+ @Test
+ public void define_importers_action() throws Exception {
+ WebService.Action importers = controller.action("importers");
+ assertThat(importers).isNotNull();
+ assertThat(importers.isPost()).isFalse();
+ assertThat(importers.isInternal()).isTrue();
+ assertThat(importers.params()).isEmpty();
+ assertThat(importers.responseExampleAsString()).isNotEmpty();
+ }
}
--- /dev/null
+{
+ "importers": [
+ {"key": "findbugs", "name": "FindBugs", "languages": ["java"]},
+ {"key": "jslint", "name": "JS Lint", "languages": ["js"]},
+ {"key": "vaadin", "name": "Vaadin", "languages": ["java", "js"]}
+ ]
+}