erAgent.mill-jib-docker_2.12.0.1.0.source-code.JibDockerWorker.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mill-jib-docker_2.12 Show documentation
Show all versions of mill-jib-docker_2.12 Show documentation
Dockerize java applications on Mill builds
The newest version!
package mill.jib.docker
import mill.api.{ClassLoader, Ctx}
import mill.define.{Discover, ExternalModule, Worker}
import mill.{Agg, T}
class JibDockerWorker {
private var jibDockerInstanceCache = Option.empty[(Long, api.JibDockerWorkerApi)]
def bridge(classpath: Agg[os.Path])(implicit ctx: Ctx) = {
val classloaderSig =
classpath.map(p => p.toString().hashCode + os.mtime(p)).sum
jibDockerInstanceCache match {
case Some((sig, bridge)) if sig == classloaderSig => bridge
case _ =>
val toolsClassPath = classpath.map(_.toIO.toURI.toURL).toVector
ctx.log.debug("Loading classes from\n"+toolsClassPath.mkString("\n"))
val cl = ClassLoader.create(
toolsClassPath,
getClass.getClassLoader
)
val bridge = cl
.loadClass("mill.jib.docker.worker.JibDockerWorkerImpl")
.getDeclaredConstructor()
.newInstance()
.asInstanceOf[api.JibDockerWorkerApi]
jibDockerInstanceCache = Some((classloaderSig, bridge))
bridge
}
}
}
object JibDockerWorkerApi extends ExternalModule {
def jibDockerWorker: Worker[JibDockerWorker] = T.worker { new JibDockerWorker() }
lazy val millDiscover = Discover[this.type]
}