summaryrefslogtreecommitdiff
path: root/src/compiler/scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-23 00:27:39 +0000
committerPaul Phillips <paulp@improving.org>2010-02-23 00:27:39 +0000
commitdf94b3c5b831e78a056f7b0b5334b1fb8d3c3bd5 (patch)
tree6be1d68b93045d6a568ac165126d4ed8e11e3fd7 /src/compiler/scala
parent8d74992310fe60a1da32606949c96531691754e9 (diff)
downloadscala-df94b3c5b831e78a056f7b0b5334b1fb8d3c3bd5.tar.gz
scala-df94b3c5b831e78a056f7b0b5334b1fb8d3c3bd5.tar.bz2
scala-df94b3c5b831e78a056f7b0b5334b1fb8d3c3bd5.zip
Some much needed housecleaning regarding system...
Some much needed housecleaning regarding system properties. If you can possibly resist the temptation, it'd be great if people could try to go through the properties classes to get and set them, and also to set property values somewhere fixed rather than using strings directly. Review by community.
Diffstat (limited to 'src/compiler/scala')
-rw-r--r--src/compiler/scala/tools/nsc/CompileSocket.scala7
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala6
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterLoop.scala4
-rw-r--r--src/compiler/scala/tools/nsc/Main.scala17
-rw-r--r--src/compiler/scala/tools/nsc/Properties.scala11
-rw-r--r--src/compiler/scala/tools/nsc/ScalaDoc.scala10
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/History.scala4
-rw-r--r--src/compiler/scala/tools/nsc/io/Directory.scala6
-rw-r--r--src/compiler/scala/tools/util/PathResolver.scala33
9 files changed, 47 insertions, 51 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala
index 305c4e211d..8d599c6c96 100644
--- a/src/compiler/scala/tools/nsc/CompileSocket.scala
+++ b/src/compiler/scala/tools/nsc/CompileSocket.scala
@@ -23,13 +23,12 @@ class CompileSocket {
/** The prefix of the port identification file, which is followed
* by the port number.
*/
- protected def dirName = "scalac-compile-server-port" //todo: lazy val
-
- protected def cmdName = Properties.cmdName //todo: lazy val
+ protected lazy val dirName = "scalac-compile-server-port"
+ protected lazy val cmdName = Properties.scalaCmd
/** The vm part of the command to start a new scala compile server */
protected val vmCommand = Properties.scalaHome match {
- case null => cmdName
+ case "" => cmdName
case dirname =>
val trial = File(dirname) / "bin" / cmdName
if (trial.canRead) trial.path
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index a805da1fcc..dd581e0878 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -26,7 +26,8 @@ class CompilerCommand(
lazy val fileEndings = Properties.fileEndings
/** The name of the command */
- val cmdName = "scalac"
+ def cmdName = "scalac"
+ private def isFsc = cmdName == "fsc"
private val helpSyntaxColumnWidth: Int =
(settings.visibleSettings map (_.helpSyntax.length)) max
@@ -53,8 +54,7 @@ class CompilerCommand(
// an informative message of some sort should be printed instead.
// (note: do not add "files.isEmpty" do this list)
val stopSettings = List[(() => Boolean, (Global) => String)](
- ((() => (settings.help.value _)() && (cmdName == "fsc")),
- fscUsageMsg + _.pluginOptionsHelp),
+ ((() => (settings.help.value _)() && isFsc), fscUsageMsg + _.pluginOptionsHelp),
(settings.help.value _, usageMsg + _.pluginOptionsHelp),
(settings.Xhelp.value _, _ => xusageMsg),
(settings.Yhelp.value _, _ => yusageMsg),
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
index b8e25c4bd4..1ef249735f 100644
--- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
@@ -555,10 +555,8 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
in = in0 match {
case Some(in0) => new SimpleReader(in0, out, true)
case None =>
- val emacsShell = System.getProperty("env.emacs", "") != ""
-
// the interpreter is passed as an argument to expose tab completion info
- if (settings.Xnojline.value || emacsShell) new SimpleReader
+ if (settings.Xnojline.value || Properties.isEmacsShell) new SimpleReader
else if (settings.noCompletion.value) InteractiveReader.createDefault()
else InteractiveReader.createDefault(interpreter)
}
diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala
index 577439990d..4f945733fd 100644
--- a/src/compiler/scala/tools/nsc/Main.scala
+++ b/src/compiler/scala/tools/nsc/Main.scala
@@ -7,6 +7,7 @@
package scala.tools.nsc
import java.io.File
+import File.pathSeparator
import scala.concurrent.SyncVar
@@ -14,6 +15,7 @@ import scala.tools.nsc.interactive.{ RefinedBuildManager, SimpleBuildManager }
import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
import scala.tools.nsc.util.{ BatchSourceFile, FakePos } //{Position}
+import Properties.{ versionString, copyrightString, residentPromptString, msilLibPath }
/** The main class for NSC, a compiler for the programming
* language Scala.
@@ -21,10 +23,10 @@ import scala.tools.nsc.util.{ BatchSourceFile, FakePos } //{Position}
object Main extends AnyRef with EvalLoop {
val versionMsg = "Scala compiler " +
- Properties.versionString + " -- " +
- Properties.copyrightString
+ versionString + " -- " +
+ copyrightString
- val prompt = Properties.residentPromptString
+ val prompt = residentPromptString
var reporter: ConsoleReporter = _
@@ -82,12 +84,9 @@ object Main extends AnyRef with EvalLoop {
buildManager.update(fileSet(command.files), Set.empty)
}
} else {
- if (command.settings.target.value == "msil") {
- val libpath = System.getProperty("msil.libpath")
- if (libpath != null)
- command.settings.assemrefs.value =
- command.settings.assemrefs.value + File.pathSeparator + libpath
- }
+ if (command.settings.target.value == "msil")
+ msilLibPath foreach (x => command.settings.assemrefs.value += (pathSeparator + x))
+
try {
val compiler = if (command.settings.Yrangepos.value) new interactive.Global(command.settings, reporter)
else new Global(command.settings, reporter)
diff --git a/src/compiler/scala/tools/nsc/Properties.scala b/src/compiler/scala/tools/nsc/Properties.scala
index 8b30929092..346f5947cd 100644
--- a/src/compiler/scala/tools/nsc/Properties.scala
+++ b/src/compiler/scala/tools/nsc/Properties.scala
@@ -13,11 +13,14 @@ object Properties extends scala.util.PropertiesTrait {
protected def pickJarBasedOn = classOf[Global]
// settings based on jar properties
- def fileEndingString = prop("file.ending", ".scala|.java")
- def residentPromptString = prop("resident.prompt", "\nnsc> ")
- def shellPromptString = prop("shell.prompt", "\nscala> ")
+ def fileEndingString = scalaPropOrElse("file.ending", ".scala|.java")
+ def residentPromptString = scalaPropOrElse("resident.prompt", "\nnsc> ")
+ def shellPromptString = scalaPropOrElse("shell.prompt", "\nscala> ")
+
+ // settings based on system properties
+ def msilLibPath = propOrNone("msil.libpath")
// derived values
- def cmdName = if (isWin) "scala.bat" else "scala"
+ def isEmacsShell = propIsSet("env.emacs")
def fileEndings = fileEndingString.split("""\|""").toList
}
diff --git a/src/compiler/scala/tools/nsc/ScalaDoc.scala b/src/compiler/scala/tools/nsc/ScalaDoc.scala
index f3c7c686a0..4a9bbe8fd3 100644
--- a/src/compiler/scala/tools/nsc/ScalaDoc.scala
+++ b/src/compiler/scala/tools/nsc/ScalaDoc.scala
@@ -11,7 +11,8 @@ import java.io.File
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
import scala.tools.nsc.util.FakePos //{Position}
-
+import Properties.msilLibPath
+import File.pathSeparator
/** The main class for scaladoc, a front-end for the Scala compiler
* that generates documentation from source files.
@@ -56,11 +57,8 @@ object ScalaDoc {
reporter.warning(null, "Phases are restricted when using Scaladoc")
else try {
- if (docSettings.target.value == "msil") {
- val libpath = System.getProperty("msil.libpath")
- if (libpath != null)
- docSettings.assemrefs.value = docSettings.assemrefs.value + File.pathSeparator + libpath
- }
+ if (docSettings.target.value == "msil")
+ msilLibPath foreach (x => docSettings.assemrefs.value += (pathSeparator + x))
val docProcessor = new scala.tools.nsc.doc.DocFactory(reporter, docSettings)
docProcessor.document(command.files)
diff --git a/src/compiler/scala/tools/nsc/interpreter/History.scala b/src/compiler/scala/tools/nsc/interpreter/History.scala
index 519d17f9d2..7bd4e89095 100644
--- a/src/compiler/scala/tools/nsc/interpreter/History.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/History.scala
@@ -9,6 +9,7 @@ package interpreter
import java.io.File
import jline.{ ConsoleReader, History => JHistory }
import scala.collection.JavaConversions.asBuffer
+import Properties.userHome
/** Primarily, a wrapper for JLine's History.
*/
@@ -22,14 +23,13 @@ class History(val jhistory: JHistory) {
object History {
val ScalaHistoryFile = ".scala_history"
- def homeDir = System.getProperty("user.home")
def apply(reader: ConsoleReader): History =
if (reader == null) apply()
else new History(reader.getHistory)
def apply(): History = new History(
- try new JHistory(new File(homeDir, ScalaHistoryFile))
+ try new JHistory(new File(userHome, ScalaHistoryFile))
// do not store history if error
catch { case _: Exception => new JHistory() }
)
diff --git a/src/compiler/scala/tools/nsc/io/Directory.scala b/src/compiler/scala/tools/nsc/io/Directory.scala
index 6a4e78560d..709ffdc1e0 100644
--- a/src/compiler/scala/tools/nsc/io/Directory.scala
+++ b/src/compiler/scala/tools/nsc/io/Directory.scala
@@ -14,11 +14,11 @@ import collection.Traversable
object Directory
{
- import scala.util.Properties.{ tmpDir, homeDir, currentDir }
+ import scala.util.Properties.{ tmpDir, userHome, userDir }
private def normalizePath(s: String) = Some(apply(Path(s).normalize))
- def Current: Option[Directory] = if (currentDir == "") None else normalizePath(currentDir)
- def Home: Option[Directory] = if (homeDir == "") None else normalizePath(homeDir)
+ def Current: Option[Directory] = if (userDir == "") None else normalizePath(userDir)
+ def Home: Option[Directory] = if (userHome == "") None else normalizePath(userHome)
def TmpDir: Option[Directory] = if (tmpDir == "") None else normalizePath(tmpDir)
def apply(path: Path) = path.toDirectory
diff --git a/src/compiler/scala/tools/util/PathResolver.scala b/src/compiler/scala/tools/util/PathResolver.scala
index 1a7c121d56..5c6bd2c884 100644
--- a/src/compiler/scala/tools/util/PathResolver.scala
+++ b/src/compiler/scala/tools/util/PathResolver.scala
@@ -7,6 +7,7 @@ package scala.tools
package util
import java.net.{ URL, MalformedURLException }
+import scala.util.Properties._
import nsc.{ Settings, GenericRunnerSettings }
import nsc.util.{ ClassPath, JavaClassPath, ScalaClassLoader }
import nsc.io.{ File, Directory, Path }
@@ -17,8 +18,6 @@ import PartialFunction.condOpt
// https://lampsvn.epfl.ch/trac/scala/wiki/Classpath
object PathResolver {
- def propOrElse(name: String, alt: String) = System.getProperty(name, alt)
- def envOrElse(name: String, alt: String) = Option(System getenv name) getOrElse alt
def firstNonEmpty(xs: String*) = xs find (_ != "") getOrElse ""
private def fileOpt(f: Path): Option[String] = f ifFile (_.path)
@@ -53,27 +52,26 @@ object PathResolver {
def sourcePathEnv = envOrElse("SOURCEPATH", "") // not used
def scalaHomeEnv = envOrElse("SCALA_HOME", "") // not used
def javaBootClassPath = propOrElse("sun.boot.class.path", searchForBootClasspath)
- def javaUserClassPath = propOrElse("java.class.path", "")
def javaExtDirs = propOrElse("java.ext.dirs", "")
- def userHome = propOrElse("user.home", "")
- def scalaHome = System.getProperty("scala.home") // keep null so we know when it's unset
+ def javaUserClassPath = propOrElse("java.class.path", classPathEnv)
def scalaExtDirs = propOrElse("scala.ext.dirs", "")
- def scalaHomeGuessed = searchForScalaHome
+
+ def scalaHome = propOrElse("scala.home", null)
def scalaHomeIsSet = scalaHome != null
+ def scalaAutodetect = propIsSet("scala.auto") && !propIsSet("scala.noauto")
override def toString = """
|object Environment {
+ | scalaHome = %s (autodetect = %s)
| javaBootClassPath = <%d chars>
- | javaUserClassPath = %s
| javaExtDirs = %s
- | userHome = %s
- | scalaHome = %s
+ | javaUserClassPath = %s
| scalaExtDirs = %s
|}""".trim.stripMargin.format(
+ scalaHome, scalaAutodetect,
javaBootClassPath.length,
- ppcp(javaUserClassPath),
ppcp(javaExtDirs),
- userHome, scalaHome,
+ ppcp(javaUserClassPath),
ppcp(scalaExtDirs)
)
}
@@ -116,15 +114,16 @@ object PathResolver {
override def toString = """
|object Defaults {
- | javaBootClassPath = %s
| scalaHome = %s
+ | javaBootClassPath = %s
| scalaLibDirFound = %s
| scalaLibFound = %s
| scalaBootClassPath = %s
| scalaPluginPath = %s
|}""".trim.stripMargin.format(
+ scalaHome,
ppcp(javaBootClassPath),
- scalaHome, scalaLibDirFound, scalaLibFound,
+ scalaLibDirFound, scalaLibFound,
ppcp(scalaBootClassPath), ppcp(scalaPluginPath)
)
}
@@ -207,17 +206,17 @@ class PathResolver(settings: Settings, context: JavaContext) {
|object Calculated {
| scalaHome = %s
| javaBootClassPath = %s
+ | javaExtDirs = %s
| javaUserClassPath = %s
| scalaBootClassPath = %s
- | javaExtDirs = %s
| scalaExtDirs = %s
| userClassPath = %s
| sourcePath = %s
|}""".trim.stripMargin.format(
scalaHome,
- ppcp(javaBootClassPath), ppcp(javaUserClassPath), ppcp(scalaBootClassPath),
- ppcp(javaExtDirs), ppcp(scalaExtDirs),
- ppcp(userClassPath), ppcp(sourcePath)
+ ppcp(javaBootClassPath), ppcp(javaExtDirs), ppcp(javaUserClassPath),
+ ppcp(scalaBootClassPath), ppcp(scalaExtDirs), ppcp(userClassPath),
+ ppcp(sourcePath)
)
}