From 6c4023605f47e31fe25ca222c3ecc2f840d31d96 Mon Sep 17 00:00:00 2001 From: Glenn Renfro Date: Wed, 13 Nov 2024 10:16:56 -0500 Subject: [PATCH] Update deprecated code to recommended strategy This is part one of an epic to replace deprecated method calls with the recommended solution. Signed-off-by: Glenn Renfro --- .../security/ManualOAuthAuthenticationProvider.java | 2 +- .../docker/compose/execution/DefaultDockerCompose.java | 2 +- .../common/test/docker/compose/execution/Docker.java | 2 +- .../ComposedTaskRunnerTaskListener.java | 4 ++-- ...ConfigJsonSecretToRegistryConfigurationConverter.java | 2 +- .../cloud/dataflow/rest/resource/HttpClientTest.java | 9 ++++----- .../server/controller/TaskSchedulerController.java | 3 +-- .../server/config/H2ServerConfigurationTests.java | 6 +++--- .../springframework/cloud/dataflow/data/CSVLoader.java | 5 ++++- 9 files changed, 18 insertions(+), 17 deletions(-) diff --git a/spring-cloud-common-security-config/spring-cloud-common-security-config-web/src/main/java/org/springframework/cloud/common/security/ManualOAuthAuthenticationProvider.java b/spring-cloud-common-security-config/spring-cloud-common-security-config-web/src/main/java/org/springframework/cloud/common/security/ManualOAuthAuthenticationProvider.java index 29a09b4855..047eb5ba52 100644 --- a/spring-cloud-common-security-config/spring-cloud-common-security-config-web/src/main/java/org/springframework/cloud/common/security/ManualOAuthAuthenticationProvider.java +++ b/spring-cloud-common-security-config/spring-cloud-common-security-config-web/src/main/java/org/springframework/cloud/common/security/ManualOAuthAuthenticationProvider.java @@ -32,7 +32,7 @@ import org.springframework.security.oauth2.core.AuthorizationGrantType; import org.springframework.security.oauth2.core.OAuth2AuthorizationException; import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse; -import org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken; +import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthenticationToken; import org.springframework.security.oauth2.server.resource.authentication.OpaqueTokenAuthenticationProvider; import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector; import org.springframework.web.client.ResourceAccessException; diff --git a/spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/DefaultDockerCompose.java b/spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/DefaultDockerCompose.java index d268a57f6b..e7a762a656 100644 --- a/spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/DefaultDockerCompose.java +++ b/spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/DefaultDockerCompose.java @@ -225,7 +225,7 @@ private Optional id(String containerName) throws IOException, Interrupte } private Process followLogs(String container) throws IOException, InterruptedException { - if (version().greaterThanOrEqualTo(VERSION_1_7_0)) { + if (version().isHigherThanOrEquivalentTo(VERSION_1_7_0)) { return rawExecutable.execute(true, "logs", "--no-color", "--follow", container); } diff --git a/spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/Docker.java b/spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/Docker.java index e3691c01d0..49dea25820 100644 --- a/spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/Docker.java +++ b/spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/Docker.java @@ -52,7 +52,7 @@ public Version configuredVersion() throws IOException, InterruptedException { String versionString = command.execute(Command.throwingOnError(), false, "-v"); Matcher matcher = VERSION_PATTERN.matcher(versionString); Assert.state(matcher.matches(), "Unexpected output of docker -v: " + versionString); - return Version.forIntegers(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), + return Version.of(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); } diff --git a/spring-cloud-dataflow-composed-task-runner/src/main/java/org/springframework/cloud/dataflow/composedtaskrunner/ComposedTaskRunnerTaskListener.java b/spring-cloud-dataflow-composed-task-runner/src/main/java/org/springframework/cloud/dataflow/composedtaskrunner/ComposedTaskRunnerTaskListener.java index c9f487df05..ca02b6bc75 100644 --- a/spring-cloud-dataflow-composed-task-runner/src/main/java/org/springframework/cloud/dataflow/composedtaskrunner/ComposedTaskRunnerTaskListener.java +++ b/spring-cloud-dataflow-composed-task-runner/src/main/java/org/springframework/cloud/dataflow/composedtaskrunner/ComposedTaskRunnerTaskListener.java @@ -3,10 +3,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.cloud.task.listener.TaskExecutionListenerSupport; +import org.springframework.cloud.task.listener.TaskExecutionListener; import org.springframework.cloud.task.repository.TaskExecution; -public class ComposedTaskRunnerTaskListener extends TaskExecutionListenerSupport { +public class ComposedTaskRunnerTaskListener implements TaskExecutionListener { private final static Logger logger = LoggerFactory.getLogger(ComposedTaskRunnerTaskListener.class); private static Long executionId = null; diff --git a/spring-cloud-dataflow-container-registry/src/main/java/org/springframework/cloud/dataflow/container/registry/authorization/DockerConfigJsonSecretToRegistryConfigurationConverter.java b/spring-cloud-dataflow-container-registry/src/main/java/org/springframework/cloud/dataflow/container/registry/authorization/DockerConfigJsonSecretToRegistryConfigurationConverter.java index 710913c7c9..2a8afd5da5 100644 --- a/spring-cloud-dataflow-container-registry/src/main/java/org/springframework/cloud/dataflow/container/registry/authorization/DockerConfigJsonSecretToRegistryConfigurationConverter.java +++ b/spring-cloud-dataflow-container-registry/src/main/java/org/springframework/cloud/dataflow/container/registry/authorization/DockerConfigJsonSecretToRegistryConfigurationConverter.java @@ -193,7 +193,7 @@ public Optional getDockerTokenServiceUri(String registryHost, boolean di return Optional.empty(); } catch (HttpClientErrorException httpError) { - if (httpError.getRawStatusCode() != 401) { + if (httpError.getStatusCode().value() != 401) { return Optional.empty(); } if (httpError.getResponseHeaders() == null diff --git a/spring-cloud-dataflow-rest-resource/src/test/java/org/springframework/cloud/dataflow/rest/resource/HttpClientTest.java b/spring-cloud-dataflow-rest-resource/src/test/java/org/springframework/cloud/dataflow/rest/resource/HttpClientTest.java index 5465fb8b32..a324df53c5 100644 --- a/spring-cloud-dataflow-rest-resource/src/test/java/org/springframework/cloud/dataflow/rest/resource/HttpClientTest.java +++ b/spring-cloud-dataflow-rest-resource/src/test/java/org/springframework/cloud/dataflow/rest/resource/HttpClientTest.java @@ -21,6 +21,7 @@ import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.core5.http.HttpHeaders; +import org.apache.hc.core5.http.io.HttpClientResponseHandler; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; @@ -61,14 +62,12 @@ void resourceBasedAuthorizationHeader() throws Exception { throw new Passed(); }) .buildHttpClient()) { - assertThatExceptionOfType(Passed.class).isThrownBy(() -> client.execute(new HttpGet(targetHost))); + assertThatExceptionOfType(Passed.class).isThrownBy(() -> client.execute(new HttpGet(targetHost), getNoOpResponseHandler())); } } - static final class TestException extends IOException { - TestException() { - super("It broke"); - } + private HttpClientResponseHandler getNoOpResponseHandler() { + return response -> "noOp"; } static final class ByteArrayCheckableResource extends ByteArrayResource implements CheckableResource { diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskSchedulerController.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskSchedulerController.java index 2aa3a77c09..f991d83882 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskSchedulerController.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskSchedulerController.java @@ -34,7 +34,6 @@ import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; import org.springframework.http.HttpStatus; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -168,7 +167,7 @@ public void save( ) { Map propertiesToUse = DeploymentPropertiesUtils.parse(properties); List argumentsToUse = DeploymentPropertiesUtils.parseArgumentList(arguments, " "); - this.schedulerService.schedule(StringUtils.trimWhitespace(scheduleName), taskDefinitionName, + this.schedulerService.schedule(scheduleName.strip(), taskDefinitionName, propertiesToUse, argumentsToUse, platform); } diff --git a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/config/H2ServerConfigurationTests.java b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/config/H2ServerConfigurationTests.java index 5d09e4b237..bcae5815b1 100644 --- a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/config/H2ServerConfigurationTests.java +++ b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/config/H2ServerConfigurationTests.java @@ -93,21 +93,21 @@ void serverDoesNotStartWhenUrlIsH2ButInvalidForm() { "spring.datasource.url=jdbc:h2:tcp://localhost:-1/mem:dataflow;DATABASE_TO_UPPER=FALSE", "spring.dataflow.embedded.database.enabled=true") .run(context -> assertThat(context) - .getFailure().getRootCause().isInstanceOf(IllegalArgumentException.class) + .getFailure().rootCause().isInstanceOf(IllegalArgumentException.class) .hasMessageMatching("DataSource URL .* does not match regex pattern: .*")); runner.withPropertyValues( "spring.datasource.url=jdbc:h2:tcp://localhost:port/mem:dataflow;DATABASE_TO_UPPER=FALSE", "spring.dataflow.embedded.database.enabled=true") .run(context -> assertThat(context) - .getFailure().getRootCause().isInstanceOf(IllegalArgumentException.class) + .getFailure().rootCause().isInstanceOf(IllegalArgumentException.class) .hasMessageMatching("DataSource URL .* does not match regex pattern: .*")); runner.withPropertyValues( "spring.datasource.url=jdbc:h2:tcp://localhost:99999/mem:dataflow;DATABASE_TO_UPPER=FALSE", "spring.dataflow.embedded.database.enabled=true") .run(context -> assertThat(context) - .getFailure().getRootCause().isInstanceOf(IllegalArgumentException.class) + .getFailure().rootCause().isInstanceOf(IllegalArgumentException.class) .hasMessage("Port value out of range: 99999")); } diff --git a/spring-cloud-dataflow-test/src/main/java/org/springframework/cloud/dataflow/data/CSVLoader.java b/spring-cloud-dataflow-test/src/main/java/org/springframework/cloud/dataflow/data/CSVLoader.java index 6e6dff5d8c..6bc3dbeb48 100644 --- a/spring-cloud-dataflow-test/src/main/java/org/springframework/cloud/dataflow/data/CSVLoader.java +++ b/spring-cloud-dataflow-test/src/main/java/org/springframework/cloud/dataflow/data/CSVLoader.java @@ -42,7 +42,10 @@ public interface DeriveType { } public static int loadCSV(String tableName, DataSource dataSource, Resource cvsResource, DeriveType deriveType) throws IOException { - CSVParser parser = CSVFormat.RFC4180.withFirstRecordAsHeader() + CSVParser parser = CSVFormat.RFC4180.builder() + .setHeader() + .setSkipHeaderRecord(true) + .build() .parse(new InputStreamReader(cvsResource.getInputStream())); List headerNames = parser.getHeaderNames(); final List records = parser.getRecords();