From: Julien Lancelot Date: Thu, 23 Jun 2016 07:51:38 +0000 (+0200) Subject: UserSession should not be used when defining WS X-Git-Tag: 6.0-RC1~235 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2ec26550db9c30a64f114acdee307f51775dd944;p=sonarqube.git UserSession should not be used when defining WS As UserSession is not set at startup, using it to get the user locale is useless. It's netter to directly use English locale (which is the default value) --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java index 2f6d5e497f9..19244fa4091 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java @@ -19,6 +19,13 @@ */ package org.sonar.server.component.ws; +import static com.google.common.collect.FluentIterable.from; +import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; +import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; +import static org.sonar.server.ws.WsUtils.writeProtobuf; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_LANGUAGE; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; + import com.google.common.base.Function; import java.util.List; import javax.annotation.Nonnull; @@ -40,13 +47,6 @@ import org.sonarqube.ws.WsComponents; import org.sonarqube.ws.WsComponents.SearchWsResponse; import org.sonarqube.ws.client.component.SearchWsRequest; -import static com.google.common.collect.FluentIterable.from; -import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; -import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; -import static org.sonar.server.ws.WsUtils.writeProtobuf; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_LANGUAGE; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; - public class SearchAction implements ComponentsWsAction { private final DbClient dbClient; private final ResourceTypes resourceTypes; @@ -73,7 +73,7 @@ public class SearchAction implements ComponentsWsAction { .setResponseExample(getClass().getResource("search-components-example.json")) .setHandler(this); - createQualifiersParameter(action, newQualifierParameterContext(userSession, i18n, resourceTypes)) + createQualifiersParameter(action, newQualifierParameterContext(i18n, resourceTypes)) .setRequired(true); action diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java index 7e46b87b2b4..3ddb250ea0b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java @@ -19,6 +19,26 @@ */ package org.sonar.server.component.ws; +import static com.google.common.base.MoreObjects.firstNonNull; +import static com.google.common.collect.FluentIterable.from; +import static com.google.common.collect.Sets.newHashSet; +import static java.lang.String.format; +import static java.util.Collections.emptyMap; +import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; +import static org.sonar.server.component.ComponentFinder.ParamNames.BASE_COMPONENT_ID_AND_KEY; +import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent; +import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; +import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; +import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; +import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; +import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.ws.WsUtils.writeProtobuf; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_ID; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_KEY; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY; + import com.google.common.base.Predicates; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Sets; @@ -45,26 +65,6 @@ import org.sonar.server.user.UserSession; import org.sonarqube.ws.WsComponents.TreeWsResponse; import org.sonarqube.ws.client.component.TreeWsRequest; -import static com.google.common.base.MoreObjects.firstNonNull; -import static com.google.common.collect.FluentIterable.from; -import static com.google.common.collect.Sets.newHashSet; -import static java.lang.String.format; -import static java.util.Collections.emptyMap; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; -import static org.sonar.server.component.ComponentFinder.ParamNames.BASE_COMPONENT_ID_AND_KEY; -import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent; -import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; -import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; -import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; -import static org.sonar.server.ws.WsUtils.checkRequest; -import static org.sonar.server.ws.WsUtils.writeProtobuf; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_ID; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_KEY; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; -import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY; - public class TreeAction implements ComponentsWsAction { private static final int MAX_SIZE = 500; private static final int QUERY_MINIMUM_LENGTH = 3; @@ -128,7 +128,7 @@ public class TreeAction implements ComponentsWsAction { "Must have at least %d characters", QUERY_MINIMUM_LENGTH)) .setExampleValue("FILE_NAM"); - createQualifiersParameter(action, newQualifierParameterContext(userSession, i18n, resourceTypes)); + createQualifiersParameter(action, newQualifierParameterContext(i18n, resourceTypes)); action.createParam(PARAM_STRATEGY) .setDescription("Strategy to search for base component descendants:" + diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java index 2b872defd6f..d0fafede87c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java @@ -19,22 +19,6 @@ */ package org.sonar.server.measure.ws; -import com.google.common.collect.ImmutableSortedSet; -import java.util.Set; -import org.sonar.api.i18n.I18n; -import org.sonar.api.resources.ResourceTypes; -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; -import org.sonar.api.server.ws.WebService.Param; -import org.sonar.api.utils.Paging; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.metric.MetricDto; -import org.sonar.server.user.UserSession; -import org.sonarqube.ws.WsMeasures; -import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse; -import org.sonarqube.ws.client.measure.ComponentTreeWsRequest; - import static java.lang.String.format; import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; import static org.sonar.server.measure.ws.ComponentDtoToWsComponent.componentDtoToWsComponent; @@ -62,6 +46,21 @@ import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_ import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; +import com.google.common.collect.ImmutableSortedSet; +import java.util.Set; +import org.sonar.api.i18n.I18n; +import org.sonar.api.resources.ResourceTypes; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; +import org.sonar.api.server.ws.WebService.Param; +import org.sonar.api.utils.Paging; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.metric.MetricDto; +import org.sonarqube.ws.WsMeasures; +import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse; +import org.sonarqube.ws.client.measure.ComponentTreeWsRequest; + /** *

Navigate through components based on different strategy with specified measures. * To limit the number of rows in database, a best value algorithm exists in database.

@@ -98,14 +97,12 @@ public class ComponentTreeAction implements MeasuresWsAction { static final Set METRIC_SORT_FILTERS = ImmutableSortedSet.of(ALL_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER); private final ComponentTreeDataLoader dataLoader; - private final UserSession userSession; private final I18n i18n; private final ResourceTypes resourceTypes; - public ComponentTreeAction(ComponentTreeDataLoader dataLoader, UserSession userSession, I18n i18n, + public ComponentTreeAction(ComponentTreeDataLoader dataLoader, I18n i18n, ResourceTypes resourceTypes) { this.dataLoader = dataLoader; - this.userSession = userSession; this.i18n = i18n; this.resourceTypes = resourceTypes; } @@ -170,7 +167,7 @@ public class ComponentTreeAction implements MeasuresWsAction { createMetricKeysParameter(action); createAdditionalFieldsParameter(action); createDeveloperParameters(action); - createQualifiersParameter(action, newQualifierParameterContext(userSession, i18n, resourceTypes)); + createQualifiersParameter(action, newQualifierParameterContext(i18n, resourceTypes)); action.createParam(PARAM_STRATEGY) .setDescription("Strategy to search for base component descendants:" + diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java index 1769c4a96b8..16f874738e6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java @@ -19,6 +19,19 @@ */ package org.sonar.server.permission.ws; +import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser; +import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey; +import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentUuid; +import static org.sonar.server.permission.ws.PermissionRequestValidator.validateQualifier; +import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters; +import static org.sonar.server.permission.ws.WsProjectRef.newOptionalWsProjectRef; +import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; +import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter; +import static org.sonar.server.ws.WsUtils.writeProtobuf; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; + import com.google.common.base.Optional; import org.sonar.api.i18n.I18n; import org.sonar.api.resources.ResourceTypes; @@ -38,19 +51,6 @@ import org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse; import org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse.Project; import org.sonarqube.ws.client.permission.SearchProjectPermissionsWsRequest; -import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser; -import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey; -import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentUuid; -import static org.sonar.server.permission.ws.PermissionRequestValidator.validateQualifier; -import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters; -import static org.sonar.server.permission.ws.WsProjectRef.newOptionalWsProjectRef; -import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; -import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter; -import static org.sonar.server.ws.WsUtils.writeProtobuf; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; - public class SearchProjectPermissionsAction implements PermissionsWsAction { private static final String PROPERTY_PREFIX = "projects_role."; private static final String DESCRIPTION_SUFFIX = ".desc"; @@ -86,7 +86,7 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction { "") .setExampleValue("apac"); createProjectParameters(action); - createRootQualifierParameter(action, newQualifierParameterContext(userSession, i18n, resourceTypes)) + createRootQualifierParameter(action, newQualifierParameterContext(i18n, resourceTypes)) .setSince("5.3"); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/BulkApplyTemplateAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/BulkApplyTemplateAction.java index 108db1cad44..8381bddfca7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/BulkApplyTemplateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/BulkApplyTemplateAction.java @@ -20,6 +20,15 @@ package org.sonar.server.permission.ws.template; +import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; +import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters; +import static org.sonar.server.permission.ws.WsTemplateRef.newTemplateRef; +import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; +import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; + import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import java.util.List; @@ -40,32 +49,20 @@ import org.sonar.server.permission.ApplyPermissionTemplateQuery; import org.sonar.server.permission.PermissionService; import org.sonar.server.permission.ws.PermissionDependenciesFinder; import org.sonar.server.permission.ws.PermissionsWsAction; -import org.sonar.server.user.UserSession; import org.sonarqube.ws.client.permission.BulkApplyTemplateWsRequest; -import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; -import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters; -import static org.sonar.server.permission.ws.WsTemplateRef.newTemplateRef; -import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; -import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; - public class BulkApplyTemplateAction implements PermissionsWsAction { private final DbClient dbClient; private final PermissionService permissionService; private final PermissionDependenciesFinder finder; - private final UserSession userSession; private final I18n i18n; private final ResourceTypes resourceTypes; - public BulkApplyTemplateAction(DbClient dbClient, PermissionService permissionService, PermissionDependenciesFinder finder, UserSession userSession, I18n i18n, + public BulkApplyTemplateAction(DbClient dbClient, PermissionService permissionService, PermissionDependenciesFinder finder, I18n i18n, ResourceTypes resourceTypes) { this.dbClient = dbClient; this.permissionService = permissionService; this.finder = finder; - this.userSession = userSession; this.i18n = i18n; this.resourceTypes = resourceTypes; } @@ -86,7 +83,7 @@ public class BulkApplyTemplateAction implements PermissionsWsAction { "
  • project keys that are exactly the same as the supplied string
  • " + "") .setExampleValue("apac"); - createRootQualifierParameter(action, newQualifierParameterContext(userSession, i18n, resourceTypes)); + createRootQualifierParameter(action, newQualifierParameterContext(i18n, resourceTypes)); createTemplateParameters(action); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java index d94f2742bfc..0f8e2702a9a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java @@ -19,6 +19,17 @@ */ package org.sonar.server.permission.ws.template; +import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty; +import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser; +import static org.sonar.server.permission.ws.PermissionRequestValidator.validateQualifier; +import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters; +import static org.sonar.server.permission.ws.WsTemplateRef.newTemplateRef; +import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; +import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; + import org.sonar.api.i18n.I18n; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.ResourceTypes; @@ -34,17 +45,6 @@ import org.sonar.server.platform.PersistentSettings; import org.sonar.server.user.UserSession; import org.sonarqube.ws.client.permission.SetDefaultTemplateWsRequest; -import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty; -import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser; -import static org.sonar.server.permission.ws.PermissionRequestValidator.validateQualifier; -import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters; -import static org.sonar.server.permission.ws.WsTemplateRef.newTemplateRef; -import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; -import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; - public class SetDefaultTemplateAction implements PermissionsWsAction { private final DbClient dbClient; private final PermissionDependenciesFinder finder; @@ -73,7 +73,7 @@ public class SetDefaultTemplateAction implements PermissionsWsAction { .setHandler(this); createTemplateParameters(action); - createRootQualifierParameter(action, newQualifierParameterContext(userSession, i18n, resourceTypes)) + createRootQualifierParameter(action, newQualifierParameterContext(i18n, resourceTypes)) .setDefaultValue(Qualifiers.PROJECT); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java index 4fb89a3fda2..533b4237fb2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java @@ -19,21 +19,21 @@ */ package org.sonar.server.ws; +import static com.google.common.base.Predicates.not; +import static com.google.common.collect.FluentIterable.from; +import static com.google.common.collect.Ordering.natural; +import static java.lang.String.format; +import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; + import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; +import java.util.Locale; import java.util.Set; import javax.annotation.Nullable; import org.sonar.api.i18n.I18n; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.ResourceTypes; import org.sonar.api.server.ws.WebService; -import org.sonar.server.user.UserSession; - -import static com.google.common.base.Predicates.not; -import static com.google.common.collect.FluentIterable.from; -import static com.google.common.collect.Ordering.natural; -import static java.lang.String.format; -import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; public class WsParameterBuilder { private static final String PARAM_QUALIFIER = "qualifier"; @@ -94,7 +94,7 @@ public class WsParameterBuilder { private static String qualifierLabel(QualifierParameterContext context, String qualifier) { String qualifiersPropertyPrefix = "qualifiers."; - return context.getI18n().message(context.getUserSession().locale(), qualifiersPropertyPrefix + qualifier, "no description available"); + return context.getI18n().message(Locale.ENGLISH, qualifiersPropertyPrefix + qualifier, "no description available"); } private enum IsDeprecatedQualifier implements Predicate { @@ -109,16 +109,14 @@ public class WsParameterBuilder { public static class QualifierParameterContext { private final I18n i18n; private final ResourceTypes resourceTypes; - private final UserSession userSession; - private QualifierParameterContext(UserSession userSession, I18n i18n, ResourceTypes resourceTypes) { + private QualifierParameterContext(I18n i18n, ResourceTypes resourceTypes) { this.i18n = i18n; this.resourceTypes = resourceTypes; - this.userSession = userSession; } - public static QualifierParameterContext newQualifierParameterContext(UserSession userSession, I18n i18n, ResourceTypes resourceTypes) { - return new QualifierParameterContext(userSession, i18n, resourceTypes); + public static QualifierParameterContext newQualifierParameterContext(I18n i18n, ResourceTypes resourceTypes) { + return new QualifierParameterContext(i18n, resourceTypes); } public I18n getI18n() { @@ -128,9 +126,5 @@ public class WsParameterBuilder { public ResourceTypes getResourceTypes() { return resourceTypes; } - - public UserSession getUserSession() { - return userSession; - } } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 258671f05d5..3a23f277d56 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -19,6 +19,35 @@ */ package org.sonar.server.measure.ws; +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.api.utils.DateUtils.parseDateTime; +import static org.sonar.db.component.ComponentTesting.newDevProjectCopy; +import static org.sonar.db.component.ComponentTesting.newDeveloper; +import static org.sonar.db.component.ComponentTesting.newDirectory; +import static org.sonar.db.component.ComponentTesting.newFileDto; +import static org.sonar.db.component.ComponentTesting.newProjectDto; +import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject; +import static org.sonar.db.measure.MeasureTesting.newMeasureDto; +import static org.sonar.db.metric.MetricTesting.newMetricDto; +import static org.sonar.server.measure.ws.ComponentTreeAction.CHILDREN_STRATEGY; +import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY; +import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_PERIOD_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.WITH_MEASURES_ONLY_METRIC_SORT_FILTER; +import static org.sonar.test.JsonAssert.assertJson; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; + import com.google.common.base.Throwables; import java.io.IOException; import java.io.InputStream; @@ -55,35 +84,6 @@ import org.sonarqube.ws.MediaTypes; import org.sonarqube.ws.WsMeasures; import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse; -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.api.utils.DateUtils.parseDateTime; -import static org.sonar.db.component.ComponentTesting.newDevProjectCopy; -import static org.sonar.db.component.ComponentTesting.newDeveloper; -import static org.sonar.db.component.ComponentTesting.newDirectory; -import static org.sonar.db.component.ComponentTesting.newFileDto; -import static org.sonar.db.component.ComponentTesting.newProjectDto; -import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject; -import static org.sonar.db.measure.MeasureTesting.newMeasureDto; -import static org.sonar.db.metric.MetricTesting.newMetricDto; -import static org.sonar.server.measure.ws.ComponentTreeAction.CHILDREN_STRATEGY; -import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY; -import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_PERIOD_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.WITH_MEASURES_ONLY_METRIC_SORT_FILTER; -import static org.sonar.test.JsonAssert.assertJson; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; - public class ComponentTreeActionTest { @Rule public UserSessionRule userSession = UserSessionRule.standalone(); @@ -101,7 +101,7 @@ public class ComponentTreeActionTest { WsActionTester ws = new WsActionTester( new ComponentTreeAction( new ComponentTreeDataLoader(dbClient, new ComponentFinder(dbClient), userSession, resourceTypes), - userSession, i18n, resourceTypes)); + i18n, resourceTypes)); @Before public void setUp() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MeasuresWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MeasuresWsTest.java index c03ec1f46d1..d03ca157ef5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MeasuresWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MeasuresWsTest.java @@ -20,21 +20,19 @@ package org.sonar.server.measure.ws; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + import org.junit.Test; import org.sonar.api.i18n.I18n; import org.sonar.api.resources.ResourceTypes; import org.sonar.api.server.ws.WebService; -import org.sonar.server.user.UserSession; import org.sonar.server.ws.WsTester; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - public class MeasuresWsTest { WsTester ws = new WsTester( new MeasuresWs( - new ComponentTreeAction(mock(ComponentTreeDataLoader.class), mock(UserSession.class), mock(I18n.class), mock(ResourceTypes.class)) - )); + new ComponentTreeAction(mock(ComponentTreeDataLoader.class), mock(I18n.class), mock(ResourceTypes.class)))); @Test public void define_ws() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java index a85274eaa32..100e3843f93 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java @@ -20,6 +20,19 @@ package org.sonar.server.permission.ws.template; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.sonar.db.component.ComponentTesting.newDeveloper; +import static org.sonar.db.component.ComponentTesting.newProjectDto; +import static org.sonar.db.component.ComponentTesting.newView; +import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto; +import static org.sonar.db.user.GroupMembershipQuery.IN; +import static org.sonar.db.user.GroupTesting.newGroupDto; +import static org.sonar.db.user.UserTesting.newUserDto; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; + import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; import java.util.List; @@ -63,19 +76,6 @@ import org.sonar.server.usergroups.ws.UserGroupFinder; import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.sonar.db.component.ComponentTesting.newDeveloper; -import static org.sonar.db.component.ComponentTesting.newProjectDto; -import static org.sonar.db.component.ComponentTesting.newView; -import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto; -import static org.sonar.db.user.GroupMembershipQuery.IN; -import static org.sonar.db.user.GroupTesting.newGroupDto; -import static org.sonar.db.user.UserTesting.newUserDto; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; -import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; - public class BulkApplyTemplateActionTest { @Rule public UserSessionRule userSession = UserSessionRule.standalone().login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); @@ -108,7 +108,7 @@ public class BulkApplyTemplateActionTest { PermissionService permissionService = new PermissionService(dbClient, repository, issueAuthorizationIndexer, userSession, componentFinder); PermissionDependenciesFinder permissionDependenciesFinder = new PermissionDependenciesFinder(dbClient, componentFinder, new UserGroupFinder(dbClient), resourceTypes); - BulkApplyTemplateAction underTest = new BulkApplyTemplateAction(dbClient, permissionService, permissionDependenciesFinder, userSession, i18n, resourceTypes); + BulkApplyTemplateAction underTest = new BulkApplyTemplateAction(dbClient, permissionService, permissionDependenciesFinder, i18n, resourceTypes); ws = new WsActionTester(underTest); user1 = userDb.insertUser(newUserDto().setLogin("user-login-1"));