diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/GenericRunnerSettings.scala | 44 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/MainGenericRunner.scala | 2 |
2 files changed, 45 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala b/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala index 297e8c107d..e097061b65 100644 --- a/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala +++ b/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala @@ -6,6 +6,7 @@ // $Id$ package scala.tools.nsc +import scala.collection.mutable.Queue class GenericRunnerSettings(error: String => Unit) extends Settings(error) { @@ -19,5 +20,46 @@ extends Settings(error) { val savecompiled = BooleanSetting( "-savecompiled", - "save the compiled script (assumes -howtorun script)") + "save the compiled script (assumes the code is a script)") + + /* For some reason, "object defines extends Setting(...)" + does not work here. The object is present but the setting + is not added to allsettings. Thus, + */ + class DefinesSetting + extends Setting("-D<prop>", "set a Java property") + { + private val props = new Queue[Pair[String, String]] + + def value = props.toList + + def tryToSet(args: List[String]): List[String] = { + args match { + case arg0::rest + if arg0.startsWith("-D") => + { + val stripD = arg0.substring(2) + val eqidx = stripD.indexOf('=') + val addition = + if(eqidx < 0) + Pair(stripD, "") + else + Pair(stripD.substring(0, eqidx), stripD.substring(eqidx+1)) + props += addition + rest + } + + case _ => args + } + } + + /** Apply the specified properties to the current JVM */ + def applyToCurrentJVM = { + val systemProps = System.getProperties + for(val Pair(key, value) <- props.toList) + systemProps.setProperty(key, value) + } + } + + val defines = new DefinesSetting } diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala index 2ee8763995..61ec457824 100644 --- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala +++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala @@ -54,6 +54,8 @@ object MainGenericRunner { settings.classpath.value = addClasspathExtras(settings.classpath.value) + settings.defines.applyToCurrentJVM + if (settings.help.value || !command.ok) { Console.println(command.usageMessage) return () |