playpants.tool.PlayDev.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of play-pants-tool Show documentation
Show all versions of play-pants-tool Show documentation
Runtime tool for play-pants.
package playpants.tool
import java.io.File
import java.lang.reflect.Method
import java.{util => ju}
import play.core.{BuildDocHandler, BuildLink}
import playpants.tool.PlayDev.Params
import scala.collection.JavaConverters._
class PantsBuildLink(params: Params) extends BuildLink {
private var firstTime = true
override def runTask(s: String): AnyRef = ???
override def reload(): AnyRef = {
if (firstTime) {
firstTime = false
getClass.getClassLoader
} else null
}
override def projectPath(): File = params.projectPath
override def settings(): ju.Map[String, String] = params.settings.asJava
override def forceReload(): Unit = ???
override def findSource(s: String, integer: Integer): Array[AnyRef] = {
println(s"Find source: $s:$integer")
Array.empty[AnyRef]
}
}
object PantsDocHandler extends BuildDocHandler {
override def maybeHandleDocRequest(request: scala.Any): AnyRef = None
}
object PlayDev {
case class Params(
projectPath: File = new File("."),
port: Int = 9000,
address: String = "127.0.0.1",
settings: Map[String, String] = Map.empty)
val parser = new scopt.OptionParser[Params]("routes-gen") {
head("routes-gen", "1.0")
opt[File]("projectPath") required() valueName("") action {
(x, c) => c.copy(projectPath = x)
} text("Path for root of project")
opt[Map[String, String]]("settings") valueName("") action {
(x, c) => c.copy(settings = x)
} text("Settings, comma seperate key=value pairs")
opt[String]("address") valueName("") action {
(x, c) => c.copy(address = x)
} text("Address to bind")
opt[Int]("port") valueName("") action {
(x, c) => c.copy(port = x)
} text("Port to bind")
}
def main(args: Array[String]): Unit = {
parser.parse(args, Params()) match {
case None => System.exit(1)
case Some(params) =>
val mainClass = Class.forName("play.core.server.DevServerStart")
val mainDev: Method = mainClass.getMethod("mainDevHttpMode", classOf[BuildLink], classOf[BuildDocHandler], classOf[Int], classOf[String])
mainDev.invoke(null, new PantsBuildLink(params), PantsDocHandler, params.port: java.lang.Integer, params.address)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy