Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ private void setBucketConfigs(S3Client s3, String bucket) {
s3.putBucketInventoryConfiguration(PutBucketInventoryConfigurationRequest.builder().bucket(bucket).inventoryConfiguration(InventoryConfiguration.builder()
.build())
.build());
s3.putBucketLifecycleConfiguration(PutBucketLifecycleConfigurationRequest.builder().bucket(bucket).lifecycleConfiguration(BucketLifecycleConfiguration.builder()
.build())
.build());
/*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()
.build())
.build());
s3.putBucketMetricsConfiguration(PutBucketMetricsConfigurationRequest.builder().bucket(bucket).metricsConfiguration(MetricsConfiguration.builder()
.build())
.build());
Expand All @@ -388,9 +388,9 @@ private void setBucketConfigs(S3Client s3, String bucket) {
s3.putBucketReplication(PutBucketReplicationRequest.builder().bucket(bucket).replicationConfiguration(ReplicationConfiguration.builder()
.build())
.build());
s3.putBucketTagging(PutBucketTaggingRequest.builder().bucket(bucket).tagging(Tagging.builder()
.build())
.build());
/*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()
.build())
.build());
s3.putBucketWebsite(PutBucketWebsiteRequest.builder().bucket(bucket).websiteConfiguration(WebsiteConfiguration.builder()
.build())
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ public void requestconstructor() {
.build());


s3.putBucketLifecycleConfiguration(
PutBucketLifecycleConfigurationRequest.builder().bucket(bucketName).lifecycleConfiguration(BucketLifecycleConfiguration.builder()
.build())
.build());
/*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(bucketName).lifecycleConfiguration(BucketLifecycleConfiguration.builder()
.build())
.build());

s3.putBucketMetricsConfiguration(
PutBucketMetricsConfigurationRequest.builder()
Expand Down Expand Up @@ -433,10 +433,10 @@ public void requestconstructor() {
.build())
.build());

s3.putBucketTagging(
PutBucketTaggingRequest.builder().bucket(bucketName).tagging(Tagging.builder()
.build())
.build());
/*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(bucketName).tagging(Tagging.builder()
.build())
.build());

DeleteObjectRequest deleteVersionRequest = DeleteObjectRequest.builder().bucket(bucketName).key(objectKey).versionId("id")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,23 @@ public class S3AddImportsAndComments extends Recipe {
private static final MethodMatcher LIST_NEXT_BATCH_VERSIONS = v1S3MethodMatcher("listNextBatchOfVersions(..)");
private static final MethodMatcher GET_METADATA = v1S3MethodMatcher("getCachedResponseMetadata(..)");
private static final MethodMatcher SET_BUCKET_ACL = v1S3MethodMatcher("setBucketAcl(..)");
private static final MethodMatcher SET_BUCKET_LOGGING = v1S3MethodMatcher("setBucketLoggingConfiguration(..)");
private static final MethodMatcher SET_ENDPOINT = v1S3MethodMatcher("setEndpoint(..)");
private static final MethodMatcher SET_OBJECT_ACL = v1S3MethodMatcher("setObjectAcl(..)");
private static final MethodMatcher SET_REGION = v1S3MethodMatcher("setRegion(..)");
private static final MethodMatcher SET_PAYMENT_CONFIGURATION = v1S3MethodMatcher("setRequestPaymentConfiguration(..)");
private static final MethodMatcher SET_S3CLIENT_OPTIONS = v1S3MethodMatcher("setS3ClientOptions(..)");
private static final MethodMatcher SELECT_OBJECT_CONTENT = v1S3MethodMatcher("selectObjectContent(..)");
private static final MethodMatcher SET_LIFECYCLE_CONFIGURATION = v1S3MethodMatcher("setBucketLifecycleConfiguration(..)");
private static final MethodMatcher SET_TAGGING_CONFIGURATION = v1S3MethodMatcher("setBucketTaggingConfiguration(..)");


private static final Pattern CANNED_ACL = Pattern.compile(V1_S3_MODEL_PKG + "CannedAccessControlList");
private static final Pattern GET_OBJECT_REQUEST = Pattern.compile(V1_S3_MODEL_PKG + "GetObjectRequest");
private static final Pattern INITIATE_MPU = Pattern.compile(V1_S3_MODEL_PKG + "InitiateMultipartUpload");
private static final Pattern MULTI_FACTOR_AUTH = Pattern.compile(V1_S3_MODEL_PKG + "MultiFactorAuthentication");
private static final Pattern SET_BUCKET_VERSION_REQUEST = Pattern.compile(V1_S3_MODEL_PKG
+ "SetBucketVersioningConfigurationRequest");

@Override
public String getDisplayName() {
Expand Down Expand Up @@ -144,6 +151,45 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
return method.withComments(createComments(comment));
}

if (SET_BUCKET_LOGGING.matches(method)) {
// TODO: add the developer guide link in the comments once the doc is published.
removeV1S3ModelImport("BucketLoggingConfiguration");
addV2S3ModelImport("BucketLoggingStatus");
addV2S3ModelImport("LoggingEnabled");

String comment = "Transform for setBucketLoggingConfiguration method not "
+ "supported. The method is renamed to putBucketLogging. Please manually migrate your code by "
+ "replacing BucketLoggingConfiguration with BucketLoggingStatus and LoggingEnabled builders, "
+ "and updating the method name and parameters";
return method.withComments(createComments(comment));
}

if (SET_PAYMENT_CONFIGURATION.matches(method)) {
String comment = "Transform for setRequestPaymentConfiguration method not supported. Payer enum is a "
+ "separate class in v2 (not nested). Please manually migrate "
+ "your code by update from RequestPaymentConfiguration.Payer to just Payer, and adjust "
+ "imports and names.";
return method.withComments(createComments(comment));
}

if (SET_LIFECYCLE_CONFIGURATION.matches(method)) {
// TODO: add the developer guide link in the comments once the doc is published.
String comment = "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.";
return method.withComments(createComments(comment));
}

if (SET_TAGGING_CONFIGURATION.matches(method)) {
// TODO: add the developer guide link in the comments once the doc is published.
String comment = "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.";
return method.withComments(createComments(comment));
}

return method;
}

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

if (type.isAssignableFrom(MULTI_FACTOR_AUTH)) {
boolean setBucketVersionUsingMFA =
type.isAssignableFrom(SET_BUCKET_VERSION_REQUEST) && newClass.getArguments().size() == 3;
if (type.isAssignableFrom(MULTI_FACTOR_AUTH) || setBucketVersionUsingMFA) {
removeV1S3ModelImport("MultiFactorAuthentication");
String comment = "v2 does not have a MultiFactorAuthentication POJO. Please manually set the String value on "
+ "the request POJO.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.amazonaws.services.s3.AmazonS3 restoreObjectV2(com.amazonaws.services.s3.model.RestoreObjectRequest)
newMethodName: restoreObject
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.amazonaws.services.s3.AmazonS3 shutdown()
newMethodName: close

- org.openrewrite.java.ChangeMethodName:
methodPattern: com.amazonaws.services.s3.AmazonS3Client getObjectMetadata(com.amazonaws.services.s3.model.GetObjectMetadataRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,28 @@ recipeList:
- java.util.List<com.amazonaws.services.s3.model.Tag>
fluentNames:
- withTagSet
- software.amazon.awssdk.v2migration.ConstructorToFluent:
clzzFqcn: com.amazonaws.services.s3.model.SetObjectTaggingRequest
parameterTypes:
- java.lang.String
- java.lang.String
- com.amazonaws.services.s3.model.ObjectTagging
fluentNames:
- withBucket
- withKey
- withTagging
- software.amazon.awssdk.v2migration.ConstructorToFluent:
clzzFqcn: com.amazonaws.services.s3.model.SetObjectTaggingRequest
parameterTypes:
- java.lang.String
- java.lang.String
- java.lang.String
- com.amazonaws.services.s3.model.ObjectTagging
fluentNames:
- withBucket
- withKey
- withVersionId
- withTagging
- software.amazon.awssdk.v2migration.ConstructorToFluent:
clzzFqcn: com.amazonaws.services.s3.model.BucketVersioningConfiguration
parameterTypes:
Expand Down
Loading