diff options
author | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-01-09 18:11:10 +0100 |
---|---|---|
committer | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-01-09 18:11:10 +0100 |
commit | 1126912bce5d098571c1bd29a04e4781e19c3d85 (patch) | |
tree | 79e753014c1adfa26e39e32911125bfc0ad8ee4c /project/VerifyClassLoad.scala | |
parent | 5a4b555c378d79d57b59dfd6edafd2b9a59866bb (diff) | |
parent | 820491ed6376e9f8f8a8102387495113dce55444 (diff) | |
download | scala-1126912bce5d098571c1bd29a04e4781e19c3d85.tar.gz scala-1126912bce5d098571c1bd29a04e4781e19c3d85.tar.bz2 scala-1126912bce5d098571c1bd29a04e4781e19c3d85.zip |
Merge branch 'master' into execution-context
Diffstat (limited to 'project/VerifyClassLoad.scala')
-rw-r--r-- | project/VerifyClassLoad.scala | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/project/VerifyClassLoad.scala b/project/VerifyClassLoad.scala new file mode 100644 index 0000000000..c8eebb1159 --- /dev/null +++ b/project/VerifyClassLoad.scala @@ -0,0 +1,46 @@ +import sbt._ + +import Build._ +import Keys._ + +// This is helper code to validate that generated class files will succed in bytecode verification at class-load time. +object VerifyClassLoad { + lazy val checkClassLoad: TaskKey[Unit] = TaskKey("check-class-load", "checks whether or not the class files generated by scala are deemed acceptable by classloaders.") + lazy val checkClassRunner: TaskKey[ClassVerifyRunner] = TaskKey("check-class-runner", "A wrapper around reflective calls to the VerifyClass class.") + + + def settings: Seq[Setting[_]] = Seq( + checkClassRunner <<= (fullClasspath in Runtime) map (cp => new ClassVerifyRunner(data(cp))), + fullClasspath in checkClassLoad := Seq(), + checkClassLoad <<= (checkClassRunner, fullClasspath in checkClassLoad, streams) map { (runner, dirs, s) => + import collection.JavaConverters._ + val results = runner.run(data(dirs).map(_.getAbsolutePath).toArray).asScala + + s.log.info("Processed " + results.size + " classes.") + val errors = results.filter(_._2 != null) + for( (name, result) <- results; if result != null) { + s.log.error(name + " had error: " + result) + } + if(errors.size > 0) error("Classload validation errors encountered") + () + } + ) + + // TODO - Use + class ClassVerifyRunner(classpath: Seq[File]) { + // Classloader that does *not* have this as parent, for differing Scala version. + lazy val classLoader = new java.net.URLClassLoader(classpath.map(_.toURI.toURL).toArray, null) + lazy val (mainClass, mainMethod) = try { + val c = classLoader.loadClass("scala.tools.util.VerifyClass") + val m = c.getMethod("run", classOf[Array[String]]) + (c,m) + } + def run(args: Array[String]): java.util.Map[String,String] = try { + mainMethod.invoke(null, args).asInstanceOf[java.util.Map[String,String]] + } catch { + case e => + //error("Could not run Partest: " + e) + throw e + } + } +} |