Skip to content

Support Regions migration #5118

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
Apr 18, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#
---
type: specs.openrewrite.org/v1beta/recipe
name: software.amazon.awssdk.ChangeRegionTypes
displayName: Change region related classes
recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.amazonaws.regions.Regions fromName(String)
newMethodName: of
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.amazonaws.regions.Regions getName()
newMethodName: id
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.amazonaws.regions.Regions
newFullyQualifiedTypeName: software.amazon.awssdk.regions.Region

## TODO: handle RegionUtils, Region
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#
---
type: specs.openrewrite.org/v1beta/recipe
name: software.amazon.awssdk.ChangeSdkCoreTypes
displayName: Change Maven dependency groupId, artifactId and/or the version example
recipeList:
- software.amazon.awssdk.ChangeRegionTypes
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ tags:
- sdk
recipeList:
- software.amazon.awssdk.UpgradeSdkDependencies
- software.amazon.awssdk.migration.recipe.ChangeSdkType
- software.amazon.awssdk.migration.recipe.ChangeSdkType
- software.amazon.awssdk.ChangeSdkCoreTypes
Copy link
Contributor

Choose a reason for hiding this comment

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

should ChangeSdkCoreTypes , ChangeRegionTypes, UpgradeSdkDependencies go under migration.recipe module?

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, they should be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it's still a moving target, I'll take a note and address it in user experience review.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.migration.recipe;

import static org.openrewrite.java.Assertions.java;

import java.io.IOException;
import java.io.InputStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.openrewrite.java.Java8Parser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;


public class ChangeRegionTypesTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
try (InputStream stream = getClass().getResourceAsStream("/META-INF/rewrite/change-region-types.yml")) {
spec.recipe(stream, "software.amazon.awssdk.ChangeRegionTypes");
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Test
@EnabledOnJre({JRE.JAVA_8})
void shouldChangeRegions() {
rewriteRun(
spec -> spec.parser(Java8Parser.builder().classpath("aws-java-sdk-core")),
java(
"import com.amazonaws.regions.Regions;\n" +
"class Test {\n" +
" static void method() {\n" +
" Regions region = Regions.fromName(\"us-east-1\");\n" +
" Regions region2 = Regions.US_EAST_1;\n" +
" }\n" +
"}\n",
"import software.amazon.awssdk.regions.Region;\n" +
"\n" +
"class Test {\n" +
" static void method() {\n" +
" Region region = Region.of(\"us-east-1\");\n" +
" Region region2 = Region.US_EAST_1;\n" +
" }\n" +
"}\n"
)
);
}
}