summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2006-07-13 09:20:14 +0000
committerLex Spoon <lex@lexspoon.org>2006-07-13 09:20:14 +0000
commit57e11c6b3526858567124d09677a4564e9f517b2 (patch)
tree36d7001d92ce8fc5f78ce0274b6324d4af0dfaca /src/compiler/scala/tools/nsc/GenericRunnerSettings.scala
parenta35c89a5e9e4cc4eb2671ec6ff03481b883fc92c (diff)
downloadscala-57e11c6b3526858567124d09677a4564e9f517b2.tar.gz
scala-57e11c6b3526858567124d09677a4564e9f517b2.tar.bz2
scala-57e11c6b3526858567124d09677a4564e9f517b2.zip
added -D for defining Java properties
Diffstat (limited to 'src/compiler/scala/tools/nsc/GenericRunnerSettings.scala')
-rw-r--r--src/compiler/scala/tools/nsc/GenericRunnerSettings.scala44
1 files changed, 43 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
}