diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-01-29 11:09:09 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-01-29 11:09:13 +0100 |
commit | d7f6c55d9bbedb86c0addac10c39ad6b3207893e (patch) | |
tree | dc36226b541187c21126f647cde92b180aef1c4e | |
parent | 55e42ef7efda721085d7be809689935f385676fd (diff) | |
download | sonarqube-d7f6c55d9bbedb86c0addac10c39ad6b3207893e.tar.gz sonarqube-d7f6c55d9bbedb86c0addac10c39ad6b3207893e.zip |
SONAR-7129 WS api/components/tree leaves strategy with qualifiers fixed
3 files changed, 26 insertions, 21 deletions
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 0855467bc91..54ebdd8eacd 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 @@ -22,6 +22,8 @@ package org.sonar.server.component.ws; import com.google.common.base.Function; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Sets; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -52,6 +54,7 @@ import org.sonarqube.ws.client.component.TreeWsRequest; import static com.google.common.base.Objects.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; @@ -210,7 +213,7 @@ public class TreeAction implements ComponentsWsAction { } private static TreeWsResponse buildResponse(ComponentDto baseComponent, List<ComponentDtoWithSnapshotId> components, Map<Long, ComponentDto> referenceComponentsById, - Paging paging) { + Paging paging) { TreeWsResponse.Builder response = TreeWsResponse.newBuilder(); response.getPagingBuilder() .setPageIndex(paging.pageIndex()) @@ -293,10 +296,9 @@ public class TreeAction implements ComponentsWsAction { return requestQualifiers; } - // intersection of request and children qualifiers - childrenQualifiers.retainAll(requestQualifiers); + Sets.SetView<String> intersectQualifiers = Sets.intersection(newHashSet(childrenQualifiers), newHashSet(requestQualifiers)); - return childrenQualifiers; + return new ArrayList<>(intersectQualifiers); } private static TreeWsRequest toTreeWsRequest(Request request) { @@ -310,7 +312,7 @@ public class TreeAction implements ComponentsWsAction { .setAsc(request.mandatoryParamAsBoolean(Param.ASCENDING)) .setPage(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)); - checkRequest(treeWsRequest.getPageSize() <= MAX_SIZE, "The '%s' parameter must be less thant %d", Param.PAGE_SIZE, MAX_SIZE); + checkRequest(treeWsRequest.getPageSize() <= MAX_SIZE, "The '%s' parameter must be less than %d", Param.PAGE_SIZE, MAX_SIZE); return treeWsRequest; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index 2fe4f1d7669..44c23ca29f7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -187,6 +187,7 @@ public class TreeActionTest { .setMediaType(MediaTypes.PROTOBUF) .setParam(PARAM_STRATEGY, "leaves") .setParam(PARAM_BASE_COMPONENT_ID, "project-uuid") + .setParam(PARAM_QUALIFIERS, Qualifiers.FILE) .execute().getInputStream(); WsComponents.TreeWsResponse response = WsComponents.TreeWsResponse.parseFrom(responseStream); @@ -296,7 +297,7 @@ public class TreeActionTest { @Test public void fail_when_page_size_above_500() { expectedException.expect(BadRequestException.class); - expectedException.expectMessage("The 'ps' parameter must be less thant 500"); + expectedException.expectMessage("The 'ps' parameter must be less than 500"); componentDb.insertComponent(newProjectDto("project-uuid")); db.commit(); diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java index eb73a9627ce..01e386f91ad 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceTypesRule.java @@ -19,8 +19,8 @@ */ package org.sonar.db.component; -import java.util.ArrayList; -import java.util.Arrays; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -29,11 +29,14 @@ import org.sonar.api.resources.ResourceType; import org.sonar.api.resources.ResourceTypeTree; import org.sonar.api.resources.ResourceTypes; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptySet; + public class ResourceTypesRule extends ResourceTypes { - private final Set<ResourceType> allResourceTypes = new HashSet<>(); - private final Set<ResourceType> rootResourceTypes = new HashSet<>(); - private final List<String> childrenQualifiers = new ArrayList<>(); - private final List<String> leavesQualifiers = new ArrayList<>(); + private Set<ResourceType> allResourceTypes = emptySet(); + private Set<ResourceType> rootResourceTypes = emptySet(); + private List<String> childrenQualifiers = emptyList(); + private List<String> leavesQualifiers = emptyList(); @Override public Collection<ResourceType> getAll() { @@ -46,32 +49,31 @@ public class ResourceTypesRule extends ResourceTypes { } public ResourceTypesRule setRootQualifiers(String... qualifiers) { - rootResourceTypes.clear(); + Set<ResourceType> resourceTypes = new HashSet<>(); for (String qualifier : qualifiers) { - rootResourceTypes.add(ResourceType.builder(qualifier).build()); + resourceTypes.add(ResourceType.builder(qualifier).build()); } + rootResourceTypes = ImmutableSet.copyOf(resourceTypes); return this; } public ResourceTypesRule setLeavesQualifiers(String... qualifiers) { - leavesQualifiers.clear(); - leavesQualifiers.addAll(Arrays.asList(qualifiers)); + leavesQualifiers = ImmutableList.copyOf(qualifiers); return this; } public ResourceTypesRule setChildrenQualifiers(String... qualifiers) { - childrenQualifiers.clear(); - childrenQualifiers.addAll(Arrays.asList(qualifiers)); - + childrenQualifiers = ImmutableList.copyOf(qualifiers); return this; } public ResourceTypesRule setAllQualifiers(String... qualifiers) { - allResourceTypes.clear(); + Set<ResourceType> resourceTypes = new HashSet<>(); for (String qualifier : qualifiers) { - allResourceTypes.add(ResourceType.builder(qualifier).build()); + resourceTypes.add(ResourceType.builder(qualifier).build()); } + allResourceTypes = ImmutableSet.copyOf(resourceTypes); return this; } |