28
28
import org .openrewrite .java .JavaTemplate ;
29
29
import org .openrewrite .java .JavaVisitor ;
30
30
import org .openrewrite .java .MethodMatcher ;
31
+ import org .openrewrite .java .tree .Expression ;
31
32
import org .openrewrite .java .tree .J ;
32
33
import org .openrewrite .java .tree .JavaType ;
33
34
import software .amazon .awssdk .annotations .SdkInternalApi ;
@@ -52,12 +53,6 @@ public class TransferManagerMethodsToV2 extends Recipe {
52
53
53
54
private static final MethodMatcher DOWNLOAD_DIR = v2TmMethodMatcher ("downloadDirectory(String, String, java.io.File)" );
54
55
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
-
61
56
private static final Pattern S3_TM_CREDENTIAL = Pattern .compile (V2_TM_CLIENT );
62
57
private static final Pattern V2_AWSCREDENTAIL = Pattern .compile ("software.amazon.awssdk.auth.credentials.AwsCredentials" );
63
58
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
115
110
method = transformDownloadDirectory (method );
116
111
return super .visitMethodInvocation (method , executionContext );
117
112
}
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
- }
130
113
131
114
return super .visitMethodInvocation (method , executionContext );
132
115
}
@@ -137,10 +120,12 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
137
120
if (!(type instanceof JavaType .FullyQualified )) {
138
121
return newClass ;
139
122
}
123
+
140
124
if (type .isAssignableFrom (S3_TM_CREDENTIAL ) &&
141
125
newClass .getArguments ().size () == 1 &&
142
126
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 )) {
144
129
addS3AsyncClientImport ();
145
130
addStaticCredentialsProviderImport ();
146
131
@@ -151,9 +136,9 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
151
136
".build())" +
152
137
".build()" )
153
138
.build ()
154
- .apply (getCursor (), newClass .getCoordinates ().replace (), newClass . getArguments (). get ( 0 ) );
139
+ .apply (getCursor (), newClass .getCoordinates ().replace (), arg );
155
140
}
156
- if (newClass . getArguments (). get ( 0 ) .getType ().isAssignableFrom (V2_CREDENTIAL_PROVIDER )) {
141
+ if (arg .getType ().isAssignableFrom (V2_CREDENTIAL_PROVIDER )) {
157
142
addS3AsyncClientImport ();
158
143
159
144
return JavaTemplate
@@ -163,33 +148,13 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
163
148
".build())" +
164
149
".build()" )
165
150
.build ()
166
- .apply (getCursor (), newClass .getCoordinates ().replace (), newClass .getArguments ().get (0 ));
167
-
151
+ .apply (getCursor (), newClass .getCoordinates ().replace (), arg );
168
152
}
169
153
}
170
154
171
155
return super .visitNewClass (newClass , executionContext );
172
156
}
173
157
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
-
193
158
private J .MethodInvocation transformDownloadDirectory (J .MethodInvocation method ) {
194
159
String v2Method = "#{any()}.downloadDirectory(DownloadDirectoryRequest.builder()"
195
160
+ ".bucket(#{any()}).listObjectsV2RequestTransformer(builder -> builder.prefix(#{any()}))"
@@ -309,13 +274,6 @@ private J.MethodInvocation transformDownloadWithBucketKeyFileTimeout(J.MethodInv
309
274
return method ;
310
275
}
311
276
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
-
319
277
private void addTmImport (String pojoName ) {
320
278
String fqcn = V2_TM_MODEL_PKG + pojoName ;
321
279
doAfterVisit (new AddImport <>(fqcn , null , false ));
0 commit comments