From e6e9a37ab668c68f4c1778fc94ae108ec949469f Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 13 Aug 2025 11:38:13 -0300 Subject: [PATCH] fix: use custom java path We can add environments before the java path and parameters to java binary like the follow code: ```bash JSIGNPDF_HOME=/jsignpdf /java/bin/java -Duser.home=/jsignpdf/ ``` When check if javaPath is a file, won't work at this scenario and we need to believe that the path is OK. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/Runtime/JavaRuntimeService.php | 5 +---- tests/Runtime/JavaRuntimeServiceTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Runtime/JavaRuntimeService.php b/src/Runtime/JavaRuntimeService.php index 1d24eac..42af604 100644 --- a/src/Runtime/JavaRuntimeService.php +++ b/src/Runtime/JavaRuntimeService.php @@ -23,10 +23,7 @@ public function getPath(JSignParam $params): string $downloadUrl = $params->getJavaDownloadUrl(); if ($javaPath && !$downloadUrl) { - if (is_file($javaPath) && is_executable($javaPath)) { - return $javaPath; - } - throw new InvalidArgumentException('Java path defined is not executable: ' . $javaPath); + return $javaPath; } if ($downloadUrl && $javaPath) { diff --git a/tests/Runtime/JavaRuntimeServiceTest.php b/tests/Runtime/JavaRuntimeServiceTest.php index 36c8887..8f16ba0 100644 --- a/tests/Runtime/JavaRuntimeServiceTest.php +++ b/tests/Runtime/JavaRuntimeServiceTest.php @@ -43,15 +43,15 @@ public function testGetPathWithCustomAndValidJavaPath(): void $this->assertEquals('vfs://download/bin/java', $path); } - public function testGetPathWithCustomAndInvalidJavaPath(): void + public function testGetPathWithCustomJavaPath(): void { $jsignParam = new JSignParam(); $service = new JavaRuntimeService(); - $jsignParam->setJavaPath(__FILE__); + $expectedPath = __FILE__; + $jsignParam->setJavaPath($expectedPath); $jsignParam->setJavaDownloadUrl(''); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessageMatches('/not executable/'); - $service->getPath($jsignParam); + $actual = $service->getPath($jsignParam); + $this->assertEquals($expectedPath, $actual); } public function testGetPathWithDownloadUrlAndNotRealDirectory(): void