mirror of https://github.com/sbt/sbt.git
Remove duped system in
I had some ideas for allowing the user to get a copy of system in during a continuous build but I can't really see a good use case now so I'm going to remove it before 1.3.0.
This commit is contained in:
parent
72df8f674c
commit
2d1c80f916
|
|
@ -79,21 +79,6 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
val inputs: Seq[DynamicInput]
|
||||
)
|
||||
|
||||
/**
|
||||
* Provides a copy of System.in that can be scanned independently from System.in itself. This task
|
||||
* will only be valid during a continuous build started via `~` or the `watch` task. The
|
||||
* motivation is that a plugin may want to completely override the parsing of System.in which
|
||||
* is not straightforward since the default implementation is hard-wired to read from and
|
||||
* parse System.in. If an invalid parser is provided by [[Keys.watchInputParser]] and
|
||||
* [[Keys.watchInputStream]] is set to this task, then a custom parser can be provided via
|
||||
* [[Keys.watchInputHandler]] and the default System.in processing will not occur.
|
||||
*
|
||||
* @return the duplicated System.in
|
||||
*/
|
||||
def dupedSystemIn: Def.Initialize[Task[InputStream]] = Def.task {
|
||||
Keys.state.value.get(DupedSystemIn).map(_.duped).getOrElse(System.in)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a function from InputStream => [[Watch.Action]] from a [[Parser]]. This is intended
|
||||
* to be used to set the watchInputHandler setting for a task.
|
||||
|
|
@ -136,12 +121,6 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
)
|
||||
}
|
||||
|
||||
private[this] val DupedSystemIn =
|
||||
AttributeKey[DupedInputStream](
|
||||
"duped-system-in",
|
||||
"Receives a copy of all of the bytes from System.in.",
|
||||
10000
|
||||
)
|
||||
private[sbt] val dynamicInputs = taskKey[Option[mutable.Set[DynamicInput]]](
|
||||
"The input globs found during task evaluation that are used in watch."
|
||||
)
|
||||
|
|
@ -298,7 +277,6 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
count: Int,
|
||||
isCommand: Boolean
|
||||
): State = withCharBufferedStdIn { in =>
|
||||
val duped = new DupedInputStream(in)
|
||||
implicit val extracted: Extracted = Project.extract(state)
|
||||
val repo = if ("polling" == System.getProperty("sbt.watch.mode")) {
|
||||
val service =
|
||||
|
|
@ -311,7 +289,6 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
val stateWithRepo = state
|
||||
.put(Keys.globalFileTreeRepository, repo)
|
||||
.put(sbt.nio.Keys.persistentFileAttributeMap, new sbt.nio.Keys.FileAttributeMap)
|
||||
.put(DupedSystemIn, duped)
|
||||
setup(stateWithRepo, command) { (commands, s, valid, invalid) =>
|
||||
EvaluateTask.withStreams(extracted.structure, s)(_.use(Keys.streams in Global) { streams =>
|
||||
implicit val logger: Logger = streams.log
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* sbt
|
||||
* Copyright 2011 - 2018, Lightbend, Inc.
|
||||
* Copyright 2008 - 2010, Mark Harrah
|
||||
* Licensed under Apache License 2.0 (see LICENSE)
|
||||
*/
|
||||
|
||||
package sbt.internal
|
||||
|
||||
import java.io.{ InputStream, PipedInputStream, PipedOutputStream }
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
/**
|
||||
* Creates a copy of the provided [[InputStream]] that forwards its contents to an arbitrary
|
||||
* number of connected [[InputStream]] instances via pipe.
|
||||
* @param in the [[InputStream]] to wrap.
|
||||
*/
|
||||
private[internal] class DupedInputStream(val in: InputStream)
|
||||
extends InputStream
|
||||
with AutoCloseable {
|
||||
|
||||
/**
|
||||
* Returns a copied [[InputStream]] that will receive the same bytes as System.in.
|
||||
* @return
|
||||
*/
|
||||
def duped: InputStream = {
|
||||
val pipedOutputStream = new PipedOutputStream()
|
||||
pipes += pipedOutputStream
|
||||
val res = new PollingInputStream(new PipedInputStream(pipedOutputStream))
|
||||
buffer.forEach(pipedOutputStream.write(_))
|
||||
res
|
||||
}
|
||||
|
||||
private[this] val pipes = new java.util.Vector[PipedOutputStream].asScala
|
||||
private[this] val buffer = new LinkedBlockingQueue[Int]
|
||||
private class PollingInputStream(val pipedInputStream: PipedInputStream) extends InputStream {
|
||||
override def available(): Int = {
|
||||
fillBuffer()
|
||||
pipedInputStream.available()
|
||||
}
|
||||
override def read(): Int = {
|
||||
fillBuffer()
|
||||
pipedInputStream.read
|
||||
}
|
||||
}
|
||||
override def available(): Int = {
|
||||
fillBuffer()
|
||||
buffer.size
|
||||
}
|
||||
override def read(): Int = {
|
||||
fillBuffer()
|
||||
buffer.take()
|
||||
}
|
||||
|
||||
private[this] def fillBuffer(): Unit = synchronized {
|
||||
@tailrec
|
||||
def impl(): Unit = in.available match {
|
||||
case i if i > 0 =>
|
||||
val res = in.read()
|
||||
buffer.add(res)
|
||||
pipes.foreach { p =>
|
||||
p.write(res)
|
||||
p.flush()
|
||||
}
|
||||
impl()
|
||||
case _ =>
|
||||
}
|
||||
impl()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue