diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-12-22 15:41:53 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-12-22 15:41:53 +0100 |
commit | e52ca10a4a1b07d05c894e0d8564ffa1b5af3e47 (patch) | |
tree | 8df9d718a33e98798413819aa8311f967bfb500d | |
parent | 1b7c506dd991ce78832defd34e34549759a8fa2b (diff) | |
download | sonarqube-e52ca10a4a1b07d05c894e0d8564ffa1b5af3e47.tar.gz sonarqube-e52ca10a4a1b07d05c894e0d8564ffa1b5af3e47.zip |
Fix quality flaws
4 files changed, 25 insertions, 33 deletions
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 12d71fb54f6..a781d229366 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 @@ -369,25 +369,26 @@ public class SearchAction implements IssuesWsAction { addMandatoryValuesToFacet(facets, PARAM_TYPES, RuleType.names()); addMandatoryValuesToFacet(facets, PARAM_COMPONENT_UUIDS, request.getComponentUuids()); - for (String facetName : request.getFacets()) { - LinkedHashMap<String, Long> buckets = facets.get(facetName); - if (!FACET_ASSIGNED_TO_ME.equals(facetName)) { - if (buckets != null) { - List<String> requestParams = wsRequest.paramAsStrings(facetName); - if (requestParams != null) { - for (String param : requestParams) { - if (!buckets.containsKey(param) && !IssueQueryService.LOGIN_MYSELF.equals(param)) { - // Prevent appearance of a glitch value due to dedicated parameter for this facet - buckets.put(param, 0L); - } - } - } - } - } + List<String> requestedFacets = request.getFacets(); + if (requestedFacets == null) { + return; } + requestedFacets.stream() + .filter(facetName -> !FACET_ASSIGNED_TO_ME.equals(facetName)) + .forEach(facetName -> { + LinkedHashMap<String, Long> buckets = facets.get(facetName); + List<String> requestParams = wsRequest.paramAsStrings(facetName); + if (buckets == null || requestParams == null) { + return; + } + requestParams.stream() + .filter(param -> !buckets.containsKey(param) && !IssueQueryService.LOGIN_MYSELF.equals(param)) + // Prevent appearance of a glitch value due to dedicated parameter for this facet + .forEach(param -> buckets.put(param, 0L)); + }); } - private void addMandatoryValuesToFacet(Facets facets, String facetName, @Nullable Iterable<String> mandatoryValues) { + private static void addMandatoryValuesToFacet(Facets facets, String facetName, @Nullable Iterable<String> mandatoryValues) { Map<String, Long> buckets = facets.get(facetName); if (buckets != null && mandatoryValues != null) { for (String mandatoryValue : mandatoryValues) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java index fae8f46b7d4..2db5c5456eb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java @@ -19,13 +19,10 @@ */ package org.sonar.server.qualitygate.ws; -import com.google.common.base.Function; -import com.google.common.base.Joiner; import com.google.common.base.Optional; -import com.google.common.collect.Lists; import java.util.Arrays; import java.util.List; -import javax.annotation.Nonnull; +import java.util.stream.Collectors; import javax.annotation.Nullable; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.server.ws.Request; @@ -59,14 +56,9 @@ import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_KEY; public class ProjectStatusAction implements QualityGatesWsAction { - private static final String QG_STATUSES_ONE_LINE = Joiner.on(", ") - .join(Lists.transform(Arrays.asList(ProjectStatusWsResponse.Status.values()), new Function<ProjectStatusWsResponse.Status, String>() { - @Nonnull - @Override - public String apply(@Nonnull ProjectStatusWsResponse.Status input) { - return input.toString(); - } - })); + private static final String QG_STATUSES_ONE_LINE = Arrays.stream(ProjectStatusWsResponse.Status.values()) + .map(Enum::toString) + .collect(Collectors.joining(", ")); private static final String MSG_ONE_PARAMETER_ONLY = String.format("One (and only one) of the following parameters must be provided '%s', '%s', '%s'", PARAM_ANALYSIS_ID, PARAM_PROJECT_ID, PARAM_PROJECT_KEY); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java index 1c913271076..453ed994b4e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java @@ -191,7 +191,7 @@ public interface WebService extends Definable<WebService.Context> { private final Map<String, Action> actions; private Controller(NewController newController) { - checkState(!newController.actions.isEmpty(), format("At least one action must be declared in the web service '%s'", newController.path)); + checkState(!newController.actions.isEmpty(), "At least one action must be declared in the web service '%s'", newController.path); this.path = newController.path; this.description = newController.description; this.since = newController.since; @@ -327,8 +327,7 @@ public interface WebService extends Definable<WebService.Context> { } public NewParam createParam(String paramKey) { - checkState(!newParams.containsKey(paramKey), - format("The parameter '%s' is defined multiple times in the action '%s'", paramKey, key)); + checkState(!newParams.containsKey(paramKey), "The parameter '%s' is defined multiple times in the action '%s'", paramKey, key); NewParam newParam = new NewParam(paramKey); newParams.put(paramKey, newParam); return newParam; @@ -485,7 +484,7 @@ public interface WebService extends Definable<WebService.Context> { this.responseExample = newAction.responseExample; this.handler = newAction.handler; - checkState(this.handler != null, "RequestHandler is not set on action " + path); + checkState(this.handler != null, "RequestHandler is not set on action %s", path); logWarningIf(isNullOrEmpty(this.description), "Description is not set on action " + path); logWarningIf(isNullOrEmpty(this.since), "Since is not set on action " + path); logWarningIf(!this.post && this.responseExample == null, "The response example is not set on action " + path); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequest.java index ed9e6481ac8..ec1eb1ace49 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequest.java @@ -30,7 +30,7 @@ public class UpdateEventRequest { public UpdateEventRequest(String event, String name) { this.event = requireNonNull(event, "Event key is required"); - this.name = requireNonNull(name, "Name is required");; + this.name = requireNonNull(name, "Name is required"); } public String getEvent() { |