diff options
Diffstat (limited to 'sonar-ws/src')
7 files changed, 23 insertions, 31 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java index 6442a6d187d..8a0a4b39a20 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java @@ -137,7 +137,7 @@ abstract class BaseRequest<SELF extends BaseRequest<SELF>> implements WsRequest parameters.setValues(key, values.stream() .filter(Objects::nonNull) .map(Object::toString) - .collect(Collectors.toList())); + .toList()); return (T) this; } @@ -203,7 +203,7 @@ abstract class BaseRequest<SELF extends BaseRequest<SELF>> implements WsRequest checkArgument(!isNullOrEmpty(key)); checkArgument(values != null && !values.isEmpty()); - keyValues.computeIfAbsent(key, k -> new ArrayList<>()).addAll(values.stream().map(Object::toString).filter(Objects::nonNull).collect(Collectors.toList())); + keyValues.computeIfAbsent(key, k -> new ArrayList<>()).addAll(values.stream().map(Object::toString).filter(Objects::nonNull).toList()); return this; } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java index a4fec2726a4..b697095cae0 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java @@ -21,6 +21,7 @@ package org.sonarqube.ws.client; import java.io.IOException; import java.net.Proxy; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; @@ -109,11 +110,11 @@ public class HttpConnector implements WsConnector { @Override public WsResponse call(WsRequest httpRequest) { - if (httpRequest instanceof RequestWithoutPayload) { - return executeRequest((RequestWithoutPayload) httpRequest); + if (httpRequest instanceof RequestWithoutPayload httpRequestWithoutPayload) { + return executeRequest(httpRequestWithoutPayload); } - if (httpRequest instanceof RequestWithPayload) { - return executeRequest((RequestWithPayload) httpRequest); + if (httpRequest instanceof RequestWithPayload httpRequestWithPayload) { + return executeRequest(httpRequestWithPayload); } throw new IllegalArgumentException(format("Unsupported implementation: %s", httpRequest.getClass())); } @@ -213,19 +214,15 @@ public class HttpConnector implements WsConnector { } private Response checkRedirect(Response response, RequestWithPayload<?> postRequest) { - switch (response.code()) { - case HTTP_MOVED_PERM: - case HTTP_MOVED_TEMP: - case HTTP_TEMP_REDIRECT: - case HTTP_PERM_REDIRECT: - // OkHttpClient does not follow the redirect with the same HTTP method. A POST is - // redirected to a GET. Because of that the redirect must be manually implemented. - // See: - // https://github.com/square/okhttp/blob/07309c1c7d9e296014268ebd155ebf7ef8679f6c/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.java#L316 - // https://github.com/square/okhttp/issues/936#issuecomment-266430151 - return followPostRedirect(response, postRequest); - default: - return response; + if (List.of(HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_TEMP_REDIRECT, HTTP_PERM_REDIRECT).contains(response.code())) { + // OkHttpClient does not follow the redirect with the same HTTP method. A POST is + // redirected to a GET. Because of that the redirect must be manually implemented. + // See: + // https://github.com/square/okhttp/blob/07309c1c7d9e296014268ebd155ebf7ef8679f6c/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.java#L316 + // https://github.com/square/okhttp/issues/936#issuecomment-266430151 + return followPostRedirect(response, postRequest); + } else { + return response; } } diff --git a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/GroupTester.java b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/GroupTester.java index bf36e3b4d8e..00bff8cdccd 100644 --- a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/GroupTester.java +++ b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/GroupTester.java @@ -88,7 +88,7 @@ public class GroupTester { public GroupTester deleteAllGenerated() { List<String> allGroups = session.wsClient().userGroups().search(new SearchRequest()).getGroupsList().stream().map(UserGroups.Group::getName) - .collect(Collectors.toList()); + .toList(); allGroups.stream() .filter(g -> g.matches("Group\\d+$")) .forEach(g -> session.wsClient().userGroups().delete(new DeleteRequest().setName(g))); @@ -97,7 +97,7 @@ public class GroupTester { public GroupTester delete(UserGroups.Group... groups) { List<String> allGroups = session.wsClient().userGroups().search(new SearchRequest()).getGroupsList().stream().map(UserGroups.Group::getName) - .collect(Collectors.toList()); + .toList(); stream(groups) .filter(g -> allGroups.contains(g.getName())) .forEach(g -> session.wsClient().userGroups().delete(new DeleteRequest().setName(g.getName()))); diff --git a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/QGateTester.java b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/QGateTester.java index 232949dffa5..b7efbfc9d2f 100644 --- a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/QGateTester.java +++ b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/QGateTester.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -import java.util.stream.Collectors; import org.sonarqube.ws.Projects.CreateWsResponse.Project; import org.sonarqube.ws.client.qualitygates.CreateRequest; import org.sonarqube.ws.client.qualitygates.DestroyRequest; @@ -54,7 +53,7 @@ public class QGateTester { void deleteAll() { List<ListWsResponse.QualityGate> builtInQualityGates = session.wsClient().qualitygates().list(new ListRequest()).getQualitygatesList().stream() .filter(ListWsResponse.QualityGate::getIsBuiltIn) - .collect(Collectors.toList()); + .toList(); if (builtInQualityGates.size() == 1) { session.wsClient().qualitygates().setAsDefault(new SetAsDefaultRequest().setName(builtInQualityGates.get(0).getName())); } diff --git a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/QProfileTester.java b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/QProfileTester.java index 99202a15657..71130367f8d 100644 --- a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/QProfileTester.java +++ b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/QProfileTester.java @@ -27,7 +27,6 @@ package org.sonarqube.ws.tester; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -import java.util.stream.Collectors; import javax.annotation.Nullable; import org.sonarqube.ws.Projects.CreateWsResponse.Project; import org.sonarqube.ws.Qualityprofiles; @@ -60,7 +59,7 @@ public class QProfileTester { .filter(qp -> !qp.getIsDefault()) .filter(qp -> !qp.getIsBuiltIn()) .filter(qp -> qp.getParentKey() == null || qp.getParentKey().equals("")) - .collect(Collectors.toList()); + .toList(); qualityProfiles.forEach( qp -> session.wsClient().qualityprofiles().delete(new DeleteRequest().setQualityProfile(qp.getName()).setLanguage(qp.getLanguage()))); diff --git a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/SettingTester.java b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/SettingTester.java index abc45cacac0..c38b997b958 100644 --- a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/SettingTester.java +++ b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/SettingTester.java @@ -19,11 +19,9 @@ */ package org.sonarqube.ws.tester; -import com.google.common.collect.ImmutableSet; import java.util.Arrays; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; import org.sonarqube.ws.Settings; @@ -38,7 +36,7 @@ import static java.util.Arrays.asList; public class SettingTester { - private static final Set<String> EMAIL_SETTINGS = ImmutableSet.of("email.smtp_host.secured", "email.smtp_port.secured", "email.smtp_secure_connection.secured", + private static final Set<String> EMAIL_SETTINGS = Set.of("email.smtp_host.secured", "email.smtp_port.secured", "email.smtp_secure_connection.secured", "email.smtp_username.secured", "email.smtp_password.secured", "email.from", "email.prefix"); private final TesterSession session; @@ -59,7 +57,7 @@ public class SettingTester { .map(Settings.Definition::getKey) .filter(key -> !key.equals(Tester.FORCE_AUTHENTICATION_PROPERTY_NAME)), EMAIL_SETTINGS.stream()) - .collect(Collectors.toList()); + .toList(); session.wsClient().settings().reset(new ResetRequest().setKeys(settingKeys)); } diff --git a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/UserTester.java b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/UserTester.java index 7966560052b..f5dbe9bb912 100644 --- a/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/UserTester.java +++ b/sonar-ws/src/testFixtures/java/org/sonarqube/ws/tester/UserTester.java @@ -25,7 +25,6 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.function.Predicate; -import java.util.stream.Collectors; import javax.annotation.Nullable; import org.sonarqube.ws.UserTokens; import org.sonarqube.ws.Users; @@ -179,7 +178,7 @@ public class UserTester { private Optional<Users.SearchWsResponse.User> queryForUser(String login, Predicate<Users.SearchWsResponse.User> predicate) { List<Users.SearchWsResponse.User> users = session.wsClient().users().search(new SearchRequest().setQ(login)).getUsersList().stream() - .filter(predicate).collect(Collectors.toList()); + .filter(predicate).toList(); if (users.size() == 1) { return Optional.of(users.get(0)); } |