summaryrefslogtreecommitdiff
path: root/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
blob: ba04267609d74267851656c0936a135d3168a00f (plain) (blame)
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
/* NEST (New Scala Test)
 * Copyright 2007-2008 LAMP/EPFL
 * @author Philipp Haller
 */

// $Id: $

package scala.tools.partest.nest

/* This class is used to load an instance of DirectRunner using
 * a custom class loader.
 * The purpose is to "auto-detect" a good classpath for the
 * rest of the classes (Worker, CompileManager etc.), so that
 * the main NestRunner can be started merely by putting its
 * class on the classpath (ideally).
 */
class ReflectiveRunner {
  // we might also use FileManager.CLASSPATH
  // to use the same classes as used by `scala` that
  // was used to start the runner.

  val fileManager = 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)

  val sepRunnerClass =
    sepLoader.loadClass("scala.tools.partest.nest.ConsoleRunner")
  val sepRunner = sepRunnerClass.newInstance()

  val stringClass = Class.forName("java.lang.String")
  val sepMainMethod =
    sepRunnerClass.getMethod("main", Array(stringClass))

  def main(args: String) {
    val cargs: Array[AnyRef] = Array(args)
    sepMainMethod.invoke(sepRunner, cargs)
  }
}