All Downloads are FREE. Search and download functionalities are using the official Maven repository.

erAgent.mill-jib-docker_2.12.0.1.0.source-code.JibDockerWorker.scala Maven / Gradle / Ivy

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]
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy