summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-03-16 13:03:02 +0000
committerPaul Phillips <paulp@improving.org>2009-03-16 13:03:02 +0000
commit00d196adeeb3aa88f2afedcb5d7eb51f0fc19896 (patch)
tree856ab3879e450c929c04907551acd6898fa51ede /src
parentff9887891f8f865617c60351a3afc8daced2db0e (diff)
downloadscala-00d196adeeb3aa88f2afedcb5d7eb51f0fc19896.tar.gz
scala-00d196adeeb3aa88f2afedcb5d7eb51f0fc19896.tar.bz2
scala-00d196adeeb3aa88f2afedcb5d7eb51f0fc19896.zip
Various cleanups and redundancy-removal related...
Various cleanups and redundancy-removal related to properties.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/CompileClient.scala14
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala8
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterLoop.scala7
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala7
-rw-r--r--src/compiler/scala/tools/nsc/Properties.scala3
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala8
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala3
-rw-r--r--src/library/scala/util/Properties.scala24
-rw-r--r--src/partest/scala/tools/partest/nest/ConsoleRunner.scala26
-rw-r--r--src/partest/scala/tools/partest/nest/ReflectiveRunner.scala69
-rw-r--r--src/partest/scala/tools/partest/utils/Properties.scala2
-rw-r--r--src/scalap/scala/tools/scalap/CodeWriter.scala2
12 files changed, 78 insertions, 95 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala
index 941c722efb..60215719bf 100644
--- a/src/compiler/scala/tools/nsc/CompileClient.scala
+++ b/src/compiler/scala/tools/nsc/CompileClient.scala
@@ -7,6 +7,7 @@
package scala.tools.nsc
import java.io.{BufferedReader, File, InputStreamReader, PrintWriter}
+import Properties.fileEndings
/** The client part of the fsc offline compiler. Instead of compiling
* things itself, it send requests to a CompileServer.
@@ -14,13 +15,10 @@ import java.io.{BufferedReader, File, InputStreamReader, PrintWriter}
class StandardCompileClient {
def compileSocket: CompileSocket = CompileSocket // todo: should be lazy val
- val versionMsg = "Fast Scala Compiler " +
- Properties.versionString + " -- " +
- Properties.copyrightString
-
- var verbose = false
- var version = false
- var shutdown = false
+ val versionMsg = "Fast " + Properties.versionMsg
+ var verbose = false
+ var version = false
+ var shutdown = false
/** Convert a filename to an absolute path */
def absFileName(path: String) = new File(path).getAbsolutePath()
@@ -34,8 +32,6 @@ class StandardCompileClient {
pathsList.map(absFileName).mkString("", sep, "")
}
- val fileEndings = Properties.fileEndingString.split("""\|""").toList
-
protected def normalize(args: Array[String]): (String, String) = {
var i = 0
val vmArgs = new StringBuilder
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index b2cd7e5206..4b98f0ada1 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -20,6 +20,9 @@ class CompilerCommand(
def this(arguments: List[String], settings: Settings, error: String => Unit, interactive: Boolean) =
this(arguments, settings, error, interactive, true)
+ /** file extensions of files that the compiler can process */
+ lazy val fileEndings = Properties.fileEndings
+
/** Private buffer for accumulating files to compile */
private var fs: List[String] = List()
@@ -29,9 +32,6 @@ class CompilerCommand(
/** The name of the command */
val cmdName = "scalac"
- /** The file extensions of files that the compiler can process */
- lazy val fileEndings = Properties.fileEndingString.split("""\|""").toList
-
private val helpSyntaxColumnWidth: Int =
Iterable.max(settings.allSettings map (_.helpSyntax.length))
@@ -91,7 +91,7 @@ class CompilerCommand(
// true if it's a legit looking source file
def isSourceFile(x: String) =
(settings.script.value != "") ||
- (fileEndings exists (ext => x endsWith ext))
+ (fileEndings exists (x endsWith _))
// given an option for scalac finds out what it is
def doOption(x: String): Unit = {
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
index ea387b39dc..52097e0ebf 100644
--- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
@@ -126,15 +126,12 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
/** Print a welcome message */
def printWelcome() {
+ import Properties._
val welcomeMsg =
"""|Welcome to Scala %s (%s, Java %s).
|Type in expressions to have them evaluated.
|Type :help for more information.""" .
- stripMargin.format(
- Properties.versionString,
- System.getProperty("java.vm.name"),
- System.getProperty("java.version")
- )
+ stripMargin.format(versionString, javaVmName, javaVersion)
out println welcomeMsg
out.flush
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index bf6f45f255..3d7b5ac7ee 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -13,6 +13,7 @@ import java.lang.reflect.InvocationTargetException
import java.net.URL
import util.ClassPath
+import File.pathSeparator
/** An object that runs Scala code. It has three possible
* sources for the code to run: pre-compiled code, a script file,
@@ -52,12 +53,12 @@ object MainGenericRunner {
filesInClasses.filter(f => f.isDirectory)
dirsInClasses.toList
}
- }.mkString("", File.pathSeparator, "")
+ }.mkString("", pathSeparator, "")
if (classpath == "")
- extraClassPath + File.pathSeparator + "."
+ extraClassPath + pathSeparator + "."
else
- classpath + File.pathSeparator + extraClassPath
+ classpath + pathSeparator + extraClassPath
}
def main(args: Array[String]) {
diff --git a/src/compiler/scala/tools/nsc/Properties.scala b/src/compiler/scala/tools/nsc/Properties.scala
index e85284dbe2..0a9e9d39aa 100644
--- a/src/compiler/scala/tools/nsc/Properties.scala
+++ b/src/compiler/scala/tools/nsc/Properties.scala
@@ -16,7 +16,10 @@ object Properties extends scala.util.PropertiesTrait {
val fileEndingString = prop("file.ending", ".scala|.java")
val residentPromptString = prop("resident.prompt", "\nnsc> ")
val shellPromptString = prop("shell.prompt", "\nscala> ")
+
+ // derived values
val cmdName = if (isWin) "scala.bat" else "scala"
+ val fileEndings = fileEndingString.split("""\|""").toList
// settings based on System properties
val envClasspath = sysprop("env.classpath", null)
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 2af4b66c05..8f8ddec2d9 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -13,7 +13,7 @@ class Settings(errorFn: String => Unit) extends ScalacSettings {
def this() = this(Console.println)
// optionizes a system property
- private def sysprop(name: String): Option[String] = onull(System.getProperty(name))
+ private def syspropopt(name: String): Option[String] = onull(System.getProperty(name))
// given any number of possible path segments, flattens down to a
// :-separated style path
@@ -21,13 +21,13 @@ class Settings(errorFn: String => Unit) extends ScalacSettings {
segments.toList.flatMap(x => x) mkString File.pathSeparator
protected def classpathDefault =
- sysprop("env.classpath") orElse sysprop("java.class.path") getOrElse ""
+ syspropopt("env.classpath") orElse syspropopt("java.class.path") getOrElse ""
protected def bootclasspathDefault =
- concatPath(sysprop("sun.boot.class.path"), guessedScalaBootClassPath)
+ concatPath(syspropopt("sun.boot.class.path"), guessedScalaBootClassPath)
protected def extdirsDefault =
- concatPath(sysprop("java.ext.dirs"), guessedScalaExtDirs)
+ concatPath(syspropopt("java.ext.dirs"), guessedScalaExtDirs)
protected def pluginsDirDefault =
guess(List("misc", "scala-devel", "plugins"), _.isDirectory) getOrElse ""
diff --git a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
index 5b50164b26..392685c4c0 100644
--- a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
@@ -23,14 +23,13 @@ trait InteractiveReader {
case e => throw e
}
+ // hack necessary for OSX jvm suspension because read calls are not restarted after SIGTSTP
private def restartSystemCall(e: Exception): Boolean =
Properties.isMac && (e.getMessage == msgEINTR)
}
object InteractiveReader {
- // hacks necessary for OSX jvm suspension because read calls are not restarted after SIGTSTP
- val vendor = System.getProperty("java.vendor", "")
val msgEINTR = "Interrupted system call"
def createDefault(): InteractiveReader = createDefault(null)
diff --git a/src/library/scala/util/Properties.scala b/src/library/scala/util/Properties.scala
index 45ccb15985..8f45c2b388 100644
--- a/src/library/scala/util/Properties.scala
+++ b/src/library/scala/util/Properties.scala
@@ -30,6 +30,7 @@ private[scala] trait PropertiesTrait
props
}
+ protected def onull[T <: AnyRef](x: T) = if (x eq null) None else Some(x)
private def quietlyDispose(action: => Unit, disposal: => Unit) =
try { action }
finally {
@@ -38,12 +39,13 @@ private[scala] trait PropertiesTrait
}
// for values based on system properties
- protected def sysprop(name: String, default: String) =
- System.getProperty(name, default)
+ def sysprop(name: String): String = sysprop(name, "")
+ def sysprop(name: String, default: String): String = System.getProperty(name, default)
+ def syspropset(name: String, value: String) = System.setProperty(name, value)
// for values based on propFilename
- protected def prop(name: String, default: String): String =
- props.getProperty(name, default)
+ def prop(name: String): String = props.getProperty(name, "")
+ def prop(name: String, default: String): String = props.getProperty(name, default)
// XXX file.encoding should not be here, as it causes system setting to
// be ignored. See https://lampsvn.epfl.ch/trac/scala/ticket/1581
@@ -54,13 +56,19 @@ private[scala] trait PropertiesTrait
val versionString = "version " + prop("version.number", "(unknown)")
val copyrightString = prop("copyright.string", "(c) 2002-2009 LAMP/EPFL")
val encodingString = prop("file.encoding", "UTF8")
- val isWin = sysprop("os.name", "") startsWith "Windows"
- val isMac = sysprop("java.vendor", "") startsWith "Apple"
- val scalaHome = sysprop("scala.home", null)
+ val isWin = sysprop("os.name") startsWith "Windows"
+ val isMac = sysprop("java.vendor") startsWith "Apple"
+ val javaClassPath = sysprop("java.class.path")
+ val javaHome = sysprop("java.home")
+ val javaVmName = sysprop("java.vm.name")
+ val javaVmVersion = sysprop("java.vm.version")
+ val javaVmInfo = sysprop("java.vm.info")
+ val javaVersion = sysprop("java.version")
+ val scalaHome = sysprop("scala.home", null) // XXX places do null checks...
// provide a main method so version info can be obtained by running this
private val writer = new java.io.PrintWriter(Console.err, true)
- private val versionMsg = "Scala %s %s -- %s".format(propCategory, versionString, copyrightString)
+ def versionMsg = "Scala %s %s -- %s".format(propCategory, versionString, copyrightString)
def main(args: Array[String]) { writer println versionMsg }
}
diff --git a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
index 065d04f332..67053ce732 100644
--- a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
+++ b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
@@ -9,6 +9,7 @@ package scala.tools.partest.nest
import java.io.{File, PrintStream, FileOutputStream, BufferedReader,
InputStreamReader, StringWriter, PrintWriter}
+import utils.Properties._
class ConsoleRunner extends DirectRunner with RunnerUtils {
@@ -38,8 +39,7 @@ class ConsoleRunner extends DirectRunner with RunnerUtils {
var fileManager: ConsoleFileManager = _
- private val version = System.getProperty("java.version", "")
- private val isJava5 = version matches "1.[5|6|7].*"
+ private val isJava5 = javaVersion matches "1.[5|6|7].*"
private var runAll = false
private var testFiles: List[File] = List()
private val errors =
@@ -54,13 +54,7 @@ class ConsoleRunner extends DirectRunner with RunnerUtils {
def denotesTestDir(arg: String) =
(new File(arg)).isDirectory
- private def printVersion {
- val versionMsg = "Scala partest "+
- utils.Properties.versionString+
- " -- "+
- scala.tools.nsc.Properties.copyrightString
- NestUI.outline(versionMsg+"\n")
- }
+ private def printVersion { NestUI outline (versionMsg + "\n") }
def main(argstr: String) {
// tokenize args. filter: "".split("\\s") yields Array("")
@@ -143,19 +137,13 @@ class ConsoleRunner extends DirectRunner with RunnerUtils {
fileManager.latestCompFile.getParentFile.getParentFile.getCanonicalFile
NestUI.outline("Scala compiler classes in: "+dir+"\n")
- val scalaVersion = "Scala compiler "+
- scala.tools.nsc.Properties.versionString+
- " -- "+
- scala.tools.nsc.Properties.copyrightString
-
- NestUI.outline("Scala version is: "+scalaVersion+"\n")
+ NestUI.outline("Scala version is: "+nsc.Properties.versionMsg+"\n")
NestUI.outline("Scalac options are: "+fileManager.SCALAC_OPTS+"\n")
- val vmBin = System.getProperty("java.home", "")+File.separator+"bin"
- val vmName = System.getProperty("java.vm.name", "")+" (build "+
- System.getProperty("java.vm.version", "")+", "+
- System.getProperty("java.vm.info", "")+")"
+ val vmBin = javaHome + File.separator + "bin"
+ val vmName = "%s (build %s, %s)".format(javaVmName, javaVmVersion, javaVmInfo)
val vmOpts = fileManager.JAVA_OPTS
+
NestUI.outline("Java binaries in: "+vmBin+"\n")
NestUI.outline("Java runtime is: "+vmName+"\n")
NestUI.outline("Java options are: "+vmOpts+"\n")
diff --git a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
index 3cb48dfd9d..c655494d4d 100644
--- a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
+++ b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
@@ -19,6 +19,12 @@ class ReflectiveRunner extends RunnerUtils {
// to use the same classes as used by `scala` that
// was used to start the runner.
+ import java.net.URLClassLoader
+ import java.io.File.pathSeparator
+ import utils.Properties.{ sysprop, syspropset }
+
+ val sepRunnerClassName = "scala.tools.partest.nest.ConsoleRunner"
+
def main(args: String) {
val argList = List.fromArray(args.split("\\s"))
@@ -37,55 +43,40 @@ class ReflectiveRunner extends RunnerUtils {
else // auto detection
new ConsoleFileManager
- import fileManager.{latestCompFile, latestLibFile, latestActFile,
- latestPartestFile, latestFjbgFile}
-
- val sepUrls = Array(latestCompFile.toURL, latestLibFile.toURL,
- latestActFile.toURL, latestPartestFile.toURL,
- latestFjbgFile.toURL)
-
- val sepLoader = new java.net.URLClassLoader(sepUrls, null)
+ import fileManager.
+ { latestCompFile, latestLibFile, latestActFile, latestPartestFile, latestFjbgFile }
+ val files =
+ Array(latestCompFile, latestLibFile, latestActFile, latestPartestFile, latestFjbgFile)
- if (fileManager.debug) {
- println("Loading classes from:")
- sepUrls foreach { url => println(url) }
- }
+ val sepUrls = files map { _.toURL }
+ val sepLoader = new URLClassLoader(sepUrls, null)
- try {
- val paths = if (!classPath.isEmpty)
- Array(latestCompFile.getPath, latestLibFile.getPath,
- latestActFile.getPath, latestPartestFile.getPath,
- latestFjbgFile.getPath)
- else
- Array(latestCompFile.getPath, latestLibFile.getPath,
- latestActFile.getPath, latestPartestFile.getPath)
- val newClasspath = paths.mkString(java.io.File.pathSeparator)
- System.setProperty("java.class.path", newClasspath)
- System.setProperty("env.classpath", newClasspath)
- System.setProperty("scala.home", "")
- if (fileManager.debug) {
- println("java.class.path: "+System.getProperty("java.class.path"))
- println("env.classpath: "+System.getProperty("env.classpath"))
- println("sun.boot.class.path: "+System.getProperty("sun.boot.class.path"))
- println("java.ext.dirs: "+System.getProperty("java.ext.dirs"))
- }
+ if (fileManager.debug)
+ println("Loading classes from:\n" + sepUrls.mkString("\n"))
- val sepRunnerClass =
- sepLoader.loadClass("scala.tools.partest.nest.ConsoleRunner")
+ val paths = (if (classPath.isEmpty) files.slice(0, 4) else files) map { _.getPath }
+ val newClasspath = paths mkString pathSeparator
- val sepRunner = sepRunnerClass.newInstance()
+ syspropset("java.class.path", newClasspath)
+ syspropset("env.classpath", newClasspath)
+ syspropset("scala.home", "")
- val stringClass = Class.forName("java.lang.String")
- val sepMainMethod =
- sepRunnerClass.getMethod("main", Array(stringClass): _*)
+ if (fileManager.debug)
+ for (prop <- List("java.class.path", "env.classpath", "sun.boot.class.path", "java.ext.dirs"))
+ println(prop + ": " + sysprop(prop))
+ try {
+ val sepRunnerClass = sepLoader loadClass sepRunnerClassName
+ val sepRunner = sepRunnerClass.newInstance()
+ val sepMainMethod = sepRunnerClass.getMethod("main", Array(classOf[String]): _*)
val cargs: Array[AnyRef] = Array(args)
sepMainMethod.invoke(sepRunner, cargs: _*)
- } catch {
+ }
+ catch {
case cnfe: ClassNotFoundException =>
cnfe.printStackTrace()
- NestUI.failure("scala.tools.partest.nest.ConsoleRunner could not be loaded from: \n")
- sepUrls foreach { url => NestUI.failure(url+"\n") }
+ NestUI.failure(sepRunnerClassName +" could not be loaded from:\n")
+ sepUrls foreach (x => NestUI.failure(x + "\n"))
}
}
}
diff --git a/src/partest/scala/tools/partest/utils/Properties.scala b/src/partest/scala/tools/partest/utils/Properties.scala
index 8c96083306..1ab1d47020 100644
--- a/src/partest/scala/tools/partest/utils/Properties.scala
+++ b/src/partest/scala/tools/partest/utils/Properties.scala
@@ -17,4 +17,4 @@ object Properties extends scala.util.PropertiesTrait {
// XXX unlikely it's intentional that only partest uses ISO-8859-1
override val encodingString = prop("file.encoding", "ISO-8859-1")
-}
+} \ No newline at end of file
diff --git a/src/scalap/scala/tools/scalap/CodeWriter.scala b/src/scalap/scala/tools/scalap/CodeWriter.scala
index 24a1a87f05..deb0e2c94a 100644
--- a/src/scalap/scala/tools/scalap/CodeWriter.scala
+++ b/src/scalap/scala/tools/scalap/CodeWriter.scala
@@ -14,7 +14,7 @@ import java.io._
class CodeWriter(writer: Writer) {
- private val nl = System.getProperty("line.separator")
+ private val nl = compat.Platform.EOL
private var step = " "
private var level = 0
private var align = false