Skip to content

Commit 5c0ae7a

Browse files
committed
comments addressed
1 parent d41acfe commit 5c0ae7a

File tree

3 files changed

+36
-49
lines changed

3 files changed

+36
-49
lines changed

v2-migration/src/main/java/software/amazon/awssdk/v2migration/TransferManagerMethodsToV2.java

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.openrewrite.java.JavaTemplate;
2929
import org.openrewrite.java.JavaVisitor;
3030
import org.openrewrite.java.MethodMatcher;
31+
import org.openrewrite.java.tree.Expression;
3132
import org.openrewrite.java.tree.J;
3233
import org.openrewrite.java.tree.JavaType;
3334
import software.amazon.awssdk.annotations.SdkInternalApi;
@@ -52,12 +53,6 @@ public class TransferManagerMethodsToV2 extends Recipe {
5253

5354
private static final MethodMatcher DOWNLOAD_DIR = v2TmMethodMatcher("downloadDirectory(String, String, java.io.File)");
5455

55-
private static final MethodMatcher RESUME_DOWNLOAD = v2TmMethodMatcher("resumeDownload(..)");
56-
private static final MethodMatcher RESUME_UPLOAD = v2TmMethodMatcher("resumeUpload(..)");
57-
private static final MethodMatcher SHUT_DOWN_NOW = v2TmMethodMatcher("shutdownNow()");
58-
59-
60-
6156
private static final Pattern S3_TM_CREDENTIAL = Pattern.compile(V2_TM_CLIENT);
6257
private static final Pattern V2_AWSCREDENTAIL = Pattern.compile("software.amazon.awssdk.auth.credentials.AwsCredentials");
6358
private static final Pattern V2_CREDENTIAL_PROVIDER = Pattern.compile("software.amazon.awssdk.auth.credentials"
@@ -115,18 +110,6 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext execu
115110
method = transformDownloadDirectory(method);
116111
return super.visitMethodInvocation(method, executionContext);
117112
}
118-
if (RESUME_DOWNLOAD.matches(method, false)) {
119-
method = transformResumeDownload(method);
120-
return super.visitMethodInvocation(method, executionContext);
121-
}
122-
if (RESUME_UPLOAD.matches(method, false)) {
123-
method = transformResumeUpload(method);
124-
return super.visitMethodInvocation(method, executionContext);
125-
}
126-
if (SHUT_DOWN_NOW.matches(method, false)) {
127-
method = transformShutDownNow(method);
128-
return super.visitMethodInvocation(method, executionContext);
129-
}
130113

131114
return super.visitMethodInvocation(method, executionContext);
132115
}
@@ -137,10 +120,12 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
137120
if (!(type instanceof JavaType.FullyQualified)) {
138121
return newClass;
139122
}
123+
140124
if (type.isAssignableFrom(S3_TM_CREDENTIAL) &&
141125
newClass.getArguments().size() == 1 &&
142126
newClass.getArguments().get(0).getType() != null) {
143-
if (newClass.getArguments().get(0).getType().isAssignableFrom(V2_AWSCREDENTAIL)) {
127+
Expression arg = newClass.getArguments().get(0);
128+
if (arg.getType().isAssignableFrom(V2_AWSCREDENTAIL)) {
144129
addS3AsyncClientImport();
145130
addStaticCredentialsProviderImport();
146131

@@ -151,9 +136,9 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
151136
".build())" +
152137
".build()")
153138
.build()
154-
.apply(getCursor(), newClass.getCoordinates().replace(), newClass.getArguments().get(0));
139+
.apply(getCursor(), newClass.getCoordinates().replace(), arg);
155140
}
156-
if (newClass.getArguments().get(0).getType().isAssignableFrom(V2_CREDENTIAL_PROVIDER)) {
141+
if (arg.getType().isAssignableFrom(V2_CREDENTIAL_PROVIDER)) {
157142
addS3AsyncClientImport();
158143

159144
return JavaTemplate
@@ -163,33 +148,13 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
163148
".build())" +
164149
".build()")
165150
.build()
166-
.apply(getCursor(), newClass.getCoordinates().replace(), newClass.getArguments().get(0));
167-
151+
.apply(getCursor(), newClass.getCoordinates().replace(), arg);
168152
}
169153
}
170154

171155
return super.visitNewClass(newClass, executionContext);
172156
}
173157

174-
private J.MethodInvocation transformResumeDownload(J.MethodInvocation method) {
175-
String v2Method = "#{any()}.resumeDownloadFile(#{any()})";
176-
177-
method = JavaTemplate.builder(v2Method).build()
178-
.apply(getCursor(), method.getCoordinates().replace(), method.getSelect(),
179-
method.getArguments().get(0));
180-
return method;
181-
}
182-
183-
private J.MethodInvocation transformResumeUpload(J.MethodInvocation method) {
184-
String v2Method = "#{any()}.resumeUploadFile(#{any()})";
185-
186-
method = JavaTemplate.builder(v2Method).build()
187-
.apply(getCursor(), method.getCoordinates().replace(), method.getSelect(),
188-
method.getArguments().get(0));
189-
return method;
190-
}
191-
192-
193158
private J.MethodInvocation transformDownloadDirectory(J.MethodInvocation method) {
194159
String v2Method = "#{any()}.downloadDirectory(DownloadDirectoryRequest.builder()"
195160
+ ".bucket(#{any()}).listObjectsV2RequestTransformer(builder -> builder.prefix(#{any()}))"
@@ -309,13 +274,6 @@ private J.MethodInvocation transformDownloadWithBucketKeyFileTimeout(J.MethodInv
309274
return method;
310275
}
311276

312-
private J.MethodInvocation transformShutDownNow(J.MethodInvocation method) {
313-
String v2Method = "#{any()}.close()";
314-
method = JavaTemplate.builder(v2Method).build()
315-
.apply(getCursor(), method.getCoordinates().replace(), method.getSelect());
316-
return method;
317-
}
318-
319277
private void addTmImport(String pojoName) {
320278
String fqcn = V2_TM_MODEL_PKG + pojoName;
321279
doAfterVisit(new AddImport<>(fqcn, null, false));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ recipeList:
5353
- software.amazon.awssdk.v2migration.S3NonStreamingRequestToV2Complex
5454
- software.amazon.awssdk.v2migration.S3PutObjectRequestToV2
5555
- software.amazon.awssdk.v2migration.SettersToBuilderV2
56+
- software.amazon.awssdk.v2migration.ChangeTransferManagerSimpleMethods
5657
- software.amazon.awssdk.v2migration.TransferManagerMethodsToV2
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
type: specs.openrewrite.org/v1beta/recipe
16+
name: software.amazon.awssdk.v2migration.ChangeTransferManagerSimpleMethods
17+
displayName: Change TransferManager simple methods to v2.
18+
description: Change TransferManager simple methods to v2.
19+
recipeList:
20+
- org.openrewrite.java.ChangeMethodName:
21+
methodPattern: software.amazon.awssdk.transfer.s3.S3TransferManager resumeDownload(..)
22+
newMethodName: resumeDownloadFile
23+
- org.openrewrite.java.ChangeMethodName:
24+
methodPattern: software.amazon.awssdk.transfer.s3.S3TransferManager resumeUpload(..)
25+
newMethodName: resumeUploadFile
26+
- org.openrewrite.java.ChangeMethodName:
27+
methodPattern: software.amazon.awssdk.transfer.s3.S3TransferManager shutdownNow()
28+
newMethodName: close

0 commit comments

Comments
 (0)