diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2019-04-04 17:45:26 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-04-04 20:21:05 +0200 |
commit | d08c839cb2433f58a35505da8f58e418c23ce1ae (patch) | |
tree | 3cee508a6cc4d0e2d6415de289ecb3b6eee2797f | |
parent | f3dffef937f4c1608e23a02f43ded50ab7854ac1 (diff) | |
download | sonarqube-d08c839cb2433f58a35505da8f58e418c23ce1ae.tar.gz sonarqube-d08c839cb2433f58a35505da8f58e418c23ce1ae.zip |
Revert "SONAR-11876 Remove ws deprecated in SonarQube 5.X"
This reverts commit e1559e763aa1d3b436b46044a352a43e16aaa38a.
48 files changed, 1149 insertions, 117 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java index b7fc096d6b7..c956af8c87d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java @@ -55,12 +55,14 @@ import static java.lang.String.format; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; +import static org.apache.commons.lang.StringUtils.defaultString; import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime; import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime; import static org.sonar.core.util.stream.MoreCollectors.toList; import static org.sonar.db.Pagination.forPage; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID; +import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_QUERY; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MAX_EXECUTED_AT; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MIN_SUBMITTED_AT; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_ONLY_CURRENTS; @@ -103,12 +105,21 @@ public class ActivityAction implements CeWsAction { new Change("6.1", "field \"logs\" is deprecated and its value is always false"), new Change("6.6", "fields \"branch\" and \"branchType\" added"), new Change("7.1", "field \"pullRequest\" added"), - new Change("7.6", format("The use of module keys in parameters '%s' is deprecated", TEXT_QUERY))) + new Change("7.6", String.format("The use of module keys in parameters '%s' and '%s' is deprecated", TEXT_QUERY, PARAM_COMPONENT_QUERY))) .setSince("5.2"); action.createParam(PARAM_COMPONENT_ID) .setDescription("Id of the component (project) to filter on") .setExampleValue(Uuids.UUID_EXAMPLE_03); + action.createParam(PARAM_COMPONENT_QUERY) + .setDescription(format("Limit search to: <ul>" + + "<li>component names that contain the supplied string</li>" + + "<li>component keys that are exactly the same as the supplied string</li>" + + "</ul>" + + "Must not be set together with %s.<br />" + + "Deprecated and replaced by '%s'", PARAM_COMPONENT_ID, TEXT_QUERY)) + .setExampleValue("Apache") + .setDeprecatedSince("5.5"); action.createParam(TEXT_QUERY) .setDescription(format("Limit search to: <ul>" + "<li>component names that contain the supplied string</li>" + @@ -141,6 +152,10 @@ public class ActivityAction implements CeWsAction { action.createParam(PARAM_MAX_EXECUTED_AT) .setDescription("Maximum date of end of task processing (inclusive)") .setExampleValue("2017-10-19T13:00:00+0200"); + action.createParam(Param.PAGE) + .setDescription("Deprecated parameter") + .setDeprecatedSince("5.5") + .setDeprecatedKey("pageIndex", "5.4"); action.createPageSize(100, MAX_PAGE_SIZE); } @@ -275,7 +290,7 @@ public class ActivityAction implements CeWsAction { private static Request toSearchWsRequest(org.sonar.api.server.ws.Request request) { Request activityWsRequest = new Request() .setComponentId(request.param(PARAM_COMPONENT_ID)) - .setQ(request.param(TEXT_QUERY)) + .setQ(defaultString(request.param(TEXT_QUERY), request.param(PARAM_COMPONENT_QUERY))) .setStatus(request.paramAsStrings(PARAM_STATUS)) .setType(request.param(PARAM_TYPE)) .setMinSubmittedAt(request.param(PARAM_MIN_SUBMITTED_AT)) @@ -284,7 +299,7 @@ public class ActivityAction implements CeWsAction { .setPs(String.valueOf(request.mandatoryParamAsInt(Param.PAGE_SIZE))); checkRequest(activityWsRequest.getComponentId() == null || activityWsRequest.getQ() == null, "%s and %s must not be set at the same time", - PARAM_COMPONENT_ID, TEXT_QUERY); + PARAM_COMPONENT_ID, PARAM_COMPONENT_QUERY); return activityWsRequest; } @@ -299,19 +314,14 @@ public class ActivityAction implements CeWsAction { private List<String> status; private String type; - Request() { - // Nothing to do - } - /** * Example value: "AU-TpxcA-iU5OvuD2FL0" */ - private Request setComponentId(@Nullable String componentId) { + private Request setComponentId(String componentId) { this.componentId = componentId; return this; } - @CheckForNull private String getComponentId() { return componentId; } @@ -319,12 +329,11 @@ public class ActivityAction implements CeWsAction { /** * Example value: "2017-10-19T13:00:00+0200" */ - private Request setMaxExecutedAt(@Nullable String maxExecutedAt) { + private Request setMaxExecutedAt(String maxExecutedAt) { this.maxExecutedAt = maxExecutedAt; return this; } - @CheckForNull private String getMaxExecutedAt() { return maxExecutedAt; } @@ -332,12 +341,11 @@ public class ActivityAction implements CeWsAction { /** * Example value: "2017-10-19T13:00:00+0200" */ - private Request setMinSubmittedAt(@Nullable String minSubmittedAt) { + private Request setMinSubmittedAt(String minSubmittedAt) { this.minSubmittedAt = minSubmittedAt; return this; } - @CheckForNull private String getMinSubmittedAt() { return minSubmittedAt; } @@ -375,12 +383,11 @@ public class ActivityAction implements CeWsAction { /** * Example value: "Apache" */ - private Request setQ(@Nullable String q) { + private Request setQ(String q) { this.q = q; return this; } - @CheckForNull private String getQ() { return q; } @@ -396,12 +403,11 @@ public class ActivityAction implements CeWsAction { * <li>"IN_PROGRESS"</li> * </ul> */ - private Request setStatus(@Nullable List<String> status) { + private Request setStatus(List<String> status) { this.status = status; return this; } - @CheckForNull private List<String> getStatus() { return status; } @@ -413,12 +419,11 @@ public class ActivityAction implements CeWsAction { * <li>"REPORT"</li> * </ul> */ - private Request setType(@Nullable String type) { + private Request setType(String type) { this.type = type; return this; } - @CheckForNull private String getType() { return type; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/CeWsParameters.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/CeWsParameters.java index 6ee0856c486..5b88b6377ef 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/CeWsParameters.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/CeWsParameters.java @@ -26,6 +26,7 @@ public class CeWsParameters { public static final String PARAM_COMPONENT_ID = "componentId"; public static final String DEPRECATED_PARAM_COMPONENT_KEY = "componentKey"; public static final String PARAM_COMPONENT = "component"; + public static final String PARAM_COMPONENT_QUERY = "componentQuery"; public static final String PARAM_TYPE = "type"; public static final String PARAM_STATUS = "status"; public static final String PARAM_ONLY_CURRENTS = "onlyCurrents"; diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentsWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentsWsModule.java index ce1d5b8c298..d594f0b4771 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentsWsModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentsWsModule.java @@ -25,6 +25,7 @@ public class ComponentsWsModule extends Module { @Override protected void configureModule() { add( + ResourcesWs.class, ComponentsWs.class, // actions AppAction.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ResourcesWs.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ResourcesWs.java new file mode 100644 index 00000000000..1fadc7b7d05 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ResourcesWs.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.component.ws; + +import org.sonar.api.server.ws.WebService; +import org.sonar.server.ws.RemovedWebServiceHandler; + +public class ResourcesWs implements WebService { + + @Override + public void define(Context context) { + NewController controller = context.createController("api/resources") + .setDescription("Removed since 6.3, please use api/components and api/measures instead") + .setSince("2.10"); + defineIndexAction(controller); + controller.done(); + } + + private static void defineIndexAction(NewController controller) { + controller.createAction("index") + .setDescription("The web service is removed and you're invited to use the alternatives: " + + "<ul>" + + "<li>if you need one component without measures: api/components/show</li>" + + "<li>if you need one component with measures: api/measures/component</li>" + + "<li>if you need several components without measures: api/components/tree</li>" + + "<li>if you need several components with measures: api/measures/component_tree</li>" + + "</ul>") + .setSince("2.10") + .setDeprecatedSince("5.4") + .setHandler(RemovedWebServiceHandler.INSTANCE) + .setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java index 863e2967a14..361b43b9300 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java @@ -67,7 +67,9 @@ import static org.sonar.core.util.stream.MoreCollectors.toHashSet; import static org.sonar.core.util.stream.MoreCollectors.toList; import static org.sonar.core.util.stream.MoreCollectors.toSet; import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_ROOTS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_IN_LAST; @@ -185,7 +187,8 @@ public class IssueQueryFactory { boolean effectiveOnComponentOnly = false; checkArgument(atMostOneNonNullElement(components, componentUuids, componentKeys, componentRootUuids, componentRoots), - "At most one of the following parameters can be provided: %s and %s", PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS); + "At most one of the following parameters can be provided: %s, %s, %s, %s, %s", + PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS, PARAM_COMPONENTS, PARAM_COMPONENT_ROOTS, PARAM_COMPONENT_UUIDS); if (componentRootUuids != null) { allComponents.addAll(getComponentsFromUuids(session, componentRootUuids)); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java index 07074faed34..a071fdbb4f2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java @@ -22,8 +22,10 @@ package org.sonar.server.issue.ws; import com.google.common.base.Strings; import com.google.common.io.Resources; import java.util.Date; +import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.apache.commons.lang.BooleanUtils; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; @@ -54,6 +56,7 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEE; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUE; public class AssignAction implements IssuesWsAction { + private static final String DEPRECATED_PARAM_ME = "me"; private static final String ASSIGN_TO_ME_VALUE = "_me"; private final System2 system2; @@ -94,6 +97,10 @@ public class AssignAction implements IssuesWsAction { action.createParam(PARAM_ASSIGNEE) .setDescription("Login of the assignee. When not set, it will unassign the issue. Use '%s' to assign to current user", ASSIGN_TO_ME_VALUE) .setExampleValue("admin"); + action.createParam(DEPRECATED_PARAM_ME) + .setDescription("(deprecated) Assign the issue to the logged-in user. Replaced by the parameter assignee=_me") + .setDeprecatedSince("5.2") + .setBooleanPossibleValues(); } @Override @@ -109,7 +116,7 @@ public class AssignAction implements IssuesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(dbSession, issueKey); DefaultIssue issue = issueDto.toDefaultIssue(); - checkArgument(issue.type() != RuleType.SECURITY_HOTSPOT, "Assigning security hotspots is not allowed"); + checkArgument(issue.type() != RuleType.SECURITY_HOTSPOT,"It is not allowed to assign a security hotspot"); UserDto user = getUser(dbSession, login); if (user != null) { checkMembership(dbSession, issueDto, user); @@ -125,7 +132,10 @@ public class AssignAction implements IssuesWsAction { @CheckForNull private String getAssignee(Request request) { String assignee = emptyToNull(request.param(PARAM_ASSIGNEE)); - return ASSIGN_TO_ME_VALUE.equals(assignee) ? userSession.getLogin() : assignee; + if (ASSIGN_TO_ME_VALUE.equals(assignee) || BooleanUtils.isTrue(request.paramAsBoolean(DEPRECATED_PARAM_ME))) { + return userSession.getLogin(); + } + return assignee; } @CheckForNull @@ -138,7 +148,7 @@ public class AssignAction implements IssuesWsAction { private void checkMembership(DbSession dbSession, IssueDto issueDto, UserDto user) { String projectUuid = requireNonNull(issueDto.getProjectUuid()); - ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, projectUuid) + ComponentDto project = Optional.ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null)) .orElseThrow(() -> new IllegalStateException(format("Unknown project %s", projectUuid))); OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(dbSession, project.getOrganizationUuid()) .orElseThrow(() -> new IllegalStateException(format("Unknown organizationMember %s", project.getOrganizationUuid()))); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java index d3fba0d5bc2..31e2af39618 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java @@ -55,8 +55,8 @@ import org.sonar.server.issue.Action; import org.sonar.server.issue.AddTagsAction; import org.sonar.server.issue.AssignAction; import org.sonar.server.issue.IssueChangePostProcessor; -import org.sonar.server.issue.RemoveTagsAction; import org.sonar.server.issue.WebIssueStorage; +import org.sonar.server.issue.RemoveTagsAction; import org.sonar.server.issue.notification.IssueChangeNotification; import org.sonar.server.notification.NotificationManager; import org.sonar.server.user.UserSession; @@ -94,6 +94,7 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGN; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMMENT; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DO_TRANSITION; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUES; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PLAN; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_REMOVE_TAGS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SEND_NOTIFICATIONS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SET_SEVERITY; @@ -154,6 +155,9 @@ public class BulkChangeAction implements IssuesWsAction { .setPossibleValues(RuleType.names()) .setSince("5.5") .setDeprecatedKey("set_type.type", "6.2"); + action.createParam(PARAM_PLAN) + .setDescription("In 5.5, action plans are dropped. Has no effect. To plan the list of issues to a specific action plan (key), or unlink all the issues from an action plan") + .setDeprecatedSince("5.5"); action.createParam(PARAM_DO_TRANSITION) .setDescription("Transition") .setExampleValue(REOPEN) diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java index 1ee42083bcf..326a3689ce4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -85,6 +85,7 @@ import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_SEARCH; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.DEPRECATED_PARAM_ACTION_PLANS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.DEPRECATED_PARAM_AUTHORS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE; import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_COUNT; @@ -95,7 +96,10 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNED; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_AUTHOR; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_BRANCH; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_ROOTS; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_ROOT_UUIDS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AT; @@ -113,6 +117,7 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_TOP_1 import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECT_KEYS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_REPORTERS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RESOLUTIONS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RESOLVED; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES; @@ -135,8 +140,10 @@ public class SearchAction implements IssuesWsAction, Startable { PARAM_SEVERITIES, PARAM_STATUSES, PARAM_RESOLUTIONS, + DEPRECATED_PARAM_ACTION_PLANS, PARAM_RULES, PARAM_ASSIGNEES, + PARAM_REPORTERS, DEPRECATED_PARAM_AUTHORS, PARAM_AUTHOR, PARAM_DIRECTORIES, @@ -181,9 +188,9 @@ public class SearchAction implements IssuesWsAction, Startable { .setHandler(this) .setDescription( "Search for issues.<br>" + - "At most one of the following parameters can be provided at the same time: %s and %s.<br>" + + "At most one of the following parameters can be provided at the same time: %s, %s, %s, %s, %s.<br>" + "Requires the 'Browse' permission on the specified project(s).", - PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS) + PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS, PARAM_COMPONENTS, PARAM_COMPONENT_ROOT_UUIDS, PARAM_COMPONENT_ROOTS) .setSince("3.6") .setChangelog( new Change("7.7", format("Value '%s' in parameter '%s' is deprecated, please use '%s' instead", DEPRECATED_PARAM_AUTHORS, FACETS, PARAM_AUTHOR)), @@ -300,7 +307,9 @@ public class SearchAction implements IssuesWsAction, Startable { private static void addComponentRelatedParams(WebService.NewAction action) { action.createParam(PARAM_ON_COMPONENT_ONLY) .setDescription("Return only issues at a component's level, not on its descendants (modules, directories, files, etc). " + - "This parameter is only considered when componentKeys or componentUuids is set.") + "This parameter is only considered when componentKeys or componentUuids is set. " + + "Using the deprecated componentRoots or componentRootUuids parameters will set this parameter to false. " + + "Using the deprecated components parameter will set this parameter to true.") .setBooleanPossibleValues() .setDefaultValue("false"); @@ -309,6 +318,10 @@ public class SearchAction implements IssuesWsAction, Startable { "A component can be a portfolio, project, module, directory or file.") .setExampleValue(KEY_PROJECT_EXAMPLE_001); + action.createParam(PARAM_COMPONENTS) + .setDeprecatedSince("5.1") + .setDescription("If used, will have the same meaning as componentKeys AND onComponentOnly=true."); + action.createParam(PARAM_COMPONENT_UUIDS) .setDescription("To retrieve issues associated to a specific list of components their sub-components (comma-separated list of component IDs). " + INTERNAL_PARAMETER_DISCLAIMER + @@ -316,6 +329,14 @@ public class SearchAction implements IssuesWsAction, Startable { .setDeprecatedSince("6.5") .setExampleValue("584a89f2-8037-4f7b-b82c-8b45d2d63fb2"); + action.createParam(PARAM_COMPONENT_ROOTS) + .setDeprecatedSince("5.1") + .setDescription("If used, will have the same meaning as componentKeys AND onComponentOnly=false."); + + action.createParam(PARAM_COMPONENT_ROOT_UUIDS) + .setDeprecatedSince("5.1") + .setDescription("If used, will have the same meaning as componentUuids AND onComponentOnly=false."); + action.createParam(PARAM_PROJECTS) .setDescription("To retrieve issues associated to a specific list of projects (comma-separated list of project keys). " + INTERNAL_PARAMETER_DISCLAIMER + @@ -511,7 +532,10 @@ public class SearchAction implements IssuesWsAction, Startable { .setAssigneesUuid(getLogins(dbSession, request.paramAsStrings(PARAM_ASSIGNEES))) .setAuthors(request.hasParam(PARAM_AUTHOR) ? request.multiParam(PARAM_AUTHOR) : request.paramAsStrings(DEPRECATED_PARAM_AUTHORS)) .setComponentKeys(request.paramAsStrings(PARAM_COMPONENT_KEYS)) + .setComponentRootUuids(request.paramAsStrings(PARAM_COMPONENT_ROOT_UUIDS)) + .setComponentRoots(request.paramAsStrings(PARAM_COMPONENT_ROOTS)) .setComponentUuids(request.paramAsStrings(PARAM_COMPONENT_UUIDS)) + .setComponents(request.paramAsStrings(PARAM_COMPONENTS)) .setCreatedAfter(request.param(PARAM_CREATED_AFTER)) .setCreatedAt(request.param(PARAM_CREATED_AT)) .setCreatedBefore(request.param(PARAM_CREATED_BEFORE)) diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 6a595e18ffa..01ca67bc742 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -166,6 +166,7 @@ import org.sonar.server.qualityprofile.QProfileRulesImpl; import org.sonar.server.qualityprofile.QProfileTreeImpl; import org.sonar.server.qualityprofile.RuleActivator; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; +import org.sonar.server.qualityprofile.ws.ProfilesWs; import org.sonar.server.qualityprofile.ws.QProfilesWsModule; import org.sonar.server.root.ws.RootWsModule; import org.sonar.server.rule.CommonRuleDefinitionsImpl; @@ -197,6 +198,7 @@ import org.sonar.server.startup.LogServerId; import org.sonar.server.telemetry.TelemetryClient; import org.sonar.server.telemetry.TelemetryDaemon; import org.sonar.server.telemetry.TelemetryDataLoader; +import org.sonar.server.test.ws.TestsWs; import org.sonar.server.text.MacroInterpreter; import org.sonar.server.ui.DeprecatedViews; import org.sonar.server.ui.PageDecorations; @@ -286,6 +288,7 @@ public class PlatformLevel4 extends PlatformLevel { XMLProfileSerializer.class, AnnotationProfileParser.class, QProfileComparison.class, + ProfilesWs.class, QProfileTreeImpl.class, QProfileRulesImpl.class, RuleActivator.class, @@ -468,6 +471,9 @@ public class PlatformLevel4 extends PlatformLevel { NotificationWsModule.class, EmailsWsModule.class, + // Tests + TestsWs.class, + // Settings PersistentSettings.class, PropertiesWs.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java new file mode 100644 index 00000000000..fe7190ba41c --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java @@ -0,0 +1,62 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.WebService; +import org.sonar.server.ws.RemovedWebServiceHandler; + +/** + * List of quality profiles WS implemented in Rails. + * New WS on quality profiles MUST be declared in {@link org.sonar.server.qualityprofile.ws.QProfilesWs} + */ +public class ProfilesWs implements WebService { + + public static final String API_ENDPOINT = "api/profiles"; + + @Override + public void define(Context context) { + NewController controller = context.createController(API_ENDPOINT) + .setDescription("Removed since 6.3, please use api/qualityprofiles instead") + .setSince("4.4"); + defineListAction(controller); + defineIndexAction(controller); + controller.done(); + } + + private static void defineIndexAction(NewController controller) { + controller.createAction("index") + .setDescription("Get a profile.<br/>" + + "The web service is removed and you're invited to use api/qualityprofiles/search instead") + .setSince("3.3") + .setDeprecatedSince("5.2") + .setHandler(RemovedWebServiceHandler.INSTANCE) + .setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()); + } + + private static void defineListAction(NewController controller) { + controller.createAction("list") + .setDescription("Get a list of profiles.<br/>" + + "The web service is removed and you're invited to use api/qualityprofiles/search instead") + .setSince("3.3") + .setDeprecatedSince("5.2") + .setHandler(RemovedWebServiceHandler.INSTANCE) + .setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java index 6cae5e46adf..79abe984374 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java @@ -96,6 +96,12 @@ public class CreateAction implements RulesWsAction { .setExampleValue("Todo_should_not_be_used"); action + .createParam("manual_key") + .setDescription("Manual rules are no more supported. This parameter is ignored") + .setExampleValue("Error_handling") + .setDeprecatedSince("5.5"); + + action .createParam(PARAM_TEMPLATE_KEY) .setDescription("Key of the template rule in order to create a custom rule (mandatory for custom rule)") .setExampleValue("java:XPath"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java index 40278e60e52..3f4d47dfd64 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java @@ -50,6 +50,7 @@ import static com.google.common.collect.Sets.newHashSet; import static java.lang.String.format; import static java.util.Collections.singletonList; import static java.util.Optional.ofNullable; +import static org.apache.commons.lang.StringUtils.defaultIfEmpty; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; import static org.sonar.server.rule.ws.CreateAction.KEY_MAXIMUM_LENGTH; import static org.sonar.server.rule.ws.CreateAction.NAME_MAXIMUM_LENGTH; @@ -61,8 +62,11 @@ public class UpdateAction implements RulesWsAction { public static final String PARAM_TAGS = "tags"; public static final String PARAM_MARKDOWN_NOTE = "markdown_note"; public static final String PARAM_REMEDIATION_FN_TYPE = "remediation_fn_type"; + public static final String DEPRECATED_PARAM_REMEDIATION_FN_TYPE = "debt_remediation_fn_type"; public static final String PARAM_REMEDIATION_FN_BASE_EFFORT = "remediation_fn_base_effort"; + public static final String DEPRECATED_PARAM_REMEDIATION_FN_OFFSET = "debt_remediation_fn_offset"; public static final String PARAM_REMEDIATION_FN_GAP_MULTIPLIER = "remediation_fy_gap_multiplier"; + public static final String DEPRECATED_PARAM_REMEDIATION_FN_COEFF = "debt_remediation_fy_coeff"; public static final String PARAM_NAME = "name"; public static final String PARAM_DESCRIPTION = "markdown_description"; public static final String PARAM_SEVERITY = "severity"; @@ -120,16 +124,26 @@ public class UpdateAction implements RulesWsAction { .setPossibleValues(DebtRemediationFunction.Type.values()) .setSince("5.5"); + action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_TYPE) + .setDeprecatedSince("5.5") + .setPossibleValues(DebtRemediationFunction.Type.values()); + action.createParam(PARAM_REMEDIATION_FN_BASE_EFFORT) .setDescription("Base effort of the remediation function of the rule") .setExampleValue("1d") .setSince("5.5"); + action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET) + .setDeprecatedSince("5.5"); + action.createParam(PARAM_REMEDIATION_FN_GAP_MULTIPLIER) .setDescription("Gap multiplier of the remediation function of the rule") .setExampleValue("3min") .setSince("5.5"); + action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_COEFF) + .setDeprecatedSince("5.5"); + action .createParam(PARAM_NAME) .setMaximumLength(NAME_MAXIMUM_LENGTH) @@ -237,15 +251,15 @@ public class UpdateAction implements RulesWsAction { } private static void readDebt(Request request, RuleUpdate update) { - String value = request.param(PARAM_REMEDIATION_FN_TYPE); + String value = defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_TYPE), request.param(DEPRECATED_PARAM_REMEDIATION_FN_TYPE)); if (value != null) { if (StringUtils.isBlank(value)) { update.setDebtRemediationFunction(null); } else { DebtRemediationFunction fn = new DefaultDebtRemediationFunction( DebtRemediationFunction.Type.valueOf(value), - request.param(PARAM_REMEDIATION_FN_GAP_MULTIPLIER), - request.param(PARAM_REMEDIATION_FN_BASE_EFFORT)); + defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_GAP_MULTIPLIER), request.param(DEPRECATED_PARAM_REMEDIATION_FN_COEFF)), + defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_BASE_EFFORT), request.param(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET))); update.setDebtRemediationFunction(fn); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/ws/TestsWs.java b/server/sonar-server/src/main/java/org/sonar/server/test/ws/TestsWs.java new file mode 100644 index 00000000000..fb477f7b9dc --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/test/ws/TestsWs.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.test.ws; + +import org.sonar.api.server.ws.Change; +import org.sonar.api.server.ws.WebService; +import org.sonar.server.ws.RemovedWebServiceHandler; + +public class TestsWs implements WebService { + + @Override + public void define(Context context) { + NewController controller = context.createController("api/tests") + .setSince("4.4") + .setDescription("Removed in 7.6"); + + controller.createAction("covered_files") + .setDescription("This web API is no longer supported") + .setSince("4.4") + .setDeprecatedSince("5.6") + .setChangelog(new Change("7.6", "This action has been removed")) + .setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()) + .setHandler(RemovedWebServiceHandler.INSTANCE); + + controller + .createAction("list") + .setDescription("This web API is no longer supported") + .setSince("5.2") + .setDeprecatedSince("5.6") + .setChangelog(new Change("7.6", "This action has been removed")) + .setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()) + .setHandler(RemovedWebServiceHandler.INSTANCE); + + controller.done(); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/ws/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/test/ws/package-info.java new file mode 100644 index 00000000000..a06b3220d5a --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/test/ws/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.server.test.ws; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SearchAction.java index 1fc93cb4f1a..d1c996b0e1f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SearchAction.java @@ -20,10 +20,12 @@ package org.sonar.server.user.ws; import com.google.common.collect.Multimap; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Function; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.server.ws.Change; @@ -48,6 +50,7 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.emptyToNull; import static java.util.Optional.ofNullable; +import static org.sonar.api.server.ws.WebService.Param.FIELDS; import static org.sonar.api.server.ws.WebService.Param.PAGE; import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; @@ -55,6 +58,16 @@ import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.api.utils.Paging.forPageIndex; import static org.sonar.core.util.stream.MoreCollectors.toList; import static org.sonar.server.es.SearchOptions.MAX_LIMIT; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_ACTIVE; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_AVATAR; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_EMAIL; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_EXTERNAL_IDENTITY; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_EXTERNAL_PROVIDER; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_GROUPS; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_LOCAL; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_NAME; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_SCM_ACCOUNTS; +import static org.sonar.server.user.ws.UserJsonWriter.FIELD_TOKENS_COUNT; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.Users.SearchWsResponse.Groups; import static org.sonarqube.ws.Users.SearchWsResponse.ScmAccounts; @@ -101,6 +114,8 @@ public class SearchAction implements UsersWsAction { .setHandler(this) .setResponseExample(getClass().getResource("search-example.json")); + action.createFieldsParam(UserJsonWriter.FIELDS) + .setDeprecatedSince("5.4"); action.addPagingParams(50, MAX_LIMIT); action.createParam(TEXT_QUERY) @@ -116,6 +131,7 @@ public class SearchAction implements UsersWsAction { private Users.SearchWsResponse doHandle(SearchRequest request) { SearchOptions options = new SearchOptions().setPage(request.getPage(), request.getPageSize()); + List<String> fields = request.getPossibleFields(); SearchResult<UserDoc> result = userIndex.search(UserQuery.builder().setTextQuery(request.getQuery()).build(), options); try (DbSession dbSession = dbClient.openSession(false)) { List<String> logins = result.getDocs().stream().map(UserDoc::login).collect(toList()); @@ -123,13 +139,14 @@ public class SearchAction implements UsersWsAction { List<UserDto> users = dbClient.userDao().selectByOrderedLogins(dbSession, logins); Map<String, Integer> tokenCountsByLogin = dbClient.userTokenDao().countTokensByUsers(dbSession, users); Paging paging = forPageIndex(request.getPage()).withPageSize(request.getPageSize()).andTotal((int) result.getTotal()); - return buildResponse(users, groupsByLogin, tokenCountsByLogin, paging); + return buildResponse(users, groupsByLogin, tokenCountsByLogin, fields, paging); } } - private SearchWsResponse buildResponse(List<UserDto> users, Multimap<String, String> groupsByLogin, Map<String, Integer> tokenCountsByLogin, Paging paging) { + private SearchWsResponse buildResponse(List<UserDto> users, Multimap<String, String> groupsByLogin, Map<String, Integer> tokenCountsByLogin, + @Nullable List<String> fields, Paging paging) { SearchWsResponse.Builder responseBuilder = newBuilder(); - users.forEach(user -> responseBuilder.addUsers(towsUser(user, firstNonNull(tokenCountsByLogin.get(user.getUuid()), 0), groupsByLogin.get(user.getLogin())))); + users.forEach(user -> responseBuilder.addUsers(towsUser(user, firstNonNull(tokenCountsByLogin.get(user.getUuid()), 0), groupsByLogin.get(user.getLogin()), fields))); responseBuilder.getPagingBuilder() .setPageIndex(paging.pageIndex()) .setPageSize(paging.pageSize()) @@ -138,30 +155,43 @@ public class SearchAction implements UsersWsAction { return responseBuilder.build(); } - private User towsUser(UserDto user, @Nullable Integer tokensCount, Collection<String> groups) { - User.Builder userBuilder = User.newBuilder().setLogin(user.getLogin()); - ofNullable(user.getName()).ifPresent(userBuilder::setName); + private User towsUser(UserDto user, @Nullable Integer tokensCount, Collection<String> groups, @Nullable Collection<String> fields) { + User.Builder userBuilder = User.newBuilder() + .setLogin(user.getLogin()); + setIfNeeded(FIELD_NAME, fields, user.getName(), userBuilder::setName); if (userSession.isLoggedIn()) { - ofNullable(emptyToNull(user.getEmail())).ifPresent(u -> userBuilder.setAvatar(avatarResolver.create(user))); - userBuilder.setActive(user.isActive()); - userBuilder.setLocal(user.isLocal()); - ofNullable(user.getExternalIdentityProvider()).ifPresent(userBuilder::setExternalProvider); - if (!user.getScmAccountsAsList().isEmpty()) { - userBuilder.setScmAccounts(ScmAccounts.newBuilder().addAllScmAccounts(user.getScmAccountsAsList())); - } + setIfNeeded(FIELD_AVATAR, fields, emptyToNull(user.getEmail()), u -> userBuilder.setAvatar(avatarResolver.create(user))); + setIfNeeded(FIELD_ACTIVE, fields, user.isActive(), userBuilder::setActive); + setIfNeeded(FIELD_LOCAL, fields, user.isLocal(), userBuilder::setLocal); + setIfNeeded(FIELD_EXTERNAL_PROVIDER, fields, user.getExternalIdentityProvider(), userBuilder::setExternalProvider); + setIfNeeded(isNeeded(FIELD_SCM_ACCOUNTS, fields) && !user.getScmAccountsAsList().isEmpty(), user.getScmAccountsAsList(), + scm -> userBuilder.setScmAccounts(ScmAccounts.newBuilder().addAllScmAccounts(scm))); } if (userSession.isSystemAdministrator() || Objects.equals(userSession.getUuid(), user.getUuid())) { - ofNullable(user.getEmail()).ifPresent(userBuilder::setEmail); - if (!groups.isEmpty()) { - userBuilder.setGroups(Groups.newBuilder().addAllGroups(groups)); - } - ofNullable(user.getExternalLogin()).ifPresent(userBuilder::setExternalIdentity); - ofNullable(tokensCount).ifPresent(userBuilder::setTokensCount); + setIfNeeded(FIELD_EMAIL, fields, user.getEmail(), userBuilder::setEmail); + setIfNeeded(isNeeded(FIELD_GROUPS, fields) && !groups.isEmpty(), groups, + g -> userBuilder.setGroups(Groups.newBuilder().addAllGroups(g))); + setIfNeeded(FIELD_EXTERNAL_IDENTITY, fields, user.getExternalLogin(), userBuilder::setExternalIdentity); + setIfNeeded(FIELD_TOKENS_COUNT, fields, tokensCount, userBuilder::setTokensCount); ofNullable(user.getLastConnectionDate()).ifPresent(date -> userBuilder.setLastConnectionDate(formatDateTime(date))); } return userBuilder.build(); } + private static <PARAM> void setIfNeeded(String field, @Nullable Collection<String> fields, @Nullable PARAM parameter, Function<PARAM, ?> setter) { + setIfNeeded(isNeeded(field, fields), parameter, setter); + } + + private static <PARAM> void setIfNeeded(boolean condition, @Nullable PARAM parameter, Function<PARAM, ?> setter) { + if (parameter != null && condition) { + setter.apply(parameter); + } + } + + private static boolean isNeeded(String field, @Nullable Collection<String> fields) { + return fields == null || fields.isEmpty() || fields.contains(field); + } + private static SearchRequest toSearchRequest(Request request) { int pageSize = request.mandatoryParamAsInt(PAGE_SIZE); checkArgument(pageSize <= MAX_PAGE_SIZE, "The '%s' parameter must be less than %s", PAGE_SIZE, MAX_PAGE_SIZE); @@ -169,6 +199,7 @@ public class SearchAction implements UsersWsAction { .setQuery(request.param(TEXT_QUERY)) .setPage(request.mandatoryParamAsInt(PAGE)) .setPageSize(pageSize) + .setPossibleFields(request.paramAsStrings(FIELDS)) .build(); } @@ -177,11 +208,13 @@ public class SearchAction implements UsersWsAction { private final Integer page; private final Integer pageSize; private final String query; + private final List<String> possibleFields; private SearchRequest(Builder builder) { this.page = builder.page; this.pageSize = builder.pageSize; this.query = builder.query; + this.possibleFields = builder.additionalFields; } @CheckForNull @@ -199,6 +232,10 @@ public class SearchAction implements UsersWsAction { return query; } + public List<String> getPossibleFields() { + return possibleFields; + } + public static Builder builder() { return new Builder(); } @@ -208,6 +245,7 @@ public class SearchAction implements UsersWsAction { private Integer page; private Integer pageSize; private String query; + private List<String> additionalFields = new ArrayList<>(); private Builder() { // enforce factory method use @@ -228,6 +266,11 @@ public class SearchAction implements UsersWsAction { return this; } + public Builder setPossibleFields(List<String> possibleFields) { + this.additionalFields = possibleFields; + return this; + } + public SearchRequest build() { return new SearchRequest(this); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java index 8df62cca4f7..aaa1d871f14 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java @@ -63,7 +63,6 @@ import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; -import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonar.api.utils.DateUtils.formatDate; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.db.ce.CeActivityDto.Status.FAILED; @@ -75,6 +74,7 @@ import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY; import static org.sonar.db.ce.CeTaskCharacteristicDto.PULL_REQUEST; import static org.sonar.db.component.BranchType.LONG; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID; +import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_QUERY; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MAX_EXECUTED_AT; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MIN_SUBMITTED_AT; import static org.sonar.server.ce.ws.CeWsParameters.PARAM_STATUS; @@ -290,7 +290,7 @@ public class ActivityActionTest { insertActivity("T2", zookeeper, SUCCESS); insertActivity("T3", eclipse, SUCCESS); - ActivityResponse activityResponse = call(ws.newRequest().setParam(TEXT_QUERY, "apac")); + ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac")); assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T1", "T2"); } @@ -302,7 +302,7 @@ public class ActivityActionTest { logInAsSystemAdministrator(); insertActivity("T2", apacheView, SUCCESS); - ActivityResponse activityResponse = call(ws.newRequest().setParam(TEXT_QUERY, "apac")); + ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac")); assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T2"); } @@ -314,7 +314,7 @@ public class ActivityActionTest { logInAsSystemAdministrator(); insertActivity("T2", apacheApp, SUCCESS); - ActivityResponse activityResponse = call(ws.newRequest().setParam(TEXT_QUERY, "apac")); + ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac")); assertThat(activityResponse.getTasksList()).extracting(Task::getId).containsOnly("T2"); } @@ -459,11 +459,11 @@ public class ActivityActionTest { @Test public void fail_if_both_filters_on_component_id_and_name() { expectedException.expect(BadRequestException.class); - expectedException.expectMessage("componentId and q must not be set at the same time"); + expectedException.expectMessage("componentId and componentQuery must not be set at the same time"); ws.newRequest() .setParam("componentId", "ID1") - .setParam("q", "apache") + .setParam("componentQuery", "apache") .setMediaType(MediaTypes.PROTOBUF) .execute(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsModuleTest.java index f209f3c21b5..a575f36e9d7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsModuleTest.java @@ -30,6 +30,6 @@ public class ComponentsWsModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new ComponentsWsModule().configure(container); - assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 7); + assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 8); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ResourcesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ResourcesWsTest.java new file mode 100644 index 00000000000..dc838e85173 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ResourcesWsTest.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.component.ws; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.server.ws.WebService; +import org.sonar.server.ws.RemovedWebServiceHandler; +import org.sonar.server.ws.WsTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ResourcesWsTest { + + WebService.Controller controller; + + @Before + public void setUp() { + WsTester tester = new WsTester(new ResourcesWs()); + controller = tester.controller("api/resources"); + } + + @Test + public void define_controller() { + assertThat(controller).isNotNull(); + assertThat(controller.since()).isEqualTo("2.10"); + assertThat(controller.description()).isNotEmpty(); + assertThat(controller.actions()).hasSize(1); + } + + @Test + public void define_index_action() { + WebService.Action action = controller.action("index"); + assertThat(action).isNotNull(); + assertThat(action.handler()).isInstanceOf(RemovedWebServiceHandler.class); + assertThat(action.responseExampleAsString()).isNotEmpty(); + assertThat(action.params()).isEmpty(); + } + +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java index 2a321a15480..4c262bee499 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java @@ -212,11 +212,11 @@ public class IssueQueryFactoryTest { @Test public void fail_if_components_and_components_uuid_params_are_set_at_the_same_time() { SearchRequest request = new SearchRequest() - .setComponentKeys(singletonList("foo")) - .setComponentUuids(singletonList("bar")); + .setComponentKeys(asList("foo")) + .setComponentUuids(asList("bar")); expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("At most one of the following parameters can be provided: componentKeys and componentUuids"); + expectedException.expectMessage("At most one of the following parameters can be provided: componentKeys, componentUuids, components, componentRoots, componentUuids"); underTest.create(request); } @@ -224,11 +224,11 @@ public class IssueQueryFactoryTest { @Test public void fail_if_both_componentRoots_and_componentRootUuids_params_are_set() { SearchRequest request = new SearchRequest() - .setComponentRoots(singletonList("foo")) - .setComponentRootUuids(singletonList("bar")); + .setComponentRoots(asList("foo")) + .setComponentRootUuids(asList("bar")); expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("At most one of the following parameters can be provided: componentKeys and componentUuids"); + expectedException.expectMessage("At most one of the following parameters can be provided: componentKeys, componentUuids, components, componentRoots, componentUuids"); underTest.create(request); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java index 7943f9e5f20..d901f322ed8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java @@ -38,9 +38,9 @@ import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.issue.IssueFieldsSetter; import org.sonar.server.issue.IssueFinder; +import org.sonar.server.issue.WebIssueStorage; import org.sonar.server.issue.IssueUpdater; import org.sonar.server.issue.TestIssueChangePostProcessor; -import org.sonar.server.issue.WebIssueStorage; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.issue.index.IssueIteratorFactory; import org.sonar.server.notification.NotificationManager; @@ -124,6 +124,21 @@ public class AssignActionTest { } @Test + public void assign_to_me_using_deprecated_me_param() { + IssueDto issue = newIssueWithBrowsePermission(); + + ws.newRequest() + .setParam("issue", issue.getKey()) + .setParam("me", "true") + .execute(); + + checkIssueAssignee(issue.getKey(), CURRENT_USER_UUID); + Optional<IssueDto> optionalIssueDto = dbClient.issueDao().selectByKey(session, issue.getKey()); + assertThat(optionalIssueDto).isPresent(); + assertThat(optionalIssueDto.get().getAssigneeUuid()).isEqualTo(CURRENT_USER_UUID); + } + + @Test public void unassign() { IssueDto issue = newIssueWithBrowsePermission(); @@ -190,7 +205,7 @@ public class AssignActionTest { UserDto arthur = insertUser("arthur"); expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Assigning security hotspots is not allowed"); + expectedException.expectMessage("It is not allowed to assign a security hotspot"); ws.newRequest() .setParam("issue", issueDto.getKey()) diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java index 4af1280a204..82b76d30674 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java @@ -649,7 +649,7 @@ public class BulkChangeActionTest { assertThat(action.key()).isEqualTo("bulk_change"); assertThat(action.isPost()).isTrue(); assertThat(action.isInternal()).isFalse(); - assertThat(action.params()).hasSize(9); + assertThat(action.params()).hasSize(10); assertThat(action.responseExample()).isNotNull(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java index 9a4bacc317d..9b30a5b98a3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java @@ -75,6 +75,7 @@ import static org.sonar.db.component.ComponentTesting.newSubView; import static org.sonar.db.component.ComponentTesting.newView; import static org.sonar.db.issue.IssueTesting.newIssue; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DIRECTORIES; @@ -288,12 +289,12 @@ public class SearchActionComponentsTest { indexIssues(); ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, file.getKey()) + .setParam(PARAM_COMPONENTS, file.getDbKey()) .execute() .assertJson(this.getClass(), "search_by_file_key.json"); ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, unitTest.getKey()) + .setParam(PARAM_COMPONENTS, unitTest.getDbKey()) .execute() .assertJson(this.getClass(), "search_by_test_key.json"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index 1f44c178677..2a5a338f4f0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -92,7 +92,7 @@ import static org.sonar.db.issue.IssueTesting.newDto; import static org.sonar.server.tester.UserSessionRule.standalone; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS; -import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_HIDE_COMMENTS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PAGE_INDEX; @@ -430,7 +430,7 @@ public class SearchActionTest { session.commit(); indexIssues(); - ws.newRequest().setParam(PARAM_COMPONENT_KEYS, file.getKey()).execute() + ws.newRequest().setParam(PARAM_COMPONENTS, file.getDbKey()).execute() .assertJson(this.getClass(), "apply_paging_with_one_component.json"); } @@ -850,7 +850,7 @@ public class SearchActionTest { assertThat(def.responseExampleAsString()).isNotEmpty(); assertThat(def.params()).extracting("key").containsExactlyInAnyOrder( - "additionalFields", "asc", "assigned", "assignees", "authors", "author", "componentKeys", "componentUuids", "branch", + "additionalFields", "asc", "assigned", "assignees", "authors", "author", "componentKeys", "componentRootUuids", "componentRoots", "componentUuids", "components", "branch", "pullRequest", "organization", "createdAfter", "createdAt", "createdBefore", "createdInLast", "directories", "facetMode", "facets", "fileUuids", "issues", "languages", "moduleUuids", "onComponentOnly", "p", "projects", "ps", "resolutions", "resolved", "rules", "s", "severities", "sinceLeakPeriod", diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java new file mode 100644 index 00000000000..9aeb479686e --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java @@ -0,0 +1,73 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.Before; +import org.junit.Test; +import org.sonar.api.server.ws.WebService; +import org.sonar.server.ws.RemovedWebServiceHandler; +import org.sonar.server.ws.WsTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ProfilesWsTest { + + private WsTester ws; + + @Before + public void setUp() { + ws = new WsTester(new ProfilesWs()); + } + + @Test + public void define_controller() { + WebService.Controller controller = controller(); + assertThat(controller).isNotNull(); + assertThat(controller.path()).isEqualTo("api/profiles"); + assertThat(controller.description()).isNotEmpty(); + assertThat(controller.actions()).hasSize(2); + } + + @Test + public void define_index_action() { + WebService.Controller controller = ws.controller("api/profiles"); + + WebService.Action restoreProfiles = controller.action("index"); + assertThat(restoreProfiles).isNotNull(); + assertThat(restoreProfiles.handler()).isInstanceOf(RemovedWebServiceHandler.class); + assertThat(restoreProfiles.responseExampleAsString()).isNotEmpty(); + assertThat(restoreProfiles.params()).isEmpty(); + } + + @Test + public void define_list_action() { + WebService.Controller controller = controller(); + + WebService.Action listProfiles = controller.action("list"); + assertThat(listProfiles).isNotNull(); + assertThat(listProfiles.handler()).isInstanceOf(RemovedWebServiceHandler.class); + assertThat(listProfiles.responseExampleAsString()).isNotEmpty(); + assertThat(listProfiles.params()).isEmpty(); + } + + private WebService.Controller controller() { + return ws.controller("api/profiles"); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java index a11505feed6..786e22c5288 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java @@ -32,6 +32,7 @@ import org.sonar.db.DbTester; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleMetadataDto; +import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsClient; import org.sonar.server.es.EsTester; @@ -59,6 +60,9 @@ import static org.sonar.api.server.debt.DebtRemediationFunction.Type.LINEAR_OFFS import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; import static org.sonar.db.rule.RuleTesting.setSystemTags; import static org.sonar.db.rule.RuleTesting.setTags; +import static org.sonar.server.rule.ws.UpdateAction.DEPRECATED_PARAM_REMEDIATION_FN_COEFF; +import static org.sonar.server.rule.ws.UpdateAction.DEPRECATED_PARAM_REMEDIATION_FN_OFFSET; +import static org.sonar.server.rule.ws.UpdateAction.DEPRECATED_PARAM_REMEDIATION_FN_TYPE; import static org.sonar.server.rule.ws.UpdateAction.PARAM_KEY; import static org.sonar.server.rule.ws.UpdateAction.PARAM_MARKDOWN_NOTE; import static org.sonar.server.rule.ws.UpdateAction.PARAM_ORGANIZATION; @@ -102,7 +106,7 @@ public class UpdateActionTest { assertThat(ws.getDef().responseExampleAsString()).isNotNull(); assertThat(ws.getDef().description()).isNotNull(); } - + @Test public void update_custom_rule() { logInAsQProfileAdministrator(); @@ -246,6 +250,46 @@ public class UpdateActionTest { } @Test + public void update_custom_rule_with_deprecated_remediation_function_parameters() { + logInAsQProfileAdministrator(); + + RuleDefinitionDto rule = RuleTesting.newRule() + .setDefRemediationFunction(LINEAR_OFFSET.toString()) + .setDefRemediationGapMultiplier("10d") + .setDefRemediationBaseEffort("5min"); + db.rules().insert(rule); + + String newType = LINEAR_OFFSET.toString(); + String newCoeff = "11d"; + String newOffset = "6min"; + + Rules.UpdateResponse result = ws.newRequest().setMethod("POST") + .setParam(PARAM_KEY, rule.getKey().toString()) + .setParam(DEPRECATED_PARAM_REMEDIATION_FN_TYPE, newType) + .setParam(DEPRECATED_PARAM_REMEDIATION_FN_COEFF, newCoeff) + .setParam(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET, newOffset) + .executeProtobuf(Rules.UpdateResponse.class); + + Rules.Rule updatedRule = result.getRule(); + assertThat(updatedRule).isNotNull(); + + assertThat(updatedRule.getKey()).isEqualTo(rule.getKey().toString()); + assertThat(updatedRule.getDefaultRemFnType()).isEqualTo(rule.getDefRemediationFunction()); + assertThat(updatedRule.getDefaultRemFnGapMultiplier()).isEqualTo(rule.getDefRemediationGapMultiplier()); + assertThat(updatedRule.getDefaultRemFnBaseEffort()).isEqualTo(rule.getDefRemediationBaseEffort()); + assertThat(updatedRule.getEffortToFixDescription()).isEqualTo(rule.getGapDescription()); + + assertThat(updatedRule.getRemFnType()).isEqualTo(newType); + assertThat(updatedRule.getDebtRemFnCoeff()).isEqualTo(newCoeff); + assertThat(updatedRule.getDebtRemFnOffset()).isEqualTo(newOffset); + + assertThat(updatedRule.getRemFnType()).isEqualTo(newType); + assertThat(updatedRule.getRemFnGapMultiplier()).isEqualTo(newCoeff); + assertThat(updatedRule.getRemFnBaseEffort()).isEqualTo(newOffset); + assertThat(updatedRule.getGapDescription()).isEqualTo(rule.getGapDescription()); + } + + @Test public void update_note() { OrganizationDto organization = db.organizations().insert(); RuleDefinitionDto rule = db.rules().insert(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java index a20573fc2ca..37edde0c6f8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java @@ -24,7 +24,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; import org.sonar.api.utils.internal.AlwaysIncreasingSystem2; import org.sonar.db.DbTester; @@ -197,14 +196,6 @@ public class ChangePasswordActionTest { .execute(); } - @Test - public void test_definition() { - WebService.Action action = tester.getDef(); - assertThat(action).isNotNull(); - assertThat(action.isPost()).isTrue(); - assertThat(action.params()).hasSize(3); - } - private void createLocalUser() { db.users().insertUser(newLocalUser("john", "John", "john@email.com")); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index b8c693cc283..e01fb412b8c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.ArgumentCaptor; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; import org.sonar.api.utils.internal.AlwaysIncreasingSystem2; import org.sonar.core.config.CorePropertyDefinitions; @@ -380,14 +379,6 @@ public class CreateActionTest { executeRequest("john"); } - @Test - public void test_definition() { - WebService.Action action = tester.getDef(); - assertThat(action).isNotNull(); - assertThat(action.isPost()).isTrue(); - assertThat(action.params()).hasSize(7); - } - private CreateWsResponse executeRequest(String login) { return call(CreateRequest.builder() .setLogin(login) diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java index ff98570dbdf..8e820541c6d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java @@ -22,7 +22,6 @@ package org.sonar.server.user.ws; import java.util.stream.IntStream; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.server.ws.WebService; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; @@ -290,18 +289,51 @@ public class SearchActionTest { userSession.logIn(user); assertThat(ws.newRequest().setParam("q", user.getLogin()) .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::getName, User::getEmail, User::getExternalIdentity, User::getExternalProvider, - User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::getTokensCount, User::hasLastConnectionDate) - .containsExactlyInAnyOrder( - tuple(user.getLogin(), user.getName(), user.getEmail(), user.getExternalLogin(), user.getExternalIdentityProvider(), true, true, true, 2, true)); + .extracting(User::getLogin, User::getName, User::getEmail, User::getExternalIdentity, User::getExternalProvider, + User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::getTokensCount, User::hasLastConnectionDate) + .containsExactlyInAnyOrder( + tuple(user.getLogin(), user.getName(), user.getEmail(), user.getExternalLogin(), user.getExternalIdentityProvider(), true, true, true, 2, true)); userSession.logIn(otherUser); assertThat(ws.newRequest().setParam("q", user.getLogin()) .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::getName, User::hasEmail, User::hasExternalIdentity, User::hasExternalProvider, - User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::hasTokensCount, User::hasLastConnectionDate) - .containsExactlyInAnyOrder( - tuple(user.getLogin(), user.getName(), false, false, true, true, true, false, false, false)); + .extracting(User::getLogin, User::getName, User::hasEmail, User::hasExternalIdentity, User::hasExternalProvider, + User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::hasTokensCount, User::hasLastConnectionDate) + .containsExactlyInAnyOrder( + tuple(user.getLogin(), user.getName(), false, false, true, true, true, false, false, false)); + } + + @Test + public void search_with_fields() { + UserDto user = db.users().insertUser(); + GroupDto group = db.users().insertGroup(db.getDefaultOrganization()); + db.users().insertMember(group, user); + userIndexer.indexOnStartup(null); + userSession.logIn().setSystemAdministrator(); + + assertThat(ws.newRequest() + .setParam(Param.FIELDS, "scmAccounts") + .executeProtobuf(SearchWsResponse.class) + .getUsersList()) + .extracting(User::getLogin, User::hasName, User::hasScmAccounts, User::hasAvatar, User::hasGroups) + .containsExactlyInAnyOrder(tuple(user.getLogin(), false, true, false, false)); + assertThat(ws.newRequest() + .setParam(Param.FIELDS, "groups") + .executeProtobuf(SearchWsResponse.class) + .getUsersList()) + .extracting(User::getLogin, User::hasName, User::hasScmAccounts, User::hasAvatar, User::hasGroups) + .containsExactlyInAnyOrder(tuple(user.getLogin(), false, false, false, true)); + assertThat(ws.newRequest() + .setParam(Param.FIELDS, "") + .executeProtobuf(SearchWsResponse.class) + .getUsersList()) + .extracting(User::getLogin, User::hasName, User::hasScmAccounts, User::hasAvatar, User::hasGroups) + .containsExactlyInAnyOrder(tuple(user.getLogin(), true, true, true, true)); + assertThat(ws.newRequest() + .executeProtobuf(SearchWsResponse.class) + .getUsersList()) + .extracting(User::getLogin, User::hasName, User::hasScmAccounts, User::hasAvatar, User::hasGroups) + .containsExactlyInAnyOrder(tuple(user.getLogin(), true, true, true, true)); } @Test @@ -372,13 +404,4 @@ public class SearchActionTest { assertJson(response).isSimilarTo(getClass().getResource("search-example.json")); } - @Test - public void test_definition() { - WebService.Action action = ws.getDef(); - assertThat(action).isNotNull(); - assertThat(action.isPost()).isFalse(); - assertThat(action.responseExampleAsString()).isNotEmpty(); - assertThat(action.params()).hasSize(3); - } - } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java index efab9c999c0..47adf248ac9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java @@ -25,7 +25,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -274,14 +273,6 @@ public class UpdateActionTest { .execute(); } - @Test - public void test_definition() { - WebService.Action action = ws.getDef(); - assertThat(action).isNotNull(); - assertThat(action.isPost()).isTrue(); - assertThat(action.params()).hasSize(5); - } - private void createUser() { UserDto userDto = newUserDto() .setEmail("john@email.com") diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsTest.java new file mode 100644 index 00000000000..a8c6d6c0380 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsTest.java @@ -0,0 +1,98 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.user.ws; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.server.ws.WebService; +import org.sonar.db.DbClient; +import org.sonar.db.DbTester; +import org.sonar.server.authentication.CredentialsLocalAuthentication; +import org.sonar.server.issue.ws.AvatarResolver; +import org.sonar.server.tester.UserSessionRule; +import org.sonar.server.user.UserUpdater; +import org.sonar.server.user.index.UserIndex; +import org.sonar.server.ws.WsTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +public class UsersWsTest { + @Rule + public UserSessionRule userSessionRule = UserSessionRule.standalone(); + @Rule + public DbTester db = DbTester.create(); + + private WebService.Controller controller; + private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); + + @Before + public void setUp() { + WsTester tester = new WsTester(new UsersWs( + new CreateAction(mock(DbClient.class), mock(UserUpdater.class), userSessionRule), + new UpdateAction(mock(UserUpdater.class), userSessionRule, mock(UserJsonWriter.class), mock(DbClient.class)), + new ChangePasswordAction(mock(DbClient.class), mock(UserUpdater.class), userSessionRule, localAuthentication), + new SearchAction(userSessionRule, mock(UserIndex.class), mock(DbClient.class), mock(AvatarResolver.class)))); + controller = tester.controller("api/users"); + } + + @Test + public void define_controller() { + assertThat(controller).isNotNull(); + assertThat(controller.description()).isNotEmpty(); + assertThat(controller.since()).isEqualTo("3.6"); + assertThat(controller.actions()).hasSize(4); + } + + @Test + public void define_search_action() { + WebService.Action action = controller.action("search"); + assertThat(action).isNotNull(); + assertThat(action.isPost()).isFalse(); + assertThat(action.responseExampleAsString()).isNotEmpty(); + assertThat(action.params()).hasSize(4); + } + + @Test + public void define_create_action() { + WebService.Action action = controller.action("create"); + assertThat(action).isNotNull(); + assertThat(action.isPost()).isTrue(); + assertThat(action.params()).hasSize(7); + } + + @Test + public void define_update_action() { + WebService.Action action = controller.action("update"); + assertThat(action).isNotNull(); + assertThat(action.isPost()).isTrue(); + assertThat(action.params()).hasSize(5); + } + + @Test + public void define_change_password_action() { + WebService.Action action = controller.action("change_password"); + assertThat(action).isNotNull(); + assertThat(action.isPost()).isTrue(); + assertThat(action.params()).hasSize(3); + } + +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java index 587899c7824..d83de740725 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java @@ -44,6 +44,7 @@ import org.sonarqube.ws.client.notifications.NotificationsService; import org.sonarqube.ws.client.organizations.OrganizationsService; import org.sonarqube.ws.client.permissions.PermissionsService; import org.sonarqube.ws.client.plugins.PluginsService; +import org.sonarqube.ws.client.profiles.ProfilesService; import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService; import org.sonarqube.ws.client.projectbadges.ProjectBadgesService; import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; @@ -55,6 +56,7 @@ import org.sonarqube.ws.client.projecttags.ProjectTagsService; import org.sonarqube.ws.client.properties.PropertiesService; import org.sonarqube.ws.client.qualitygates.QualitygatesService; import org.sonarqube.ws.client.qualityprofiles.QualityprofilesService; +import org.sonarqube.ws.client.resources.ResourcesService; import org.sonarqube.ws.client.roots.RootsService; import org.sonarqube.ws.client.rules.RulesService; import org.sonarqube.ws.client.securityreports.SecurityReportsService; @@ -107,6 +109,7 @@ class DefaultWsClient implements WsClient { private final OrganizationsService organizationsService; private final PermissionsService permissionsService; private final PluginsService pluginsService; + private final ProfilesService profilesService; private final ProjectAnalysesService projectAnalysesService; private final ProjectBadgesService projectBadgesService; private final ProjectBranchesService projectBranchesService; @@ -118,6 +121,7 @@ class DefaultWsClient implements WsClient { private final PropertiesService propertiesService; private final QualitygatesService qualitygatesService; private final QualityprofilesService qualityprofilesService; + private final ResourcesService resourcesService; private final RootsService rootsService; private final RulesService rulesService; private final ServerService serverService; @@ -163,6 +167,7 @@ class DefaultWsClient implements WsClient { this.organizationsService = new OrganizationsService(wsConnector); this.permissionsService = new PermissionsService(wsConnector); this.pluginsService = new PluginsService(wsConnector); + this.profilesService = new ProfilesService(wsConnector); this.projectAnalysesService = new ProjectAnalysesService(wsConnector); this.projectBadgesService = new ProjectBadgesService(wsConnector); this.projectBranchesService = new ProjectBranchesService(wsConnector); @@ -174,6 +179,7 @@ class DefaultWsClient implements WsClient { this.propertiesService = new PropertiesService(wsConnector); this.qualitygatesService = new QualitygatesService(wsConnector); this.qualityprofilesService = new QualityprofilesService(wsConnector); + this.resourcesService = new ResourcesService(wsConnector); this.rootsService = new RootsService(wsConnector); this.rulesService = new RulesService(wsConnector); this.serverService = new ServerService(wsConnector); @@ -316,6 +322,11 @@ class DefaultWsClient implements WsClient { } @Override + public ProfilesService profiles() { + return profilesService; + } + + @Override public ProjectAnalysesService projectAnalyses() { return projectAnalysesService; } @@ -371,6 +382,11 @@ class DefaultWsClient implements WsClient { } @Override + public ResourcesService resources() { + return resourcesService; + } + + @Override public RootsService roots() { return rootsService; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java index 5fdba68259d..30df290cd00 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java @@ -44,6 +44,7 @@ import org.sonarqube.ws.client.notifications.NotificationsService; import org.sonarqube.ws.client.organizations.OrganizationsService; import org.sonarqube.ws.client.permissions.PermissionsService; import org.sonarqube.ws.client.plugins.PluginsService; +import org.sonarqube.ws.client.profiles.ProfilesService; import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService; import org.sonarqube.ws.client.projectbadges.ProjectBadgesService; import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; @@ -55,6 +56,7 @@ import org.sonarqube.ws.client.projecttags.ProjectTagsService; import org.sonarqube.ws.client.properties.PropertiesService; import org.sonarqube.ws.client.qualitygates.QualitygatesService; import org.sonarqube.ws.client.qualityprofiles.QualityprofilesService; +import org.sonarqube.ws.client.resources.ResourcesService; import org.sonarqube.ws.client.roots.RootsService; import org.sonarqube.ws.client.rules.RulesService; import org.sonarqube.ws.client.securityreports.SecurityReportsService; @@ -142,6 +144,8 @@ public interface WsClient { PluginsService plugins(); + ProfilesService profiles(); + ProjectAnalysesService projectAnalyses(); ProjectBadgesService projectBadges(); @@ -164,6 +168,8 @@ public interface WsClient { QualityprofilesService qualityprofiles(); + ResourcesService resources(); + RootsService roots(); RulesService rules(); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/ActivityRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/ActivityRequest.java index 9b4cafe70ae..ad47a8c0a8b 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/ActivityRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/ActivityRequest.java @@ -32,9 +32,11 @@ import javax.annotation.Generated; public class ActivityRequest { private String componentId; + private String componentQuery; private String maxExecutedAt; private String minSubmittedAt; private String onlyCurrents; + private String p; private String ps; private String q; private List<String> status; @@ -53,6 +55,20 @@ public class ActivityRequest { } /** + * Example value: "Apache" + * @deprecated since 5.5 + */ + @Deprecated + public ActivityRequest setComponentQuery(String componentQuery) { + this.componentQuery = componentQuery; + return this; + } + + public String getComponentQuery() { + return componentQuery; + } + + /** * Example value: "2017-10-19T13:00:00+0200" */ public ActivityRequest setMaxExecutedAt(String maxExecutedAt) { @@ -95,6 +111,19 @@ public class ActivityRequest { } /** + * @deprecated since 5.5 + */ + @Deprecated + public ActivityRequest setP(String p) { + this.p = p; + return this; + } + + public String getP() { + return p; + } + + /** * Example value: "20" */ public ActivityRequest setPs(String ps) { diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java index 030f8d30c83..2269d55f60f 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java @@ -57,9 +57,11 @@ public class CeService extends BaseService { return call( new GetRequest(path("activity")) .setParam("componentId", request.getComponentId()) + .setParam("componentQuery", request.getComponentQuery()) .setParam("maxExecutedAt", request.getMaxExecutedAt()) .setParam("minSubmittedAt", request.getMinSubmittedAt()) .setParam("onlyCurrents", request.getOnlyCurrents()) + .setParam("p", request.getP()) .setParam("ps", request.getPs()) .setParam("q", request.getQ()) .setParam("status", request.getStatus() == null ? null : request.getStatus().stream().collect(Collectors.joining(","))) diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesWsParameters.java index 551ee1e4130..041813066b1 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesWsParameters.java @@ -52,8 +52,11 @@ public class IssuesWsParameters { public static final String PARAM_STATUSES = "statuses"; public static final String PARAM_RESOLUTIONS = "resolutions"; public static final String PARAM_RESOLVED = "resolved"; + public static final String PARAM_COMPONENTS = "components"; public static final String PARAM_COMPONENT_KEYS = "componentKeys"; public static final String PARAM_COMPONENT_UUIDS = "componentUuids"; + public static final String PARAM_COMPONENT_ROOTS = "componentRoots"; + public static final String PARAM_COMPONENT_ROOT_UUIDS = "componentRootUuids"; public static final String PARAM_MODULE_UUIDS = "moduleUuids"; public static final String PARAM_PROJECTS = "projects"; public static final String PARAM_PROJECT_KEYS = "projectKeys"; @@ -67,10 +70,23 @@ public class IssuesWsParameters { public static final String PARAM_ASSIGN = "assign"; public static final String PARAM_SET_SEVERITY = "set_severity"; public static final String PARAM_SET_TYPE = "set_type"; + public static final String PARAM_PLAN = "plan"; public static final String PARAM_DO_TRANSITION = "do_transition"; public static final String PARAM_ADD_TAGS = "add_tags"; public static final String PARAM_REMOVE_TAGS = "remove_tags"; public static final String PARAM_SEND_NOTIFICATIONS = "sendNotifications"; + + /** + * @deprecated since 5.5, action plan feature has been removed + */ + @Deprecated + public static final String DEPRECATED_PARAM_ACTION_PLANS = "actionPlans"; + + /** + * @deprecated since 5.5, manual issue feature has been dropped. + */ + @Deprecated + public static final String PARAM_REPORTERS = "reporters"; public static final String PARAM_ASSIGNEES = "assignees"; /** @@ -87,6 +103,12 @@ public class IssuesWsParameters { public static final String PARAM_SANS_TOP_25 = "sansTop25"; public static final String PARAM_CWE = "cwe"; public static final String PARAM_ASSIGNED = "assigned"; + + /** + * @deprecated since 5.5, action plan feature has been removed + */ + @Deprecated + public static final String PARAM_PLANNED = "planned"; public static final String PARAM_HIDE_COMMENTS = "hideComments"; public static final String PARAM_CREATED_AFTER = "createdAfter"; public static final String PARAM_CREATED_AT = "createdAt"; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/AssignRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/AssignRequest.java index dd377affe65..525b7878ccd 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/AssignRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/AssignRequest.java @@ -33,6 +33,7 @@ public class AssignRequest { private String assignee; private String issue; + private String me; /** * Example value: "admin" @@ -59,4 +60,23 @@ public class AssignRequest { return issue; } + /** + * Possible values: + * <ul> + * <li>"true"</li> + * <li>"false"</li> + * <li>"yes"</li> + * <li>"no"</li> + * </ul> + * @deprecated since 5.2 + */ + @Deprecated + public AssignRequest setMe(String me) { + this.me = me; + return this; + } + + public String getMe() { + return me; + } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/BulkChangeRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/BulkChangeRequest.java index cc9a67ef188..29a2305259b 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/BulkChangeRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/BulkChangeRequest.java @@ -36,6 +36,7 @@ public class BulkChangeRequest { private List<String> comment; private String doTransition; private List<String> issues; + private List<String> plan; private String removeTags; private String sendNotifications; private List<String> setSeverity; @@ -113,6 +114,19 @@ public class BulkChangeRequest { } /** + * @deprecated since 5.5 + */ + @Deprecated + public BulkChangeRequest setPlan(List<String> plan) { + this.plan = plan; + return this; + } + + public List<String> getPlan() { + return plan; + } + + /** * Example value: "security,java8" */ public BulkChangeRequest setRemoveTags(String removeTags) { diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/IssuesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/IssuesService.java index 5ba7108f346..bd898f434d9 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/IssuesService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/IssuesService.java @@ -75,7 +75,8 @@ public class IssuesService extends BaseService { return call( new PostRequest(path("assign")) .setParam("assignee", request.getAssignee()) - .setParam("issue", request.getIssue()), + .setParam("issue", request.getIssue()) + .setParam("me", request.getMe()), AssignResponse.parser()); } @@ -111,6 +112,7 @@ public class IssuesService extends BaseService { .setParam("comment", request.getComment() == null ? null : request.getComment().stream().collect(Collectors.joining(","))) .setParam("do_transition", request.getDoTransition()) .setParam("issues", request.getIssues() == null ? null : request.getIssues().stream().collect(Collectors.joining(","))) + .setParam("plan", request.getPlan() == null ? null : request.getPlan().stream().collect(Collectors.joining(","))) .setParam("remove_tags", request.getRemoveTags()) .setParam("sendNotifications", request.getSendNotifications()) .setParam("set_severity", request.getSetSeverity() == null ? null : request.getSetSeverity().stream().collect(Collectors.joining(","))) @@ -212,7 +214,10 @@ public class IssuesService extends BaseService { .setParam("authors", request.getAuthors() == null ? null : request.getAuthors().stream().collect(Collectors.joining(","))) .setParam("branch", request.getBranch()) .setParam("componentKeys", request.getComponentKeys() == null ? null : request.getComponentKeys().stream().collect(Collectors.joining(","))) + .setParam("componentRootUuids", request.getComponentRootUuids()) + .setParam("componentRoots", request.getComponentRoots()) .setParam("componentUuids", request.getComponentUuids() == null ? null : request.getComponentUuids().stream().collect(Collectors.joining(","))) + .setParam("components", request.getComponents()) .setParam("createdAfter", request.getCreatedAfter()) .setParam("createdAt", request.getCreatedAt()) .setParam("createdBefore", request.getCreatedBefore()) diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java index 8d2c4cd012d..08407bcda0e 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java @@ -39,7 +39,10 @@ public class SearchRequest { private List<String> authors; private String branch; private List<String> componentKeys; + private String componentRootUuids; + private String componentRoots; private List<String> componentUuids; + private String components; private String createdAfter; private String createdAt; private String createdBefore; @@ -192,6 +195,32 @@ public class SearchRequest { } /** + * @deprecated since 5.1 + */ + @Deprecated + public SearchRequest setComponentRootUuids(String componentRootUuids) { + this.componentRootUuids = componentRootUuids; + return this; + } + + public String getComponentRootUuids() { + return componentRootUuids; + } + + /** + * @deprecated since 5.1 + */ + @Deprecated + public SearchRequest setComponentRoots(String componentRoots) { + this.componentRoots = componentRoots; + return this; + } + + public String getComponentRoots() { + return componentRoots; + } + + /** * Example value: "584a89f2-8037-4f7b-b82c-8b45d2d63fb2" * @deprecated since 6.5 */ @@ -206,6 +235,19 @@ public class SearchRequest { } /** + * @deprecated since 5.1 + */ + @Deprecated + public SearchRequest setComponents(String components) { + this.components = components; + return this; + } + + public String getComponents() { + return components; + } + + /** * Example value: "2017-10-19 or 2017-10-19T13:00:00+0200" */ public SearchRequest setCreatedAfter(String createdAfter) { diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/profiles/ProfilesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/profiles/ProfilesService.java new file mode 100644 index 00000000000..c1b2f9cb5a2 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/profiles/ProfilesService.java @@ -0,0 +1,71 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.profiles; + +import java.util.stream.Collectors; +import javax.annotation.Generated; +import org.sonarqube.ws.MediaTypes; +import org.sonarqube.ws.client.BaseService; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.PostRequest; +import org.sonarqube.ws.client.WsConnector; + +/** + * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/profiles">Further information about this web service online</a> + */ +@Generated("sonar-ws-generator") +public class ProfilesService extends BaseService { + + public ProfilesService(WsConnector wsConnector) { + super(wsConnector, "api/profiles"); + } + + /** + * + * This is part of the internal API. + * This is a GET request. + * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/profiles/index">Further information about this action online (including a response example)</a> + * @since 3.3 + * @deprecated since 5.2 + */ + @Deprecated + public String index() { + return call( + new GetRequest(path("index")) + .setMediaType(MediaTypes.JSON) + ).content(); + } + + /** + * + * This is part of the internal API. + * This is a GET request. + * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/profiles/list">Further information about this action online (including a response example)</a> + * @since 3.3 + * @deprecated since 5.2 + */ + @Deprecated + public String list() { + return call( + new GetRequest(path("list")) + .setMediaType(MediaTypes.JSON) + ).content(); + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/profiles/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/profiles/package-info.java new file mode 100644 index 00000000000..006b0a0e14c --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/profiles/package-info.java @@ -0,0 +1,26 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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. + */ +@ParametersAreNonnullByDefault +@Generated("sonar-ws-generator") +package org.sonarqube.ws.client.profiles; + +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.Generated; + diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/resources/ResourcesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/resources/ResourcesService.java new file mode 100644 index 00000000000..1fb3839586f --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/resources/ResourcesService.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.resources; + +import javax.annotation.Generated; +import org.sonarqube.ws.MediaTypes; +import org.sonarqube.ws.client.BaseService; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.WsConnector; + +/** + * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/resources">Further information about this web service online</a> + */ +@Generated("sonar-ws-generator") +public class ResourcesService extends BaseService { + + public ResourcesService(WsConnector wsConnector) { + super(wsConnector, "api/resources"); + } + + /** + * + * This is part of the internal API. + * This is a GET request. + * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/resources/index">Further information about this action online (including a response example)</a> + * @since 2.10 + * @deprecated since 5.4 + */ + @Deprecated + public String index() { + return call( + new GetRequest(path("index")) + .setMediaType(MediaTypes.JSON) + ).content(); + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/resources/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/resources/package-info.java new file mode 100644 index 00000000000..889693352d6 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/resources/package-info.java @@ -0,0 +1,26 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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. + */ +@ParametersAreNonnullByDefault +@Generated("sonar-ws-generator") +package org.sonarqube.ws.client.resources; + +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.Generated; + diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/CreateRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/CreateRequest.java index 12ee49ce9f2..4f4258db45f 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/CreateRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/CreateRequest.java @@ -32,6 +32,7 @@ import javax.annotation.Generated; public class CreateRequest { private String customKey; + private String manualKey; private String markdownDescription; private String name; private List<String> params; @@ -55,6 +56,20 @@ public class CreateRequest { } /** + * Example value: "Error_handling" + * @deprecated since 5.5 + */ + @Deprecated + public CreateRequest setManualKey(String manualKey) { + this.manualKey = manualKey; + return this; + } + + public String getManualKey() { + return manualKey; + } + + /** * This is a mandatory parameter. * Example value: "Description of my custom rule" */ diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/RulesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/RulesService.java index 9e0f771a90b..9765e85ed3f 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/RulesService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/RulesService.java @@ -68,6 +68,7 @@ public class RulesService extends BaseService { call( new PostRequest(path("create")) .setParam("custom_key", request.getCustomKey()) + .setParam("manual_key", request.getManualKey()) .setParam("markdown_description", request.getMarkdownDescription()) .setParam("name", request.getName()) .setParam("params", request.getParams() == null ? null : request.getParams().stream().collect(Collectors.joining(","))) @@ -203,6 +204,10 @@ public class RulesService extends BaseService { public void update(UpdateRequest request) { call( new PostRequest(path("update")) + .setParam("debt_remediation_fn_offset", request.getDebtRemediationFnOffset()) + .setParam("debt_remediation_fn_type", request.getDebtRemediationFnType()) + .setParam("debt_remediation_fy_coeff", request.getDebtRemediationFyCoeff()) + .setParam("debt_sub_characteristic", request.getDebtSubCharacteristic()) .setParam("key", request.getKey()) .setParam("markdown_description", request.getMarkdownDescription()) .setParam("markdown_note", request.getMarkdownNote()) diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/UpdateRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/UpdateRequest.java index c741af1eacc..bb36c8fbc36 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/UpdateRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/rules/UpdateRequest.java @@ -31,6 +31,10 @@ import javax.annotation.Generated; @Generated("sonar-ws-generator") public class UpdateRequest { + private String debtRemediationFnOffset; + private String debtRemediationFnType; + private String debtRemediationFyCoeff; + private String debtSubCharacteristic; private String key; private String markdownDescription; private String markdownNote; @@ -45,6 +49,64 @@ public class UpdateRequest { private List<String> tags; /** + * @deprecated since 5.5 + */ + @Deprecated + public UpdateRequest setDebtRemediationFnOffset(String debtRemediationFnOffset) { + this.debtRemediationFnOffset = debtRemediationFnOffset; + return this; + } + + public String getDebtRemediationFnOffset() { + return debtRemediationFnOffset; + } + + /** + * Possible values: + * <ul> + * <li>"LINEAR"</li> + * <li>"LINEAR_OFFSET"</li> + * <li>"CONSTANT_ISSUE"</li> + * </ul> + * @deprecated since 5.5 + */ + @Deprecated + public UpdateRequest setDebtRemediationFnType(String debtRemediationFnType) { + this.debtRemediationFnType = debtRemediationFnType; + return this; + } + + public String getDebtRemediationFnType() { + return debtRemediationFnType; + } + + /** + * @deprecated since 5.5 + */ + @Deprecated + public UpdateRequest setDebtRemediationFyCoeff(String debtRemediationFyCoeff) { + this.debtRemediationFyCoeff = debtRemediationFyCoeff; + return this; + } + + public String getDebtRemediationFyCoeff() { + return debtRemediationFyCoeff; + } + + /** + * @deprecated since 5.5 + */ + @Deprecated + public UpdateRequest setDebtSubCharacteristic(String debtSubCharacteristic) { + this.debtSubCharacteristic = debtSubCharacteristic; + return this; + } + + public String getDebtSubCharacteristic() { + return debtSubCharacteristic; + } + + /** * This is a mandatory parameter. * Example value: "javascript:NullCheck" */ diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/users/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/users/SearchRequest.java index 3b206b526e2..e3cfead6dae 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/users/SearchRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/users/SearchRequest.java @@ -31,11 +31,37 @@ import javax.annotation.Generated; @Generated("sonar-ws-generator") public class SearchRequest { + private List<String> f; private String p; private String ps; private String q; /** + * Possible values: + * <ul> + * <li>"name"</li> + * <li>"email"</li> + * <li>"avatart"</li> + * <li>"scmAccounts"</li> + * <li>"groups"</li> + * <li>"active"</li> + * <li>"local"</li> + * <li>"externalIdentity"</li> + * <li>"externalProvider"</li> + * </ul> + * @deprecated since 5.4 + */ + @Deprecated + public SearchRequest setF(List<String> f) { + this.f = f; + return this; + } + + public List<String> getF() { + return f; + } + + /** * Example value: "42" */ public SearchRequest setP(String p) { diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/users/UsersService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/users/UsersService.java index c96a7aa4930..dcbda8e2c2b 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/users/UsersService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/users/UsersService.java @@ -149,6 +149,7 @@ public class UsersService extends BaseService { public SearchWsResponse search(SearchRequest request) { return call( new GetRequest(path("search")) + .setParam("f", request.getF() == null ? null : request.getF().stream().collect(Collectors.joining(","))) .setParam("p", request.getP()) .setParam("ps", request.getPs()) .setParam("q", request.getQ()), |