diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-09-20 14:15:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-20 14:15:50 +0800 |
commit | d551ee9d751201491a1d64e4da76ab03e3815df6 (patch) | |
tree | 60471609f0957401fa1a7002578ad8c1acd6bc75 /main/core/src | |
parent | c8fd6bd9e1dc18c24e64147fcd221e0bf91c2d06 (diff) | |
download | mill-d551ee9d751201491a1d64e4da76ab03e3815df6.tar.gz mill-d551ee9d751201491a1d64e4da76ab03e3815df6.tar.bz2 mill-d551ee9d751201491a1d64e4da76ab03e3815df6.zip |
Include scaladoc as part of mill inspect (#435)
Diffstat (limited to 'main/core/src')
-rw-r--r-- | main/core/src/mill/define/BaseModule.scala | 10 | ||||
-rw-r--r-- | main/core/src/mill/define/Caller.scala | 13 | ||||
-rw-r--r-- | main/core/src/mill/define/Ctx.scala | 9 | ||||
-rw-r--r-- | main/core/src/mill/define/Task.scala | 9 | ||||
-rw-r--r-- | main/core/src/mill/util/ClassLoader.scala | 36 |
5 files changed, 47 insertions, 30 deletions
diff --git a/main/core/src/mill/define/BaseModule.scala b/main/core/src/mill/define/BaseModule.scala index 70826be7..03bdeccc 100644 --- a/main/core/src/mill/define/BaseModule.scala +++ b/main/core/src/mill/define/BaseModule.scala @@ -12,7 +12,8 @@ abstract class BaseModule(millSourcePath0: Path, (implicit millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, millName0: sourcecode.Name, - millFile0: sourcecode.File) + millFile0: sourcecode.File, + caller: Caller) extends Module()( mill.define.Ctx.make( implicitly, @@ -23,7 +24,8 @@ abstract class BaseModule(millSourcePath0: Path, mill.util.Router.Overrides(0), Ctx.External(external0), Ctx.Foreign(foreign0), - millFile0 + millFile0, + caller ) ){ // A BaseModule should provide an empty Segments list to it's children, since @@ -40,7 +42,9 @@ abstract class BaseModule(millSourcePath0: Path, abstract class ExternalModule(implicit millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, millName0: sourcecode.Name) - extends BaseModule(ammonite.ops.pwd, external0 = true, foreign0 = false){ + extends BaseModule(ammonite.ops.pwd, external0 = true, foreign0 = false)( + implicitly, implicitly, implicitly, implicitly, Caller(()) + ){ implicit def millDiscoverImplicit: Discover[_] = millDiscover assert( diff --git a/main/core/src/mill/define/Caller.scala b/main/core/src/mill/define/Caller.scala new file mode 100644 index 00000000..6d2d4d1d --- /dev/null +++ b/main/core/src/mill/define/Caller.scala @@ -0,0 +1,13 @@ +package mill.define + +import sourcecode.Compat.Context +import language.experimental.macros +case class Caller(value: Any) +object Caller { + def apply()(implicit c: Caller) = c.value + implicit def generate: Caller = macro impl + def impl(c: Context): c.Tree = { + import c.universe._ + q"new _root_.mill.define.Caller(this)" + } +}
\ No newline at end of file diff --git a/main/core/src/mill/define/Ctx.scala b/main/core/src/mill/define/Ctx.scala index fb15dc19..ba4fae9e 100644 --- a/main/core/src/mill/define/Ctx.scala +++ b/main/core/src/mill/define/Ctx.scala @@ -69,7 +69,8 @@ case class Ctx(enclosing: String, overrides: Int, external: Boolean, foreign: Boolean, - fileName: String){ + fileName: String, + enclosingCls: Class[_]){ } object Ctx{ @@ -83,7 +84,8 @@ object Ctx{ overrides0: mill.util.Router.Overrides, external0: External, foreign0: Foreign, - fileName: sourcecode.File): Ctx = { + fileName: sourcecode.File, + enclosing: Caller): Ctx = { Ctx( millModuleEnclosing0.value, millModuleLine0.value, @@ -93,7 +95,8 @@ object Ctx{ overrides0.value, external0.value, foreign0.value, - fileName.value + fileName.value, + enclosing.value.getClass ) } } diff --git a/main/core/src/mill/define/Task.scala b/main/core/src/mill/define/Task.scala index d5f8680e..64e868f8 100644 --- a/main/core/src/mill/define/Task.scala +++ b/main/core/src/mill/define/Task.scala @@ -254,15 +254,6 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul def zip[A, B](a: Task[A], b: Task[B]) = a.zip(b) } -case class Caller[A](value: A) -object Caller { - def apply[T]()(implicit c: Caller[T]) = c.value - implicit def generate[T]: Caller[T] = macro impl[T] - def impl[T: c.WeakTypeTag](c: Context): c.Tree = { - import c.universe._ - q"new _root_.mill.define.Caller[${weakTypeOf[T]}](this)" - } -} abstract class NamedTaskImpl[+T](ctx0: mill.define.Ctx, t: Task[T]) extends NamedTask[T]{ def evaluate(args: mill.util.Ctx) = args[T](0) val ctx = ctx0.copy(segments = ctx0.segments ++ Seq(ctx0.segment)) diff --git a/main/core/src/mill/util/ClassLoader.scala b/main/core/src/mill/util/ClassLoader.scala index 17268fb0..ebe8e50b 100644 --- a/main/core/src/mill/util/ClassLoader.scala +++ b/main/core/src/mill/util/ClassLoader.scala @@ -5,15 +5,18 @@ import java.net.{URL, URLClassLoader} import ammonite.ops._ import io.github.retronym.java9rtexport.Export -object ClassLoader { - - def create(urls: Seq[URL], parent: java.lang.ClassLoader)( - implicit ctx: Ctx.Home): URLClassLoader = create(urls, parent, _ => None) +import scala.util.Try +object ClassLoader { + def create(urls: Seq[URL], + parent: java.lang.ClassLoader) + (implicit ctx: Ctx.Home): URLClassLoader = { + create(urls, parent, _ => None) + } def create(urls: Seq[URL], parent: java.lang.ClassLoader, - customFindClass: String => Option[Class[_]])( - implicit ctx: Ctx.Home): URLClassLoader = { + customFindClass: String => Option[Class[_]]) + (implicit ctx: Ctx.Home): URLClassLoader = { new URLClassLoader( makeUrls(urls).toArray, refinePlatformParent(parent) @@ -25,6 +28,7 @@ object ClassLoader { } } + /** * Return `ClassLoader.getPlatformClassLoader` for java 9 and above, if parent class loader is null, * otherwise return same parent class loader. @@ -34,15 +38,17 @@ object ClassLoader { * mill could be compiled only with jdk 9 or above. We don't want to introduce this restriction now. */ private def refinePlatformParent(parent: java.lang.ClassLoader): ClassLoader = { - if (ammonite.util.Util.java9OrAbove) { - if (parent == null) - classOf[ClassLoader] - .getMethod("getPlatformClassLoader") - .invoke(null) - .asInstanceOf[ClassLoader] - else parent - } else { - parent + if (!ammonite.util.Util.java9OrAbove || parent != null) parent + else { + // Make sure when `parent == null`, we only delegate java.* classes + // to the parent getPlatformClassLoader. This is necessary because + // in Java 9+, somehow the getPlatformClassLoader ends up with all + // sorts of other non-java stuff on it's classpath, which is not what + // we want for an "isolated" classloader! + classOf[ClassLoader] + .getMethod("getPlatformClassLoader") + .invoke(null) + .asInstanceOf[ClassLoader] } } |