Cleanup runProj

This commit is contained in:
Dale Wijnand 2016-06-18 01:19:50 +02:00
parent 954b74654f
commit 8226ed7682
4 changed files with 6 additions and 98 deletions

View File

@ -9,22 +9,6 @@ import java.util.Locale
import sbt.util.Logger
import scala.sys.process.{ Process, ProcessBuilder }
@deprecated("Use ForkOptions", "0.13.0")
trait ForkJava {
def javaHome: Option[File]
def outputStrategy: Option[OutputStrategy]
def connectInput: Boolean
}
@deprecated("Use ForkOptions", "0.13.0")
trait ForkScala extends ForkJava {
def scalaJars: Iterable[File]
}
@deprecated("Use ForkOptions", "0.13.0")
trait ForkScalaRun extends ForkScala {
def workingDirectory: Option[File]
def runJVMOptions: Seq[String]
}
/**
* Configures forking.
*
@ -36,10 +20,7 @@ trait ForkScalaRun extends ForkScala {
* @param connectInput If true, the standard input of the forked process is connected to the standard input of this process. Otherwise, it is connected to an empty input stream. Connecting input streams can be problematic, especially on versions before Java 7.
* @param envVars The environment variables to provide to the forked process. By default, none are provided.
*/
final case class ForkOptions(javaHome: Option[File] = None, outputStrategy: Option[OutputStrategy] = None, bootJars: Seq[File] = Nil, workingDirectory: Option[File] = None, runJVMOptions: Seq[String] = Nil, connectInput: Boolean = false, envVars: Map[String, String] = Map.empty) extends ForkScalaRun {
@deprecated("Use bootJars.", "0.13.0")
def scalaJars: Iterable[File] = bootJars
}
final case class ForkOptions(javaHome: Option[File] = None, outputStrategy: Option[OutputStrategy] = None, bootJars: Seq[File] = Nil, workingDirectory: Option[File] = None, runJVMOptions: Seq[String] = Nil, connectInput: Boolean = false, envVars: Map[String, String] = Map.empty)
/** Configures where the standard output and error streams from a forked process go.*/
sealed abstract class OutputStrategy
@ -73,7 +54,7 @@ import java.lang.{ ProcessBuilder => JProcessBuilder }
* @param commandName The java-like binary to fork. This is expected to exist in bin/ of the Java home directory.
* @param runnerClass If Some, this will be prepended to the `arguments` passed to the `apply` or `fork` methods.
*/
sealed class Fork(val commandName: String, val runnerClass: Option[String]) {
final class Fork(val commandName: String, val runnerClass: Option[String]) {
/**
* Forks the configured process, waits for it to complete, and returns the exit code.
* The command executed is the `commandName` defined for this Fork instance.
@ -121,8 +102,8 @@ object Fork {
private val ScalaMainClass = "scala.tools.nsc.MainGenericRunner"
private val JavaCommandName = "java"
val java = new ForkJava(JavaCommandName)
val javac = new ForkJava("javac")
val java = new Fork(JavaCommandName, None)
val javac = new Fork("javac", None)
val scala = new Fork(JavaCommandName, Some(ScalaMainClass))
val scalac = new Fork(JavaCommandName, Some(ScalacMainClass))
@ -156,74 +137,4 @@ object Fork {
val home = javaHome.getOrElse(new File(System.getProperty("java.home")))
new File(new File(home, "bin"), name)
}
@deprecated("Use Fork", "0.13.0")
final class ForkJava(commandName: String) extends Fork(commandName, None) {
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def apply(javaHome: Option[File], options: Seq[String], log: Logger): Int =
apply(javaHome, options, BufferedOutput(log))
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def apply(javaHome: Option[File], options: Seq[String], outputStrategy: OutputStrategy): Int =
apply(javaHome, options, None, outputStrategy)
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def apply(javaHome: Option[File], options: Seq[String], workingDirectory: Option[File], log: Logger): Int =
apply(javaHome, options, workingDirectory, BufferedOutput(log))
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def apply(javaHome: Option[File], options: Seq[String], workingDirectory: Option[File], outputStrategy: OutputStrategy): Int =
apply(javaHome, options, workingDirectory, Map.empty, outputStrategy)
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def apply(javaHome: Option[File], options: Seq[String], workingDirectory: Option[File], env: Map[String, String], outputStrategy: OutputStrategy): Int =
fork(javaHome, options, workingDirectory, env, false, outputStrategy).exitValue
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def fork(javaHome: Option[File], options: Seq[String], workingDirectory: Option[File], env: Map[String, String], connectInput: Boolean, outputStrategy: OutputStrategy): Process =
{
val executable = javaCommand(javaHome, commandName).getAbsolutePath
val command = (executable :: options.toList).toArray
val builder = new JProcessBuilder(command: _*)
workingDirectory.foreach(wd => builder.directory(wd))
val environment = builder.environment
for ((key, value) <- env)
environment.put(key, value)
outputStrategy match {
case StdoutOutput => Process(builder).run(connectInput)
case BufferedOutput(logger) => logger.buffer { Process(builder).run(logger, connectInput) }
case LoggedOutput(logger) => Process(builder).run(logger, connectInput)
case CustomOutput(output) => (Process(builder) #> output).run(connectInput)
}
}
}
@deprecated("Use Fork", "0.13.0")
final class ForkScala(mainClassName: String) {
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def apply(javaHome: Option[File], jvmOptions: Seq[String], scalaJars: Iterable[File], arguments: Seq[String], log: Logger): Int =
apply(javaHome, jvmOptions, scalaJars, arguments, None, BufferedOutput(log))
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def apply(javaHome: Option[File], jvmOptions: Seq[String], scalaJars: Iterable[File], arguments: Seq[String], workingDirectory: Option[File], log: Logger): Int =
apply(javaHome, jvmOptions, scalaJars, arguments, workingDirectory, BufferedOutput(log))
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def apply(javaHome: Option[File], jvmOptions: Seq[String], scalaJars: Iterable[File], arguments: Seq[String], workingDirectory: Option[File], outputStrategy: OutputStrategy): Int =
fork(javaHome, jvmOptions, scalaJars, arguments, workingDirectory, false, outputStrategy).exitValue()
@deprecated("Use fork(ForkOptions, Seq[String])", "0.13.0")
def fork(javaHome: Option[File], jvmOptions: Seq[String], scalaJars: Iterable[File], arguments: Seq[String], workingDirectory: Option[File], connectInput: Boolean, outputStrategy: OutputStrategy): Process =
fork(javaHome, jvmOptions, scalaJars, arguments, workingDirectory, Map.empty, connectInput, outputStrategy)
@deprecated("Use apply(ForkOptions, Seq[String])", "0.13.0")
def fork(javaHome: Option[File], jvmOptions: Seq[String], scalaJars: Iterable[File], arguments: Seq[String], workingDirectory: Option[File], env: Map[String, String], connectInput: Boolean, outputStrategy: OutputStrategy): Process =
{
if (scalaJars.isEmpty) sys.error("Scala jars not specified")
val scalaClasspathString = "-Xbootclasspath/a:" + scalaJars.map(_.getAbsolutePath).mkString(File.pathSeparator)
val mainClass = if (mainClassName.isEmpty) Nil else mainClassName :: Nil
val options = jvmOptions ++ (scalaClasspathString :: mainClass ::: arguments.toList)
Fork.java.fork(javaHome, options, workingDirectory, env, connectInput, outputStrategy)
}
}
}

View File

@ -18,9 +18,6 @@ trait ScalaRun {
def run(mainClass: String, classpath: Seq[File], options: Seq[String], log: Logger): Option[String]
}
class ForkRun(config: ForkOptions) extends ScalaRun {
@deprecated("Use the `ForkRun(ForkOptions) constructor`", "0.13.0")
def this(options: ForkScalaRun) = this(ForkOptions(options.javaHome, options.outputStrategy, options.scalaJars.toSeq, options.workingDirectory, options.runJVMOptions, options.connectInput))
def run(mainClass: String, classpath: Seq[File], options: Seq[String], log: Logger): Option[String] =
{
log.info("Running " + mainClass + " " + options.mkString(" "))

View File

@ -485,7 +485,7 @@ private final class TrapExit(delegateManager: SecurityManager) extends SecurityM
allFrames.foreach(_.dispose) // dispose all top-level windows, which will cause the AWT-EventQueue-* threads to exit
val waitSeconds = 2
log.debug(s"Waiting $waitSeconds s to let AWT thread exit.")
Thread.sleep(waitSeconds * 1000) // AWT Thread doesn't exit immediately, so wait to interrupt it
Thread.sleep(waitSeconds * 1000L) // AWT Thread doesn't exit immediately, so wait to interrupt it
}
}
/** Returns true if the given thread is in the 'system' thread group or is an AWT thread other than AWT-EventQueue.*/

View File

@ -51,7 +51,7 @@ object ForkTest extends Properties("Fork") {
private[this] def trimClasspath(cp: String): String =
if (cp.length > MaximumClasspathLength) {
val lastEntryI = cp.lastIndexOf(File.pathSeparatorChar, MaximumClasspathLength)
val lastEntryI = cp.lastIndexOf(File.pathSeparatorChar.toInt, MaximumClasspathLength)
if (lastEntryI > 0)
cp.substring(0, lastEntryI)
else