Skip to content

Commit 1f2b0f3

Browse files
authored
Minor refactoring and updating readme (#5370)
1 parent c0d444b commit 1f2b0f3

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

migration-tool/README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AWS SDK for Java v2 Migration Tool
22

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

77
## Usage
@@ -17,7 +17,7 @@ find the latest version.
1717

1818
```
1919
mvn org.openrewrite.maven:rewrite-maven-plugin:dryRun \
20-
-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:{sdkversion}
20+
-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:{sdkversion} \
2121
-Drewrite.activeRecipes=software.amazon.awssdk.UpgradeJavaSdk2
2222
```
2323

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

2828
```
2929
mvn org.openrewrite.maven:rewrite-maven-plugin:run \
30-
-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:{sdkversion}
30+
-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:{sdkversion} \
3131
-Drewrite.activeRecipes=software.amazon.awssdk.UpgradeJavaSdk2
3232
```
3333

34+
35+
## Development
36+
37+
To build this module locally for fast development, run the following command.
38+
39+
```
40+
mvn clean install -pl :bom-internal,:bom,:migration-tool -P quick --am
41+
```
42+
43+
### Testing
44+
45+
There are two types of tests available: unit tests and end-to-end functional tests.
46+
- Unit tests
47+
48+
Unit tests reside in the test folder in this module. They use [RewriteTest][rewrite-test] interface
49+
50+
- End-to-end functional tests
51+
52+
End-to-end functional tests are in [migration-tool-tests module][migration-tool-tests]. It contains
53+
sample applications using the AWS SDK for Java v1 and compares the transformed code with the expected v2
54+
code and ensures it compiles.
55+
3456
[open-rewrite]: https://docs.openrewrite.org/
3557
[open-rewrite-usage]: https://docs.openrewrite.org/running-recipes
3658
[open-rewrite-plugin]: https://docs.openrewrite.org/reference/rewrite-maven-plugin
37-
[maven-central]: https://central.sonatype.com/artifact/software.amazon.awssdk/migration-tool
59+
[maven-central]: https://central.sonatype.com/artifact/software.amazon.awssdk/migration-tool
60+
[rewrite-test]:https://docs.openrewrite.org/authoring-recipes/recipe-testing#rewritetest-interface
61+
[migration-tool-tests]:../test/migration-tool-tests

migration-tool/src/main/java/software/amazon/awssdk/migration/internal/recipe/V1GetterToV2.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
import org.openrewrite.Recipe;
2222
import org.openrewrite.TreeVisitor;
2323
import org.openrewrite.java.JavaIsoVisitor;
24-
import org.openrewrite.java.tree.Expression;
2524
import org.openrewrite.java.tree.J;
2625
import org.openrewrite.java.tree.JavaType;
27-
import org.openrewrite.java.tree.TypeUtils;
2826
import software.amazon.awssdk.annotations.SdkInternalApi;
2927
import software.amazon.awssdk.migration.internal.utils.NamingUtils;
3028

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

54-
JavaType selectType;
55-
56-
Expression select = method.getSelect();
52+
JavaType.Method methodType = method.getMethodType();
5753

58-
if (select == null || select.getType() == null) {
54+
if (methodType == null) {
5955
return method;
6056
}
61-
selectType = select.getType();
6257

6358
String methodName = method.getSimpleName();
64-
JavaType.FullyQualified fullyQualified = TypeUtils.asFullyQualified(selectType);
59+
JavaType.FullyQualified fullyQualified = methodType.getDeclaringType();
6560

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

74-
JavaType.Method methodType = method.getMethodType();
75-
76-
if (methodType != null) {
77-
methodType = methodType.withName(methodName)
78-
.withReturnType(selectType);
79-
80-
if (fullyQualified != null) {
81-
methodType = methodType.withDeclaringType(fullyQualified);
82-
}
83-
84-
method = method.withName(method.getName()
85-
.withSimpleName(methodName)
86-
.withType(methodType))
87-
.withMethodType(methodType);
88-
}
69+
methodType = methodType.withName(methodName);
70+
method = method.withName(method.getName()
71+
.withSimpleName(methodName)
72+
.withType(methodType))
73+
.withMethodType(methodType);
8974

9075
return method;
9176
}

0 commit comments

Comments
 (0)