Changed partest ant task not to use reflection, instead using

the path with which scala was invoked.  No review.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@21109 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2010-03-08 18:46:35 +00:00
parent 573701e870
commit 87ea1aa955
3 changed files with 43 additions and 65 deletions

View File

@ -1397,10 +1397,10 @@ BOOTRAPING TEST AND TEST SUITE
<partest showlog="yes" erroronfailed="yes" javacmd="${java.home}/bin/java"
timeout="1200000" javaccmd="${javac.cmd}"
scalacopts="${scalac.args.optimise}">
<classpath>
<compilationpath>
<path refid="pack.classpath"/>
<fileset dir="${partest.dir}/files/lib" includes="*.jar"/>
</classpath>
<fileset dir="${partest.dir}/files/lib" includes="*.jar" />
</compilationpath>
<runtests dir="${partest.dir}/files">
<include name="run/**/*.scala"/>
<include name="jvm/**/*.scala"/>
@ -1412,10 +1412,10 @@ BOOTRAPING TEST AND TEST SUITE
<partest showlog="yes" erroronfailed="yes" javacmd="${java.home}/bin/java"
timeout="2400000" javaccmd="${javac.cmd}"
scalacopts="${scalac.args.optimise}">
<classpath>
<compilationpath>
<path refid="pack.classpath"/>
<fileset dir="${partest.dir}/files/lib" includes="*.jar"/>
</classpath>
<fileset dir="${partest.dir}/files/lib" includes="*.jar" />
</compilationpath>
<postests dir="${partest.dir}/files/pos" includes="*.scala"/>
<negtests dir="${partest.dir}/files/neg" includes="*.scala"/>
<runtests dir="${partest.dir}/files">

View File

@ -14,7 +14,28 @@ import java.io.File
import org.apache.tools.ant.Task
import org.apache.tools.ant.types.{Path, Reference}
trait TaskArgs { this: Task =>
trait CompilationPathProperty {
this: Task =>
protected var compilationPath: Option[Path] = None
def setCompilationPath(input: Path) {
if (compilationPath.isEmpty) compilationPath = Some(input)
else compilationPath.get.append(input)
}
def createCompilationPath: Path = {
if (compilationPath.isEmpty) compilationPath = Some(new Path(getProject()))
compilationPath.get.createPath()
}
def setCompilationPathRef(input: Reference) {
createCompilationPath.setRefid(input)
}
}
trait TaskArgs extends CompilationPathProperty {
this: Task =>
def setId(input: String) {
id = Some(input)
@ -31,20 +52,6 @@ trait TaskArgs { this: Task =>
compTarget = Some(input)
}
def setCompilationPath(input: Path) {
if (compilationPath.isEmpty) compilationPath = Some(input)
else compilationPath.get.append(input)
}
def createCompilationPath: Path = {
if (compilationPath.isEmpty) compilationPath = Some(new Path(getProject()))
compilationPath.get.createPath()
}
def setCompilationPathRef(input: Reference) {
createCompilationPath.setRefid(input)
}
def setSrcPath(input: Path) {
if (sourcePath.isEmpty) sourcePath = Some(input)
else sourcePath.get.append(input)
@ -80,7 +87,6 @@ trait TaskArgs { this: Task =>
protected var id: Option[String] = None
protected var params: Option[String] = None
protected var compTarget: Option[String] = None
protected var compilationPath: Option[Path] = None
protected var sourcePath: Option[Path] = None
protected var compilerPath: Option[Path] = None
protected var destinationDir: Option[File] = None

View File

@ -18,6 +18,7 @@ import io.{ Directory }
import nsc.Settings
import nsc.util.ClassPath
import util.PathResolver
import scala.tools.ant.sabbus.CompilationPathProperty
import java.io.File
import java.net.URLClassLoader
@ -26,7 +27,7 @@ import java.lang.reflect.Method
import org.apache.tools.ant.Task
import org.apache.tools.ant.types.{Path, Reference, FileSet}
class PartestTask extends Task {
class PartestTask extends Task with CompilationPathProperty {
def addConfiguredPosTests(input: FileSet) {
posFiles = Some(input)
@ -174,23 +175,11 @@ class PartestTask extends Task {
private def getShootoutFiles = getFiles(shootoutFiles)
private def getScalapFiles = getFiles(scalapFiles)
private def findMethod(target: AnyRef, name: String, types: Class[_]*): Method =
target.getClass.getMethod(name, Array(types: _*): _*)
private def invokeMethod[T](target: AnyRef, m: Method, args: AnyRef*): T =
m.invoke(target, args: _*).asInstanceOf[T]
private def invoke[T](target: AnyRef, name: String, args: Any*): T = {
val boxed = args map (_.asInstanceOf[AnyRef])
val m = findMethod(target, name, boxed map (_.getClass): _*)
invokeMethod[T](target, m, boxed: _*)
}
override def execute() {
if (isPartestDebug)
setProp("partest.debug", "true")
val classpath = this.classpath getOrElse error("Mandatory attribute 'classpath' is not set.")
val classpath = this.compilationPath getOrElse error("Mandatory attribute 'compilationPath' is not set.")
val scalaLibrary = {
(classpath.list map { fs => new File(fs) }) find { f =>
@ -202,36 +191,19 @@ class PartestTask extends Task {
}
} getOrElse error("Provided classpath does not contain a Scala library.")
val classloader = this.getClass.getClassLoader
def load(name: String) = classloader.loadClass(name).newInstance().asInstanceOf[AnyRef]
val antRunner = new scala.tools.partest.nest.AntRunner
val antFileManager = antRunner.fileManager
val antRunner = load("scala.tools.partest.nest.AntRunner")
val antFileManager = invoke[AnyRef](antRunner, "fileManager")
val runMethod = findMethod(antRunner, "reflectiveRunTestsForFiles", classOf[Array[File]], classOf[String])
antFileManager.showDiff = showDiff
antFileManager.showLog = showLog
antFileManager.failed = runFailed
antFileManager.CLASSPATH = ClassPath.join(classpath.list: _*)
antFileManager.LATEST_LIB = scalaLibrary.getAbsolutePath
def runTestsForFiles(kindFiles: Array[File], kind: String) =
invokeMethod[Map[String, Int]](antRunner, runMethod, kindFiles, kind)
def setFileManagerBooleanProperty(name: String, value: Boolean) {
val setMethod = findMethod(antFileManager, name + "_$eq", classOf[Boolean])
invokeMethod[Unit](antFileManager, setMethod, Boolean.box(value))
}
def setFileManagerStringProperty(name: String, value: String) {
val setMethod = findMethod(antFileManager, name + "_$eq", classOf[String])
invokeMethod[Unit](antFileManager, setMethod, value)
}
setFileManagerBooleanProperty("showDiff", showDiff)
setFileManagerBooleanProperty("showLog", showLog)
setFileManagerBooleanProperty("failed", runFailed)
setFileManagerStringProperty("CLASSPATH", ClassPath.join(classpath.list: _*))
setFileManagerStringProperty("LATEST_LIB", scalaLibrary.getAbsolutePath)
javacmd foreach (x => setFileManagerStringProperty("JAVACMD", x.getAbsolutePath))
javaccmd foreach (x => setFileManagerStringProperty("JAVAC_CMD", x.getAbsolutePath))
scalacOpts foreach (x => setFileManagerStringProperty("SCALAC_OPTS", x))
timeout foreach (x => setFileManagerStringProperty("timeout", x))
javacmd foreach (x => antFileManager.JAVACMD = x.getAbsolutePath)
javaccmd foreach (x => antFileManager.JAVAC_CMD = x.getAbsolutePath)
scalacOpts foreach (antFileManager.SCALAC_OPTS = _)
timeout foreach (antFileManager.timeout = _)
type TFSet = (Array[File], String, String)
val testFileSets = List(
@ -252,7 +224,7 @@ class PartestTask extends Task {
if (files.isEmpty) (0, 0, List())
else {
log(msg)
val results: Iterable[(String, Int)] = runTestsForFiles(files, name)
val results: Iterable[(String, Int)] = antRunner.reflectiveRunTestsForFiles(files, name)
val (succs, fails) = resultsToStatistics(results)
val failed: Iterable[String] = results partialMap {