aboutsummaryrefslogtreecommitdiff
path: root/stage1/Stage1Lib.scala
diff options
context:
space:
mode:
Diffstat (limited to 'stage1/Stage1Lib.scala')
-rw-r--r--stage1/Stage1Lib.scala93
1 files changed, 0 insertions, 93 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala
index 40b3fed..ab95a41 100644
--- a/stage1/Stage1Lib.scala
+++ b/stage1/Stage1Lib.scala
@@ -432,99 +432,6 @@ ${sourceFiles.sorted.mkString(" \\\n")}
outputLastModified
)
}
-
- def asyncPipeCharacterStreamSyncLines( inputStream: InputStream, outputStream: OutputStream, lock: AnyRef ): Thread = {
- new Thread(
- new Runnable{
- def run = {
- val b = new BufferedInputStream( inputStream )
- Iterator.continually{
- b.read // block until and read next character
- }.takeWhile(_ != -1).map{ c =>
- lock.synchronized{ // synchronize with other invocations
- outputStream.write(c)
- Iterator
- .continually( b.read )
- .takeWhile( _ != -1 )
- .map{ c =>
- try{
- outputStream.write(c)
- outputStream.flush
- (
- c != '\n' // release lock when new line was encountered, allowing other writers to slip in
- && b.available > 0 // also release when nothing is available to not block other outputs
- )
- } catch {
- case e: IOException if e.getMessage == "Stream closed" => false
- }
- }
- .takeWhile(identity)
- .length // force entire iterator
- }
- }.length // force entire iterator
- }
- }
- )
- }
-
- def asyncPipeCharacterStream( inputStream: InputStream, outputStream: OutputStream, continue: => Boolean ) = {
- new Thread(
- new Runnable{
- def run = {
- Iterator
- .continually{ inputStream.read }
- .takeWhile(_ != -1)
- .map{ c =>
- try{
- outputStream.write(c)
- outputStream.flush
- true
- } catch {
- case e: IOException if e.getMessage == "Stream closed" => false
- }
- }
- .takeWhile( identity )
- .takeWhile( _ => continue )
- .length // force entire iterator
- }
- }
- )
- }
-
- def runWithIO( commandLine: Seq[String], directory: Option[File] = None ): ExitCode = {
- val (out,err,in) = lib.getOutErrIn match { case (l,r, in) => (l.get,r.get, in) }
- val pb = new ProcessBuilder( commandLine: _* )
- val exitCode =
- if( !NailgunLauncher.runningViaNailgun ){
- pb.inheritIO.start.waitFor
- } else {
- val process = directory.map( pb.directory( _ ) ).getOrElse( pb )
- .redirectInput(ProcessBuilder.Redirect.PIPE)
- .redirectOutput(ProcessBuilder.Redirect.PIPE)
- .redirectError(ProcessBuilder.Redirect.PIPE)
- .start
-
- val lock = new AnyRef
-
- val t1 = lib.asyncPipeCharacterStreamSyncLines( process.getErrorStream, err, lock )
- val t2 = lib.asyncPipeCharacterStreamSyncLines( process.getInputStream, out, lock )
- val t3 = lib.asyncPipeCharacterStream( System.in, process.getOutputStream, process.isAlive )
-
- t1.start
- t2.start
- t3.start
-
- t1.join
- t2.join
-
- val e = process.waitFor
- System.err.println( scala.Console.RESET + "Please press ENTER to continue..." )
- t3.join
- e
- }
-
- ExitCode( exitCode )
- }
}
import scala.reflect._