From cf55f3c2775ec7a49b4db1de64610bfce809d81e Mon Sep 17 00:00:00 2001 From: Khoi Pham Date: Fri, 22 Nov 2024 12:28:17 -0800 Subject: [PATCH 1/2] fix: Restrict the condition for Gradle JVM string to make sure it doesn't parse the wrong one --- .../workflows/java_gradle/gradle_validator.py | 2 +- .../workflows/java_gradle/test_gradle_validator.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/aws_lambda_builders/workflows/java_gradle/gradle_validator.py b/aws_lambda_builders/workflows/java_gradle/gradle_validator.py index 5107b9c2d..e283e0563 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 "JVM" in l_dec: + if l_dec.startswith("JVM") or l_dec.startswith("Launcher JVM") : 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 f51bf5c9f..ec5b03bf9 100644 --- a/tests/unit/workflows/java_gradle/test_gradle_validator.py +++ b/tests/unit/workflows/java_gradle/test_gradle_validator.py @@ -69,8 +69,14 @@ def test_emits_warning_when_gradle_excutable_fails(self): validator.validate(runtime_path=self.runtime_path) self.mock_log.warning.assert_called_with(GradleValidator.VERSION_STRING_WARNING, self.runtime_path) - def test_emits_warning_when_version_string_not_found(self): - version_string = "The Java Version: 9.0.0".encode() + @parameterized.expand( + [ + "The Java Version: 9.0.0", + "Daemon JVM: /Library/Java/JavaVirtualMachines/amazon-corretto-21.jdk/Contents/Home (no JDK specified, using current Java home)" + ] + ) + def test_emits_warning_when_version_string_not_found(self, path): + version_string = path.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 3daf35aa3973a21731f2910bfdf1537645351017 Mon Sep 17 00:00:00 2001 From: Khoi Pham Date: Fri, 22 Nov 2024 12:31:58 -0800 Subject: [PATCH 2/2] Fix format --- aws_lambda_builders/workflows/java_gradle/gradle_validator.py | 2 +- tests/unit/workflows/java_gradle/test_gradle_validator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aws_lambda_builders/workflows/java_gradle/gradle_validator.py b/aws_lambda_builders/workflows/java_gradle/gradle_validator.py index e283e0563..5c25a9fc9 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 l_dec.startswith("JVM") or l_dec.startswith("Launcher JVM"): 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 ec5b03bf9..96ae2c22a 100644 --- a/tests/unit/workflows/java_gradle/test_gradle_validator.py +++ b/tests/unit/workflows/java_gradle/test_gradle_validator.py @@ -72,7 +72,7 @@ def test_emits_warning_when_gradle_excutable_fails(self): @parameterized.expand( [ "The Java Version: 9.0.0", - "Daemon JVM: /Library/Java/JavaVirtualMachines/amazon-corretto-21.jdk/Contents/Home (no JDK specified, using current Java home)" + "Daemon JVM: /Library/Java/JavaVirtualMachines/amazon-corretto-21.jdk/Contents/Home (no JDK specified, using current Java home)", ] ) def test_emits_warning_when_version_string_not_found(self, path):