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

Remove the possibility to read proeprties from.jvmopts #1707

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions bloopgun/src/main/scala/bloop/bloopgun/util/Environment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ object Environment {
/**
* Reads all jvm options required to start the Bloop server, in order of priority:
*
* Parses `-J` prefixed jvm options in the arguments passed to the server command.
*
* Prior to 1.5.0 it used to also:
* 1. Read `$$HOME/.bloop/.jvmopts` file.
* 2. Read `.jvmopts` file right next to the location of the bloop server jar.
* 3. Parse `-J` prefixed jvm options in the arguments passed to the server command.
* Now, it only logs a warning if the file detected.
*
* Returns a list of jvm options with no `-J` prefix.
*/
Expand All @@ -62,27 +65,19 @@ object Environment {
serverArgs: List[String],
logger: Logger
): List[String] = {
def readJvmOptsFile(jvmOptsFile: Path): List[String] = {
if (!Files.isReadable(jvmOptsFile)) {
if (Files.exists(jvmOptsFile)) {
logger.error(s"Ignored unreadable ${jvmOptsFile.toAbsolutePath()}")
}

Nil
} else {
val contents = new String(Files.readAllBytes(jvmOptsFile), StandardCharsets.UTF_8)
contents.linesIterator.toList
def detectJvmOptsFile(jvmOptsFile: Path): Unit = {
if (Files.exists(jvmOptsFile)) {
logger.warn(s"Since Bloop 1.5.0 ${jvmOptsFile.toAbsolutePath()} is ignored.")
}
}

val jvmServerArgs = serverArgs.filter(_.startsWith("-J"))
val jvmOptionsFromHome = readJvmOptsFile(Environment.defaultBloopDirectory.resolve(".jvmopts"))
val jvmOptionsFromPathNextToBinary = server match {
case AvailableAtPath(binary) => readJvmOptsFile(binary.getParent.resolve(".jvmopts"))
detectJvmOptsFile(Environment.defaultBloopDirectory.resolve(".jvmopts"))
server match {
case AvailableAtPath(binary) => detectJvmOptsFile(binary.getParent.resolve(".jvmopts"))
case _ => Nil
}

(jvmOptionsFromHome ++ jvmOptionsFromPathNextToBinary ++ jvmServerArgs).map(_.stripPrefix("-J"))
jvmServerArgs.map(_.stripPrefix("-J"))
}

// TODO: Add more options to better tweak GC based on benchmarks
Expand Down