Skip to content

Commit b3e7c89

Browse files
authored
Merge pull request #347 from lwronski/fix-parsing-bloop-config
Fix parsing bloop config - ignore error during parsing
2 parents ff411ae + 59ad052 commit b3e7c89

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
package scala.cli.commands
22

3-
case class BloopJson(javaHome: String, javaOptions: Array[String])
3+
import upickle.default.{ReadWriter, macroRW}
4+
5+
case class BloopJson(javaOptions: List[String] = Nil)
6+
7+
case object BloopJson {
8+
implicit lazy val jsonCodec: ReadWriter[BloopJson] = macroRW
9+
}

modules/cli/src/main/scala/scala/cli/commands/SharedCompilationServerOptions.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package scala.cli.commands
22

33
import caseapp._
4-
import com.google.gson.Gson
54
import upickle.default.{ReadWriter, macroRW}
65

7-
import java.io.{BufferedReader, File, FileReader}
6+
import java.io.File
7+
import java.nio.charset.Charset
88
import java.nio.file.{AtomicMoveNotSupportedException, FileAlreadyExistsException, Files}
99
import java.util.{Locale, Random}
1010

@@ -13,6 +13,7 @@ import scala.build.blooprifle.{BloopRifleConfig, BloopVersion, BspConnectionAddr
1313
import scala.build.{Bloop, Logger, Os}
1414
import scala.cli.internal.Pid
1515
import scala.concurrent.duration.{Duration, FiniteDuration}
16+
import scala.io.Codec
1617
import scala.util.Properties
1718

1819
// format: off
@@ -190,21 +191,23 @@ final case class SharedCompilationServerOptions(
190191
))(v => BloopRifleConfig.Strict(BloopVersion(v)))
191192

192193
def bloopDefaultJvmOptions(logger: Logger): List[String] = {
193-
val file = new File(bloopGlobalOptionsFile)
194-
if (file.exists() && file.isFile())
194+
val filePath = os.Path(bloopGlobalOptionsFile, Os.pwd)
195+
if (os.exists(filePath) && os.isFile(filePath))
195196
try {
196-
val reader = new BufferedReader(new FileReader(file))
197-
val gson = new Gson()
198-
val json = gson.fromJson(reader, classOf[BloopJson])
199-
json.javaOptions.toList
197+
val json = ujson.read(
198+
os.read(filePath: os.ReadablePath, charSet = Codec(Charset.defaultCharset()))
199+
)
200+
val bloopJson = upickle.default.read(json)(BloopJson.jsonCodec)
201+
bloopJson.javaOptions
200202
}
201203
catch {
202204
case e: Throwable =>
205+
System.err.println(s"Error parsing global bloop config in '$filePath':")
203206
e.printStackTrace()
204207
List.empty
205208
}
206209
else {
207-
logger.debug(s"Bloop global options file '${file.toPath().toAbsolutePath()}' not found.")
210+
logger.debug(s"Bloop global options file '$filePath' not found.")
208211
List.empty
209212
}
210213
}

0 commit comments

Comments
 (0)