Skip to content
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,56 @@
/*
* 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.v2migrationtests;

import static software.amazon.awssdk.v2migrationtests.TestUtils.replaceVersion;

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;

/**
* The transformed code will not compile, only testing the transform itself
*/
public class MavenNoCompileTest extends MavenTestBase {

@BeforeAll
static void setUp() throws IOException {
mavenBefore = new File(MavenNoCompileTest.class.getResource("maven-nocompile/before").getFile()).toPath();
mavenAfter = new File(MavenNoCompileTest.class.getResource("maven-nocompile/after").getFile()).toPath();
target = new File(MavenNoCompileTest.class.getResource("/").getFile()).toPath().getParent();

mavenActual = target.resolve("maven-nocompile/actual");
mavenExpected = target.resolve("maven-nocompile/expected");

deleteTempDirectories();

FileUtils.copyDirectory(mavenBefore.toFile(), mavenActual.toFile());
FileUtils.copyDirectory(mavenAfter.toFile(), mavenExpected.toFile());

replaceVersion(mavenExpected.resolve("pom.xml"), sdkVersion);
replaceVersion(mavenActual.resolve("pom.xml"), sdkVersion);
}

@Test
@EnabledIf("versionAvailable")
void mavenProject_shouldConvert() throws IOException {
boolean experimental = true;
verifyTransformation(experimental);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,19 @@

package software.amazon.awssdk.v2migrationtests;

import static java.util.Collections.addAll;
import static software.amazon.awssdk.v2migrationtests.TestUtils.assertTwoDirectoriesHaveSameStructure;
import static software.amazon.awssdk.v2migrationtests.TestUtils.getMigrationToolVersion;
import static software.amazon.awssdk.v2migrationtests.TestUtils.getVersion;
import static software.amazon.awssdk.v2migrationtests.TestUtils.replaceVersion;
import static software.amazon.awssdk.v2migrationtests.TestUtils.run;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import software.amazon.awssdk.utils.Logger;

public class MavenProjectTest {
private static final Logger log = Logger.loggerFor(MavenProjectTest.class);
private static String sdkVersion;
private static Path mavenBefore;
private static Path mavenAfter;
private static Path target;
private static Path mavenActual;
private static Path mavenExpected;
public class MavenProjectTest extends MavenTestBase {

@BeforeAll
static void setUp() throws IOException {
sdkVersion = getVersion();
mavenBefore = new File(MavenProjectTest.class.getResource("maven/before").getFile()).toPath();
mavenAfter = new File(MavenProjectTest.class.getResource("maven/after").getFile()).toPath();
target = new File(MavenProjectTest.class.getResource("/").getFile()).toPath().getParent();
Expand All @@ -61,38 +44,11 @@ static void setUp() throws IOException {
replaceVersion(mavenActual.resolve("pom.xml"), sdkVersion);
}

private static void deleteTempDirectories() throws IOException {
FileUtils.deleteDirectory(mavenActual.toFile());
FileUtils.deleteDirectory(mavenExpected.toFile());
}

@Test
@EnabledIf("versionAvailable")
void mavenProject_shouldConvert() throws IOException {
verifyTransformation();
boolean experimental = false;
verifyTransformation(experimental);
verifyCompilation();
}

private static void verifyTransformation() throws IOException {
List<String> rewriteArgs = new ArrayList<>();
// pin version since updates have broken tests
String rewriteMavenPluginVersion = "5.46.0";
addAll(rewriteArgs, "mvn", "org.openrewrite.maven:rewrite-maven-plugin:" + rewriteMavenPluginVersion + ":run",
"-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:v2-migration:"+ getMigrationToolVersion() + "-PREVIEW",
"-Drewrite.activeRecipes=software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2");

run(mavenActual, rewriteArgs.toArray(new String[0]));
FileUtils.deleteDirectory(mavenActual.resolve("target").toFile());
assertTwoDirectoriesHaveSameStructure(mavenActual, mavenExpected);
}

private static void verifyCompilation() {
List<String> packageArgs = new ArrayList<>();
addAll(packageArgs, "mvn", "package");
run(mavenActual, packageArgs.toArray(new String[0]));
}

boolean versionAvailable() {
return TestUtils.versionAvailable(sdkVersion);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.v2migrationtests;

import static java.util.Collections.addAll;
import static software.amazon.awssdk.v2migrationtests.TestUtils.assertTwoDirectoriesHaveSameStructure;
import static software.amazon.awssdk.v2migrationtests.TestUtils.getMigrationToolVersion;
import static software.amazon.awssdk.v2migrationtests.TestUtils.getVersion;
import static software.amazon.awssdk.v2migrationtests.TestUtils.run;

import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeAll;

public class MavenTestBase {

protected static String sdkVersion;
protected static Path mavenBefore;
protected static Path mavenAfter;
protected static Path target;
protected static Path mavenActual;
protected static Path mavenExpected;

@BeforeAll
static void init() throws IOException {
sdkVersion = getVersion();
}

protected static void deleteTempDirectories() throws IOException {
FileUtils.deleteDirectory(mavenActual.toFile());
FileUtils.deleteDirectory(mavenExpected.toFile());
}

protected static void verifyTransformation(boolean experimental) throws IOException {
String recipeCmd = "-Drewrite.activeRecipes=software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2";
if (experimental) {
recipeCmd += "Experimental";
}

List<String> rewriteArgs = new ArrayList<>();
// pin version since updates have broken tests
String rewriteMavenPluginVersion = "5.46.0";
addAll(rewriteArgs, "mvn", "org.openrewrite.maven:rewrite-maven-plugin:" + rewriteMavenPluginVersion + ":run",
"-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:v2-migration:"+ getMigrationToolVersion() + "-PREVIEW",
recipeCmd);

run(mavenActual, rewriteArgs.toArray(new String[0]));
FileUtils.deleteDirectory(mavenActual.resolve("target").toFile());
assertTwoDirectoriesHaveSameStructure(mavenActual, mavenExpected);
}

protected static void verifyCompilation() {
List<String> packageArgs = new ArrayList<>();
addAll(packageArgs, "mvn", "package");
run(mavenActual, packageArgs.toArray(new String[0]));
}

boolean versionAvailable() {
return TestUtils.versionAvailable(sdkVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,42 @@

package software.amazon.awssdk.v2migrationtests;

import static java.util.Collections.addAll;
import static software.amazon.awssdk.v2migrationtests.TestUtils.assertTwoDirectoriesHaveSameStructure;
import static software.amazon.awssdk.v2migrationtests.TestUtils.getMigrationToolVersion;
import static software.amazon.awssdk.v2migrationtests.TestUtils.getVersion;
import static software.amazon.awssdk.v2migrationtests.TestUtils.replaceVersion;
import static software.amazon.awssdk.v2migrationtests.TestUtils.run;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import software.amazon.awssdk.utils.Logger;

public class MavenTransferManagerTest {
private static final Logger log = Logger.loggerFor(MavenTransferManagerTest.class);
private static String sdkVersion;
private static Path mavenTmBefore;
private static Path mavenTmAfter;
private static Path target;
private static Path mavenTmActual;
private static Path mavenTmExpected;
public class MavenTransferManagerTest extends MavenTestBase {

@BeforeAll
static void setUp() throws IOException {
sdkVersion = getVersion();
mavenTmBefore = new File(MavenTransferManagerTest.class.getResource("maven-tm/before").getFile()).toPath();
mavenTmAfter = new File(MavenTransferManagerTest.class.getResource("maven-tm/after").getFile()).toPath();
mavenBefore = new File(MavenTransferManagerTest.class.getResource("maven-tm/before").getFile()).toPath();
mavenAfter = new File(MavenTransferManagerTest.class.getResource("maven-tm/after").getFile()).toPath();
target = new File(MavenTransferManagerTest.class.getResource("/").getFile()).toPath().getParent();

mavenTmActual = target.resolve("maven-tm/actual");
mavenTmExpected = target.resolve("maven-tm/expected");
mavenActual = target.resolve("maven-tm/actual");
mavenExpected = target.resolve("maven-tm/expected");

deleteTempDirectories();

FileUtils.copyDirectory(mavenTmBefore.toFile(), mavenTmActual.toFile());
FileUtils.copyDirectory(mavenTmAfter.toFile(), mavenTmExpected.toFile());
FileUtils.copyDirectory(mavenBefore.toFile(), mavenActual.toFile());
FileUtils.copyDirectory(mavenAfter.toFile(), mavenExpected.toFile());

replaceVersion(mavenTmExpected.resolve("pom.xml"), sdkVersion);
replaceVersion(mavenTmActual.resolve("pom.xml"), sdkVersion);
}

private static void deleteTempDirectories() throws IOException {
FileUtils.deleteDirectory(mavenTmActual.toFile());
FileUtils.deleteDirectory(mavenTmExpected.toFile());
replaceVersion(mavenExpected.resolve("pom.xml"), sdkVersion);
replaceVersion(mavenActual.resolve("pom.xml"), sdkVersion);
}

@Test
@EnabledIf("versionAvailable")
void mavenProject_shouldConvert() throws IOException {
verifyTransformation();
boolean experimental = true;
verifyTransformation(experimental);
verifyCompilation();
}

private static void verifyTransformation() throws IOException {
List<String> rewriteArgs = new ArrayList<>();
// pin version since updates have broken tests
String rewriteMavenPluginVersion = "5.46.0";
addAll(rewriteArgs, "mvn", "org.openrewrite.maven:rewrite-maven-plugin:" + rewriteMavenPluginVersion + ":run",
"-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:v2-migration:"+ getMigrationToolVersion() + "-PREVIEW",
"-Drewrite.activeRecipes=software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2Experimental");

run(mavenTmActual, rewriteArgs.toArray(new String[0]));
FileUtils.deleteDirectory(mavenTmActual.resolve("target").toFile());
assertTwoDirectoriesHaveSameStructure(mavenTmActual, mavenTmExpected);
}

private static void verifyCompilation() {
List<String> packageArgs = new ArrayList<>();
addAll(packageArgs, "mvn", "package");
run(mavenTmActual, packageArgs.toArray(new String[0]));
}

boolean versionAvailable() {
return TestUtils.versionAvailable(sdkVersion);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>software.amazon.awssdk</groupId>
<artifactId>sample-application</artifactId>
<version>1.2.3</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>V2_VERSION</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>V2_VERSION</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3-transfer-manager</artifactId>
<version>V2_VERSION</version>
</dependency>
</dependencies>
</project>
Loading
Loading