From a22703021ed668f6f9567766533fe5b8eb36aa53 Mon Sep 17 00:00:00 2001 From: Jeffry Angtoni Date: Thu, 5 Sep 2024 22:10:15 +0700 Subject: [PATCH 1/5] fix(validator): support version string from old and newest gradle --- .../workflows/java_gradle/gradle_validator.py | 2 +- .../java_gradle/test_gradle_validator.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/aws_lambda_builders/workflows/java_gradle/gradle_validator.py b/aws_lambda_builders/workflows/java_gradle/gradle_validator.py index 2972e75b..ce9066ca 100644 --- a/aws_lambda_builders/workflows/java_gradle/gradle_validator.py +++ b/aws_lambda_builders/workflows/java_gradle/gradle_validator.py @@ -83,5 +83,5 @@ def _get_jvm_string(self, gradle_path): for line in stdout.splitlines(): l_dec = decode(line) - if l_dec.startswith("JVM"): + if l_dec.startswith("JVM") or l_dec.startswith("Launcher"): return l_dec diff --git a/tests/unit/workflows/java_gradle/test_gradle_validator.py b/tests/unit/workflows/java_gradle/test_gradle_validator.py index 2815b4f6..fad8ecc0 100644 --- a/tests/unit/workflows/java_gradle/test_gradle_validator.py +++ b/tests/unit/workflows/java_gradle/test_gradle_validator.py @@ -78,6 +78,24 @@ def test_emits_warning_when_version_string_not_found(self): validator.validate(runtime_path=self.runtime_path) self.mock_log.warning.assert_called_with(GradleValidator.VERSION_STRING_WARNING, self.runtime_path) + def test_does_not_emit_warning_for_version_string_in_gradle_lt_8_9(self): + version_string = "JVM: 9.0.0".encode() + self.mock_os_utils.popen.side_effect = [FakePopen(stdout=version_string, returncode=0)] + validator = GradleValidator( + runtime=self.runtime, architecture=self.architecture, os_utils=self.mock_os_utils, log=self.mock_log + ) + validator.validate(runtime_path=self.runtime_path) + self.mock_log.warning.assert_not_called() + + def test_does_not_emit_warning_for_version_string_in_gradle_ge_8_9(self): + version_string = "Launcher JVM: 9.0.0".encode() + self.mock_os_utils.popen.side_effect = [FakePopen(stdout=version_string, returncode=0)] + validator = GradleValidator( + runtime=self.runtime, architecture=self.architecture, os_utils=self.mock_os_utils, log=self.mock_log + ) + validator.validate(runtime_path=self.runtime_path) + self.mock_log.warning.assert_not_called() + @parameterized.expand( [ ("11.0.0", "java11"), From bf105bea21d412ad039505ace5b6d5435d1271d5 Mon Sep 17 00:00:00 2001 From: Jeffry Angtoni Date: Thu, 5 Sep 2024 22:36:22 +0700 Subject: [PATCH 2/5] fix(test): fix unit test --- tests/unit/workflows/java_gradle/test_gradle_validator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/workflows/java_gradle/test_gradle_validator.py b/tests/unit/workflows/java_gradle/test_gradle_validator.py index fad8ecc0..63edff66 100644 --- a/tests/unit/workflows/java_gradle/test_gradle_validator.py +++ b/tests/unit/workflows/java_gradle/test_gradle_validator.py @@ -79,7 +79,7 @@ def test_emits_warning_when_version_string_not_found(self): self.mock_log.warning.assert_called_with(GradleValidator.VERSION_STRING_WARNING, self.runtime_path) def test_does_not_emit_warning_for_version_string_in_gradle_lt_8_9(self): - version_string = "JVM: 9.0.0".encode() + version_string = "JVM: 1.8.9".encode() self.mock_os_utils.popen.side_effect = [FakePopen(stdout=version_string, returncode=0)] validator = GradleValidator( runtime=self.runtime, architecture=self.architecture, os_utils=self.mock_os_utils, log=self.mock_log @@ -88,7 +88,7 @@ def test_does_not_emit_warning_for_version_string_in_gradle_lt_8_9(self): self.mock_log.warning.assert_not_called() def test_does_not_emit_warning_for_version_string_in_gradle_ge_8_9(self): - version_string = "Launcher JVM: 9.0.0".encode() + version_string = "Launcher JVM: 1.8.9".encode() self.mock_os_utils.popen.side_effect = [FakePopen(stdout=version_string, returncode=0)] validator = GradleValidator( runtime=self.runtime, architecture=self.architecture, os_utils=self.mock_os_utils, log=self.mock_log From 233ea52e8dba02338414d9ae5cab409f287f80f9 Mon Sep 17 00:00:00 2001 From: Jeffry Angtoni Date: Fri, 6 Sep 2024 06:18:14 +0700 Subject: [PATCH 3/5] test: add more version and runtime to the test --- .../java_gradle/test_gradle_validator.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/unit/workflows/java_gradle/test_gradle_validator.py b/tests/unit/workflows/java_gradle/test_gradle_validator.py index 63edff66..f51bf5c9 100644 --- a/tests/unit/workflows/java_gradle/test_gradle_validator.py +++ b/tests/unit/workflows/java_gradle/test_gradle_validator.py @@ -78,20 +78,36 @@ def test_emits_warning_when_version_string_not_found(self): validator.validate(runtime_path=self.runtime_path) self.mock_log.warning.assert_called_with(GradleValidator.VERSION_STRING_WARNING, self.runtime_path) - def test_does_not_emit_warning_for_version_string_in_gradle_lt_8_9(self): - version_string = "JVM: 1.8.9".encode() + @parameterized.expand( + [ + ("1.8.0", "java8"), + ("11.0.0", "java11"), + ("17.0.0", "java17"), + ("21.0.0", "java21"), + ] + ) + def test_does_not_emit_warning_for_version_string_in_gradle_lt_8_9(self, version, runtime): + version_string = f"JVM: {version}".encode() self.mock_os_utils.popen.side_effect = [FakePopen(stdout=version_string, returncode=0)] validator = GradleValidator( - runtime=self.runtime, architecture=self.architecture, os_utils=self.mock_os_utils, log=self.mock_log + runtime=runtime, architecture=self.architecture, os_utils=self.mock_os_utils, log=self.mock_log ) validator.validate(runtime_path=self.runtime_path) self.mock_log.warning.assert_not_called() - def test_does_not_emit_warning_for_version_string_in_gradle_ge_8_9(self): - version_string = "Launcher JVM: 1.8.9".encode() + @parameterized.expand( + [ + ("1.8.0", "java8"), + ("11.0.0", "java11"), + ("17.0.0", "java17"), + ("21.0.0", "java21"), + ] + ) + def test_does_not_emit_warning_for_version_string_in_gradle_ge_8_9(self, version, runtime): + version_string = f"Launcher JVM: {version}".encode() self.mock_os_utils.popen.side_effect = [FakePopen(stdout=version_string, returncode=0)] validator = GradleValidator( - runtime=self.runtime, architecture=self.architecture, os_utils=self.mock_os_utils, log=self.mock_log + runtime=runtime, architecture=self.architecture, os_utils=self.mock_os_utils, log=self.mock_log ) validator.validate(runtime_path=self.runtime_path) self.mock_log.warning.assert_not_called() From 50e35ac7d5053d0414bb0e1c9b8e5ec6dd26daea Mon Sep 17 00:00:00 2001 From: Jeffry Angtoni Date: Sun, 8 Sep 2024 22:07:55 +0700 Subject: [PATCH 4/5] refactor(validator): use full label instead --- aws_lambda_builders/workflows/java_gradle/gradle_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_builders/workflows/java_gradle/gradle_validator.py b/aws_lambda_builders/workflows/java_gradle/gradle_validator.py index ce9066ca..5c25a9fc 100644 --- a/aws_lambda_builders/workflows/java_gradle/gradle_validator.py +++ b/aws_lambda_builders/workflows/java_gradle/gradle_validator.py @@ -83,5 +83,5 @@ def _get_jvm_string(self, gradle_path): for line in stdout.splitlines(): l_dec = decode(line) - if l_dec.startswith("JVM") or l_dec.startswith("Launcher"): + if l_dec.startswith("JVM") or l_dec.startswith("Launcher JVM"): return l_dec From 2e24e33214ab9e5e00eb2d268c672fc29d842319 Mon Sep 17 00:00:00 2001 From: Jeffry Angtoni Date: Fri, 13 Sep 2024 06:36:03 +0700 Subject: [PATCH 5/5] fix(validator): use in operator to check JVM substring --- aws_lambda_builders/workflows/java_gradle/gradle_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_builders/workflows/java_gradle/gradle_validator.py b/aws_lambda_builders/workflows/java_gradle/gradle_validator.py index 5c25a9fc..5107b9c2 100644 --- a/aws_lambda_builders/workflows/java_gradle/gradle_validator.py +++ b/aws_lambda_builders/workflows/java_gradle/gradle_validator.py @@ -83,5 +83,5 @@ def _get_jvm_string(self, gradle_path): for line in stdout.splitlines(): l_dec = decode(line) - if l_dec.startswith("JVM") or l_dec.startswith("Launcher JVM"): + if "JVM" in l_dec: return l_dec