Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions io/src/main/scala/sbt/internal/io/DeferredWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import java.io.Writer

/** A `Writer` that avoids constructing the underlying `Writer` with `make` until a method other than `close` is called on this `Writer`. */
private[sbt] final class DeferredWriter(make: => Writer) extends Writer {
private[this] var opened = false
private[this] var delegate0: Writer = _
private[this] def delegate: Writer = synchronized {
private var opened = false
private var delegate0: Writer = _
private def delegate: Writer = synchronized {
if (delegate0 eq null) {
delegate0 = make
opened = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private[sbt] final class WatchState private (
private[sbt] val service: WatchService,
private[sbt] val registered: Map[Path, WatchKey]
) extends AutoCloseable {
private[this] val closed = new AtomicBoolean(false)
private val closed = new AtomicBoolean(false)
def accept(p: Path): Boolean = sources.exists(_.accept(p))
def unregister(path: Path): Unit = service match {
case s: Unregisterable => s.unregister(path)
Expand Down
18 changes: 9 additions & 9 deletions io/src/main/scala/sbt/internal/nio/FileCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ private[nio] class FileCache[+T](converter: Path => T, globs: mutable.Set[Glob])
def this(converter: Path => T) =
this(converter, ConcurrentHashMap.newKeySet[Glob].asScala)
import FileCache._
private[this] val files =
private val files =
Collections.synchronizedSortedMap(new ConcurrentSkipListMap[Path, T])
private[this] val view: FileTreeView.Nio[FileAttributes] = FileTreeView.default
private val view: FileTreeView.Nio[FileAttributes] = FileTreeView.default
private[nio] def update(
path: Path,
attributes: FileAttributes,
Expand Down Expand Up @@ -108,12 +108,12 @@ private[nio] class FileCache[+T](converter: Path => T, globs: mutable.Set[Glob])
}
}
}
private[this] def remove(subMap: util.SortedMap[Path, T]): Seq[(Path, T)] = {
private def remove(subMap: util.SortedMap[Path, T]): Seq[(Path, T)] = {
val allEntries = subMap.asScala.toIndexedSeq
allEntries.foreach { case (p, _) => subMap.remove(p) }
allEntries
}
private[this] def add(glob: Glob, fileAttributes: FileAttributes): Unit = {
private def add(glob: Glob, fileAttributes: FileAttributes): Unit = {
if (fileAttributes != NonExistent) {
val newFiles = new util.HashMap[Path, T]
val asScala = newFiles.asScala
Expand All @@ -123,13 +123,13 @@ private[nio] class FileCache[+T](converter: Path => T, globs: mutable.Set[Glob])
files.putAll(newFiles)
}
}
private[this] def globInclude: Path => Boolean = { path =>
private def globInclude: Path => Boolean = { path =>
globs.exists(g => g.matches(path) || g.base == path)
}
private[this] def globExcludes: Path => Boolean = { path =>
private def globExcludes: Path => Boolean = { path =>
!globs.exists(g => g.matches(path) || g.base == path)
}
private[this] def updateGlob(path: Path): Glob = {
private def updateGlob(path: Path): Glob = {
val depth = globs.toIndexedSeq.view
.map(g =>
if (path.startsWith(g.base)) {
Expand All @@ -147,9 +147,9 @@ private[nio] class FileCache[+T](converter: Path => T, globs: mutable.Set[Glob])
case d => (1 to d).foldLeft(Glob(path)) { case (g, _) => g / AnyPath }
}
}
private[this] val ceilingChar = (java.io.File.separatorChar.toInt + 1).toChar
private val ceilingChar = (java.io.File.separatorChar.toInt + 1).toChar
// This is a mildly hacky way of specifying an upper bound for children of a path
private[this] def ceiling(path: Path): Path = Paths.get(path.toString + ceilingChar)
private def ceiling(path: Path): Path = Paths.get(path.toString + ceilingChar)
}
private[nio] object FileCache {
private implicit class GlobOps(val glob: Glob) extends AnyVal {
Expand Down
8 changes: 4 additions & 4 deletions io/src/main/scala/sbt/internal/nio/FileEventMonitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private[sbt] object FileEventMonitor {
retentionPeriod: FiniteDuration
)(implicit timeSource: TimeSource)
extends FileEventMonitor[FileEvent[T]] {
private[this] val antiEntropyDeadlines = new ConcurrentHashMap[JPath, Deadline].asScala
private val antiEntropyDeadlines = new ConcurrentHashMap[JPath, Deadline].asScala
/*
* It is very common for file writes to be implemented as a move, which manifests as a delete
* followed by a write. In sbt, this can manifest as continuous builds triggering for the delete
Expand All @@ -234,8 +234,8 @@ private[sbt] object FileEventMonitor {
* creation is detected. This provides a reasonable compromise between low latency and
* correctness.
*/
private[this] val quarantinedEvents = new ConcurrentHashMap[JPath, FileEvent[T]].asScala
private[this] def quarantineDuration = {
private val quarantinedEvents = new ConcurrentHashMap[JPath, FileEvent[T]].asScala
private def quarantineDuration = {
val now = Deadline.now
val waits = quarantinedEvents.map(_._2.occurredAt + quarantinePeriod - now).toVector
if (waits.isEmpty) None else Some(waits.min)
Expand All @@ -245,7 +245,7 @@ private[sbt] object FileEventMonitor {
filter: FileEvent[T] => Boolean
): Seq[FileEvent[T]] = pollImpl(duration, filter)
@tailrec
private[this] final def pollImpl(
private final def pollImpl(
duration: Duration,
filter: FileEvent[T] => Boolean
): Seq[FileEvent[T]] = {
Expand Down
12 changes: 6 additions & 6 deletions io/src/main/scala/sbt/internal/nio/FileTreeRepositoryImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import scala.util.Properties
* @tparam T the type of the values.
*/
private[sbt] class FileTreeRepositoryImpl[T] extends FileTreeRepository[FileAttributes] {
private[this] val closed = new AtomicBoolean(false)
private[this] val underlying = FileTreeRepositories.get[FileAttributes](
private val closed = new AtomicBoolean(false)
private val underlying = FileTreeRepositories.get[FileAttributes](
(typedPath: STypedPath) => {
FileAttributes(
isDirectory = typedPath.isDirectory,
Expand All @@ -47,9 +47,9 @@ private[sbt] class FileTreeRepositoryImpl[T] extends FileTreeRepository[FileAttr
},
true
)
private[this] val observers = new Observers[FileEvent[FileAttributes]]
private[this] val registered = ConcurrentHashMap.newKeySet[NioPath].asScala
private[this] val isMac = Properties.isMac
private val observers = new Observers[FileEvent[FileAttributes]]
private val registered = ConcurrentHashMap.newKeySet[NioPath].asScala
private val isMac = Properties.isMac

underlying.addCacheObserver(new CacheObserver[FileAttributes] {
override def onCreate(newEntry: FileTreeDataViews.Entry[FileAttributes]): Unit = {
Expand Down Expand Up @@ -140,7 +140,7 @@ private[sbt] class FileTreeRepositoryImpl[T] extends FileTreeRepository[FileAttr
override def close(): Unit = if (closed.compareAndSet(false, true)) {
underlying.close()
}
private[this] def throwIfClosed(method: String): Unit =
private def throwIfClosed(method: String): Unit =
if (closed.get()) {
val ex = new IllegalStateException(s"Tried to invoke $method on closed repository $this")
ex.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ import scala.concurrent.duration._
*/
private[sbt] class LegacyFileTreeRepository(logger: WatchLogger, watchService: WatchService)
extends FileTreeRepository[FileAttributes] {
private[this] val view: FileTreeView.Nio[FileAttributes] = FileTreeView.default
private[this] val globs = ConcurrentHashMap.newKeySet[Glob].asScala
private[this] val fileCache = new FileCache(p => FileAttributes(p).getOrElse(NonExistent), globs)
private[this] val observable
private val view: FileTreeView.Nio[FileAttributes] = FileTreeView.default
private val globs = ConcurrentHashMap.newKeySet[Glob].asScala
private val fileCache = new FileCache(p => FileAttributes(p).getOrElse(NonExistent), globs)
private val observable
: Observable[FileEvent[FileAttributes]] & Registerable[FileEvent[FileAttributes]] =
new WatchServiceBackedObservable(
new NewWatchState(globs, watchService, new ConcurrentHashMap[Path, WatchKey].asScala),
100.millis,
closeService = true,
logger
)
private[this] val observers = new Observers[FileEvent[FileAttributes]]
private[this] val handle =
private val observers = new Observers[FileEvent[FileAttributes]]
private val handle =
observable.addObserver((event: FileEvent[FileAttributes]) => {
val attributes = event match {
case _: Deletion[?] => NonExistent
Expand Down
6 changes: 3 additions & 3 deletions io/src/main/scala/sbt/internal/nio/Observers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ private[sbt] class Observers[T] extends Observer[T] with Observable[T] {
()
}
}
private[this] val id = new AtomicInteger(0)
private[this] val observers = new ConcurrentHashMap[Int, Observer[T]]
private[this] val observables = new WeakHashMap[AutoCloseable, Unit]
private val id = new AtomicInteger(0)
private val observers = new ConcurrentHashMap[Int, Observer[T]]
private val observables = new WeakHashMap[AutoCloseable, Unit]

private[sbt] def addObservable(observable: Observable[T]): AutoCloseable =
observables.synchronized {
Expand Down
30 changes: 15 additions & 15 deletions io/src/main/scala/sbt/internal/nio/PollingWatchService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ private[sbt] class PollingWatchService(delay: FiniteDuration, timeSource: TimeSo
extends WatchService
with Unregisterable {
def this(delay: FiniteDuration) = this(delay, TimeSource.default)
private[this] implicit def ts: TimeSource = timeSource
private[this] val closed = new AtomicBoolean(false)
private[this] val registered = new ConcurrentHashMap[Path, PollingWatchKey].asScala
private[this] val lastModifiedConverter: Path => Long = p => IO.getModifiedTimeOrZero(p.toFile)
private[this] val pollQueue: util.Queue[PollingWatchKey] =
private implicit def ts: TimeSource = timeSource
private val closed = new AtomicBoolean(false)
private val registered = new ConcurrentHashMap[Path, PollingWatchKey].asScala
private val lastModifiedConverter: Path => Long = p => IO.getModifiedTimeOrZero(p.toFile)
private val pollQueue: util.Queue[PollingWatchKey] =
new LinkedBlockingDeque[PollingWatchKey]
private[this] val random = new Random()
private val random = new Random()
override def close(): Unit = if (closed.compareAndSet(false, true)) {
registered.clear()
}
Expand Down Expand Up @@ -120,19 +120,19 @@ private[sbt] class PollingWatchService(delay: FiniteDuration, timeSource: TimeSo
private[PollingWatchService] val path: Path,
eventKinds: WatchEvent.Kind[Path]*
) extends WatchKey {
private[this] val events =
private val events =
new ArrayBlockingQueue[FileEvent[Long]](256)
private[this] val hasOverflow = new AtomicBoolean(false)
private[this] lazy val acceptCreate = eventKinds.contains(ENTRY_CREATE)
private[this] lazy val acceptDelete = eventKinds.contains(ENTRY_DELETE)
private[this] lazy val acceptModify = eventKinds.contains(ENTRY_MODIFY)
private[this] val glob = Glob(path, AnyPath)
private[this] val fileCache =
private val hasOverflow = new AtomicBoolean(false)
private lazy val acceptCreate = eventKinds.contains(ENTRY_CREATE)
private lazy val acceptDelete = eventKinds.contains(ENTRY_DELETE)
private lazy val acceptModify = eventKinds.contains(ENTRY_MODIFY)
private val glob = Glob(path, AnyPath)
private val fileCache =
new FileCache[Long](lastModifiedConverter)
fileCache.register(glob)
private[this] def nextPollTime: Deadline =
private def nextPollTime: Deadline =
Deadline.now + random.nextInt(2 * delay.toMillis.toInt).millis
private[this] val lastPolled = new AtomicReference(nextPollTime)
private val lastPolled = new AtomicReference(nextPollTime)
override def cancel(): Unit = {
reset()
registered.remove(path)
Expand Down
2 changes: 1 addition & 1 deletion io/src/main/scala/sbt/internal/nio/SwovalConverters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private[nio] object SwovalConverters {
}
}
private[sbt] object SwovalFileTreeView extends FileTreeView.Nio[FileAttributes] {
private[this] val view = FileTreeViews.getDefault(true)
private val view = FileTreeViews.getDefault(true)
override def list(path: Path): Seq[(Path, FileAttributes)] =
Retry(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ private[sbt] class WatchServiceBackedObservable(
) extends Registerable[FileEvent[FileAttributes]]
with Observable[FileEvent[FileAttributes]] {
import WatchServiceBackedObservable.eventThreadId
private[this] type Event = FileEvent[FileAttributes]
private[this] val closed = new AtomicBoolean(false)
private[this] val observers = new Observers[FileEvent[FileAttributes]]
private[this] val fileCache = new FileCache(p => FileAttributes(p).getOrElse(NonExistent))
private[this] val view: FileTreeView.Nio[FileAttributes] = FileTreeView.default
private[this] val thread: Thread = {
private type Event = FileEvent[FileAttributes]
private val closed = new AtomicBoolean(false)
private val observers = new Observers[FileEvent[FileAttributes]]
private val fileCache = new FileCache(p => FileAttributes(p).getOrElse(NonExistent))
private val view: FileTreeView.Nio[FileAttributes] = FileTreeView.default
private val thread: Thread = {
val latch = new CountDownLatch(1)
new Thread(s"watch-state-event-thread-${eventThreadId.incrementAndGet()}") {
setDaemon(true)
Expand Down
6 changes: 3 additions & 3 deletions io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ object IO {
case _ => None
}

private[this] def uriToFile(uriString: String): File = uriToFile(new URI(uriString))
private def uriToFile(uriString: String): File = uriToFile(new URI(uriString))

/**
* Converts the given file URI to a File.
*/
private[this] def uriToFile(uri: URI): File = {
private def uriToFile(uri: URI): File = {
val part = uri.getSchemeSpecificPart
// scheme might be omitted for relative URI reference.
assert(
Expand Down Expand Up @@ -1237,7 +1237,7 @@ object IO {
/** Returns `true` if the filesystem supports user-defined file attribute view. */
lazy val hasUserDefinedFileAttributeView: Boolean = supportedFileAttributeViews.contains("user")

private[this] lazy val supportedFileAttributeViews: Set[String] = {
private lazy val supportedFileAttributeViews: Set[String] = {
FileSystems.getDefault.supportedFileAttributeViews.asScala.toSet
}

Expand Down
2 changes: 1 addition & 1 deletion io/src/main/scala/sbt/io/NameFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ sealed class SimpleFilter(val acceptFunction: String => Boolean) extends NameFil
/** A [[NameFilter]] that accepts a name if it matches the regular expression defined by `pattern`. */
final class PatternFilter(val parts: Seq[String], val pattern: Pattern) extends NameFilter {
def this(pattern: Pattern) = this(Nil: Seq[String], pattern)
private[this] val lock = new Object
private val lock = new Object
def accept(name: String): Boolean = lock.synchronized(pattern.matcher(name).matches)
override def toString = s"PatternFilter($pattern)"
override def equals(o: Any): Boolean = o match {
Expand Down
2 changes: 1 addition & 1 deletion io/src/main/scala/sbt/io/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ private abstract class FilterFiles extends PathFinderImpl with FileFilter {

final def accept(file: File): Boolean = filter.accept(file)

private[this] val getFiles: (File, FileFilter) => Seq[File] = Path.defaultChildHandler
private val getFiles: (File, FileFilter) => Seq[File] = Path.defaultChildHandler
protected def handleFile(file: File, fileSet: mutable.Set[File]): Unit =
for (matchedFile <- getFiles(file, this))
fileSet += new File(file, matchedFile.getName)
Expand Down
2 changes: 1 addition & 1 deletion io/src/main/scala/sbt/io/PathMapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ abstract class Mapper {
pair relativeTo(baseDirectory)
)

private[this] def fold[A, B, T](zero: A => Option[B], in: Iterable[T])(
private def fold[A, B, T](zero: A => Option[B], in: Iterable[T])(
f: T => A => Option[B]
): A => Option[B] =
in.foldLeft(zero)((mapper, base) => a => f(base)(a) orElse mapper(a))
Expand Down
9 changes: 4 additions & 5 deletions io/src/main/scala/sbt/nio/file/FileTreeView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,10 @@ object FileTreeView {
params.foreach(p => remainingGlobs.add(p._3))
val remainingPaths = new util.LinkedList[Path]()
new Iterator[(Path, FileAttributes)] {
private[this] val buffer = new util.LinkedList[(Path, FileAttributes)]
private[this] val maybeAdd: ((Path, FileAttributes)) => Unit = {
case pair @ (path, attributes) =>
if (totalFilter(path, attributes)) buffer.add(pair)
()
private val buffer = new util.LinkedList[(Path, FileAttributes)]
private val maybeAdd: ((Path, FileAttributes)) => Unit = { case pair @ (path, attributes) =>
if (totalFilter(path, attributes)) buffer.add(pair)
()
}
private def listPath(path: Path): Unit = {
try {
Expand Down
14 changes: 7 additions & 7 deletions io/src/main/scala/sbt/nio/file/Glob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sealed trait Glob {
}

object Glob {
private[this] def comp[T](left: T, right: T)(implicit ordering: Ordering[T]): Int =
private def comp[T](left: T, right: T)(implicit ordering: Ordering[T]): Int =
ordering.compare(left, right)

/**
Expand Down Expand Up @@ -337,7 +337,7 @@ object Glob {
private[sbt] case object Error extends RelativeGlobViewOption
private[sbt] case object Ignore extends RelativeGlobViewOption
}
private[this] def errorMessage(relative: Glob, warn: Boolean): String = {
private def errorMessage(relative: Glob, warn: Boolean): String = {
val prefix = if (warn) "Warning" else "Error"
val action =
if (warn) "To disable this warning, "
Expand Down Expand Up @@ -528,11 +528,11 @@ object Glob {
*/
def toGlob: Glob = new PathOps(file.toPath).toGlob
}
private[this] val windowsEscapable = "(){}"
private[this] val allMeta = "*{([?"
private val windowsEscapable = "(){}"
private val allMeta = "*{([?"
private[file] val hasMeta: String => Boolean = _.exists(allMeta.contains(_))
private[file] val isWin = Properties.isWin
private[this] val splitter: (String, Boolean) => List[String] = {
private val splitter: (String, Boolean) => List[String] = {
if (Glob.isWin) { (glob, isRegex) =>
{
val stringBuilder = new StringBuilder(glob.length)
Expand Down Expand Up @@ -904,11 +904,11 @@ object RelativeGlob {
override def hashCode: Int = glob.hashCode
}
private final class GlobMatcher(override val glob: String) extends SingleComponentMatcher {
private[this] val (prefixString, pattern) = glob.indexOf(":") match {
private val (prefixString, pattern) = glob.indexOf(":") match {
case -1 => ("glob", glob)
case i => (glob.substring(0, i), glob.substring(i + 1))
}
private[this] val matcher = FileSystems.getDefault.getPathMatcher(s"$prefixString:$pattern")
private val matcher = FileSystems.getDefault.getPathMatcher(s"$prefixString:$pattern")
override def matches(path: Path): Boolean = matcher.matches(path)
override def equals(o: Any): Boolean = o match {
case that: GlobMatcher => this.glob == that.glob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private[sbt] trait EventMonitorSpec { self: AnyFlatSpec & Matchers =>
def newObservable(file: File): Observable[Event] =
newObservable(Seq(Glob(file.toPath.toRealPath(), RecursiveGlob)), NullLogger)
private val maxWait = 2 * pollDelay
private[this] val random = new scala.util.Random()
private val random = new scala.util.Random()
private def randomTouch(file: File, add: Boolean = true): Unit = {
IO.touch(file)
val rand = (10000 + random.nextInt(50000)) * (if (add) 1 else -1)
Expand Down
2 changes: 1 addition & 1 deletion io/src/test/scala/sbt/io/NameFilterSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object NameFilterSpecification extends Properties("NameFilter") {
*/
private def stripAsterisksAndControl(s: String) = (s filter validChar).toString

private[this] def validChar(c: Char) = (
private def validChar(c: Char) = (
!java.lang.Character.isISOControl(c)
&& c != '*'
&& !Character.isHighSurrogate(c)
Expand Down