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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '11'
java-version: '17'
- run: make init
- run: pytest -vv tests/integration/workflows/java_maven

Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- run: make init
- run: pytest -vv tests/integration/workflows/java_gradle

Expand Down
1 change: 1 addition & 0 deletions aws_lambda_builders/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ruby2.7": [ARM64, X86_64],
"java8": [ARM64, X86_64],
"java11": [ARM64, X86_64],
"java17": [ARM64, X86_64],
"go1.x": [ARM64, X86_64],
"dotnetcore3.1": [ARM64, X86_64],
"dotnet6": [ARM64, X86_64],
Expand Down
47 changes: 30 additions & 17 deletions tests/integration/workflows/java_gradle/test_java_gradle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from pathlib import Path
from os.path import join

from parameterized import parameterized_class


from aws_lambda_builders.builder import LambdaBuilder
from aws_lambda_builders.exceptions import WorkflowFailedError
Expand All @@ -16,6 +18,14 @@
)


@parameterized_class(
("runtime",),
[
["java8"],
["java11"],
["java17"],
],
)
class TestJavaGradle(TestCase):
# Have to use str(Path(__file__).resolve()) here to workaround a Windows VSCode issue
# __file__ will return lower case drive letters. Ex: c:\folder\test.py instead of C:\folder\test.py
Expand All @@ -28,23 +38,22 @@ def setUp(self):
self.scratch_dir = tempfile.mkdtemp()
self.dependencies_dir = tempfile.mkdtemp()
self.builder = LambdaBuilder(language="java", dependency_manager="gradle", application_framework=None)
self.runtime = "java11"

def tearDown(self):
shutil.rmtree(self.artifacts_dir)
shutil.rmtree(self.scratch_dir)
shutil.rmtree(self.dependencies_dir)

def test_build_single_build_with_deps(self):
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "with-deps")
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "with-deps")
manifest_path = join(source_dir, "build.gradle")
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, manifest_path, runtime=self.runtime)
expected_files = [join("aws", "lambdabuilders", "Main.class"), join("lib", "annotations-2.1.0.jar")]

expected_files = [join("aws", "lambdabuilders", "Main.class"), join("lib", "annotations-2.1.0.jar")]
self.assertTrue(does_folder_contain_all_files(self.artifacts_dir, expected_files))

def test_build_single_build_with_resources(self):
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "with-resources")
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "with-resources")
manifest_path = join(source_dir, "build.gradle")
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, manifest_path, runtime=self.runtime)
expected_files = [
Expand All @@ -56,7 +65,7 @@ def test_build_single_build_with_resources(self):
self.assertTrue(does_folder_contain_all_files(self.artifacts_dir, expected_files))

def test_build_single_build_with_test_deps_test_jars_not_included(self):
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "with-test-deps")
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "with-test-deps")
manifest_path = join(source_dir, "build.gradle")
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, manifest_path, runtime=self.runtime)
expected_files = [join("aws", "lambdabuilders", "Main.class"), join("lib", "annotations-2.1.0.jar")]
Expand All @@ -65,7 +74,7 @@ def test_build_single_build_with_test_deps_test_jars_not_included(self):
self.assertFalse(does_folder_contain_file(self.artifacts_dir, join("lib", "s3-2.1.0.jar")))

def test_build_single_build_with_deps_gradlew(self):
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "with-deps-gradlew")
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "with-deps")
manifest_path = join(source_dir, "build.gradle")
self.builder.build(
source_dir,
Expand All @@ -80,10 +89,11 @@ def test_build_single_build_with_deps_gradlew(self):
self.assertTrue(does_folder_contain_all_files(self.artifacts_dir, expected_files))

def test_build_multi_build_with_deps_lambda1(self):
parent_dir = join(self.MULTI_BUILD_TEST_DATA_DIR, "with-deps")
parent_dir = join(self.MULTI_BUILD_TEST_DATA_DIR, self.runtime, "with-deps")
manifest_path = join(parent_dir, "lambda1", "build.gradle")

lambda1_source = join(parent_dir, "lambda1")

self.builder.build(lambda1_source, self.artifacts_dir, self.scratch_dir, manifest_path, runtime=self.runtime)

lambda1_expected_files = [
Expand All @@ -93,7 +103,7 @@ def test_build_multi_build_with_deps_lambda1(self):
self.assertTrue(does_folder_contain_all_files(self.artifacts_dir, lambda1_expected_files))

def test_build_multi_build_with_deps_lambda2(self):
parent_dir = join(self.MULTI_BUILD_TEST_DATA_DIR, "with-deps")
parent_dir = join(self.MULTI_BUILD_TEST_DATA_DIR, self.runtime, "with-deps")
manifest_path = join(parent_dir, "lambda2", "build.gradle")

lambda2_source = join(parent_dir, "lambda2")
Expand All @@ -106,10 +116,11 @@ def test_build_multi_build_with_deps_lambda2(self):
self.assertTrue(does_folder_contain_all_files(self.artifacts_dir, lambda2_expected_files))

def test_build_multi_build_with_deps_inter_module(self):
parent_dir = join(self.MULTI_BUILD_TEST_DATA_DIR, "with-deps-inter-module")
parent_dir = join(self.MULTI_BUILD_TEST_DATA_DIR, self.runtime, "with-deps-inter-module")
manifest_path = join(parent_dir, "lambda1", "build.gradle")

lambda1_source = join(parent_dir, "lambda1")

self.builder.build(lambda1_source, self.artifacts_dir, self.scratch_dir, manifest_path, runtime=self.runtime)

lambda1_expected_files = [
Expand All @@ -120,14 +131,14 @@ def test_build_multi_build_with_deps_inter_module(self):
self.assertTrue(does_folder_contain_all_files(self.artifacts_dir, lambda1_expected_files))

def test_build_single_build_with_deps_broken(self):
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "with-deps-broken")
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "with-deps-broken")
manifest_path = join(source_dir, "build.gradle")
with self.assertRaises(WorkflowFailedError) as raised:
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, manifest_path, runtime=self.runtime)
self.assertTrue(raised.exception.args[0].startswith("JavaGradleWorkflow:GradleBuild - Gradle Failed"))

def test_build_single_build_with_deps_dir(self):
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "with-deps")
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "with-deps")
manifest_path = join(source_dir, "build.gradle")
self.builder.build(
source_dir,
Expand All @@ -137,16 +148,18 @@ def test_build_single_build_with_deps_dir(self):
runtime=self.runtime,
dependencies_dir=self.dependencies_dir,
)
artifact_expected_files = [join("aws", "lambdabuilders", "Main.class"), join("lib", "annotations-2.1.0.jar")]
artifact_expected_files = [
join("aws", "lambdabuilders", "Main.class"),
join("lib", "annotations-2.1.0.jar"),
]
dependencies_expected_files = [join("lib", "annotations-2.1.0.jar")]

self.assertTrue(does_folder_contain_all_files(self.artifacts_dir, artifact_expected_files))
self.assertTrue(does_folder_contain_all_files(self.dependencies_dir, dependencies_expected_files))

def test_build_multi_build_with_deps_dir_inter_module(self):
parent_dir = join(self.MULTI_BUILD_TEST_DATA_DIR, "with-deps-inter-module")
parent_dir = join(self.MULTI_BUILD_TEST_DATA_DIR, self.runtime, "with-deps-inter-module")
manifest_path = join(parent_dir, "lambda1", "build.gradle")

lambda1_source = join(parent_dir, "lambda1")
self.builder.build(
lambda1_source,
Expand All @@ -170,7 +183,7 @@ def test_build_multi_build_with_deps_dir_inter_module(self):
self.assertTrue(does_folder_contain_all_files(self.dependencies_dir, dependencies_expected_files))

def test_build_single_build_with_deps_dir_wtihout_combine_dependencies(self):
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "with-deps")
source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "with-deps")
manifest_path = join(source_dir, "build.gradle")
self.builder.build(
source_dir,
Expand All @@ -194,7 +207,7 @@ def test_build_with_layers_and_scope(self):
self.validate_function_build()

def validate_layer_build(self):
layer_source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "layer")
layer_source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "layer")
layer_manifest_path = join(layer_source_dir, "build.gradle")
self.builder.build(
layer_source_dir,
Expand All @@ -212,7 +225,7 @@ def validate_layer_build(self):

def validate_function_build(self):
self.setUp() # re-initialize folders
function_source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, "with-layer-deps")
function_source_dir = join(self.SINGLE_BUILD_TEST_DATA_DIR, self.runtime, "with-layer-deps")
function_manifest_path = join(function_source_dir, "build.gradle")
self.builder.build(
function_source_dir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ repositories {
dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
implementation project(':common')
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
implementation project(':common')
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ repositories {
dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ repositories {
dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
allprojects {
repositories {
mavenCentral()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package aws.lambdabuilders;

public class Foo {
public void sayHello() {
System.out.println("Hello world!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
implementation project(':common')
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package aws.lambdabuilders;

public class Lambda1_Main {
public static void main(String[] args) {
System.out.println("Hello AWS Lambda Builders!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package aws.lambdabuilders;

public class Lambda2_Main {
public static void main(String[] args) {
System.out.println("Hello AWS Lambda Builders!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'multi-build'
include 'lambda1', 'lambda2', 'common'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
allprojects {
repositories {
mavenCentral()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package aws.lambdabuilders;

public class Lambda1_Main {
public static void main(String[] args) {
System.out.println("Hello AWS Lambda Builders!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'software.amazon.awssdk:annotations:2.1.0'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package aws.lambdabuilders;

public class Lambda2_Main {
public static void main(String[] args) {
System.out.println("Hello AWS Lambda Builders!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'multi-build'
include 'lambda1', 'lambda2'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
allprojects {
repositories {
mavenCentral()
}
}
Loading