Skip to content

Commit 0734f68

Browse files
authored
Add S3StreamingResponseToV2 to migration recipe (#5180)
Update migration tool tests.
1 parent e860bba commit 0734f68

File tree

8 files changed

+91
-1
lines changed

8 files changed

+91
-1
lines changed

migration-tool/src/main/java/software/amazon/awssdk/migration/internal/recipe/S3StreamingResponseToV2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext execu
118118
}
119119

120120
if (GET_OBJECT_CONTENT.matches(method)) {
121-
return select;
121+
return select.withPrefix(method.getPrefix());
122122
}
123123

124124
JavaType.Method methodType = method.getMethodType();

migration-tool/src/main/resources/META-INF/rewrite/java-sdk-v1-to-v2.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ tags:
2323
recipeList:
2424
# TODO: update recipe naming to be consistent
2525
- software.amazon.awssdk.UpgradeSdkDependencies
26+
- software.amazon.awssdk.S3GetObjectConstructorToFluent
27+
- software.amazon.awssdk.migration.internal.recipe.S3StreamingResponseToV2
2628
- software.amazon.awssdk.migration.recipe.ChangeSdkType
2729
- software.amazon.awssdk.ChangeSdkCoreTypes
2830
- software.amazon.awssdk.migration.recipe.V1BuilderVariationsToV2Builder
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License").
5+
# You may not use this file except in compliance with the License.
6+
# A copy of the License is located at
7+
#
8+
# http://aws.amazon.com/apache2.0
9+
#
10+
# or in the "license" file accompanying this file. This file is distributed
11+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
# express or implied. See the License for the specific language governing
13+
# permissions and limitations under the License.
14+
#
15+
---
16+
type: specs.openrewrite.org/v1beta/recipe
17+
name: software.amazon.awssdk.S3GetObjectConstructorToFluent
18+
displayName: Change auth related classes
19+
recipeList:
20+
- software.amazon.awssdk.migration.internal.recipe.ConstructorToFluent:
21+
clzzFqcn: com.amazonaws.services.s3.model.GetObjectRequest
22+
parameterTypes:
23+
- java.lang.String
24+
- java.lang.String
25+
fluentNames:
26+
- withBucket
27+
- withKey

test/migration-tool-tests/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
<artifactId>aws-java-sdk-sqs</artifactId>
4949
<scope>test</scope>
5050
</dependency>
51+
<dependency>
52+
<groupId>com.amazonaws</groupId>
53+
<artifactId>aws-java-sdk-s3</artifactId>
54+
<scope>test</scope>
55+
</dependency>
5156
<dependency>
5257
<groupId>software.amazon.awssdk</groupId>
5358
<artifactId>migration-tool</artifactId>

test/migration-tool-tests/src/test/resources/after/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@
4242
<artifactId>sqs</artifactId>
4343
<version>2.23.16-SNAPSHOT</version>
4444
</dependency>
45+
<dependency>
46+
<groupId>software.amazon.awssdk</groupId>
47+
<artifactId>s3</artifactId>
48+
<version>2.23.16-SNAPSHOT</version>
49+
</dependency>
4550
</dependencies>
4651
</project>

test/migration-tool-tests/src/test/resources/after/src/main/java/foo/bar/Application.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@
1515

1616
package foo.bar;
1717

18+
import software.amazon.awssdk.services.s3.S3Client;
19+
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
1820
import software.amazon.awssdk.services.sqs.SqsClient;
1921
import software.amazon.awssdk.services.sqs.model.ListQueuesRequest;
2022
import software.amazon.awssdk.services.sqs.model.ListQueuesResponse;
2123

24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
28+
import java.nio.file.StandardCopyOption;
29+
import software.amazon.awssdk.core.ResponseInputStream;
30+
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
31+
2232
public class Application {
2333

2434
private Application() {
@@ -34,4 +44,18 @@ public static void main(String... args) {
3444
ListQueuesResponse listQueuesResult = sqs.listQueues(request);
3545
System.out.println(listQueuesResult);
3646
}
47+
48+
private static Path downloadFile(S3Client s3, String bucket, String key, Path dst) throws IOException {
49+
GetObjectRequest getObject = GetObjectRequest.builder().bucket(bucket).key(key).build();
50+
51+
ResponseInputStream<GetObjectResponse> s3Object = s3.getObject(getObject);
52+
53+
InputStream content = s3Object;
54+
55+
Files.copy(content, dst, StandardCopyOption.REPLACE_EXISTING);
56+
57+
s3Object.close();
58+
59+
return dst;
60+
}
3761
}

test/migration-tool-tests/src/test/resources/before/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,9 @@
4141
<groupId>com.amazonaws</groupId>
4242
<artifactId>aws-java-sdk-sqs</artifactId>
4343
</dependency>
44+
<dependency>
45+
<groupId>com.amazonaws</groupId>
46+
<artifactId>aws-java-sdk-s3</artifactId>
47+
</dependency>
4448
</dependencies>
4549
</project>

test/migration-tool-tests/src/test/resources/before/src/main/java/foo/bar/Application.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@
1515

1616
package foo.bar;
1717

18+
import com.amazonaws.services.s3.AmazonS3;
19+
import com.amazonaws.services.s3.model.GetObjectRequest;
20+
import com.amazonaws.services.s3.model.S3Object;
1821
import com.amazonaws.services.sqs.AmazonSQS;
1922
import com.amazonaws.services.sqs.model.ListQueuesRequest;
2023
import com.amazonaws.services.sqs.model.ListQueuesResult;
2124

25+
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.nio.file.Files;
28+
import java.nio.file.Path;
29+
import java.nio.file.StandardCopyOption;
30+
2231
public class Application {
2332

2433
private Application() {
@@ -34,4 +43,18 @@ public static void main(String... args) {
3443
ListQueuesResult listQueuesResult = sqs.listQueues(request);
3544
System.out.println(listQueuesResult);
3645
}
46+
47+
private static Path downloadFile(AmazonS3 s3, String bucket, String key, Path dst) throws IOException {
48+
GetObjectRequest getObject = new GetObjectRequest(bucket, key);
49+
50+
S3Object s3Object = s3.getObject(getObject);
51+
52+
InputStream content = s3Object.getObjectContent();
53+
54+
Files.copy(content, dst, StandardCopyOption.REPLACE_EXISTING);
55+
56+
s3Object.getObjectContent().close();
57+
58+
return dst;
59+
}
3760
}

0 commit comments

Comments
 (0)