@@ -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 = {
0 commit comments