diff options
author | Lex Spoon <lex@lexspoon.org> | 2006-06-22 13:59:39 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2006-06-22 13:59:39 +0000 |
commit | f7040354189e7413657f55745ca7c7d120ad39d7 (patch) | |
tree | a483d9b118ff6cab4c36759aa4a2386f8c5b46d8 | |
parent | 1ab98be85b4a4ecdfb7afdf0c98bd0ef7e634b4e (diff) | |
download | scala-f7040354189e7413657f55745ca7c7d120ad39d7.tar.gz scala-f7040354189e7413657f55745ca7c7d120ad39d7.tar.bz2 scala-f7040354189e7413657f55745ca7c7d120ad39d7.zip |
1a.
1b. Add "." to the classpath if the user does not specify any
classpath at all. 2. Handle exceptions that are now thrown by
ObjectRunner, that is: ClassNotFoundException, NoSuchMethodError, and
InvocationTargetException. For InvocationTargetException, go ahead and
print a stack trace.
-rw-r--r-- | src/compiler/scala/tools/nsc/MainGenericRunner.scala | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala index 65f9534e9e..12388cf2bd 100644 --- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala +++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala @@ -8,13 +8,39 @@ package scala.tools.nsc import java.io.File - +import java.lang.reflect.InvocationTargetException /** An object that runs Scala code. It has three possible * sources for the code to run: pre-compiled code, a script file, * or interactive entry. */ object MainGenericRunner { + /** Append jars found in ${scala.home}/lib to + * a specified classpath. Also append "." if the + * input classpath is empty; otherwise do not. + */ + def addClasspathExtras(classpath: String): String = { + val scalaHome = System.getProperty("scala.home") + if (scalaHome == null) + return classpath + + val libdir = new File(new File(scalaHome), "lib") + if(!libdir.exists || libdir.isFile) + return classpath + + val filesInLib = libdir.listFiles + val jarsInLib = + filesInLib.filter(f => + f.isFile && f.getName.endsWith(".jar")) + val sep = File.pathSeparator + val extraClassPath = jarsInLib.mkString("", sep, "") + + if(classpath == "") + extraClassPath + sep + "." + else + classpath + sep + extraClassPath + } + def main(args: Array[String]): Unit = { def error(str: String) = Console.println(str) val command = new GenericRunnerCommand(args.toList, error) @@ -25,6 +51,9 @@ object MainGenericRunner { val settings = command.settings + settings.classpath.value = + addClasspathExtras(settings.classpath.value) + if (settings.help.value) { Console.println(command.usageMessage) return () @@ -59,7 +88,16 @@ object MainGenericRunner { paths(settings.bootclasspath.value) ::: paths(settings.classpath.value) - ObjectRunner.run(classpath, thingToRun, command.arguments) + try { + ObjectRunner.run(classpath, thingToRun, command.arguments) + } catch { + case e: ClassNotFoundException => + Console.println(e) + case e: NoSuchMethodError => + Console.println(e) + case e: InvocationTargetException => + e.getCause.printStackTrace + } } else { MainScript.runScript(settings, thingToRun, command.arguments) } |