Skip to content

Skip transformation for S3 Transfer Manager and DynamoDB mapper #5364

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
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
20 changes: 18 additions & 2 deletions migration-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.12.472</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -87,7 +94,17 @@
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<scope>test</scope>
<version>1.12.472</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson</groupId>
Expand All @@ -99,7 +116,6 @@
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<scope>test</scope>
<version>1.12.472</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static software.amazon.awssdk.migration.internal.utils.SdkTypeUtils.isV1ModelClass;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
Expand All @@ -44,6 +45,7 @@
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.java.tree.TypedTree;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.utils.Logger;
import software.amazon.awssdk.utils.Pair;

/**
Expand All @@ -58,10 +60,15 @@
*/
@SdkInternalApi
public class ChangeSdkType extends Recipe {
private static final Logger log = Logger.loggerFor(ChangeSdkType.class);
private static final String V1_SERVICE_MODEL_WILD_CARD_CLASS_PATTERN =
"com\\.amazonaws\\.services\\.[a-zA-Z0-9]+\\.model\\.\\*";
private static final String V1_SERVICE_WILD_CARD_CLASS_PATTERN = "com\\.amazonaws\\.services\\.[a-zA-Z0-9]+\\.\\*";

private static final Set<String> PACKAGES_TO_SKIP = new HashSet<>(
Arrays.asList("com.amazonaws.services.s3.transfer",
"com.amazonaws.services.dynamodbv2.datamodeling"));

@Override
public String getDisplayName() {
return "Change AWS SDK for Java v1 types to v2 equivalents";
Expand Down Expand Up @@ -131,9 +138,20 @@ private static boolean isWildcard(String fullName) {
}

private static boolean isV1Class(JavaType.FullyQualified fullyQualified) {
String fullyQualifiedName = fullyQualified.getFullyQualifiedName();
if (shouldSkip(fullyQualifiedName)) {
log.info(() -> String.format("Skipping transformation for %s because it is not supported in the migration "
+ "tooling at the moment", fullyQualifiedName));
return false;
}

return isV1ModelClass(fullyQualified) || isV1ClientClass(fullyQualified);
}

private static boolean shouldSkip(String fqcn) {
return PACKAGES_TO_SKIP.stream().anyMatch(fqcn::startsWith);
}

@Override
public JavaType visitType(JavaType javaType, ExecutionContext ctx) {
if (javaType == null || javaType instanceof JavaType.Unknown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ recipeList:
groupId: software.amazon.awssdk
artifactId: apache-client
version: 2.23.16-SNAPSHOT
onlyIfUsing: com.amazonaws.ClientConfiguration
- org.openrewrite.maven.AddDependency:
groupId: software.amazon.awssdk
artifactId: netty-nio-client
version: 2.23.16-SNAPSHOT
onlyIfUsing: com.amazonaws.ClientConfiguration
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: com.amazonaws
oldArtifactId: aws-java-sdk-core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ def write_bom_recipe(f, version):
newVersion: {0}'''
f.write(change_bom.format(version))

def add_dependencies(f, version):
# Only add apache-client and netty-nio-client if ClientConfiguration is used
def add_http_client_dependencies_if_needed(f, version):
add_dependencies_str = '''
- org.openrewrite.maven.AddDependency:
groupId: software.amazon.awssdk
artifactId: apache-client
version: {0}
onlyIfUsing: com.amazonaws.ClientConfiguration
- org.openrewrite.maven.AddDependency:
groupId: software.amazon.awssdk
artifactId: netty-nio-client
version: {0}'''
version: {0}
onlyIfUsing: com.amazonaws.ClientConfiguration'''
f.write(add_dependencies_str.format(version))

def replace_core_dependencies(f, version):
Expand Down Expand Up @@ -98,7 +101,7 @@ def write_recipe_yml_file(service_mapping):
with open(filename, 'w') as f:
write_copy_right_header(f)
write_recipe_metadata(f, version)
add_dependencies(f, version)
add_http_client_dependencies_if_needed(f, version)
replace_core_dependencies(f, version)
write_bom_recipe(f, version)
for s in service_mapping:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class ChangeSdkTypeTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new ChangeSdkType()).parser(Java8Parser.builder().classpath("aws-java-sdk-sqs","sqs"));
spec.recipe(new ChangeSdkType()).parser(Java8Parser.builder().classpath("aws-java-sdk-sqs","sqs", "aws-java-sdk-s3",
"aws-java-sdk-dynamodb"));
}

@Test
Expand Down Expand Up @@ -215,4 +216,30 @@ void shouldChangeFieldsInInnerClass() {
)
);
}

@Test
@EnabledOnJre({JRE.JAVA_8})
void hasUnsupportedFeature_shouldSkip() {
rewriteRun(
java(
"import com.amazonaws.services.s3.transfer.TransferManager;\n" +
"import com.amazonaws.services.sqs.model.DeleteQueueRequest;\n" +
"import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;\n" +
"class Test {\n" +
" private TransferManager transferManager;\n" +
" private DeleteQueueRequest deleteQueue;\n" +
" private DynamoDBMapper ddbMapper;\n" +
"}\n",
"import com.amazonaws.services.s3.transfer.TransferManager;\n"
+ "import software.amazon.awssdk.services.sqs.model.DeleteQueueRequest;\n"
+ "import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;\n"
+ "\n"
+ "class Test {\n"
+ " private TransferManager transferManager;\n"
+ " private DeleteQueueRequest deleteQueue;\n"
+ " private DynamoDBMapper ddbMapper;\n"
+ "}"
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

package software.amazon.awssdk.migration.recipe;

import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.Assertions.mavenProject;
import static org.openrewrite.java.Assertions.srcMainJava;
import static org.openrewrite.maven.Assertions.pomXml;

import java.io.IOException;
Expand All @@ -25,13 +28,28 @@
import java.util.Optional;
import org.junit.jupiter.api.BeforeAll;
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 UpgradeSdkDependenciesTest implements RewriteTest {

private static String sdkVersion;

private final String useClientConfiguration = " import com.amazonaws.services.sqs.AmazonSQSClient;\n"
+ " import com.amazonaws.ClientConfiguration;\n"
+ " public class Test {\n"
+ " private ClientConfiguration configuration;\n"
+ " private AmazonSQSClient sqsClient;\n"
+ " }";

private final String noClientConfiguration = " import com.amazonaws.services.sqs.AmazonSQSClient;\n"
+ " public class Test {\n"
+ " private AmazonSQSClient sqsClient;\n"
+ " }";

@BeforeAll
static void setUp() throws IOException {
sdkVersion = getVersion();
Expand All @@ -40,7 +58,9 @@ static void setUp() throws IOException {
@Override
public void defaults(RecipeSpec spec) {
try (InputStream stream = getClass().getResourceAsStream("/META-INF/rewrite/upgrade-sdk-dependencies.yml")) {
spec.recipe(stream, "software.amazon.awssdk.UpgradeSdkDependencies");
spec.recipe(stream, "software.amazon.awssdk.UpgradeSdkDependencies")
.parser(Java8Parser.builder().classpath(
"aws-java-sdk-sqs", "aws-java-sdk-core"));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -63,10 +83,11 @@ private static String getVersion() throws IOException {
}

@Test
@EnabledOnJre({JRE.JAVA_8})
void standardClient_shouldChangeDependencyGroupIdAndArtifactId() throws IOException {
getVersion();
String currentVersion = getVersion();
rewriteRun(
mavenProject("project", srcMainJava(java(noClientConfiguration)),
pomXml(
" <project>\n"
+ " <groupId>com.test.app</groupId>\n"
Expand Down Expand Up @@ -100,20 +121,65 @@ void standardClient_shouldChangeDependencyGroupIdAndArtifactId() throws IOExcept
+ " <artifactId>sqs</artifactId>\n"
+ " <version>2.23.16-SNAPSHOT</version>\n"
+ " </dependency>\n"
+ " <dependency>\n"
+ " <groupId>software.amazon.awssdk</groupId>\n"
+ " <artifactId>apache-client</artifactId>\n"
+ " <version>2.23.16-SNAPSHOT</version>\n"
+ " </dependency>\n"
+ " <dependency>\n"
+ " <groupId>software.amazon.awssdk</groupId>\n"
+ " <artifactId>netty-nio-client</artifactId>\n"
+ " <version>2.23.16-SNAPSHOT</version>\n"
+ " </dependency>\n"
+ " </dependencies>\n"
+ "</project>", currentVersion)

)
);
)));
}

@Test
@EnabledOnJre({JRE.JAVA_8})
void useClientConfiguration_shouldAddHttpDependencies() throws IOException {
String currentVersion = getVersion();
rewriteRun(
mavenProject("project", srcMainJava(java(useClientConfiguration)),
pomXml(
" <project>\n"
+ " <groupId>com.test.app</groupId>\n"
+ " <artifactId>my-app</artifactId>\n"
+ " <version>1</version>\n"
+ " <dependencies>\n"
+ " <dependency>\n"
+ " <groupId>com.amazonaws</groupId>\n"
+ " <artifactId>aws-java-sdk-core</artifactId>\n"
+ " <version>1.12.100</version>\n"
+ " </dependency>\n"
+ " <dependency>\n"
+ " <groupId>com.amazonaws</groupId>\n"
+ " <artifactId>aws-java-sdk-sqs</artifactId>\n"
+ " <version>1.12.100</version>\n"
+ " </dependency>\n"
+ " </dependencies>\n"
+ " </project>",
String.format("<project>\n"
+ " <groupId>com.test.app</groupId>\n"
+ " <artifactId>my-app</artifactId>\n"
+ " <version>1</version>\n"
+ " <dependencies>\n"
+ " <dependency>\n"
+ " <groupId>software.amazon.awssdk</groupId>\n"
+ " <artifactId>aws-core</artifactId>\n"
+ " <version>2.23.16-SNAPSHOT</version>\n"
+ " </dependency>\n"
+ " <dependency>\n"
+ " <groupId>software.amazon.awssdk</groupId>\n"
+ " <artifactId>sqs</artifactId>\n"
+ " <version>2.23.16-SNAPSHOT</version>\n"
+ " </dependency>\n"
+ " <dependency>\n"
+ " <groupId>software.amazon.awssdk</groupId>\n"
+ " <artifactId>apache-client</artifactId>\n"
+ " <version>2.23.16-SNAPSHOT</version>\n"
+ " </dependency>\n"
+ " <dependency>\n"
+ " <groupId>software.amazon.awssdk</groupId>\n"
+ " <artifactId>netty-nio-client</artifactId>\n"
+ " <version>2.23.16-SNAPSHOT</version>\n"
+ " </dependency>\n"
+ " </dependencies>\n"
+ "</project>", currentVersion)

)));
}

}
Loading