Skip to content

Commit 1f87626

Browse files
tgodzikGedochao
authored andcommitted
bugfix: Don't try to always get system jvm first
Previously, we would always first specify `system|` when downloading default JVM, which would coursier just return java from JAVA_HOME without any checks even if we needed to download never Java. Now, we only use specific versions, since java home is handled before.
1 parent c4a76f1 commit 1f87626

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

modules/core/src/main/scala/scala/build/internals/OsLibc.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,7 @@ object OsLibc {
7474
}
7575

7676
def defaultJvm(os: String): String = {
77-
val hasEmptyJavaHome = Option(System.getenv("JAVA_HOME")).exists(_.trim.isEmpty)
78-
val defaultJvm0 = baseDefaultJvm(os, defaultJvmVersion)
79-
if (hasEmptyJavaHome)
80-
// Not using the system JVM if JAVA_HOME is set to an empty string
81-
// (workaround for https://github.com/coursier/coursier/issues/2292)
82-
defaultJvm0
83-
else
84-
s"${JavaHome.systemId}|$defaultJvm0"
77+
baseDefaultJvm(os, defaultJvmVersion)
8578
}
8679

8780
def javaVersion(javaCmd: String): Int = {

modules/integration/src/test/scala/scala/cli/integration/StandaloneLauncherTests.scala

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ import java.io.File
66

77
class StandaloneLauncherTests extends ScalaCliSuite {
88

9-
if (TestUtil.isJvmCli)
10-
test(s"Standalone launcher should run with java 8") {
11-
// It should download Java 17 and use it to run itself
12-
val message = "Hello World"
13-
val inputs = TestInputs(
14-
os.rel / "hello.sc" -> s"""println("$message")"""
9+
test(s"Standalone launcher should run with java 8") {
10+
// It should download Java 17 and use it to run itself
11+
val message = "Hello World"
12+
val inputs = TestInputs(
13+
os.rel / "hello.sc" -> s"""println("$message")"""
14+
)
15+
inputs.fromRoot { root =>
16+
val java8Home =
17+
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd)
18+
19+
val extraEnv = Map(
20+
"JAVA_HOME" -> java8Home.toString,
21+
"PATH" -> ((java8Home / "bin").toString + File.pathSeparator + System.getenv("PATH"))
1522
)
16-
inputs.fromRoot { root =>
17-
val java8Home =
18-
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd)
1923

20-
val extraEnv = Map(
21-
"JAVA_HOME" -> java8Home.toString,
22-
"PATH" -> ((java8Home / "bin").toString + File.pathSeparator + System.getenv("PATH"))
23-
)
24+
// we need to exit to check if the launcher is actually starting the right version of java
25+
os.proc(TestUtil.cli, "--power", "bloop", "exit").call(cwd = root, env = extraEnv).out.trim()
2426

25-
val output =
26-
os.proc(TestUtil.cli, ".").call(cwd = root, env = extraEnv).out.trim()
27+
val output =
28+
os.proc(TestUtil.cli, ".").call(cwd = root, env = extraEnv).out.trim()
2729

28-
expect(output == message)
29-
}
30+
expect(output == message)
3031
}
32+
}
3133
}

0 commit comments

Comments
 (0)