Skip to content

Commit a3ab730

Browse files
authored
Added comments in migration tool for all remaining S3 method (#6044)
* added comments for other method * more comments for unsupported method and pojo * fix integration test * another case for SetObjectTaggingRequest added * typo fixed * test case fixed
1 parent 883b2a4 commit a3ab730

File tree

5 files changed

+88
-15
lines changed

5 files changed

+88
-15
lines changed

test/v2-migration-tests/src/test/resources/software/amazon/awssdk/v2migrationtests/maven/after/src/main/java/foo/bar/S3.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ private void setBucketConfigs(S3Client s3, String bucket) {
373373
s3.putBucketInventoryConfiguration(PutBucketInventoryConfigurationRequest.builder().bucket(bucket).inventoryConfiguration(InventoryConfiguration.builder()
374374
.build())
375375
.build());
376-
s3.putBucketLifecycleConfiguration(PutBucketLifecycleConfigurationRequest.builder().bucket(bucket).lifecycleConfiguration(BucketLifecycleConfiguration.builder()
377-
.build())
378-
.build());
376+
/*AWS SDK for Java v2 migration: Transform for setBucketLifecycleConfiguration method not supported. Please manually migrate your code by using builder pattern, update from BucketLifecycleConfiguration.Rule to LifecycleRule, StorageClass to TransitionStorageClass, and adjust imports and names.*/s3.putBucketLifecycleConfiguration(PutBucketLifecycleConfigurationRequest.builder().bucket(bucket).lifecycleConfiguration(BucketLifecycleConfiguration.builder()
377+
.build())
378+
.build());
379379
s3.putBucketMetricsConfiguration(PutBucketMetricsConfigurationRequest.builder().bucket(bucket).metricsConfiguration(MetricsConfiguration.builder()
380380
.build())
381381
.build());
@@ -388,9 +388,9 @@ private void setBucketConfigs(S3Client s3, String bucket) {
388388
s3.putBucketReplication(PutBucketReplicationRequest.builder().bucket(bucket).replicationConfiguration(ReplicationConfiguration.builder()
389389
.build())
390390
.build());
391-
s3.putBucketTagging(PutBucketTaggingRequest.builder().bucket(bucket).tagging(Tagging.builder()
392-
.build())
393-
.build());
391+
/*AWS SDK for Java v2 migration: Transform for setBucketTaggingConfiguration method not supported. Please manually migrate your code by using builder pattern, replacing TagSet.setTag() with .tagSet(Arrays.asList(Tag.builder())), and use Tagging instead of BucketTaggingConfiguration, and adjust imports and names.*/s3.putBucketTagging(PutBucketTaggingRequest.builder().bucket(bucket).tagging(Tagging.builder()
392+
.build())
393+
.build());
394394
s3.putBucketWebsite(PutBucketWebsiteRequest.builder().bucket(bucket).websiteConfiguration(WebsiteConfiguration.builder()
395395
.build())
396396
.build());

test/v2-migration-tests/src/test/resources/software/amazon/awssdk/v2migrationtests/maven/after/src/main/java/foo/bar/S3RequestConstructor.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,10 @@ public void requestconstructor() {
398398
.build());
399399

400400

401-
s3.putBucketLifecycleConfiguration(
402-
PutBucketLifecycleConfigurationRequest.builder().bucket(bucketName).lifecycleConfiguration(BucketLifecycleConfiguration.builder()
403-
.build())
404-
.build());
401+
/*AWS SDK for Java v2 migration: Transform for setBucketLifecycleConfiguration method not supported. Please manually migrate your code by using builder pattern, update from BucketLifecycleConfiguration.Rule to LifecycleRule, StorageClass to TransitionStorageClass, and adjust imports and names.*/s3.putBucketLifecycleConfiguration(
402+
PutBucketLifecycleConfigurationRequest.builder().bucket(bucketName).lifecycleConfiguration(BucketLifecycleConfiguration.builder()
403+
.build())
404+
.build());
405405

406406
s3.putBucketMetricsConfiguration(
407407
PutBucketMetricsConfigurationRequest.builder()
@@ -433,10 +433,10 @@ public void requestconstructor() {
433433
.build())
434434
.build());
435435

436-
s3.putBucketTagging(
437-
PutBucketTaggingRequest.builder().bucket(bucketName).tagging(Tagging.builder()
438-
.build())
439-
.build());
436+
/*AWS SDK for Java v2 migration: Transform for setBucketTaggingConfiguration method not supported. Please manually migrate your code by using builder pattern, replacing TagSet.setTag() with .tagSet(Arrays.asList(Tag.builder())), and use Tagging instead of BucketTaggingConfiguration, and adjust imports and names.*/s3.putBucketTagging(
437+
PutBucketTaggingRequest.builder().bucket(bucketName).tagging(Tagging.builder()
438+
.build())
439+
.build());
440440

441441
DeleteObjectRequest deleteVersionRequest = DeleteObjectRequest.builder().bucket(bucketName).key(objectKey).versionId("id")
442442
.build();

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

+49-1
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,23 @@ public class S3AddImportsAndComments extends Recipe {
4343
private static final MethodMatcher LIST_NEXT_BATCH_VERSIONS = v1S3MethodMatcher("listNextBatchOfVersions(..)");
4444
private static final MethodMatcher GET_METADATA = v1S3MethodMatcher("getCachedResponseMetadata(..)");
4545
private static final MethodMatcher SET_BUCKET_ACL = v1S3MethodMatcher("setBucketAcl(..)");
46+
private static final MethodMatcher SET_BUCKET_LOGGING = v1S3MethodMatcher("setBucketLoggingConfiguration(..)");
4647
private static final MethodMatcher SET_ENDPOINT = v1S3MethodMatcher("setEndpoint(..)");
4748
private static final MethodMatcher SET_OBJECT_ACL = v1S3MethodMatcher("setObjectAcl(..)");
4849
private static final MethodMatcher SET_REGION = v1S3MethodMatcher("setRegion(..)");
50+
private static final MethodMatcher SET_PAYMENT_CONFIGURATION = v1S3MethodMatcher("setRequestPaymentConfiguration(..)");
4951
private static final MethodMatcher SET_S3CLIENT_OPTIONS = v1S3MethodMatcher("setS3ClientOptions(..)");
5052
private static final MethodMatcher SELECT_OBJECT_CONTENT = v1S3MethodMatcher("selectObjectContent(..)");
53+
private static final MethodMatcher SET_LIFECYCLE_CONFIGURATION = v1S3MethodMatcher("setBucketLifecycleConfiguration(..)");
54+
private static final MethodMatcher SET_TAGGING_CONFIGURATION = v1S3MethodMatcher("setBucketTaggingConfiguration(..)");
55+
5156

5257
private static final Pattern CANNED_ACL = Pattern.compile(V1_S3_MODEL_PKG + "CannedAccessControlList");
5358
private static final Pattern GET_OBJECT_REQUEST = Pattern.compile(V1_S3_MODEL_PKG + "GetObjectRequest");
5459
private static final Pattern INITIATE_MPU = Pattern.compile(V1_S3_MODEL_PKG + "InitiateMultipartUpload");
5560
private static final Pattern MULTI_FACTOR_AUTH = Pattern.compile(V1_S3_MODEL_PKG + "MultiFactorAuthentication");
61+
private static final Pattern SET_BUCKET_VERSION_REQUEST = Pattern.compile(V1_S3_MODEL_PKG
62+
+ "SetBucketVersioningConfigurationRequest");
5663

5764
@Override
5865
public String getDisplayName() {
@@ -144,6 +151,45 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
144151
return method.withComments(createComments(comment));
145152
}
146153

154+
if (SET_BUCKET_LOGGING.matches(method)) {
155+
// TODO: add the developer guide link in the comments once the doc is published.
156+
removeV1S3ModelImport("BucketLoggingConfiguration");
157+
addV2S3ModelImport("BucketLoggingStatus");
158+
addV2S3ModelImport("LoggingEnabled");
159+
160+
String comment = "Transform for setBucketLoggingConfiguration method not "
161+
+ "supported. The method is renamed to putBucketLogging. Please manually migrate your code by "
162+
+ "replacing BucketLoggingConfiguration with BucketLoggingStatus and LoggingEnabled builders, "
163+
+ "and updating the method name and parameters";
164+
return method.withComments(createComments(comment));
165+
}
166+
167+
if (SET_PAYMENT_CONFIGURATION.matches(method)) {
168+
String comment = "Transform for setRequestPaymentConfiguration method not supported. Payer enum is a "
169+
+ "separate class in v2 (not nested). Please manually migrate "
170+
+ "your code by update from RequestPaymentConfiguration.Payer to just Payer, and adjust "
171+
+ "imports and names.";
172+
return method.withComments(createComments(comment));
173+
}
174+
175+
if (SET_LIFECYCLE_CONFIGURATION.matches(method)) {
176+
// TODO: add the developer guide link in the comments once the doc is published.
177+
String comment = "Transform for setBucketLifecycleConfiguration method not supported. Please manually migrate"
178+
+ " your code by using builder pattern, update from BucketLifecycleConfiguration.Rule to "
179+
+ "LifecycleRule, StorageClass to TransitionStorageClass, and adjust "
180+
+ "imports and names.";
181+
return method.withComments(createComments(comment));
182+
}
183+
184+
if (SET_TAGGING_CONFIGURATION.matches(method)) {
185+
// TODO: add the developer guide link in the comments once the doc is published.
186+
String comment = "Transform for setBucketTaggingConfiguration method not supported. Please manually migrate"
187+
+ " your code by using builder pattern, replacing TagSet.setTag() with .tagSet(Arrays.asList"
188+
+ "(Tag.builder())), and use Tagging instead of BucketTaggingConfiguration, and adjust imports"
189+
+ " and names.";
190+
return method.withComments(createComments(comment));
191+
}
192+
147193
return method;
148194
}
149195

@@ -154,7 +200,9 @@ public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
154200
return newClass;
155201
}
156202

157-
if (type.isAssignableFrom(MULTI_FACTOR_AUTH)) {
203+
boolean setBucketVersionUsingMFA =
204+
type.isAssignableFrom(SET_BUCKET_VERSION_REQUEST) && newClass.getArguments().size() == 3;
205+
if (type.isAssignableFrom(MULTI_FACTOR_AUTH) || setBucketVersionUsingMFA) {
158206
removeV1S3ModelImport("MultiFactorAuthentication");
159207
String comment = "v2 does not have a MultiFactorAuthentication POJO. Please manually set the String value on "
160208
+ "the request POJO.";

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

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ recipeList:
110110
- org.openrewrite.java.ChangeMethodName:
111111
methodPattern: com.amazonaws.services.s3.AmazonS3 restoreObjectV2(com.amazonaws.services.s3.model.RestoreObjectRequest)
112112
newMethodName: restoreObject
113+
- org.openrewrite.java.ChangeMethodName:
114+
methodPattern: com.amazonaws.services.s3.AmazonS3 shutdown()
115+
newMethodName: close
113116

114117
- org.openrewrite.java.ChangeMethodName:
115118
methodPattern: com.amazonaws.services.s3.AmazonS3Client getObjectMetadata(com.amazonaws.services.s3.model.GetObjectMetadataRequest)

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

+22
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,28 @@ recipeList:
748748
- java.util.List<com.amazonaws.services.s3.model.Tag>
749749
fluentNames:
750750
- withTagSet
751+
- software.amazon.awssdk.v2migration.ConstructorToFluent:
752+
clzzFqcn: com.amazonaws.services.s3.model.SetObjectTaggingRequest
753+
parameterTypes:
754+
- java.lang.String
755+
- java.lang.String
756+
- com.amazonaws.services.s3.model.ObjectTagging
757+
fluentNames:
758+
- withBucket
759+
- withKey
760+
- withTagging
761+
- software.amazon.awssdk.v2migration.ConstructorToFluent:
762+
clzzFqcn: com.amazonaws.services.s3.model.SetObjectTaggingRequest
763+
parameterTypes:
764+
- java.lang.String
765+
- java.lang.String
766+
- java.lang.String
767+
- com.amazonaws.services.s3.model.ObjectTagging
768+
fluentNames:
769+
- withBucket
770+
- withKey
771+
- withVersionId
772+
- withTagging
751773
- software.amazon.awssdk.v2migration.ConstructorToFluent:
752774
clzzFqcn: com.amazonaws.services.s3.model.BucketVersioningConfiguration
753775
parameterTypes:

0 commit comments

Comments
 (0)