Skip to content

Minor refactoring and updating readme #5370

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

Merged
merged 1 commit into from
Jul 8, 2024
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
32 changes: 28 additions & 4 deletions migration-tool/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AWS SDK for Java v2 Migration Tool

## Description
This is a migration tool to automate migration from AWS SDK for Java v1 to AWS SDK for Java v2.
This is a migration tool to automate migration from AWS SDK for Java v1 to AWS SDK for Java v2.
It uses [OpenRewrite][open-rewrite].

## Usage
Expand All @@ -17,7 +17,7 @@ find the latest version.

```
mvn org.openrewrite.maven:rewrite-maven-plugin:dryRun \
-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:{sdkversion}
-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:{sdkversion} \
-Drewrite.activeRecipes=software.amazon.awssdk.UpgradeJavaSdk2
```

Expand All @@ -27,11 +27,35 @@ With this mode, it runs the SDK recipes and applies the changes locally.

```
mvn org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:{sdkversion}
-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:{sdkversion} \
-Drewrite.activeRecipes=software.amazon.awssdk.UpgradeJavaSdk2
```


## Development

To build this module locally for fast development, run the following command.

```
mvn clean install -pl :bom-internal,:bom,:migration-tool -P quick --am
```

### Testing

There are two types of tests available: unit tests and end-to-end functional tests.
- Unit tests

Unit tests reside in the test folder in this module. They use [RewriteTest][rewrite-test] interface

- End-to-end functional tests

End-to-end functional tests are in [migration-tool-tests module][migration-tool-tests]. It contains
sample applications using the AWS SDK for Java v1 and compares the transformed code with the expected v2
code and ensures it compiles.

[open-rewrite]: https://docs.openrewrite.org/
[open-rewrite-usage]: https://docs.openrewrite.org/running-recipes
[open-rewrite-plugin]: https://docs.openrewrite.org/reference/rewrite-maven-plugin
[maven-central]: https://central.sonatype.com/artifact/software.amazon.awssdk/migration-tool
[maven-central]: https://central.sonatype.com/artifact/software.amazon.awssdk/migration-tool
[rewrite-test]:https://docs.openrewrite.org/authoring-recipes/recipe-testing#rewritetest-interface
[migration-tool-tests]:../test/migration-tool-tests
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.TypeUtils;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.migration.internal.utils.NamingUtils;

Expand All @@ -51,17 +49,14 @@ private static class V1GetterToV2Visitor extends JavaIsoVisitor<ExecutionContext
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) {
method = super.visitMethodInvocation(method, executionContext);

JavaType selectType;

Expression select = method.getSelect();
JavaType.Method methodType = method.getMethodType();

if (select == null || select.getType() == null) {
if (methodType == null) {
return method;
}
selectType = select.getType();

String methodName = method.getSimpleName();
JavaType.FullyQualified fullyQualified = TypeUtils.asFullyQualified(selectType);
JavaType.FullyQualified fullyQualified = methodType.getDeclaringType();

if (!shouldChangeGetter(fullyQualified)) {
return method;
Expand All @@ -71,21 +66,11 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
methodName = NamingUtils.removeGet(methodName);
}

JavaType.Method methodType = method.getMethodType();

if (methodType != null) {
methodType = methodType.withName(methodName)
.withReturnType(selectType);

if (fullyQualified != null) {
methodType = methodType.withDeclaringType(fullyQualified);
}

method = method.withName(method.getName()
.withSimpleName(methodName)
.withType(methodType))
.withMethodType(methodType);
}
methodType = methodType.withName(methodName);
method = method.withName(method.getName()
.withSimpleName(methodName)
.withType(methodType))
.withMethodType(methodType);

return method;
}
Expand Down
Loading