ActivateRuleAction.class,
DeactivateRuleAction.class,
SearchAction.class,
- SetDefaultAction.class
+ SetDefaultAction.class,
+ ShowAction.class
);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.NewAction;
+import org.sonarqube.ws.QualityProfiles.ShowWsResponse;
+import org.sonarqube.ws.QualityProfiles.ShowWsResponse.CompareToSonarWay;
+
+import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
+import static org.sonar.server.ws.WsUtils.writeProtobuf;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+
+public class ShowAction implements QProfileWsAction {
+
+ @Override
+ public void define(WebService.NewController controller) {
+ NewAction show = controller.createAction("show")
+ .setSince("6.5")
+ .setDescription("Show a quality profile")
+ .setResponseExample(getClass().getResource("show-example.json"))
+ .setInternal(true)
+ .setHandler(this);
+
+ show.createParam(PARAM_PROFILE)
+ .setDescription("Quality profile key")
+ .setExampleValue(UUID_EXAMPLE_01)
+ .setRequired(true);
+
+ show.createParam(PARAM_COMPARE_TO_SONAR_WAY)
+ .setDescription("Add the number of missing rules from the related Sonar way profile in the response")
+ .setInternal(true)
+ .setBooleanPossibleValues();
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ ShowWsResponse showWsResponse = ShowWsResponse.newBuilder()
+ .setProfile(ShowWsResponse.QualityProfile.newBuilder()
+ .setKey("AU-TpxcA-iU5OvuD2FL3")
+ .setName("My Company Profile")
+ .setLanguage("cs")
+ .setLanguageName("C#")
+ .setIsInherited(true)
+ .setIsBuiltIn(false)
+ .setIsDefault(false)
+ .setParentKey("AU-TpxcA-iU5OvuD2FL1")
+ .setParentName("Parent Company Profile")
+ .setActiveRuleCount(10)
+ .setActiveDeprecatedRuleCount(0)
+ .setProjectCount(7)
+ .setRuleUpdatedAt("2016-12-22T19:10:03+0100")
+ .setLastUsed("2016-12-01T19:10:03+0100"))
+ .setCompareToSonarWay(CompareToSonarWay.newBuilder()
+ .setProfile("iU5OvuD2FLz")
+ .setProfileName("Sonar way")
+ .setMissingRuleCount(4)
+ .build())
+ .build();
+ writeProtobuf(showWsResponse, request, response);
+ }
+
+}
--- /dev/null
+{
+ "profile": {
+ "key": "AU-TpxcA-iU5OvuD2FL3",
+ "name": "My Company Profile",
+ "language": "cs",
+ "languageName": "C#",
+ "isInherited": true,
+ "isBuiltIn": false,
+ "isDefault": false,
+ "parentKey": "AU-TpxcA-iU5OvuD2FL1",
+ "parentName": "Parent Company Profile",
+ "activeRuleCount": 10,
+ "activeDeprecatedRuleCount": 0,
+ "projectCount": 7,
+ "ruleUpdatedAt": "2016-12-22T19:10:03+0100",
+ "lastUsed": "2016-12-01T19:10:03+0100"
+ },
+ "compareToSonarWay": {
+ "profile": "iU5OvuD2FLz",
+ "profileName": "Sonar way",
+ "missingRuleCount": 4
+ }
+}
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new QProfilesWsModule().configure(container);
- assertThat(container.size()).isEqualTo(26 + 2);
+ assertThat(container.size()).isEqualTo(27 + 2);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.Rule;
+import org.junit.Test;
+import org.sonar.api.resources.Language;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.db.DbTester;
+import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.server.ws.WsActionTester;
+
+import static java.util.stream.IntStream.range;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.language.LanguageTesting.newLanguage;
+import static org.sonar.test.JsonAssert.assertJson;
+
+public class ShowActionTest {
+
+ @Rule
+ public DbTester db = DbTester.create();
+
+ private WsActionTester ws = new WsActionTester(new ShowAction());
+
+ @Test
+ public void test_definition() {
+ WebService.Action action = ws.getDef();
+ assertThat(action.key()).isEqualTo("show");
+ assertThat(action.responseExampleAsString()).isNotEmpty();
+ assertThat(action.isPost()).isFalse();
+ assertThat(action.since()).isEqualTo("6.5");
+
+ WebService.Param profile = action.param("profile");
+ assertThat(profile).isNotNull();
+ assertThat(profile.isRequired()).isTrue();
+ assertThat(profile.isInternal()).isFalse();
+ assertThat(profile.description()).isNotEmpty();
+
+ WebService.Param compareToSonarWay = action.param("compareToSonarWay");
+ assertThat(compareToSonarWay).isNotNull();
+ assertThat(compareToSonarWay.isRequired()).isFalse();
+ assertThat(compareToSonarWay.isInternal()).isTrue();
+ assertThat(compareToSonarWay.description()).isNotEmpty();
+ assertThat(compareToSonarWay.possibleValues()).contains("true", "false");
+ }
+
+ @Test
+ public void test_example() {
+ Language cs = newLanguage("cs", "C#");
+ QProfileDto parentProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setKee("AU-TpxcA-iU5OvuD2FL1").setName("Parent Company Profile"));
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p
+ .setKee("AU-TpxcA-iU5OvuD2FL3")
+ .setName("My Company Profile")
+ .setLanguage(cs.getKey())
+ .setIsBuiltIn(false)
+ .setRulesUpdatedAt("2016-12-22T19:10:03+0100")
+ .setParentKee(parentProfile.getKee()));
+ // Active rules
+ range(0, 10)
+ .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey())).getDefinition())
+ .forEach(r -> db.qualityProfiles().activateRule(profile, r));
+ // Projects
+ range(0, 7)
+ .mapToObj(i -> db.components().insertPrivateProject())
+ .forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
+
+ String result = ws.newRequest().execute().getInput();
+
+ assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString());
+ }
+}
public static final String PARAM_TARGET_SEVERITY = "targetSeverity";
public static final String PARAM_TO = "to";
public static final String PARAM_TO_NAME = "toName";
+ public static final String PARAM_COMPARE_TO_SONAR_WAY = "compareToSonarWay";
private QualityProfileWsParameters() {
// Only static stuff
optional bool isInherited = 6;
optional string parentKey = 7;
}
+
+// WS api/qualityprofiles/show
+message ShowWsResponse {
+ optional QualityProfile profile = 1;
+ optional CompareToSonarWay compareToSonarWay = 2;
+
+ message QualityProfile {
+ optional string key = 1;
+ optional string name = 2;
+ optional string language = 3;
+ optional string languageName = 4;
+ optional bool isInherited = 5;
+ optional string parentKey = 6;
+ optional string parentName = 7;
+ optional bool isDefault = 8;
+ optional int64 activeRuleCount = 9;
+ optional int64 activeDeprecatedRuleCount = 12;
+ optional int64 projectCount = 10;
+ optional string ruleUpdatedAt = 11;
+ optional string lastUsed = 13;
+ optional string userUpdatedAt = 14;
+ optional string organization = 15;
+ optional bool isBuiltIn = 16;
+ }
+
+ message CompareToSonarWay {
+ optional string profile = 1;
+ optional string profileName = 2;
+ optional int64 missingRuleCount = 3;
+ }
+}