1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* NSC -- new Scala compiler
* Copyright 2006 LAMP/EPFL
* @author Lex Spoon
*/
// $Id$
package scala.tools.nsc
import java.lang.System.getProperties
import scala.collection.mutable.Queue
class GenericRunnerSettings(error: String => Unit)
extends Settings(error) {
val howtorun =
ChoiceSetting(
"-howtorun",
"how to run the specified code",
List("guess", "object", "script"),
"guess")
val savecompiled =
BooleanSetting(
"-savecompiled",
"save the compiled script (assumes the code is a script)")
val nocompdaemon =
BooleanSetting(
"-nocompdaemon",
"do not use the fsc compilation daemon")
/* 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[(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)
(stripD, "")
else
(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 = getProperties
for(val (key, value) <- props.toList)
systemProps.setProperty(key, value)
}
def unparse: List[String] =
(props.toList.foldLeft[List[String]]
(Nil)
((args, prop) =>
("-D" + prop._1 + "=" + prop._2) :: args))
}
val defines = new DefinesSetting
}
|