diff options
author | Lex Spoon <lex@lexspoon.org> | 2006-07-13 07:28:00 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2006-07-13 07:28:00 +0000 |
commit | 1b41a79cb7e4f5e627aa49cdacf876d15d5f9157 (patch) | |
tree | d4fc36863d2751f4b94bd16263cfd7c050c25118 /src/compiler/scala/tools/nsc/ObjectRunner.scala | |
parent | 637494513954e26fdef6593d113f15c38022314a (diff) | |
download | scala-1b41a79cb7e4f5e627aa49cdacf876d15d5f9157.tar.gz scala-1b41a79cb7e4f5e627aa49cdacf876d15d5f9157.tar.bz2 scala-1b41a79cb7e4f5e627aa49cdacf876d15d5f9157.zip |
reverse the order of guesses about howtorun: fi...
reverse the order of guesses about howtorun: first look for an object,
then look for a script file
Diffstat (limited to 'src/compiler/scala/tools/nsc/ObjectRunner.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ObjectRunner.scala | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/ObjectRunner.scala b/src/compiler/scala/tools/nsc/ObjectRunner.scala index 4034e088c4..6ff96fa74a 100644 --- a/src/compiler/scala/tools/nsc/ObjectRunner.scala +++ b/src/compiler/scala/tools/nsc/ObjectRunner.scala @@ -13,6 +13,25 @@ import java.net.URLClassLoader /** An object that runs another object specified by name. */ object ObjectRunner { + /** Look up a class with a given class path */ + def findClass(classpath: List[String], objectName: String) + : Option[Class] = + { + val classpathURLs = classpath.map(s => new File(s).toURL).toArray + val mainLoader = new URLClassLoader(classpathURLs, null) + try { + Some(Class.forName(objectName, true, mainLoader)) + } catch { + case _:ClassNotFoundException => None + } + } + + /** Check whether a class with the specified name + * exists on the specified class path. + */ + def classExists(classpath: List[String], objectName: String) = + !(findClass(classpath, objectName).isEmpty) + /** Run a given object, specified by name, using a * specified classpath and argument list. * @@ -24,9 +43,10 @@ object ObjectRunner { objectName: String, arguments: Seq[String]): Unit = { - val classpathURLs = classpath.map(s => new File(s).toURL).toArray - val mainLoader = new URLClassLoader(classpathURLs, null) - val clsToRun = Class.forName(objectName, true, mainLoader) + val clsToRun = findClass(classpath, objectName) match { + case Some(cls) => cls + case None => throw new ClassNotFoundException(objectName) + } val method = clsToRun.getMethod("main", List(classOf[Array[String]]).toArray) |