diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-11 07:26:09 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-11 07:37:28 -0800 |
commit | efbaf34d7d977a13a083638426b86f5a2218eceb (patch) | |
tree | db3971c665693a8f024c1a50350b5052e56c0e61 /scalaplugin | |
parent | 337508c82cbe598b8796fc532cd92e8230b099cb (diff) | |
download | mill-efbaf34d7d977a13a083638426b86f5a2218eceb.tar.gz mill-efbaf34d7d977a13a083638426b86f5a2218eceb.tar.bz2 mill-efbaf34d7d977a13a083638426b86f5a2218eceb.zip |
First sketch at SBT test integration works
Diffstat (limited to 'scalaplugin')
-rw-r--r-- | scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala b/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala index 59538a69..f30e74d2 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala @@ -2,8 +2,10 @@ package mill package scalaplugin import java.io.File +import java.lang.annotation.Annotation +import java.net.URLClassLoader -import ammonite.ops.{Path, ls, mkdir, pwd} +import ammonite.ops.{Path, ls, mkdir, pwd, up} import coursier.{Cache, Dependency, Fetch, MavenRepository, Module, Repository, Resolution} import mill.define.Task import mill.define.Task.Cacher @@ -12,11 +14,39 @@ import mill.util.Args import play.api.libs.json._ import sbt.internal.inc.{FreshCompilerCache, ScalaInstance, ZincUtil} import sbt.internal.util.{ConsoleOut, MainAppender} +import sbt.testing.{AnnotatedFingerprint, SubclassFingerprint} import sbt.util.LogExchange import xsbti.api.{ClassLike, DependencyContext} import xsbti.compile.DependencyChanges + + object Subproject{ + def runTests(frameworkName: String, + testClassloader: URLClassLoader) = { + val framework = Class.forName(frameworkName) + .newInstance() + .asInstanceOf[sbt.testing.Framework] + + val fingerprints = framework.fingerprints() + val testClasses = for{ + url <- testClassloader.getURLs + path <- ls.rec(ammonite.ops.Path(url.getFile)).toIterator + if path.ext == "class" + className = (path/up/path.last.stripSuffix(".class")).segments.mkString(".") + cls = testClassloader.loadClass(className) + if fingerprints.exists{ + case f: SubclassFingerprint => + cls.isAssignableFrom(cls) + case f: AnnotatedFingerprint => + cls.isAnnotationPresent( + Class.forName(f.annotationName()).asInstanceOf[Class[Annotation]] + ) + } + } yield cls + + + } def compileScala(scalaVersion: String, sources: PathRef, compileClasspath: Seq[PathRef], |