Skip to content

Commit 2c01373

Browse files
Merge commit '3d9d78524' into merge-upstream
2 parents 21449f8 + 3d9d785 commit 2c01373

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

frontend/src/main/scala/bloop/cli/CommonOptions.scala

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,37 @@ case class CommonOptions(
3030
@Hidden env: CommonOptions.PrettyProperties = CommonOptions.currentEnv
3131
) {
3232
def workingPath: AbsolutePath = AbsolutePath(workingDirectory)
33+
34+
def withEnv(env: CommonOptions.PrettyProperties): CommonOptions =
35+
copy(env = env)
3336
}
3437

3538
object CommonOptions {
3639
final val default: CommonOptions = CommonOptions()
3740

3841
// Our own version of properties in which we override `toString`
39-
final class PrettyProperties extends Properties {
40-
override def toString: String = synchronized {
41-
super.keySet().toArray.map(_.toString).mkString(", ")
42+
final class PrettyProperties(val toMap: Map[String, String]) {
43+
override def toString: String = {
44+
toMap.keySet.mkString(", ")
4245
}
4346

44-
def toMap: Map[String, String] = {
45-
import scala.collection.JavaConverters._
46-
this.asScala.toMap
47+
def containsKey(key: String): Boolean = toMap.contains(key)
48+
def withProperty(key: String, value: String): PrettyProperties = {
49+
new PrettyProperties(toMap + (key -> value))
4750
}
4851
}
4952

5053
object PrettyProperties {
5154
def from(p: Properties): PrettyProperties = {
52-
val pp = new PrettyProperties()
53-
// Scala bug #10418 work-around
54-
import scala.collection.JavaConverters._
55-
p.asScala.foreach {
56-
case (k, v) =>
57-
pp.setProperty(k, v)
58-
}
59-
60-
pp
55+
import scala.collection.JavaConverters.propertiesAsScalaMapConverter
56+
val propertiesMap = p.asScala.toMap
57+
new PrettyProperties(propertiesMap)
6158
}
6259
}
6360

6461
final lazy val currentEnv: PrettyProperties = {
6562
import scala.collection.JavaConverters._
66-
System.getenv().asScala.foldLeft(new PrettyProperties()) {
67-
case (props, (key, value)) => props.setProperty(key, value); props
68-
}
63+
new PrettyProperties(System.getenv().asScala.toMap)
6964
}
7065

7166
implicit lazy val parser: Parser[CommonOptions] = Parser.derive

frontend/src/main/scala/bloop/exec/JvmProcessForker.scala

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ trait JvmProcessForker {
4444
* @param mainClass The fully qualified name of the class to run
4545
* @param args The arguments to pass to the main method.
4646
* @param jvmOptions The java options to pass to the jvm.
47+
* @param envVars Env vars which should be passed to the jvm.
4748
* @param logger Where to log the messages from execution
4849
* @param opts The options to run the program with
4950
* @param extraClasspath Paths to append to the classpath before running
5051
* @return 0 if the execution exited successfully, a non-zero number otherwise
5152
*/
52-
def runMain(
53+
final def runMain(
5354
cwd: AbsolutePath,
5455
mainClass: String,
5556
args: Array[String],
@@ -58,6 +59,28 @@ trait JvmProcessForker {
5859
logger: Logger,
5960
opts: CommonOptions,
6061
extraClasspath: Array[AbsolutePath] = Array.empty
62+
): Task[Int] = {
63+
val newEnv = envVars.foldLeft(opts.env) {
64+
case (properties, line) =>
65+
val eqIdx = line.indexOf("=")
66+
if (eqIdx > 0 && eqIdx != line.length - 1) {
67+
val key = line.substring(0, eqIdx)
68+
val value = line.substring(eqIdx + 1)
69+
properties.withProperty(key, value)
70+
} else properties
71+
}
72+
val commonOptionWithEnv = opts.withEnv(newEnv)
73+
runMain(cwd, mainClass, args, jvmOptions, logger, commonOptionWithEnv, extraClasspath)
74+
}
75+
76+
protected[exec] def runMain(
77+
cwd: AbsolutePath,
78+
mainClass: String,
79+
args: Array[String],
80+
jvmOptions: Array[String],
81+
logger: Logger,
82+
opts: CommonOptions,
83+
extraClasspath: Array[AbsolutePath]
6184
): Task[Int]
6285
}
6386

@@ -99,22 +122,13 @@ final class JvmForker(config: JdkConfig, classpath: Array[AbsolutePath]) extends
99122
mainClass: String,
100123
args: Array[String],
101124
jargs: Array[String],
102-
envVars: List[String],
103125
logger: Logger,
104126
opts: CommonOptions,
105127
extraClasspath: Array[AbsolutePath]
106128
): Task[Int] = {
107129
val jvmOptions = jargs ++ config.javaOptions
108130
val fullClasspath = classpath ++ extraClasspath
109131
val fullClasspathStr = fullClasspath.map(_.syntax).mkString(File.pathSeparator)
110-
envVars.foreach(line => {
111-
val eqIdx = line.indexOf("=")
112-
if (eqIdx > 0 && eqIdx != line.length - 1) {
113-
val key = line.substring(0, eqIdx)
114-
val value = line.substring(eqIdx + 1)
115-
opts.env.setProperty(key, value)
116-
}
117-
})
118132

119133
// Windows max cmd line length is 32767, which seems to be the least of the common shells.
120134
val processCmdCharLimit = 30000
@@ -228,13 +242,12 @@ final class JvmDebuggingForker(underlying: JvmProcessForker) extends JvmProcessF
228242
mainClass: String,
229243
args: Array[String],
230244
jargs0: Array[String],
231-
envVars: List[String],
232245
logger: Logger,
233246
opts: CommonOptions,
234247
extraClasspath: Array[AbsolutePath]
235248
): Task[Int] = {
236249
val jargs = jargs0 :+ enableDebugInterface
237-
underlying.runMain(cwd, mainClass, args, jargs, envVars, logger, opts, extraClasspath)
250+
underlying.runMain(cwd, mainClass, args, jargs, logger, opts, extraClasspath)
238251
}
239252

240253
private def enableDebugInterface: String = {

frontend/src/test/scala/bloop/util/TestUtil.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ object TestUtil {
267267
}
268268

269269
private[bloop] def runAndTestProperties = {
270-
val props = new bloop.cli.CommonOptions.PrettyProperties()
271-
props.put("BLOOP_OWNER", "owner")
272-
props
270+
new bloop.cli.CommonOptions.PrettyProperties(Map("BLOOP_OWNER" -> "owner"))
273271
}
274272

275273
/**

0 commit comments

Comments
 (0)