From b894fb71078f84debfb64435ec7beea565d8450c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=8BAndrzej=20Ressel?= Date: Mon, 7 Aug 2023 23:26:05 +0200 Subject: [PATCH 1/3] Add support for absolute paths in Bloopgun error handling --- bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala b/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala index e3e19dfcfd..9569be8624 100644 --- a/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala +++ b/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala @@ -509,11 +509,11 @@ class BloopgunCli( .map(Paths.get(_).resolve("bin/java")) .filter(_.toFile().isFile()) .map(_.toString()) - val javaErrorMessage = "Cannot run program \"java\"" + val javaErrorMessage = "Cannot run program \".*java\"".r val errorCode = "error=2" javaExec match { case Some(java) - if e.getMessage().contains(javaErrorMessage) && e.getMessage.contains(errorCode) => + if javaErrorMessage.pattern.matcher(e.getMessage()).find() && e.getMessage.contains(errorCode) => logger.info(s"Java executable was not available on PATH, retrying with $java") val (cmd, usedExtraJvmOpts) = cmdWithArgs(found, extraJvmOpts, List(java), globalSettings) From 3e6352e5b1f4eeb0e8e69bd2c353480357cc95ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=8BAndrzej=20Ressel?= Date: Sun, 20 Aug 2023 18:54:31 +0200 Subject: [PATCH 2/3] Add support for absolute paths in Bloopgun error handling Fix formatting --- bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala b/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala index 9569be8624..599408b897 100644 --- a/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala +++ b/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala @@ -513,7 +513,9 @@ class BloopgunCli( val errorCode = "error=2" javaExec match { case Some(java) - if javaErrorMessage.pattern.matcher(e.getMessage()).find() && e.getMessage.contains(errorCode) => + if javaErrorMessage.pattern.matcher(e.getMessage()).find() && e.getMessage.contains( + errorCode + ) => logger.info(s"Java executable was not available on PATH, retrying with $java") val (cmd, usedExtraJvmOpts) = cmdWithArgs(found, extraJvmOpts, List(java), globalSettings) From 054b1513f48c9aa2e9e5a8195b544784923ad564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=8BAndrzej=20Ressel?= Date: Thu, 7 Sep 2023 03:05:45 +0200 Subject: [PATCH 3/3] Fix java executable name and related test --- bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala | 7 ++++++- .../test/scala/bloop/launcher/GlobalSettingsSpec.scala | 8 ++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala b/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala index 599408b897..4514aa1954 100644 --- a/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala +++ b/bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala @@ -503,10 +503,15 @@ class BloopgunCli( (exitServerStatus, usedExtraJvmOpts) } catch { case e: IOException => + val javaBinaryName = if (Environment.isWindows) { + "java.exe" + } else { + "java" + } val javaExec = sys.env .get("JAVA_HOME") .orElse(sys.props.get("java.home")) - .map(Paths.get(_).resolve("bin/java")) + .map(Paths.get(_).resolve(s"bin/${javaBinaryName}")) .filter(_.toFile().isFile()) .map(_.toString()) val javaErrorMessage = "Cannot run program \".*java\"".r diff --git a/launcher-test/src/test/scala/bloop/launcher/GlobalSettingsSpec.scala b/launcher-test/src/test/scala/bloop/launcher/GlobalSettingsSpec.scala index ebedb8429d..fcacce6cd8 100644 --- a/launcher-test/src/test/scala/bloop/launcher/GlobalSettingsSpec.scala +++ b/launcher-test/src/test/scala/bloop/launcher/GlobalSettingsSpec.scala @@ -49,15 +49,11 @@ object GlobalSettingsSpec extends LauncherBaseSuite(BuildInfo.version, BuildInfo } } - test("fail to start server when bloop.json Java home is invalid") { + test("should start server even when bloop.json Java home is invalid") { // Create bloop.json with Java home pointing to non-existent path. val doesnotexist = "does-not-exist" runBspLauncherWithGlobalJsonSettings(s"""{"javaHome": "$doesnotexist"}""") { result => - assert(result.status == Some(LauncherStatus.FailedToConnectToServer)) - assertLogsContain( - List(doesnotexist, "Error when starting server"), - result.launcherLogs - ) + assert(result.status == Some(LauncherStatus.SuccessfulRun)) } }