Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transforming S3 PUT override #5218

Open
wants to merge 2 commits into
base: feature/master/migration-tool
Choose a base branch
from

Conversation

dagnir
Copy link
Contributor

@dagnir dagnir commented May 10, 2024

This transforms the AmazonS3#putObject(String,String,File) override.

Motivation and Context

Modifications

Testing

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

This transforms the AmazonS3#putObject(String,String,File) override.
@dagnir dagnir requested a review from a team as a code owner May 10, 2024 23:41
Copy link

sonarcloud bot commented May 13, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
38.4% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

+ " }\n"
+ "}\n",
"import com.amazonaws.services.s3.AmazonS3Client;\n"
+ "import com.amazonaws.services.s3.model.PutObjectRequest;\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these imports be updated to v2 or is this handled by another recipe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah It's only testing for this recipe. I see less value in adding other recipes here since I want to test just the changes this specific recipe is expected to make

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so the tests actually are not failing due to method reference not found (don't remember the exact message)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I think that only fails when loading the before code, where it does the type validation

+ "\n"
+ " File myFile = new File(\"test.txt\");\n"
+ "\n"
+ " s3.putObject(new PutObjectRequest(BUCKET, KEY), RequestBody.fromFile(myFile));\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be builder for PutObjectRequest? What about AsyncRequestBody for async client?

Copy link
Contributor Author

@dagnir dagnir May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be builder for PutObjectRequest?

No, this is intentional. Changing this to the builder pattern is left to a downstream recipe https://github.com/aws/aws-sdk-java-v2/blob/e59e29d7927e8bf099a9118ee287d96ec1e5c565/migration-tool/src/main/resources/META-INF/rewrite/s3-putbject-constructor-to-fluent.yml

What about AsyncRequestBody for async client?

There is no async client for v1 s3.

@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) {
if (PUT_OBJECT.matches(method, false)) {
method = transformPutFileOverload(method);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to invoke super.visitMethodInvocation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, on 72. I don't think ordering matters here


J.Identifier requestBodyId = IdentifierUtils.makeId(REQUEST_BODY.getClassName(), REQUEST_BODY);

JavaType.Method fromFileType = new JavaType.Method(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 9-argu ctors always look intimating to me 😨

---
type: specs.openrewrite.org/v1beta/recipe
name: software.amazon.awssdk.S3PutObjectConstructorToFluent
displayName: Change auth related classes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: display name is not updated

+ " }\n"
+ "}\n",
"import com.amazonaws.services.s3.AmazonS3Client;\n"
+ "import com.amazonaws.services.s3.model.PutObjectRequest;\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants