Skip to content

Commit b87a023

Browse files
committed
Update formatting and comments
1 parent 96d0f62 commit b87a023

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ void upload(S3TransferManager tm, String bucket, String key) {
3737
}
3838

3939
private void generatePresignedUrl(S3Client s3, String bucket, String key, Date expiration) {
40-
URL urlHead = /*AWS SDK for Java v2 migration: S3 generatePresignedUrl() with HEAD HTTP method is not supported in v2.*/s3.generatePresignedUrl(bucket, key, expiration, HttpMethod.HEAD);
40+
URL urlHead = /*AWS SDK for Java v2 migration: S3 generatePresignedUrl() with HEAD HTTP method is not supported in v2. Only GET, PUT, and DELETE are supported - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/presigner/S3Presigner.html*/s3.generatePresignedUrl(bucket, key, expiration, HttpMethod.HEAD);
4141

42-
URL urlPatch = /*AWS SDK for Java v2 migration: S3 generatePresignedUrl() with PATCH HTTP method is not supported in v2.*/s3.generatePresignedUrl(bucket, key, expiration, HttpMethod.PATCH);
42+
URL urlPatch = /*AWS SDK for Java v2 migration: S3 generatePresignedUrl() with PATCH HTTP method is not supported in v2. Only GET, PUT, and DELETE are supported - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/presigner/S3Presigner.html*/s3.generatePresignedUrl(bucket, key, expiration, HttpMethod.PATCH);
4343

44-
URL urlPost = /*AWS SDK for Java v2 migration: S3 generatePresignedUrl() with POST HTTP method is not supported in v2.*/s3.generatePresignedUrl(bucket, key, expiration, HttpMethod.POST);
44+
URL urlPost = /*AWS SDK for Java v2 migration: S3 generatePresignedUrl() with POST HTTP method is not supported in v2. Only GET, PUT, and DELETE are supported - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/presigner/S3Presigner.html*/s3.generatePresignedUrl(bucket, key, expiration, HttpMethod.POST);
4545

4646

4747
HttpMethod httpMethod = HttpMethod.PUT;
48-
URL urlWithHttpMethodVariable = /*AWS SDK for Java v2 migration: Transform for S3 generatePresignedUrl() with an assigned variable for HttpMethod is not supported. Update your code to pass in HttpMethod literal enum, or manually migrate your code.*/s3.generatePresignedUrl(bucket, key, expiration, httpMethod);
48+
URL urlWithHttpMethodVariable = /*AWS SDK for Java v2 migration: Transform for S3 generatePresignedUrl() with an assigned variable for HttpMethod is not supported. Update your code to pass in enum instead and run the migration tool again, or manually migrate your code - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/presigner/S3Presigner.html*/s3.generatePresignedUrl(bucket, key, expiration, httpMethod);
4949

5050
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, key);
51-
/*AWS SDK for Java v2 migration: Transforms are not supported for GeneratePresignedUrlRequest, please manually migrate your code.*/s3.generatePresignedUrl(request);
51+
/*AWS SDK for Java v2 migration: Transforms are not supported for GeneratePresignedUrlRequest, please manually migrate your code.- https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/presigner/S3Presigner.html*/s3.generatePresignedUrl(request);
5252
}
5353
}

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,24 @@ private void s3Uri(URI uri, String uriAsString) {
409409
}
410410

411411
private void generatePresignedUrl(S3Client s3, String bucket, String key, Date expiration) {
412-
URL urlGet1 = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build().presignGetObject(p -> p.getObjectRequest(r -> r.bucket(bucket).key(key)).signatureDuration(Duration.between(Instant.now(), expiration.toInstant()))).url();
413-
414-
URL urlPut = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build().presignPutObject(p -> p.putObjectRequest(r -> r.bucket(bucket).key(key)).signatureDuration(Duration.between(Instant.now(), expiration.toInstant()))).url();
415-
416-
URL urlGet2 = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build().presignGetObject(p -> p.getObjectRequest(r -> r.bucket(bucket).key(key)).signatureDuration(Duration.between(Instant.now(), expiration.toInstant()))).url();
417-
418-
URL urlDelete = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build().presignDeleteObject(p -> p.deleteObjectRequest(r -> r.bucket(bucket).key(key)).signatureDuration(Duration.between(Instant.now(), expiration.toInstant()))).url();
412+
URL urlGet1 = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build()
413+
.presignGetObject(p -> p.getObjectRequest(r -> r.bucket(bucket).key(key))
414+
.signatureDuration(Duration.between(Instant.now(), expiration.toInstant())))
415+
.url();
416+
417+
URL urlPut = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build()
418+
.presignPutObject(p -> p.putObjectRequest(r -> r.bucket(bucket).key(key))
419+
.signatureDuration(Duration.between(Instant.now(), expiration.toInstant())))
420+
.url();
421+
422+
URL urlGet2 = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build()
423+
.presignGetObject(p -> p.getObjectRequest(r -> r.bucket(bucket).key(key))
424+
.signatureDuration(Duration.between(Instant.now(), expiration.toInstant())))
425+
.url();
426+
427+
URL urlDelete = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build()
428+
.presignDeleteObject(p -> p.deleteObjectRequest(r -> r.bucket(bucket).key(key))
429+
.signatureDuration(Duration.between(Instant.now(), expiration.toInstant())))
430+
.url();
419431
}
420432
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
8686
return transformCompleteMpuRequestCompletedPartsArg(method);
8787
}
8888
if (isGeneratePresignedUrl(method)) {
89-
return transformGeneratePresignedUrl(method);
89+
return maybeAutoFormat(method, transformGeneratePresignedUrl(method), executionContext);
9090
}
9191
if (DISABLE_REQUESTER_PAYS.matches(method, false)) {
9292
return transformSetRequesterPays(method, false);
@@ -136,9 +136,10 @@ private J.MethodInvocation transformGeneratePresignedUrl(J.MethodInvocation meth
136136
return method.withComments(assignedVariableHttpMethodNotSupportedComment());
137137
}
138138

139-
String v2Method = String.format("S3Presigner.builder().s3Client(#{any()}).build().presign%sObject"
140-
+ "(p -> p.%sObjectRequest(r -> r.bucket(#{any()}).key(#{any()}))"
141-
+ ".signatureDuration(Duration.between(Instant.now(), #{any()}.toInstant()))).url()",
139+
String v2Method = String.format("S3Presigner.builder().s3Client(#{any()}).build()\n"
140+
+ ".presign%sObject(p -> p.%sObjectRequest(r -> r.bucket(#{any()}).key(#{any()}))\n"
141+
+ ".signatureDuration(Duration.between(Instant.now(), #{any()}.toInstant())))\n"
142+
+ ".url()",
142143
httpMethod, httpMethod.toLowerCase(Locale.ROOT));
143144

144145
removeV1HttpMethodImport();

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,23 @@ public static boolean isUnsupportedHttpMethod(String httpMethod) {
7979

8080
public static List<Comment> assignedVariableHttpMethodNotSupportedComment() {
8181
String comment = "Transform for S3 generatePresignedUrl() with an assigned variable for HttpMethod is not supported."
82-
+ " Update your code to pass in HttpMethod literal enum, or manually migrate your code.";
82+
+ " Update your code to pass in enum instead and run the migration tool again, or manually migrate "
83+
+ "your code - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/presigner"
84+
+ "/S3Presigner.html";
8385
return createComments(comment);
8486
}
8587

8688
public static List<Comment> requestPojoTransformNotSupportedComment() {
87-
String comment = "Transforms are not supported for GeneratePresignedUrlRequest, please manually migrate your code.";
89+
String comment = "Transforms are not supported for GeneratePresignedUrlRequest, please manually migrate your code."
90+
+ "- https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/presigner"
91+
+ "/S3Presigner.html";
8892
return createComments(comment);
8993
}
9094

9195
public static List<Comment> httpMethodNotSupportedComment(String httpMethod) {
92-
String comment = String.format("S3 generatePresignedUrl() with %s HTTP method is not supported in v2.",
96+
String comment = String.format("S3 generatePresignedUrl() with %s HTTP method is not supported in v2. Only GET, PUT, "
97+
+ "and DELETE are supported - https://sdk.amazonaws"
98+
+ ".com/java/api/latest/software/amazon/awssdk/services/s3/presigner/S3Presigner.html",
9399
httpMethod.toUpperCase(Locale.ROOT));
94100
return createComments(comment);
95101
}

0 commit comments

Comments
 (0)