Skip to content

Add S3StreamingResponseToV2 to migration recipe #5180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext execu
}

if (GET_OBJECT_CONTENT.matches(method)) {
return select;
return select.withPrefix(method.getPrefix());
}

JavaType.Method methodType = method.getMethodType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ tags:
recipeList:
# TODO: update recipe naming to be consistent
- software.amazon.awssdk.UpgradeSdkDependencies
- software.amazon.awssdk.S3GetObjectConstructorToFluent
- software.amazon.awssdk.migration.internal.recipe.S3StreamingResponseToV2
- software.amazon.awssdk.migration.recipe.ChangeSdkType
- software.amazon.awssdk.ChangeSdkCoreTypes
- software.amazon.awssdk.migration.recipe.V1BuilderVariationsToV2Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#
---
type: specs.openrewrite.org/v1beta/recipe
name: software.amazon.awssdk.S3GetObjectConstructorToFluent
displayName: Change auth related classes
recipeList:
- software.amazon.awssdk.migration.internal.recipe.ConstructorToFluent:
clzzFqcn: com.amazonaws.services.s3.model.GetObjectRequest
parameterTypes:
- java.lang.String
- java.lang.String
fluentNames:
- withBucket
- withKey
5 changes: 5 additions & 0 deletions test/migration-tool-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<artifactId>aws-java-sdk-sqs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>migration-tool</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions test/migration-tool-tests/src/test/resources/after/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@
<artifactId>sqs</artifactId>
<version>2.23.16-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.23.16-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@

package foo.bar;

import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.model.ListQueuesRequest;
import software.amazon.awssdk.services.sqs.model.ListQueuesResponse;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;

public class Application {

private Application() {
Expand All @@ -34,4 +44,18 @@ public static void main(String... args) {
ListQueuesResponse listQueuesResult = sqs.listQueues(request);
System.out.println(listQueuesResult);
}

private static Path downloadFile(S3Client s3, String bucket, String key, Path dst) throws IOException {
GetObjectRequest getObject = GetObjectRequest.builder().bucket(bucket).key(key).build();

ResponseInputStream<GetObjectResponse> s3Object = s3.getObject(getObject);

InputStream content = s3Object;

Files.copy(content, dst, StandardCopyOption.REPLACE_EXISTING);

s3Object.close();

return dst;
}
}
4 changes: 4 additions & 0 deletions test/migration-tool-tests/src/test/resources/before/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@

package foo.bar;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.model.ListQueuesRequest;
import com.amazonaws.services.sqs.model.ListQueuesResult;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public class Application {

private Application() {
Expand All @@ -34,4 +43,18 @@ public static void main(String... args) {
ListQueuesResult listQueuesResult = sqs.listQueues(request);
System.out.println(listQueuesResult);
}

private static Path downloadFile(AmazonS3 s3, String bucket, String key, Path dst) throws IOException {
GetObjectRequest getObject = new GetObjectRequest(bucket, key);

S3Object s3Object = s3.getObject(getObject);

InputStream content = s3Object.getObjectContent();

Files.copy(content, dst, StandardCopyOption.REPLACE_EXISTING);

s3Object.getObjectContent().close();

return dst;
}
}