Skip to content

Commit 59eb492

Browse files
authored
Add support for remaining s3 pojos and methods in migration tool (#6049)
* added comments for other method * more comments for unsupported method and pojo * fix integration test * add coverage for two pojos * another case for SetObjectTaggingRequest added * support for version added * deleteObjectsResults comment added * mapping for lambdaConfiguration added * typo fixed * comments for BucketNotificationConfiguration added * typo fixed
1 parent a619c77 commit 59eb492

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

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

+30-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ public class S3AddImportsAndComments extends Recipe {
5656

5757
private static final Pattern CANNED_ACL = Pattern.compile(V1_S3_MODEL_PKG + "CannedAccessControlList");
5858
private static final Pattern GET_OBJECT_REQUEST = Pattern.compile(V1_S3_MODEL_PKG + "GetObjectRequest");
59+
private static final Pattern CREATE_BUCKET_REQUEST = Pattern.compile(V1_S3_MODEL_PKG + "CreateBucketRequest");
60+
private static final Pattern DELETE_OBJECTS_RESULT = Pattern.compile(V1_S3_MODEL_PKG + "DeleteObjectsResult");
5961
private static final Pattern INITIATE_MPU = Pattern.compile(V1_S3_MODEL_PKG + "InitiateMultipartUpload");
6062
private static final Pattern MULTI_FACTOR_AUTH = Pattern.compile(V1_S3_MODEL_PKG + "MultiFactorAuthentication");
6163
private static final Pattern SET_BUCKET_VERSION_REQUEST = Pattern.compile(V1_S3_MODEL_PKG
6264
+ "SetBucketVersioningConfigurationRequest");
65+
private static final Pattern BUCKET_NOTIFICATION_CONFIG = Pattern.compile(V1_S3_MODEL_PKG
66+
+ "BucketNotificationConfiguration");
6367

6468
@Override
6569
public String getDisplayName() {
@@ -167,15 +171,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
167171
if (SET_PAYMENT_CONFIGURATION.matches(method)) {
168172
String comment = "Transform for setRequestPaymentConfiguration method not supported. Payer enum is a "
169173
+ "separate class in v2 (not nested). Please manually migrate "
170-
+ "your code by update from RequestPaymentConfiguration.Payer to just Payer, and adjust "
174+
+ "your code by updating from RequestPaymentConfiguration.Payer to just Payer, and adjust "
171175
+ "imports and names.";
172176
return method.withComments(createComments(comment));
173177
}
174178

175179
if (SET_LIFECYCLE_CONFIGURATION.matches(method)) {
176180
// TODO: add the developer guide link in the comments once the doc is published.
177181
String comment = "Transform for setBucketLifecycleConfiguration method not supported. Please manually migrate"
178-
+ " your code by using builder pattern, update from BucketLifecycleConfiguration.Rule to "
182+
+ " your code by using builder pattern, updating from BucketLifecycleConfiguration.Rule to "
179183
+ "LifecycleRule, StorageClass to TransitionStorageClass, and adjust "
180184
+ "imports and names.";
181185
return method.withComments(createComments(comment));
@@ -223,6 +227,30 @@ public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
223227
return newClass.withComments(createComments(comment));
224228
}
225229

230+
if (type.isAssignableFrom(CREATE_BUCKET_REQUEST) && newClass.getArguments().size() == 2) {
231+
String comment = "Transform for createBucketRequest with region is not supported. Please manually "
232+
+ "migrate your code by configuring the region as locationConstraint in "
233+
+ "createBucketConfiguration in the request builder";
234+
return newClass.withComments(createComments(comment));
235+
}
236+
237+
if (type.isAssignableFrom(DELETE_OBJECTS_RESULT)) {
238+
String comment = "Transform for DeleteObjectsResult class is not supported. DeletedObject class is a "
239+
+ "separate class in v2 (not nested). Please manually migrate your code by updating "
240+
+ "DeleteObjectsResult.DeletedObject to s3.model.DeletedObject";
241+
return newClass.withComments(createComments(comment));
242+
}
243+
244+
if (type.isAssignableFrom(BUCKET_NOTIFICATION_CONFIG)) {
245+
// TODO: add the developer guide link in the comments once the doc is published.
246+
String comment = "Transform for BucketNotificationConfiguration class is not supported. "
247+
+ "BucketNotificationConfiguration is renamed to NotificationConfiguration. There is no common"
248+
+ " abstract class for lambdaFunction/topic/queue configurations. Use specific builders "
249+
+ "instead of addConfiguration() to add configurations. Change the vararg arguments or EnumSet "
250+
+ "in specific configurations constructor to List<String> in v2";
251+
return newClass.withComments(createComments(comment));
252+
}
253+
226254
return newClass;
227255
}
228256

v2-migration/src/main/java/software/amazon/awssdk/v2migration/internal/utils/NamingConversionUtils.java

+4
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ public final class NamingConversionUtils {
182182
S3_POJO_MAPPING.put("RoutingRuleCondition", "Condition");
183183
S3_POJO_MAPPING.put("S3ObjectSummary", "S3Object");
184184
S3_POJO_MAPPING.put("ObjectListing", "ListObjectsResponse");
185+
S3_POJO_MAPPING.put("VersionListing", "ListObjectVersionsResponse");
186+
S3_POJO_MAPPING.put("S3VersionSummary", "ObjectVersion");
185187
S3_POJO_MAPPING.put("AmazonS3Exception", "S3Exception");
188+
S3_POJO_MAPPING.put("CloudFunctionConfiguration", "LambdaFunctionConfiguration");
189+
S3_POJO_MAPPING.put("LambdaConfiguration", "LambdaFunctionConfiguration");
186190

187191
//Special Enum mapping
188192
S3_POJO_MAPPING.put("S3Event", "Event");

v2-migration/src/main/resources/META-INF/rewrite/change-s3-methods.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,10 @@ recipeList:
228228
newMethodName: withRequestPayer
229229
- org.openrewrite.java.ChangeMethodName:
230230
methodPattern: com.amazonaws.services.s3.model.SetBucketPolicyRequest withPolicyText(String)
231-
newMethodName: withPolicy
231+
newMethodName: withPolicy
232+
- org.openrewrite.java.ChangeMethodName:
233+
methodPattern: com.amazonaws.services.s3.model.BucketPolicy getPolicyText()
234+
newMethodName: policy
235+
- org.openrewrite.java.ChangeMethodName:
236+
methodPattern: com.amazonaws.services.s3.model.VersionListing getVersionSummaries()
237+
newMethodName: versions

v2-migration/src/main/resources/META-INF/rewrite/s3-methods-constructor-to-fluent.yml

+8
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,14 @@ recipeList:
730730
- java.lang.String
731731
fluentNames:
732732
- withEmailAddress
733+
- software.amazon.awssdk.v2migration.ConstructorToFluent:
734+
clzzFqcn: com.amazonaws.services.s3.model.Grant
735+
parameterTypes:
736+
- com.amazonaws.services.s3.model.Grantee
737+
- com.amazonaws.services.s3.model.Permission
738+
fluentNames:
739+
- withGrantee
740+
- withPermission
733741
- software.amazon.awssdk.v2migration.ConstructorToFluent:
734742
clzzFqcn: com.amazonaws.services.s3.model.GetRequestPaymentConfigurationRequest
735743
parameterTypes:

0 commit comments

Comments
 (0)