Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Don't try to always get system jvm first #2508

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ object OsLibc {
}

def defaultJvm(os: String): String = {
val hasEmptyJavaHome = Option(System.getenv("JAVA_HOME")).exists(_.trim.isEmpty)
val defaultJvm0 = baseDefaultJvm(os, defaultJvmVersion)
if (hasEmptyJavaHome)
// Not using the system JVM if JAVA_HOME is set to an empty string
// (workaround for https://github.com/coursier/coursier/issues/2292)
Gedochao marked this conversation as resolved.
Show resolved Hide resolved
defaultJvm0
else
s"${JavaHome.systemId}|$defaultJvm0"
baseDefaultJvm(os, defaultJvmVersion)
}

def javaVersion(javaCmd: String): Int = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ import java.io.File

class StandaloneLauncherTests extends ScalaCliSuite {

if (TestUtil.isJvmCli)
test(s"Standalone launcher should run with java 8") {
// It should download Java 17 and use it to run itself
val message = "Hello World"
val inputs = TestInputs(
os.rel / "hello.sc" -> s"""println("$message")"""
test(s"Standalone launcher should run with java 8") {
// It should download Java 17 and use it to run itself
val message = "Hello World"
val inputs = TestInputs(
os.rel / "hello.sc" -> s"""println("$message")"""
)
inputs.fromRoot { root =>
val java8Home =
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd)

val extraEnv = Map(
"JAVA_HOME" -> java8Home.toString,
"PATH" -> ((java8Home / "bin").toString + File.pathSeparator + System.getenv("PATH"))
)
inputs.fromRoot { root =>
val java8Home =
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd)

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

val output =
os.proc(TestUtil.cli, ".").call(cwd = root, env = extraEnv).out.trim()
val output =
os.proc(TestUtil.cli, ".").call(cwd = root, env = extraEnv).out.trim()

expect(output == message)
}
expect(output == message)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ object BuildOptions {
def envUpdates(currentEnv: Map[String, String]): Map[String, String] = {
// On Windows, AFAIK, env vars are "case-insensitive but case-preserving".
// If PATH was defined as "Path", we need to update "Path", not "PATH".
// Same for JAVA_HOME.
// Same for JAVA_HOME
def keyFor(name: String) =
if (Properties.isWin)
currentEnv.keys.find(_.equalsIgnoreCase(name)).getOrElse(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ final case class JavaOptions(
}

private def findLocalDefaultJava(): Option[Positioned[os.Path]] =
Option(System.getenv("JAVA_HOME")).map(p =>
Option(System.getenv("JAVA_HOME")).filter(_.nonEmpty).map(p =>
Positioned(Position.Custom("JAVA_HOME env"), os.Path(p, os.pwd))
).orElse(
sys.props.get("java.home").map(p =>
Expand Down