|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.awssdk.v2migrationtests; |
| 17 | + |
| 18 | +import static java.util.Collections.addAll; |
| 19 | +import static software.amazon.awssdk.v2migrationtests.TestUtils.assertTwoDirectoriesHaveSameStructure; |
| 20 | +import static software.amazon.awssdk.v2migrationtests.TestUtils.getMigrationToolVersion; |
| 21 | +import static software.amazon.awssdk.v2migrationtests.TestUtils.getVersion; |
| 22 | +import static software.amazon.awssdk.v2migrationtests.TestUtils.replaceVersion; |
| 23 | +import static software.amazon.awssdk.v2migrationtests.TestUtils.run; |
| 24 | + |
| 25 | +import java.io.File; |
| 26 | +import java.io.IOException; |
| 27 | +import java.nio.file.Path; |
| 28 | +import java.util.ArrayList; |
| 29 | +import java.util.List; |
| 30 | +import org.apache.commons.io.FileUtils; |
| 31 | +import org.junit.jupiter.api.BeforeAll; |
| 32 | +import org.junit.jupiter.api.Test; |
| 33 | +import org.junit.jupiter.api.condition.EnabledIf; |
| 34 | +import software.amazon.awssdk.utils.Logger; |
| 35 | + |
| 36 | +public class MavenTransferManagerTest { |
| 37 | + private static final Logger log = Logger.loggerFor(MavenTransferManagerTest.class); |
| 38 | + private static String sdkVersion; |
| 39 | + private static Path mavenTmBefore; |
| 40 | + private static Path mavenTmAfter; |
| 41 | + private static Path target; |
| 42 | + private static Path mavenTmActual; |
| 43 | + private static Path mavenTmExpected; |
| 44 | + |
| 45 | + @BeforeAll |
| 46 | + static void setUp() throws IOException { |
| 47 | + sdkVersion = getVersion(); |
| 48 | + mavenTmBefore = new File(MavenTransferManagerTest.class.getResource("maven-tm/before").getFile()).toPath(); |
| 49 | + mavenTmAfter = new File(MavenTransferManagerTest.class.getResource("maven-tm/after").getFile()).toPath(); |
| 50 | + target = new File(MavenTransferManagerTest.class.getResource("/").getFile()).toPath().getParent(); |
| 51 | + |
| 52 | + mavenTmActual = target.resolve("maven-tm/actual"); |
| 53 | + mavenTmExpected = target.resolve("maven-tm/expected"); |
| 54 | + |
| 55 | + deleteTempDirectories(); |
| 56 | + |
| 57 | + FileUtils.copyDirectory(mavenTmBefore.toFile(), mavenTmActual.toFile()); |
| 58 | + FileUtils.copyDirectory(mavenTmAfter.toFile(), mavenTmExpected.toFile()); |
| 59 | + |
| 60 | + replaceVersion(mavenTmExpected.resolve("pom.xml"), sdkVersion); |
| 61 | + replaceVersion(mavenTmActual.resolve("pom.xml"), sdkVersion); |
| 62 | + } |
| 63 | + |
| 64 | + private static void deleteTempDirectories() throws IOException { |
| 65 | + FileUtils.deleteDirectory(mavenTmActual.toFile()); |
| 66 | + FileUtils.deleteDirectory(mavenTmExpected.toFile()); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + @EnabledIf("versionAvailable") |
| 71 | + void mavenProject_shouldConvert() throws IOException { |
| 72 | + verifyTransformation(); |
| 73 | + verifyCompilation(); |
| 74 | + } |
| 75 | + |
| 76 | + private static void verifyTransformation() throws IOException { |
| 77 | + List<String> rewriteArgs = new ArrayList<>(); |
| 78 | + // pin version since updates have broken tests |
| 79 | + String rewriteMavenPluginVersion = "5.46.0"; |
| 80 | + addAll(rewriteArgs, "mvn", "org.openrewrite.maven:rewrite-maven-plugin:" + rewriteMavenPluginVersion + ":run", |
| 81 | + "-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:v2-migration:"+ getMigrationToolVersion() + "-PREVIEW", |
| 82 | + "-Drewrite.activeRecipes=software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2Experimental"); |
| 83 | + |
| 84 | + run(mavenTmActual, rewriteArgs.toArray(new String[0])); |
| 85 | + FileUtils.deleteDirectory(mavenTmActual.resolve("target").toFile()); |
| 86 | + assertTwoDirectoriesHaveSameStructure(mavenTmActual, mavenTmExpected); |
| 87 | + } |
| 88 | + |
| 89 | + private static void verifyCompilation() { |
| 90 | + List<String> packageArgs = new ArrayList<>(); |
| 91 | + addAll(packageArgs, "mvn", "package"); |
| 92 | + run(mavenTmActual, packageArgs.toArray(new String[0])); |
| 93 | + } |
| 94 | + |
| 95 | + boolean versionAvailable() { |
| 96 | + return TestUtils.versionAvailable(sdkVersion); |
| 97 | + } |
| 98 | +} |
0 commit comments