import org.sonar.server.es.SearchOptions;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleQuery;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse.CompareToSonarWay;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse.QualityProfile;
+import org.sonarqube.ws.QualityProfiles;
+import org.sonarqube.ws.QualityProfiles.ShowResponse;
+import org.sonarqube.ws.QualityProfiles.ShowResponse.CompareToSonarWay;
+import org.sonarqube.ws.QualityProfiles.ShowResponse.QualityProfile;
import static java.util.Collections.singletonList;
import static org.sonar.api.rule.RuleStatus.DEPRECATED;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.server.ws.WsUtils.checkFound;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SHOW;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
@Override
public void define(WebService.NewController controller) {
- NewAction show = controller.createAction("show")
+ NewAction show = controller.createAction(ACTION_SHOW)
.setSince("6.5")
.setDescription("Show a quality profile")
.setResponseExample(getClass().getResource("show-example.json"))
.build();
}
- private static ShowWsResponse buildResponse(QProfileDto profile, boolean isDefault, Language language, long activeRules, long deprecatedActiveRules, long projects,
- @Nullable CompareToSonarWay compareToSonarWay) {
- ShowWsResponse.Builder showResponseBuilder = ShowWsResponse.newBuilder();
+ private static ShowResponse buildResponse(QProfileDto profile, boolean isDefault, Language language, long activeRules, long deprecatedActiveRules, long projects,
+ @Nullable CompareToSonarWay compareToSonarWay) {
+ ShowResponse.Builder showResponseBuilder = QualityProfiles.ShowResponse.newBuilder();
QualityProfile.Builder profileBuilder = QualityProfile.newBuilder()
.setKey(profile.getKee())
.setName(profile.getName())
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.MediaTypes;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse.CompareToSonarWay;
+import org.sonarqube.ws.QualityProfiles;
+import org.sonarqube.ws.QualityProfiles.ShowResponse;
+import org.sonarqube.ws.QualityProfiles.ShowResponse.CompareToSonarWay;
import static java.util.stream.IntStream.range;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.server.language.LanguageTesting.newLanguage;
import static org.sonar.test.JsonAssert.assertJson;
-import static org.sonarqube.ws.QualityProfiles.ShowWsResponse.QualityProfile;
+import static org.sonarqube.ws.QualityProfiles.ShowResponse.QualityProfile;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
public void profile_info() {
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ QualityProfiles.ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile())
.extracting(QualityProfile::getKey, QualityProfile::getName, QualityProfile::getIsBuiltIn, QualityProfile::getLanguage, QualityProfile::getLanguageName,
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
db.qualityProfiles().setAsDefault(profile);
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ QualityProfiles.ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile().getIsDefault()).isTrue();
}
QProfileDto defaultProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
db.qualityProfiles().setAsDefault(defaultProfile);
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile().getIsDefault()).isFalse();
}
.setLastUsed(time)
.setUserUpdatedAt(time));
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ QualityProfiles.ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile().getRulesUpdatedAt()).isEqualTo("2016-12-21T19:10:03+0100");
assertThat(parseDateTime(result.getProfile().getLastUsed()).getTime()).isEqualTo(time);
.mapToObj(i -> db.components().insertPrivateProject())
.forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ QualityProfiles.ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile())
.extracting(QualityProfile::getActiveRuleCount, QualityProfile::getActiveDeprecatedRuleCount, QualityProfile::getProjectCount)
p -> p.setIsBuiltIn(true).setName("Another Sonar way").setLanguage(XOO1.getKey()));
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest()
+ ShowResponse result = call(ws.newRequest()
.setParam(PARAM_PROFILE, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"));
QProfileDto sonarWayProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
QProfileDto anotherBuiltInProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(true).setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest()
+ QualityProfiles.ShowResponse result = call(ws.newRequest()
.setParam(PARAM_PROFILE, anotherBuiltInProfile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"));
QProfileDto sonarWayProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(false).setName("Sonar way").setLanguage(XOO1.getKey()));
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest()
+ QualityProfiles.ShowResponse result = call(ws.newRequest()
.setParam(PARAM_PROFILE, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"));
QProfileDto sonarWayProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest()
+ QualityProfiles.ShowResponse result = call(ws.newRequest()
.setParam(PARAM_PROFILE, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "false"));
assertJson(result).ignoreFields("rulesUpdatedAt", "lastUsed", "userUpdatedAt").isSimilarTo(ws.getDef().responseExampleAsString());
}
- private ShowWsResponse call(TestRequest request) {
+ private ShowResponse call(TestRequest request) {
TestRequest wsRequest = request.setMediaType(MediaTypes.PROTOBUF);
- return wsRequest.executeProtobuf(ShowWsResponse.class);
+ return wsRequest.executeProtobuf(QualityProfiles.ShowResponse.class);
}
}
public static final String ACTION_REMOVE_PROJECT = "remove_project";
public static final String ACTION_RESTORE = "restore";
public static final String ACTION_SEARCH = "search";
+ public static final String ACTION_SHOW = "show";
public static final String ACTION_SET_DEFAULT = "set_default";
public static final String PARAM_DEFAULTS = "defaults";
package org.sonarqube.ws.client.qualityprofile;
import org.sonarqube.ws.MediaTypes;
+import org.sonarqube.ws.QualityProfiles;
import org.sonarqube.ws.QualityProfiles.CopyWsResponse;
import org.sonarqube.ws.QualityProfiles.CreateWsResponse;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
+import org.sonarqube.ws.QualityProfiles.ShowResponse;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_RESTORE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SET_DEFAULT;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SHOW;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.CONTROLLER_QUALITY_PROFILES;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_FROM_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
SearchWsResponse.parser());
}
+ public QualityProfiles.ShowResponse show(ShowRequest request) {
+ return call(
+ new GetRequest(path(ACTION_SHOW))
+ .setParam(PARAM_PROFILE, request.getProfile())
+ .setParam(PARAM_COMPARE_TO_SONAR_WAY, request.getCompareToSonarWay()),
+ ShowResponse.parser());
+ }
+
public void addProject(AddProjectRequest request) {
call(new PostRequest(path(ACTION_ADD_PROJECT))
.setParam(PARAM_LANGUAGE, request.getLanguage())
--- /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.sonarqube.ws.client.qualityprofile;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class ShowRequest {
+ private String profile;
+ private Boolean compareToSonarWay;
+
+ @CheckForNull
+ public String getProfile() {
+ return profile;
+ }
+
+ public ShowRequest setProfile(@Nullable String profile) {
+ this.profile = profile;
+ return this;
+ }
+
+ @CheckForNull
+ public Boolean getCompareToSonarWay() {
+ return compareToSonarWay;
+ }
+
+ public ShowRequest setCompareToSonarWay(@Nullable Boolean compareToSonarWay) {
+ this.compareToSonarWay = compareToSonarWay;
+ return this;
+ }
+}
}
// WS api/qualityprofiles/show
-message ShowWsResponse {
+message ShowResponse {
optional QualityProfile profile = 1;
optional CompareToSonarWay compareToSonarWay = 2;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.ws.Common.Severity;
-import org.sonarqube.ws.QualityProfiles;
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
+import org.sonarqube.ws.QualityProfiles.ShowResponse;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.ServiceTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_FROM_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
.setProfileName("profile"));
GetRequest getRequest = serviceTester.getGetRequest();
- assertThat(serviceTester.getGetParser()).isSameAs(QualityProfiles.SearchWsResponse.parser());
+ assertThat(serviceTester.getGetParser()).isSameAs(SearchWsResponse.parser());
serviceTester.assertThat(getRequest)
.hasPath("search")
.hasParam(PARAM_DEFAULTS, true)
.andNoOtherParam();
}
+ @Test
+ public void show() {
+ underTest.show(new ShowRequest()
+ .setProfile("profile")
+ .setCompareToSonarWay(true));
+ GetRequest getRequest = serviceTester.getGetRequest();
+
+ assertThat(serviceTester.getGetParser()).isSameAs(ShowResponse.parser());
+ serviceTester.assertThat(getRequest)
+ .hasPath("show")
+ .hasParam(PARAM_PROFILE, "profile")
+ .hasParam(PARAM_COMPARE_TO_SONAR_WAY, true)
+ .andNoOtherParam();
+ }
+
@Test
public void add_project() throws Exception {
underTest.addProject(AddProjectRequest.builder()