From 8461d2b5119ecc954f781adb63ac5d4f1dd26b3c Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 3 May 2019 21:17:58 -0400 Subject: [PATCH 1/3] bump plugins --- .scalafmt.conf | 11 +++++++++++ .travis.yml | 2 +- build.sbt | 4 ++-- project/build.properties | 2 +- project/plugins.sbt | 4 ++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index e4ab3651..718ce5ae 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,3 +1,4 @@ +version = 2.0.0-RC6 maxColumn = 100 project.git = true project.excludeFilters = [ /sbt-test/, /input_sources/, /contraband-scala/ ] @@ -8,3 +9,13 @@ docstrings = JavaDoc # This also seems more idiomatic to include whitespace in import x.{ yyy } spaces.inImportCurlyBraces = true + +# This is more idiomatic Scala. +# http://docs.scala-lang.org/style/indentation.html#methods-with-numerous-arguments +align.openParenCallSite = false +align.openParenDefnSite = false + +# For better code clarity +danglingParentheses = true + +trailingCommas = preserve diff --git a/.travis.yml b/.travis.yml index c408bec0..42b19724 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ matrix: include: - scala: 2.12.8 env: - CMD="mimaReportBinaryIssues scalafmtCheck test whitesourceCheckPolicies doc" + CMD="mimaReportBinaryIssues scalafmtCheckAll test whitesourceCheckPolicies doc" TRAVIS_SCALA_VERSION=2.12.8 TRAVIS_JDK=adopt@1.8.192-12 os: linux diff --git a/build.sbt b/build.sbt index 9f9b818a..3ea71278 100644 --- a/build.sbt +++ b/build.sbt @@ -1,8 +1,6 @@ import Dependencies._ import com.typesafe.tools.mima.core._, ProblemFilters._ - -ThisBuild / scalafmtOnCompile := true ThisBuild / git.baseVersion := "1.3.0" ThisBuild / bintrayPackage := "io" ThisBuild / homepage := Some(url("https://github.com/sbt/io")) @@ -25,6 +23,8 @@ def commonSettings: Seq[Setting[_]] = Seq( javacOptions in compile ++= Seq("-Xlint", "-Xlint:-serial"), crossScalaVersions := Seq(scala212, scala213), headerLicense := (ThisBuild / headerLicense).value, + scalafmtOnCompile := true, + Test / scalafmtOnCompile := true, ) lazy val ioRoot = (project in file(".")) diff --git a/project/build.properties b/project/build.properties index 6d441921..c59667ce 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.2.4 +sbt.version=1.3.0-M3 diff --git a/project/plugins.sbt b/project/plugins.sbt index bb331f4a..27e85e9a 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,6 @@ addSbtPlugin("org.scala-sbt" % "sbt-houserules" % "0.3.9") -addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0") addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.4.1") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0") -addSbtPlugin("com.lightbend" % "sbt-whitesource" % "0.1.9") +addSbtPlugin("com.lightbend" % "sbt-whitesource" % "0.1.14") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.1.0") From 9b76cb17dee9946fb477a8354263c4c68f8fd316 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 3 May 2019 21:19:03 -0400 Subject: [PATCH 2/3] applying Scalafmt 2.0.0-RC6 with sbt/sbt rules --- .../scala/sbt/internal/io/ErrorHandling.scala | 12 ++- io/src/main/scala/sbt/internal/io/Milli.scala | 79 +++++++++------- io/src/main/scala/sbt/internal/io/Retry.scala | 18 ++-- .../internal/io/SourceModificationWatch.scala | 27 +++--- .../internal/nio/DefaultFileTreeView.scala | 10 +- .../scala/sbt/internal/nio/FileCache.scala | 20 ++-- .../scala/sbt/internal/nio/FileEvent.scala | 26 +++--- .../sbt/internal/nio/FileEventMonitor.scala | 79 +++++++++------- .../sbt/internal/nio/FileTreeRepository.scala | 6 +- .../internal/nio/FileTreeRepositoryImpl.scala | 16 ++-- .../nio/LegacyFileTreeRepository.scala | 2 +- .../scala/sbt/internal/nio/Observers.scala | 9 +- .../internal/nio/PollingWatchService.scala | 22 +++-- .../scala/sbt/internal/nio/WatchLogger.scala | 5 +- .../nio/WatchServiceBackedObservable.scala | 24 +++-- io/src/main/scala/sbt/io/Hash.scala | 4 +- io/src/main/scala/sbt/io/IO.scala | 93 +++++++++++++------ io/src/main/scala/sbt/io/Path.scala | 32 ++++--- io/src/main/scala/sbt/io/Using.scala | 19 ++-- .../scala/sbt/nio/file/FileAttributes.scala | 43 +++++---- .../scala/sbt/nio/file/FileTreeView.scala | 38 ++++---- io/src/main/scala/sbt/nio/file/Glob.scala | 10 +- .../internal/io/PollingWatchServiceSpec.scala | 6 +- .../io/SourceModificationWatchSpec.scala | 22 +++-- .../scala/sbt/internal/io/SourceSpec.scala | 20 ++-- .../io/WatchServiceBackedObservableSpec.scala | 8 +- .../internal/nio/FileEventMonitorSpec.scala | 35 ++++--- .../internal/nio/FileTreeRepositorySpec.scala | 3 +- io/src/test/scala/sbt/io/CopySpec.scala | 20 ++-- .../sbt/io/FileUtilitiesSpecification.scala | 6 +- io/src/test/scala/sbt/io/IOSpec.scala | 27 ++++-- .../sbt/io/NameFilterSpecification.scala | 6 +- io/src/test/scala/sbt/io/PathMapperSpec.scala | 5 +- .../test/scala/sbt/nio/FileTreeViewSpec.scala | 4 +- .../test/scala/sbt/nio/GlobFilterSpec.scala | 6 +- .../scala/sbt/nio/GlobPathFinderSpec.scala | 3 +- .../test/scala/sbt/nio/GlobSyntaxSpec.scala | 28 +++--- 37 files changed, 492 insertions(+), 301 deletions(-) diff --git a/io/src/main/scala/sbt/internal/io/ErrorHandling.scala b/io/src/main/scala/sbt/internal/io/ErrorHandling.scala index 3c9eb7e1..d921c828 100644 --- a/io/src/main/scala/sbt/internal/io/ErrorHandling.scala +++ b/io/src/main/scala/sbt/internal/io/ErrorHandling.scala @@ -14,20 +14,26 @@ import java.io.IOException private[sbt] object ErrorHandling { def translate[T](msg: => String)(f: => T) = - try { f } catch { + try { + f + } catch { case e: IOException => throw new TranslatedIOException(msg + e.toString, e) case e: Exception => throw new TranslatedException(msg + e.toString, e) } def wideConvert[T](f: => T): Either[Throwable, T] = - try { Right(f) } catch { + try { + Right(f) + } catch { case ex @ (_: Exception | _: StackOverflowError) => Left(ex) case err @ (_: ThreadDeath | _: VirtualMachineError) => throw err case x: Throwable => Left(x) } def convert[T](f: => T): Either[Exception, T] = - try { Right(f) } catch { case e: Exception => Left(e) } + try { + Right(f) + } catch { case e: Exception => Left(e) } def reducedToString(e: Throwable): String = if (e.getClass == classOf[RuntimeException]) { diff --git a/io/src/main/scala/sbt/internal/io/Milli.scala b/io/src/main/scala/sbt/internal/io/Milli.scala index 1cf6aaff..a03f67fe 100644 --- a/io/src/main/scala/sbt/internal/io/Milli.scala +++ b/io/src/main/scala/sbt/internal/io/Milli.scala @@ -81,9 +81,11 @@ private abstract class MilliPosixBase[Interface <: PosixBase: ClassTag, Native] private val options = scala.collection.Map[String, Object]().asJava private final val ENOENT = 2 protected val libc: Interface = - (JNANative.loadLibrary(Platform.C_LIBRARY_NAME, - classTag[Interface].runtimeClass.asInstanceOf[Class[Interface]], - options)): Interface + (JNANative.loadLibrary( + Platform.C_LIBRARY_NAME, + classTag[Interface].runtimeClass.asInstanceOf[Class[Interface]], + options + )): Interface protected def checkedIO[T](filePath: String)(f: => Int) = { if (f != 0) { val errno = JNANative.getLastError() @@ -220,16 +222,20 @@ private object Linux32Milli extends PosixMilliIntUtim[Linux32] { } private trait Mac extends Library with Posix[Long] { - def getattrlist(path: String, - attrlist: Attrlist, - attrBuf: TimeBuf, - attrBufSize: Int, - options: Int): Int - def setattrlist(path: String, - attrlist: Attrlist, - attrBuf: Timespec, - attrBufSize: Int, - options: Int): Int + def getattrlist( + path: String, + attrlist: Attrlist, + attrBuf: TimeBuf, + attrBufSize: Int, + options: Int + ): Int + def setattrlist( + path: String, + attrlist: Attrlist, + attrBuf: Timespec, + attrBufSize: Int, + options: Int + ): Int } private object MacMilli extends PosixMilliLong[Mac] { private val attr = new Attrlist @@ -255,13 +261,15 @@ private object WinMilli extends MilliNative[FILETIME] { import Kernel32.INSTANCE._ private def getHandle(lpFileName: String, dwDesiredAccess: Int, dwShareMode: Int): HANDLE = { - val hFile = CreateFile(lpFileName, - dwDesiredAccess, - dwShareMode, - null, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, - null) + val hFile = CreateFile( + lpFileName, + dwDesiredAccess, + dwShareMode, + null, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + null + ) if (hFile == INVALID_HANDLE_VALUE) { val err = GetLastError() if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) @@ -275,35 +283,43 @@ private object WinMilli extends MilliNative[FILETIME] { } protected def getModifiedTimeNative(filePath: String): FILETIME = { - val hFile = getHandle(filePath, - FILE_READ_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE) + val hFile = getHandle( + filePath, + FILE_READ_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE + ) val mtime = try { val modifiedTime = new FILETIME.ByReference() if (!GetFileTime(hFile, /*creationTime*/ null, /*accessTime*/ null, modifiedTime)) throw new IOException( - "GetFileTime() failed with error " + GetLastError() + " for file " + filePath) + "GetFileTime() failed with error " + GetLastError() + " for file " + filePath + ) modifiedTime } finally { if (!CloseHandle(hFile)) throw new IOException( - "CloseHandle() after GetFileTime() failed with error " + GetLastError() + " for file " + filePath) + "CloseHandle() after GetFileTime() failed with error " + GetLastError() + " for file " + filePath + ) } mtime } protected def setModifiedTimeNative(filePath: String, fileTime: FILETIME): Unit = { - val hFile = getHandle(filePath, - FILE_WRITE_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE) + val hFile = getHandle( + filePath, + FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE + ) try { if (SetFileTime(hFile, null, null, fileTime) == 0) throw new IOException( - "SetFileTime() failed with error " + GetLastError() + " for file " + filePath) + "SetFileTime() failed with error " + GetLastError() + " for file " + filePath + ) } finally { if (!CloseHandle(hFile)) throw new IOException( - "CloseHandle() after SetFileTime() failed with error " + GetLastError() + " for file " + filePath) + "CloseHandle() after SetFileTime() failed with error " + GetLastError() + " for file " + filePath + ) } } @@ -384,7 +400,8 @@ object Milli { } finally { if (!file.delete()) throw new IOException( - "Unexpected: could not delete temporary file: " + file.getAbsolutePath) + "Unexpected: could not delete temporary file: " + file.getAbsolutePath + ) } } } diff --git a/io/src/main/scala/sbt/internal/io/Retry.scala b/io/src/main/scala/sbt/internal/io/Retry.scala index 1f1635c9..636f6998 100644 --- a/io/src/main/scala/sbt/internal/io/Retry.scala +++ b/io/src/main/scala/sbt/internal/io/Retry.scala @@ -22,16 +22,16 @@ private[sbt] object Retry { } private[sbt] def apply[T](f: => T, excludedExceptions: Class[_ <: IOException]*): T = apply(f, limit, excludedExceptions: _*) - private[sbt] def apply[T](f: => T, - limit: Int, - excludedExceptions: Class[_ <: IOException]*): T = { + private[sbt] def apply[T]( + f: => T, + limit: Int, + excludedExceptions: Class[_ <: IOException]* + ): T = { lazy val filter: Exception => Boolean = excludedExceptions match { case s if s.nonEmpty => - (e: Exception) => - !excludedExceptions.exists(_.isAssignableFrom(e.getClass)) + (e: Exception) => !excludedExceptions.exists(_.isAssignableFrom(e.getClass)) case _ => - (_: Exception) => - true + (_: Exception) => true } @tailrec def impl(attempt: Int): T = { @@ -40,7 +40,9 @@ private[sbt] object Retry { case e: IOException if filter(e) && (attempt < limit) => (true, Left(e)) case e: IOException => (false, Left(e)) } - if (retry) { Thread.sleep(0); impl(attempt + 1) } else { + if (retry) { + Thread.sleep(0); impl(attempt + 1) + } else { res match { case Right(r) => r case Left(e) => throw e diff --git a/io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala b/io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala index 87bfcb34..248675b6 100644 --- a/io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala +++ b/io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala @@ -35,7 +35,8 @@ private[sbt] object SourceModificationWatch { */ @deprecated("This is superseded by FileEventMonitor.poll", "1.1.7") def watch(delay: FiniteDuration, state: WatchState)( - terminationCondition: => Boolean): (Boolean, WatchState) = { + terminationCondition: => Boolean + ): (Boolean, WatchState) = { if (state.count == 0) { (true, state.withCount(1)) } else { @@ -47,11 +48,13 @@ private[sbt] object SourceModificationWatch { NullWatchLogger ) val monitor: FileEventMonitor[FileEvent[FileAttributes]] = - FileEventMonitor.antiEntropy(observable, - 200.milliseconds, - NullWatchLogger, - 50.milliseconds, - 10.minutes) + FileEventMonitor.antiEntropy( + observable, + 200.milliseconds, + NullWatchLogger, + 50.milliseconds, + 10.minutes + ) @tailrec def poll(): Boolean = { monitor.poll(10.millis) match { @@ -146,10 +149,11 @@ private[sbt] final class WatchState private ( } } -private[sbt] class NewWatchState(private[sbt] val globs: mutable.Set[Glob], - private[sbt] val service: WatchService, - private[sbt] val registered: mutable.Map[Path, WatchKey]) - extends AutoCloseable { +private[sbt] class NewWatchState( + private[sbt] val globs: mutable.Set[Glob], + private[sbt] val service: WatchService, + private[sbt] val registered: mutable.Map[Path, WatchKey] +) extends AutoCloseable { private[sbt] def register(path: Path): WatchKey = try { registered.get(path) match { @@ -205,7 +209,8 @@ final class Source( else includeFilter (if (!recursive) p.getParent == base.toPath else p.startsWith(base.toPath)) && inc.accept( - p.toFile) && !excludeFilter.accept(p.toFile) + p.toFile + ) && !excludeFilter.accept(p.toFile) } /** diff --git a/io/src/main/scala/sbt/internal/nio/DefaultFileTreeView.scala b/io/src/main/scala/sbt/internal/nio/DefaultFileTreeView.scala index d6e4dfd9..6e021369 100644 --- a/io/src/main/scala/sbt/internal/nio/DefaultFileTreeView.scala +++ b/io/src/main/scala/sbt/internal/nio/DefaultFileTreeView.scala @@ -32,10 +32,12 @@ private[sbt] object DefaultFileTreeView extends FileTreeView.Nio[FileAttributes] .asScala .map { typedPath => typedPath.getPath -> - FileAttributes(isDirectory = typedPath.isDirectory, - isOther = false, - isRegularFile = typedPath.isFile, - isSymbolicLink = typedPath.isSymbolicLink) + FileAttributes( + isDirectory = typedPath.isDirectory, + isOther = false, + isRegularFile = typedPath.isFile, + isSymbolicLink = typedPath.isSymbolicLink + ) } .toVector } catch { diff --git a/io/src/main/scala/sbt/internal/nio/FileCache.scala b/io/src/main/scala/sbt/internal/nio/FileCache.scala index 049e5187..763048db 100644 --- a/io/src/main/scala/sbt/internal/nio/FileCache.scala +++ b/io/src/main/scala/sbt/internal/nio/FileCache.scala @@ -120,15 +120,17 @@ private[nio] class FileCache[+T](converter: Path => T, globs: mutable.Set[Glob]) } private[this] def updateGlob(path: Path): Glob = { val depth = globs.toIndexedSeq.view - .map(g => - if (path.startsWith(g.base)) { - if (path == g.base) g.range._2 - else - g.range._2 match { - case Int.MaxValue => Int.MaxValue - case d => d - g.base.relativize(path).getNameCount - } - } else Int.MinValue) + .map( + g => + if (path.startsWith(g.base)) { + if (path == g.base) g.range._2 + else + g.range._2 match { + case Int.MaxValue => Int.MaxValue + case d => d - g.base.relativize(path).getNameCount + } + } else Int.MinValue + ) .min depth match { case Int.MaxValue => Glob(path, RecursiveGlob) diff --git a/io/src/main/scala/sbt/internal/nio/FileEvent.scala b/io/src/main/scala/sbt/internal/nio/FileEvent.scala index 38c590a5..f2bf5c2f 100644 --- a/io/src/main/scala/sbt/internal/nio/FileEvent.scala +++ b/io/src/main/scala/sbt/internal/nio/FileEvent.scala @@ -32,9 +32,10 @@ private[sbt] object FileEvent { case Deletion(path, attributes) => Some((path, attributes)) case Update(path, _, attributes) => Some((path, attributes)) } - private[sbt] abstract case class Creation[+T] private[FileEvent] (override val path: Path, - attributes: T) - extends FileEvent[T] { + private[sbt] abstract case class Creation[+T] private[FileEvent] ( + override val path: Path, + attributes: T + ) extends FileEvent[T] { override def exists: Boolean = true } private[sbt] object Creation { @@ -43,15 +44,17 @@ private[sbt] object FileEvent { def apply[T](path: Path, attributes: T, deadline: Deadline): Creation[T] = new Creation(path, attributes) { override val occurredAt: Deadline = deadline } } - private[sbt] abstract case class Update[+T] private[FileEvent] (override val path: Path, - previousAttributes: T, - attributes: T) - extends FileEvent[T] { + private[sbt] abstract case class Update[+T] private[FileEvent] ( + override val path: Path, + previousAttributes: T, + attributes: T + ) extends FileEvent[T] { override def exists: Boolean = true } private[sbt] object Update { def apply[T](path: Path, previousAttributes: T, attributes: T)( - implicit timeSource: TimeSource): Update[T] = + implicit timeSource: TimeSource + ): Update[T] = new Update(path, previousAttributes, attributes) { override val occurredAt: Deadline = timeSource.now } @@ -60,9 +63,10 @@ private[sbt] object FileEvent { override val occurredAt: Deadline = deadline } } - private[sbt] abstract case class Deletion[+T] private[FileEvent] (override val path: Path, - override val attributes: T) - extends FileEvent[T] { + private[sbt] abstract case class Deletion[+T] private[FileEvent] ( + override val path: Path, + override val attributes: T + ) extends FileEvent[T] { override def exists: Boolean = false } private[sbt] object Deletion { diff --git a/io/src/main/scala/sbt/internal/nio/FileEventMonitor.scala b/io/src/main/scala/sbt/internal/nio/FileEventMonitor.scala index 1f725254..6a79195c 100644 --- a/io/src/main/scala/sbt/internal/nio/FileEventMonitor.scala +++ b/io/src/main/scala/sbt/internal/nio/FileEventMonitor.scala @@ -44,9 +44,10 @@ private[sbt] trait FileEventMonitor[+T] extends AutoCloseable { } private[sbt] object FileEventMonitor { - private[sbt] def apply[T](observable: Observable[FileEvent[T]], - logger: WatchLogger = NullWatchLogger)( - implicit timeSource: TimeSource): FileEventMonitor[FileEvent[T]] = + private[sbt] def apply[T]( + observable: Observable[FileEvent[T]], + logger: WatchLogger = NullWatchLogger + )(implicit timeSource: TimeSource): FileEventMonitor[FileEvent[T]] = new FileEventMonitorImpl[T](observable, logger) /** @@ -72,17 +73,20 @@ private[sbt] object FileEventMonitor { * @tparam T the generic type for the [[Observable]] that we're monitoring * @return the [[FileEventMonitor]] instance. */ - private[sbt] def antiEntropy[T](observable: Observable[FileEvent[T]], - period: FiniteDuration, - logger: WatchLogger, - quarantinePeriod: FiniteDuration, - retentionPeriod: FiniteDuration)( - implicit timeSource: TimeSource): FileEventMonitor[FileEvent[T]] = { - new AntiEntropyFileEventMonitor(period, - new FileEventMonitorImpl[T](observable, logger), - logger, - quarantinePeriod, - retentionPeriod) + private[sbt] def antiEntropy[T]( + observable: Observable[FileEvent[T]], + period: FiniteDuration, + logger: WatchLogger, + quarantinePeriod: FiniteDuration, + retentionPeriod: FiniteDuration + )(implicit timeSource: TimeSource): FileEventMonitor[FileEvent[T]] = { + new AntiEntropyFileEventMonitor( + period, + new FileEventMonitorImpl[T](observable, logger), + logger, + quarantinePeriod, + retentionPeriod + ) } /** @@ -108,22 +112,25 @@ private[sbt] object FileEventMonitor { * @tparam T the generic type for the [[Observable]] that we're monitoring * @return the [[FileEventMonitor]] instance. */ - private[sbt] def antiEntropy[T](fileEventMonitor: FileEventMonitor[FileEvent[T]], - period: FiniteDuration, - logger: WatchLogger, - quarantinePeriod: FiniteDuration, - retentionPeriod: FiniteDuration)( - implicit timeSource: TimeSource): FileEventMonitor[FileEvent[T]] = { - new AntiEntropyFileEventMonitor(period, - fileEventMonitor, - logger, - quarantinePeriod, - retentionPeriod) + private[sbt] def antiEntropy[T]( + fileEventMonitor: FileEventMonitor[FileEvent[T]], + period: FiniteDuration, + logger: WatchLogger, + quarantinePeriod: FiniteDuration, + retentionPeriod: FiniteDuration + )(implicit timeSource: TimeSource): FileEventMonitor[FileEvent[T]] = { + new AntiEntropyFileEventMonitor( + period, + fileEventMonitor, + logger, + quarantinePeriod, + retentionPeriod + ) } private class FileEventMonitorImpl[T](observable: Observable[FileEvent[T]], logger: WatchLogger)( - implicit timeSource: TimeSource) - extends FileEventMonitor[FileEvent[T]] { + implicit timeSource: TimeSource + ) extends FileEventMonitor[FileEvent[T]] { private case object Trigger private val events = new ConcurrentHashMap[JPath, FileEvent[T]]().asScala @@ -169,8 +176,10 @@ private[sbt] object FileEventMonitor { } private val handle = observable.addObserver(add) - final override def poll(duration: Duration, - filter: FileEvent[T] => Boolean): Seq[FileEvent[T]] = { + final override def poll( + duration: Duration, + filter: FileEvent[T] => Boolean + ): Seq[FileEvent[T]] = { val limit = duration match { case d: FiniteDuration => Deadline.now + d case _ => Deadline.now + 1.day @@ -210,7 +219,8 @@ private[sbt] object FileEventMonitor { fileEventMonitor: FileEventMonitor[FileEvent[T]], logger: WatchLogger, quarantinePeriod: FiniteDuration, - retentionPeriod: FiniteDuration)(implicit timeSource: TimeSource) + retentionPeriod: FiniteDuration + )(implicit timeSource: TimeSource) extends FileEventMonitor[FileEvent[T]] { private[this] val antiEntropyDeadlines = new ConcurrentHashMap[JPath, Deadline].asScala /* @@ -225,8 +235,10 @@ private[sbt] object FileEventMonitor { */ private[this] val quarantinedEvents = new ConcurrentHashMap[JPath, FileEvent[T]].asScala @tailrec - override final def poll(duration: Duration, - filter: FileEvent[T] => Boolean): Seq[FileEvent[T]] = { + override final def poll( + duration: Duration, + filter: FileEvent[T] => Boolean + ): Seq[FileEvent[T]] = { val start = Deadline.now /* * The impl is tail recursive to handle the case when we quarantine a deleted file or find @@ -247,7 +259,8 @@ private[sbt] object FileEventMonitor { case Some(d @ Deletion(_, oldAttributes)) => antiEntropyDeadlines.put(path, d.occurredAt + period) logger.debug( - s"Triggering event for newly created path $path that was previously quarantined.") + s"Triggering event for newly created path $path that was previously quarantined." + ) Some(Update(path, oldAttributes, attributes, d.occurredAt)) case _ => antiEntropyDeadlines.get(path) match { diff --git a/io/src/main/scala/sbt/internal/nio/FileTreeRepository.scala b/io/src/main/scala/sbt/internal/nio/FileTreeRepository.scala index 4818ee3e..8d07d4f9 100644 --- a/io/src/main/scala/sbt/internal/nio/FileTreeRepository.scala +++ b/io/src/main/scala/sbt/internal/nio/FileTreeRepository.scala @@ -57,8 +57,10 @@ private[sbt] object FileTreeRepository { * @tparam T the generic type of the custom file attributes * @return a file repository. */ - private[sbt] def legacy[T](logger: WatchLogger, - watchService: WatchService): FileTreeRepository[FileAttributes] = + private[sbt] def legacy[T]( + logger: WatchLogger, + watchService: WatchService + ): FileTreeRepository[FileAttributes] = new LegacyFileTreeRepository(logger, watchService) } diff --git a/io/src/main/scala/sbt/internal/nio/FileTreeRepositoryImpl.scala b/io/src/main/scala/sbt/internal/nio/FileTreeRepositoryImpl.scala index e0a5efa0..f3a41e99 100644 --- a/io/src/main/scala/sbt/internal/nio/FileTreeRepositoryImpl.scala +++ b/io/src/main/scala/sbt/internal/nio/FileTreeRepositoryImpl.scala @@ -34,10 +34,12 @@ private[sbt] class FileTreeRepositoryImpl[T] extends FileTreeRepository[FileAttr private[this] val closed = new AtomicBoolean(false) private[this] val underlying = FileTreeRepositories.get[FileAttributes]( (typedPath: STypedPath) => { - FileAttributes(isDirectory = typedPath.isDirectory, - isOther = false, - isRegularFile = typedPath.isFile, - isSymbolicLink = typedPath.isSymbolicLink) + FileAttributes( + isDirectory = typedPath.isDirectory, + isOther = false, + isRegularFile = typedPath.isFile, + isSymbolicLink = typedPath.isSymbolicLink + ) }, true ) @@ -58,8 +60,10 @@ private[sbt] class FileTreeRepositoryImpl[T] extends FileTreeRepository[FileAttr } () } - override def onUpdate(oldEntry: FileTreeDataViews.Entry[FileAttributes], - newEntry: FileTreeDataViews.Entry[FileAttributes]): Unit = { + override def onUpdate( + oldEntry: FileTreeDataViews.Entry[FileAttributes], + newEntry: FileTreeDataViews.Entry[FileAttributes] + ): Unit = { val path = newEntry.getTypedPath.getPath val oldEither = oldEntry.getValue.asScala val newEither = newEntry.getValue.asScala diff --git a/io/src/main/scala/sbt/internal/nio/LegacyFileTreeRepository.scala b/io/src/main/scala/sbt/internal/nio/LegacyFileTreeRepository.scala index 5b4fcbfa..1875ec37 100644 --- a/io/src/main/scala/sbt/internal/nio/LegacyFileTreeRepository.scala +++ b/io/src/main/scala/sbt/internal/nio/LegacyFileTreeRepository.scala @@ -34,7 +34,7 @@ private[sbt] class LegacyFileTreeRepository(logger: WatchLogger, watchService: W private[this] val globs = ConcurrentHashMap.newKeySet[Glob].asScala private[this] val fileCache = new FileCache(p => FileAttributes(p).getOrElse(NonExistent), globs) private[this] val observable - : Observable[FileEvent[FileAttributes]] with Registerable[FileEvent[FileAttributes]] = + : Observable[FileEvent[FileAttributes]] with Registerable[FileEvent[FileAttributes]] = new WatchServiceBackedObservable( new NewWatchState(globs, watchService, new ConcurrentHashMap[Path, WatchKey].asScala), 100.millis, diff --git a/io/src/main/scala/sbt/internal/nio/Observers.scala b/io/src/main/scala/sbt/internal/nio/Observers.scala index a68804a6..094d9c73 100644 --- a/io/src/main/scala/sbt/internal/nio/Observers.scala +++ b/io/src/main/scala/sbt/internal/nio/Observers.scala @@ -115,7 +115,8 @@ private[sbt] class Observers[T] extends Observer[T] with Observable[T] { observers.values.foreach( o => try o.onNext(t) - catch { case NonFatal(_) => }) + catch { case NonFatal(_) => } + ) } } private[sbt] class RegisterableObservable[T](val delegate: Observers[FileEvent[T]]) extends AnyVal { @@ -140,8 +141,10 @@ private[sbt] trait Registerable[+T] extends AutoCloseable { def register(glob: Glob): Either[IOException, Observable[T]] } private[sbt] object Registerable { - def apply[T](glob: Glob, - delegate: Observers[FileEvent[T]]): Either[IOException, Observable[FileEvent[T]]] = { + def apply[T]( + glob: Glob, + delegate: Observers[FileEvent[T]] + ): Either[IOException, Observable[FileEvent[T]]] = { val filter = glob.toFileFilter val underlying = new Observers[FileEvent[T]] val observers = diff --git a/io/src/main/scala/sbt/internal/nio/PollingWatchService.scala b/io/src/main/scala/sbt/internal/nio/PollingWatchService.scala index 85084ca2..6a165008 100644 --- a/io/src/main/scala/sbt/internal/nio/PollingWatchService.scala +++ b/io/src/main/scala/sbt/internal/nio/PollingWatchService.scala @@ -63,9 +63,11 @@ private[sbt] class PollingWatchService(delay: FiniteDuration, timeSource: TimeSo } @tailrec - private def pollImpl(batchSize: Int, - duration: FiniteDuration, - deadline: Deadline): Option[WatchKey] = { + private def pollImpl( + batchSize: Int, + duration: FiniteDuration, + deadline: Deadline + ): Option[WatchKey] = { pollQueue.poll() match { case null => None case key => @@ -73,7 +75,9 @@ private[sbt] class PollingWatchService(delay: FiniteDuration, timeSource: TimeSo key.poll() match { case r if r.isDefined => r case _ => - if (batchSize > 1) { pollImpl(batchSize - 1, duration, deadline) } else if (!deadline.isOverdue) { + if (batchSize > 1) { + pollImpl(batchSize - 1, duration, deadline) + } else if (!deadline.isOverdue) { Thread.sleep(duration.toMillis) pollImpl(batchSize, duration, deadline) } else { @@ -111,9 +115,10 @@ private[sbt] class PollingWatchService(delay: FiniteDuration, timeSource: TimeSo private object Overflow extends PollingWatchEvent(null, OVERFLOW.asInstanceOf[WatchEvent.Kind[Path]]) - private class PollingWatchKey(private[PollingWatchService] val path: Path, - eventKinds: WatchEvent.Kind[Path]*) - extends WatchKey { + private class PollingWatchKey( + private[PollingWatchService] val path: Path, + eventKinds: WatchEvent.Kind[Path]* + ) extends WatchKey { private[this] val events = new ArrayBlockingQueue[FileEvent[Long]](256) private[this] val hasOverflow = new AtomicBoolean(false) @@ -168,7 +173,8 @@ private[sbt] class PollingWatchService(delay: FiniteDuration, timeSource: TimeSo } } private[PollingWatchService] def maybeAddEvent( - event: FileEvent[Long]): Option[PollingWatchKey] = { + event: FileEvent[Long] + ): Option[PollingWatchKey] = { def offer(event: FileEvent[Long]): Option[PollingWatchKey] = { if (!events.synchronized(events.offer(event))) hasOverflow.set(true) Some(this) diff --git a/io/src/main/scala/sbt/internal/nio/WatchLogger.scala b/io/src/main/scala/sbt/internal/nio/WatchLogger.scala index f1f4d37f..828b4f3a 100644 --- a/io/src/main/scala/sbt/internal/nio/WatchLogger.scala +++ b/io/src/main/scala/sbt/internal/nio/WatchLogger.scala @@ -14,6 +14,9 @@ private[sbt] trait WatchLogger { def debug(msg: Any): Unit } private[sbt] object NullWatchLogger extends WatchLogger { - private def ignoreArg[T](f: => T): Unit = if (false) { f; () } else () + private def ignoreArg[T](f: => T): Unit = + if (false) { + f; () + } else () override def debug(msg: Any): Unit = ignoreArg(msg) } diff --git a/io/src/main/scala/sbt/internal/nio/WatchServiceBackedObservable.scala b/io/src/main/scala/sbt/internal/nio/WatchServiceBackedObservable.scala index 40c5a556..16a66389 100644 --- a/io/src/main/scala/sbt/internal/nio/WatchServiceBackedObservable.scala +++ b/io/src/main/scala/sbt/internal/nio/WatchServiceBackedObservable.scala @@ -30,11 +30,12 @@ import scala.util.control.NonFatal private[sbt] object WatchServiceBackedObservable { private val eventThreadId = new AtomicInteger(0) } -private[sbt] class WatchServiceBackedObservable(s: NewWatchState, - delay: FiniteDuration, - closeService: Boolean, - logger: WatchLogger) - extends Registerable[FileEvent[FileAttributes]] +private[sbt] class WatchServiceBackedObservable( + s: NewWatchState, + delay: FiniteDuration, + closeService: Boolean, + logger: WatchLogger +) extends Registerable[FileEvent[FileAttributes]] with Observable[FileEvent[FileAttributes]] { import WatchServiceBackedObservable.eventThreadId private[this] type Event = FileEvent[FileAttributes] @@ -58,7 +59,8 @@ private[sbt] class WatchServiceBackedObservable(s: NewWatchState, } catch { case NonFatal(e) => logger.debug( - s"Error getting files from ${s.service}: $e\n${e.getStackTrace mkString "\n"}") + s"Error getting files from ${s.service}: $e\n${e.getStackTrace mkString "\n"}" + ) } if (!closed.get) loopImpl() } @@ -107,10 +109,12 @@ private[sbt] class WatchServiceBackedObservable(s: NewWatchState, case e => e :: Nil }).map { case d @ Deletion(path, attributes) => - val newAttrs = FileAttributes(isDirectory = attributes.isDirectory, - isOther = false, - isRegularFile = attributes.isRegularFile, - isSymbolicLink = attributes.isSymbolicLink) + val newAttrs = FileAttributes( + isDirectory = attributes.isDirectory, + isOther = false, + isRegularFile = attributes.isRegularFile, + isSymbolicLink = attributes.isSymbolicLink + ) Deletion(path, newAttrs, d.occurredAt) case e => e } diff --git a/io/src/main/scala/sbt/io/Hash.scala b/io/src/main/scala/sbt/io/Hash.scala index 2d40a261..f1092029 100644 --- a/io/src/main/scala/sbt/io/Hash.scala +++ b/io/src/main/scala/sbt/io/Hash.scala @@ -84,7 +84,9 @@ object Hash { while (dis.read(buffer) >= 0) {} dis.close() digest.digest - } finally { stream.close() } + } finally { + stream.close() + } } private def toHex(b: Byte): Char = { diff --git a/io/src/main/scala/sbt/io/IO.scala b/io/src/main/scala/sbt/io/IO.scala index 3ba6b2fc..d24a5fd8 100644 --- a/io/src/main/scala/sbt/io/IO.scala +++ b/io/src/main/scala/sbt/io/IO.scala @@ -105,7 +105,8 @@ object IO { */ @deprecated( "classLocationFile may not work on JDK 11. Use classfileLocation, classLocationFileOption, or classLocationPath instead.", - "1.3.0") + "1.3.0" + ) def classLocationFile(cl: Class[_]): File = classLocationFileOption(cl).getOrElse(sys.error(s"Unable to create File from $cl")) @@ -116,7 +117,8 @@ object IO { */ @deprecated( "classLocationFile may not work on JDK 11. Use classfileLocation, classLocationFileOption, or classLocationPath instead.", - "1.3.0") + "1.3.0" + ) def classLocationFile[T](implicit mf: SManifest[T]): File = classLocationFile(mf.runtimeClass) /** @@ -139,23 +141,28 @@ object IO { try { localcl .orElse(syscl) - .map(url => - url.getProtocol match { - case "jar" => - val path = url.getPath - val end = path.indexOf('!') - new URL( - if (end == -1) path - else path.substring(0, end)) - case "jrt" => - val path = url.getPath - val end = path.indexOf('/', 1) - new URL("jrt", - null, - if (end == -1) path - else path.substring(0, end)) - case _ => url - }) + .map( + url => + url.getProtocol match { + case "jar" => + val path = url.getPath + val end = path.indexOf('!') + new URL( + if (end == -1) path + else path.substring(0, end) + ) + case "jrt" => + val path = url.getPath + val end = path.indexOf('/', 1) + new URL( + "jrt", + null, + if (end == -1) path + else path.substring(0, end) + ) + case _ => url + } + ) .getOrElse(sys.error("No class location for " + cl)) } catch { case NonFatal(e) => @@ -216,10 +223,14 @@ object IO { * `val u4 = new URL("file:////unc/Users/foo/.sbt/preloaded")`. */ def toFile(url: URL): File = - try { uriToFile(url.toURI) } catch { case _: URISyntaxException => new File(url.getPath) } + try { + uriToFile(url.toURI) + } catch { case _: URISyntaxException => new File(url.getPath) } def toFile(uri: URI): File = - try { uriToFile(uri) } catch { case _: URISyntaxException => new File(uri.getPath) } + try { + uriToFile(uri) + } catch { case _: URISyntaxException => new File(uri.getPath) } /** Converts the given URL to a File. If the URL is for an entry in a jar, the File for the jar is returned. */ def asFile(url: URL): File = urlAsFile(url) getOrElse sys.error("URL is not a file: " + url) @@ -463,7 +474,9 @@ object IO { } } read() - } finally { if (close) in.close } + } finally { + if (close) in.close + } } /** @@ -472,7 +485,11 @@ object IO { */ def withTemporaryDirectory[T](action: File => T, keepDirectory: Boolean): T = { val dir = createTemporaryDirectory - try { action(dir) } finally { if (!keepDirectory) delete(dir) } + try { + action(dir) + } finally { + if (!keepDirectory) delete(dir) + } } /** @@ -493,7 +510,9 @@ object IO { val randomName = "sbt_" + java.lang.Integer.toHexString(random.nextInt) val f = new File(baseDirectory, randomName) - try { createDirectory(f); f } catch { case NonFatal(_) => create(tries + 1) } + try { + createDirectory(f); f + } catch { case NonFatal(_) => create(tries + 1) } } } create(0) @@ -510,7 +529,11 @@ object IO { action: File => T ): T = { val file = File.createTempFile(prefix, postfix) - try { action(file) } finally { if (!keepFile) file.delete(); () } + try { + action(file) + } finally { + if (!keepFile) file.delete(); () + } } /** @@ -703,7 +726,11 @@ object IO { (new JarOutputStream(fileOut, mf), "jar") case None => (new ZipOutputStream(fileOut), "zip") } - try { f(zipOut) } finally { zipOut.close } + try { + f(zipOut) + } finally { + zipOut.close + } } } @@ -1021,9 +1048,13 @@ object IO { val stashed = stashLocations(dir, files.toArray) move(stashed) - try { f } catch { + try { + f + } catch { case e: Exception => - try { move(stashed.map(_.swap)); throw e } catch { case _: Exception => throw e } + try { + move(stashed.map(_.swap)); throw e + } catch { case _: Exception => throw e } } } @@ -1293,8 +1324,10 @@ object IO { * @see getModifiedTime * @see copyModifiedTime */ - @deprecated("This method might be removed in the future, also see setModifiedTimeOrFalse()", - "1.1.3") + @deprecated( + "This method might be removed in the future, also see setModifiedTimeOrFalse()", + "1.1.3" + ) def setModifiedTime(file: File, mtime: Long): Unit = Milli.setModifiedTime(file, mtime) /** diff --git a/io/src/main/scala/sbt/io/Path.scala b/io/src/main/scala/sbt/io/Path.scala index 2a8da3d1..8bb07ceb 100644 --- a/io/src/main/scala/sbt/io/Path.scala +++ b/io/src/main/scala/sbt/io/Path.scala @@ -278,8 +278,10 @@ sealed trait RichNioPath extends Any { */ def setGroup(group: String): Unit = { val fileSystem: FileSystem = asPath.getFileSystem - Files.setOwner(asPath, - fileSystem.getUserPrincipalLookupService.lookupPrincipalByGroupName(group)) + Files.setOwner( + asPath, + fileSystem.getUserPrincipalLookupService.lookupPrincipalByGroupName(group) + ) () } } @@ -402,8 +404,10 @@ object PathFinder { override def ---(excludePaths: PathFinder): PathFinder = new SingleFile(file) --- excludePaths override def pair[T](mapper: File => Option[T], errorIfNone: Boolean): Seq[(File, T)] = new SingleFile(file).pair(mapper) - override def descendantsExcept(include: FileFilter, - intermediateExclude: FileFilter): PathFinder = + override def descendantsExcept( + include: FileFilter, + intermediateExclude: FileFilter + ): PathFinder = new SingleFile(file).descendantsExcept(include, intermediateExclude) override def filter(f: File => Boolean): PathFinder = new SingleFile(file).filter(f) override def flatMap(f: File => PathFinder): PathFinder = new SingleFile(file).flatMap(f) @@ -503,8 +507,10 @@ sealed trait PathFinderDefaults extends PathFinder.Combinator { * @param filter only include files that this filter accepts * @param walker use this walker to traverse the file system */ - def globRecursive(filter: FileFilter, - walker: (File, FileFilter, mutable.Set[File]) => Unit): PathFinder = + def globRecursive( + filter: FileFilter, + walker: (File, FileFilter, mutable.Set[File]) => Unit + ): PathFinder = new DescendantOrSelfPathFinder(this, filter, walker) /** Alias of globRecursive. */ @@ -604,7 +610,9 @@ private abstract class PathFinderImpl extends PathFinder { private class SingleFile(asFile: File) extends PathFinderImpl { override private[sbt] def addTo(fileSet: mutable.Set[File]): Unit = - if (asFile.exists) { fileSet += asFile; () } + if (asFile.exists) { + fileSet += asFile; () + } override def toString: String = s"SingleFile($asFile)" override def equals(o: Any): Boolean = o match { @@ -636,8 +644,8 @@ private abstract class FilterFiles extends PathFinderImpl with FileFilter { private class DescendantOrSelfPathFinder( val parent: PathFinder, val filter: FileFilter, - handleFileDescendant: (File, FileFilter, mutable.Set[File]) => Unit) - extends FilterFiles { + handleFileDescendant: (File, FileFilter, mutable.Set[File]) => Unit +) extends FilterFiles { def this(parent: PathFinder, filter: FileFilter) = this(parent, filter, DescendantOrSelfPathFinder.default(_, _, _, Int.MaxValue)) override private[sbt] def addTo(fileSet: mutable.Set[File]): Unit = { @@ -683,8 +691,10 @@ private object DescendantOrSelfPathFinder { mutable.Set(FileVisitOption.FOLLOW_LINKS).asJava, depth - 1, new FileVisitor[NioPath] { - override def preVisitDirectory(dir: NioPath, - attrs: BasicFileAttributes): FileVisitResult = { + override def preVisitDirectory( + dir: NioPath, + attrs: BasicFileAttributes + ): FileVisitResult = { val file = dir.toFile if (filter.accept(file)) fileSet += file FileVisitResult.CONTINUE diff --git a/io/src/main/scala/sbt/io/Using.scala b/io/src/main/scala/sbt/io/Using.scala index 5bb044b9..b74b457b 100644 --- a/io/src/main/scala/sbt/io/Using.scala +++ b/io/src/main/scala/sbt/io/Using.scala @@ -23,7 +23,11 @@ abstract class Using[Source, T] { protected def open(src: Source): T def apply[R](src: Source)(f: T => R): R = { val resource = open(src) - try { f(resource) } finally { close(resource) } + try { + f(resource) + } finally { + close(resource) + } } protected def close(out: T): Unit } @@ -94,7 +98,8 @@ object Using { val fileInputStream = file(f => new BufferedInputStream(new FileInputStream(f))) val urlInputStream = resource( - (u: URL) => translate("Error opening " + u + ": ")(new BufferedInputStream(u.openStream))) + (u: URL) => translate("Error opening " + u + ": ")(new BufferedInputStream(u.openStream)) + ) val fileOutputChannel = file(f => new FileOutputStream(f).getChannel) val fileInputChannel = file(f => new FileInputStream(f).getChannel) @@ -126,8 +131,10 @@ object Using { val jarInputStream = wrap((in: InputStream) => new JarInputStream(in)) def zipEntry(zip: ZipFile) = - resource((entry: ZipEntry) => - translate("Error opening " + entry.getName + " in " + zip + ": ") { - zip.getInputStream(entry) - }) + resource( + (entry: ZipEntry) => + translate("Error opening " + entry.getName + " in " + zip + ": ") { + zip.getInputStream(entry) + } + ) } diff --git a/io/src/main/scala/sbt/nio/file/FileAttributes.scala b/io/src/main/scala/sbt/nio/file/FileAttributes.scala index 0462112a..7d575742 100644 --- a/io/src/main/scala/sbt/nio/file/FileAttributes.scala +++ b/io/src/main/scala/sbt/nio/file/FileAttributes.scala @@ -48,11 +48,12 @@ object FileAttributes { override def isSymbolicLink: Boolean = false override def isOther: Boolean = false } - private final class FileAttributesImpl(override val isDirectory: Boolean, - override val isOther: Boolean, - override val isRegularFile: Boolean, - override val isSymbolicLink: Boolean) - extends FileAttributes { + private final class FileAttributesImpl( + override val isDirectory: Boolean, + override val isOther: Boolean, + override val isRegularFile: Boolean, + override val isSymbolicLink: Boolean + ) extends FileAttributes { override def hashCode: Int = (((isRegularFile.hashCode * 31) ^ isDirectory.hashCode) * 31) ^ isSymbolicLink.hashCode override def equals(o: Any): Boolean = o match { @@ -77,17 +78,23 @@ object FileAttributes { try { val linkAttrs = Files.readAttributes(path, classOf[BasicFileAttributes]) Right( - apply(linkAttrs.isDirectory, - linkAttrs.isOther, - linkAttrs.isRegularFile, - isSymbolicLink = true)) + apply( + linkAttrs.isDirectory, + linkAttrs.isOther, + linkAttrs.isRegularFile, + isSymbolicLink = true + ) + ) } catch { case _: NoSuchFieldException => Right( - apply(isDirectory = false, - isOther = false, - isRegularFile = false, - isSymbolicLink = true)) + apply( + isDirectory = false, + isOther = false, + isRegularFile = false, + isSymbolicLink = true + ) + ) } } else Right(apply(attrs.isDirectory, attrs.isOther, attrs.isRegularFile, isSymbolicLink = false)) @@ -95,9 +102,11 @@ object FileAttributes { case _: NoSuchFileException => Right(NonExistent) case e: IOException => Left(e) } - def apply(isDirectory: Boolean, - isOther: Boolean, - isRegularFile: Boolean, - isSymbolicLink: Boolean): FileAttributes = + def apply( + isDirectory: Boolean, + isOther: Boolean, + isRegularFile: Boolean, + isSymbolicLink: Boolean + ): FileAttributes = new FileAttributesImpl(isDirectory, isOther, isRegularFile, isSymbolicLink) } diff --git a/io/src/main/scala/sbt/nio/file/FileTreeView.scala b/io/src/main/scala/sbt/nio/file/FileTreeView.scala index 8b3a9d58..9812b34d 100644 --- a/io/src/main/scala/sbt/nio/file/FileTreeView.scala +++ b/io/src/main/scala/sbt/nio/file/FileTreeView.scala @@ -40,10 +40,12 @@ object FileTreeView { .asScala .map { typedPath => typedPath.getPath -> - FileAttributes(isDirectory = typedPath.isDirectory, - isOther = false, - isRegularFile = typedPath.isFile, - isSymbolicLink = typedPath.isSymbolicLink) + FileAttributes( + isDirectory = typedPath.isDirectory, + isOther = false, + isRegularFile = typedPath.isFile, + isSymbolicLink = typedPath.isSymbolicLink + ) } .toVector } catch { @@ -73,40 +75,44 @@ object FileTreeView { val converter: ((Path, A)) => (Path, B) = { case (path: Path, attrs) => path -> f(path, attrs) } - path: Path => - view.list(path).map(converter) + path: Path => view.list(path).map(converter) } def flatMap[B, A >: T](f: (Path, A) => Traversable[B]): FileTreeView.Nio[B] = { val converter: ((Path, A)) => Traversable[(Path, B)] = { case (path: Path, attrs) => f(path, attrs).map(path -> _) } - path: Path => - view.list(path).flatMap(converter(_)) + path: Path => view.list(path).flatMap(converter(_)) } } - private[sbt] def all(globs: Traversable[Glob], - view: FileTreeView.Nio[FileAttributes]): Seq[(Path, FileAttributes)] = + private[sbt] def all( + globs: Traversable[Glob], + view: FileTreeView.Nio[FileAttributes] + ): Seq[(Path, FileAttributes)] = all(globs, view, (_, _) => true) - private[sbt] def all(globs: Traversable[Glob], - view: FileTreeView.Nio[FileAttributes], - filter: (Path, FileAttributes) => Boolean): Seq[(Path, FileAttributes)] = + private[sbt] def all( + globs: Traversable[Glob], + view: FileTreeView.Nio[FileAttributes], + filter: (Path, FileAttributes) => Boolean + ): Seq[(Path, FileAttributes)] = iterator(globs, view, filter).toVector private[sbt] def iterator( globs: Traversable[Glob], - view: FileTreeView.Nio[FileAttributes]): Iterator[(Path, FileAttributes)] = + view: FileTreeView.Nio[FileAttributes] + ): Iterator[(Path, FileAttributes)] = iterator(globs, view, (_, _) => true) private[sbt] def iterator( globs: Traversable[Glob], view: FileTreeView.Nio[FileAttributes], - filter: (Path, FileAttributes) => Boolean): Iterator[(Path, FileAttributes)] = { + filter: (Path, FileAttributes) => Boolean + ): Iterator[(Path, FileAttributes)] = { val params = globs.toSeq.sorted.map(_.fileTreeViewListParameters) val needListDirectory: Path => Boolean = (path: Path) => params.exists { case (base, maxDepth, _) => path.startsWith(base) && base.relativize(path).getNameCount < maxDepth - } + } val visited = new util.HashSet[Path] val pathFilter: Path => Boolean = path => params.exists(_._3.matches(path)) val totalFilter: (Path, FileAttributes) => Boolean = { (path, attributes) => diff --git a/io/src/main/scala/sbt/nio/file/Glob.scala b/io/src/main/scala/sbt/nio/file/Glob.scala index 99820ac7..15985b1c 100644 --- a/io/src/main/scala/sbt/nio/file/Glob.scala +++ b/io/src/main/scala/sbt/nio/file/Glob.scala @@ -173,7 +173,8 @@ object Glob extends LowPriorityGlobOps { } else path } private[sbt] def fileTreeViewListParameters( - implicit option: RelativeGlobViewOption): (Path, Int, Glob) = { + implicit option: RelativeGlobViewOption + ): (Path, Int, Glob) = { val b = base val r = range._2 val g = glob match { @@ -419,9 +420,10 @@ object RelativeGlob { override def hashCode: Int = f.hashCode override def toString: String = f.toString } - private[file] final class SingleFileFunctionMatcher(private val base: Path, - private val fileFilter: FileFilter) - extends Matcher { + private[file] final class SingleFileFunctionMatcher( + private val base: Path, + private val fileFilter: FileFilter + ) extends Matcher { override def matches(path: Path): Boolean = fileFilter.accept(base.resolve(path).toFile) override private[sbt] def matchers: List[Matcher] = this :: Nil override def equals(o: Any): Boolean = o match { diff --git a/io/src/test/scala/sbt/internal/io/PollingWatchServiceSpec.scala b/io/src/test/scala/sbt/internal/io/PollingWatchServiceSpec.scala index ef7391e4..f43f95af 100644 --- a/io/src/test/scala/sbt/internal/io/PollingWatchServiceSpec.scala +++ b/io/src/test/scala/sbt/internal/io/PollingWatchServiceSpec.scala @@ -5,5 +5,7 @@ import sbt.internal.nio.PollingWatchService import scala.concurrent.duration._ class PollingWatchServiceSpec - extends SourceModificationWatchSpec((d: FiniteDuration) => new PollingWatchService(d), - DefaultWatchServiceSpec.pollDelay) + extends SourceModificationWatchSpec( + (d: FiniteDuration) => new PollingWatchService(d), + DefaultWatchServiceSpec.pollDelay + ) diff --git a/io/src/test/scala/sbt/internal/io/SourceModificationWatchSpec.scala b/io/src/test/scala/sbt/internal/io/SourceModificationWatchSpec.scala index fb53c9f6..3a5c79c9 100644 --- a/io/src/test/scala/sbt/internal/io/SourceModificationWatchSpec.scala +++ b/io/src/test/scala/sbt/internal/io/SourceModificationWatchSpec.scala @@ -222,7 +222,8 @@ private[sbt] trait EventMonitorSpec { self: FlatSpec with Matchers => assert( watchTest(parentDir, isDeletion(willBeDeleted.toPath), hasDeletion(willBeDeleted.toPath)) { IO.delete(willBeDeleted) - }) + } + ) } it should "ignore deletion of files not included in inclusion filter in subdirectories" in @@ -443,16 +444,19 @@ private[sbt] trait EventMonitorSpec { self: FlatSpec with Matchers => } } - def watchTest(monitor: FileEventMonitor[FileEvent[_]], - filter: FileEvent[_] => Boolean, - check: Seq[FileEvent[_]] => Boolean)(modifier: => Unit): Boolean = { + def watchTest( + monitor: FileEventMonitor[FileEvent[_]], + filter: FileEvent[_] => Boolean, + check: Seq[FileEvent[_]] => Boolean + )(modifier: => Unit): Boolean = { modifier val events = monitor.poll(maxWait * 2, filter) check(events) } def watchTest(base: File, filter: FileEvent[_] => Boolean, check: Seq[FileEvent[_]] => Boolean)( - modifier: => Unit): Boolean = { + modifier: => Unit + ): Boolean = { val globs = base.toPath.toRealPath().toFile.scalaSourceGlobs val logger = new CachingWatchLogger val observable: Observable[Event] = newObservable(globs, logger) @@ -528,9 +532,11 @@ object EventMonitorSpec { object NullLogger extends Logger { override def debug(msg: Any): Unit = {} } // This can't be defined in MonitorOps because of a bug in the scala 2.10 compiler @tailrec - private def drain(monitor: FileEventMonitor[Event], - duration: FiniteDuration, - events: Seq[Event]): Seq[Event] = { + private def drain( + monitor: FileEventMonitor[Event], + duration: FiniteDuration, + events: Seq[Event] + ): Seq[Event] = { val newEvents = monitor.poll(duration) if (newEvents.isEmpty) events else drain(monitor, duration, events ++ newEvents) } diff --git a/io/src/test/scala/sbt/internal/io/SourceSpec.scala b/io/src/test/scala/sbt/internal/io/SourceSpec.scala index 797ba48d..e5b6c035 100644 --- a/io/src/test/scala/sbt/internal/io/SourceSpec.scala +++ b/io/src/test/scala/sbt/internal/io/SourceSpec.scala @@ -17,18 +17,22 @@ class SourceSpec extends FlatSpec with Matchers { source.accept(Paths.get("/foo/bar/baz")) shouldBe false } it should "apply include filter" in { - val source = new Source(new File("/foo"), - new SimpleFileFilter(_.toString.endsWith(".scala")), - NothingFilter, - true) + val source = new Source( + new File("/foo"), + new SimpleFileFilter(_.toString.endsWith(".scala")), + NothingFilter, + true + ) source.accept(Paths.get("/foo/bar/baz.scala")) shouldBe true source.accept(Paths.get("/foo/bar/baz.java")) shouldBe false } it should "apply exclude filter" in { - val source = new Source(new File("/foo"), - new SimpleFileFilter(_.toString.endsWith(".scala")), - new SimpleFileFilter(_ == sbt.io.syntax.file("/foo/bar/buzz.scala")), - true) + val source = new Source( + new File("/foo"), + new SimpleFileFilter(_.toString.endsWith(".scala")), + new SimpleFileFilter(_ == sbt.io.syntax.file("/foo/bar/buzz.scala")), + true + ) source.accept(Paths.get("/foo/bar/baz.scala")) shouldBe true source.accept(Paths.get("/foo/bar/buzz.scala")) shouldBe false } diff --git a/io/src/test/scala/sbt/internal/io/WatchServiceBackedObservableSpec.scala b/io/src/test/scala/sbt/internal/io/WatchServiceBackedObservableSpec.scala index 8aec7746..8356514f 100644 --- a/io/src/test/scala/sbt/internal/io/WatchServiceBackedObservableSpec.scala +++ b/io/src/test/scala/sbt/internal/io/WatchServiceBackedObservableSpec.scala @@ -19,9 +19,11 @@ class WatchServiceBackedObservableSpec extends FlatSpec { val path = dir.getCanonicalFile.toPath val subdir = Files.createDirectories(path.resolve("a").resolve("b").resolve("c")).toRealPath() val watchState = - new NewWatchState(ConcurrentHashMap.newKeySet[Glob].asScala, - WatchService.default, - new ConcurrentHashMap[Path, WatchKey].asScala) + new NewWatchState( + ConcurrentHashMap.newKeySet[Glob].asScala, + WatchService.default, + new ConcurrentHashMap[Path, WatchKey].asScala + ) val observable = new WatchServiceBackedObservable( watchState, diff --git a/io/src/test/scala/sbt/internal/nio/FileEventMonitorSpec.scala b/io/src/test/scala/sbt/internal/nio/FileEventMonitorSpec.scala index 9011c6bb..ed47f76f 100644 --- a/io/src/test/scala/sbt/internal/nio/FileEventMonitorSpec.scala +++ b/io/src/test/scala/sbt/internal/nio/FileEventMonitorSpec.scala @@ -14,12 +14,15 @@ class FileEventMonitorSpec extends FlatSpec with Matchers { private[nio] def antiEntropyMonitor[T <: FileAttributes]( observable: Observable[FileEvent[T]], period: FiniteDuration, - logger: WatchLogger)(implicit timeSource: TimeSource): FileEventMonitor[FileEvent[T]] = + logger: WatchLogger + )(implicit timeSource: TimeSource): FileEventMonitor[FileEvent[T]] = FileEventMonitor.antiEntropy(observable, period, logger, 50.millis, 10.minutes) object TestAttributes { - def apply(isDirectory: Boolean = false, - isRegularFile: Boolean = false, - isSymbolicLink: Boolean = false): FileAttributes = + def apply( + isDirectory: Boolean = false, + isRegularFile: Boolean = false, + isSymbolicLink: Boolean = false + ): FileAttributes = FileAttributes(isDirectory, isOther = false, isRegularFile, isSymbolicLink) } class DeterminsticTimeSource extends TimeSource with AutoCloseable { @@ -124,11 +127,13 @@ class FileEventMonitorSpec extends FlatSpec with Matchers { val antiEntropyPeriod = 40.millis val quarantinePeriod = antiEntropyPeriod / 2 val monitor = - FileEventMonitor.antiEntropy(observers, - antiEntropyPeriod, - NullWatchLogger, - quarantinePeriod, - 10.minutes) + FileEventMonitor.antiEntropy( + observers, + antiEntropyPeriod, + NullWatchLogger, + quarantinePeriod, + 10.minutes + ) val foo = Paths.get("foo") val fooAttributes = FileAttributes.NonExistent val fooDeletion = Deletion(foo, fooAttributes, Deadline.now) @@ -142,11 +147,13 @@ class FileEventMonitorSpec extends FlatSpec with Matchers { val antiEntropyPeriod = 40.millis val quarantinePeriod = antiEntropyPeriod / 2 val monitor = - FileEventMonitor.antiEntropy(observers, - antiEntropyPeriod, - NullWatchLogger, - quarantinePeriod, - 10.minutes) + FileEventMonitor.antiEntropy( + observers, + antiEntropyPeriod, + NullWatchLogger, + quarantinePeriod, + 10.minutes + ) val foo = Paths.get("foo") val deletionAttributes = FileAttributes.NonExistent val fooDeletion = Deletion(foo, deletionAttributes) diff --git a/io/src/test/scala/sbt/internal/nio/FileTreeRepositorySpec.scala b/io/src/test/scala/sbt/internal/nio/FileTreeRepositorySpec.scala index 49a9f1c9..48db8c81 100644 --- a/io/src/test/scala/sbt/internal/nio/FileTreeRepositorySpec.scala +++ b/io/src/test/scala/sbt/internal/nio/FileTreeRepositorySpec.scala @@ -49,7 +49,8 @@ object FileTreeRepositorySpec { override def onNext(t: FileEvent[FileAttributes]): Unit = f(t.path) }) def simpleCache( - observer: Observer[FileEvent[FileAttributes]]): FileTreeRepository[FileAttributes] = { + observer: Observer[FileEvent[FileAttributes]] + ): FileTreeRepository[FileAttributes] = { val underlying = new FileTreeRepositoryImpl() underlying.addObserver(observer) underlying diff --git a/io/src/test/scala/sbt/io/CopySpec.scala b/io/src/test/scala/sbt/io/CopySpec.scala index 42c5798c..6da6593c 100644 --- a/io/src/test/scala/sbt/io/CopySpec.scala +++ b/io/src/test/scala/sbt/io/CopySpec.scala @@ -22,15 +22,17 @@ object CopySpec extends Properties("Copy") { 1 -> Gen.const(0) ) - property("same contents") = forAll(fileSizeGen, arbLong.arbitrary)((size: Long, seed: Long) => - IO.withTemporaryDirectory { dir => - val f1 = new File(dir, "source") - val f2 = new File(dir, "dest") - generate(seed = seed, size = size, file = f1) - IO.copyFile(f1, f2) - checkContentsSame(f1, f2) - true - }) + property("same contents") = forAll(fileSizeGen, arbLong.arbitrary)( + (size: Long, seed: Long) => + IO.withTemporaryDirectory { dir => + val f1 = new File(dir, "source") + val f2 = new File(dir, "dest") + generate(seed = seed, size = size, file = f1) + IO.copyFile(f1, f2) + checkContentsSame(f1, f2) + true + } + ) def generate(seed: Long, size: Long, file: File) = { val rnd = new java.util.Random(seed) diff --git a/io/src/test/scala/sbt/io/FileUtilitiesSpecification.scala b/io/src/test/scala/sbt/io/FileUtilitiesSpecification.scala index ba3ed47a..9ce02c92 100644 --- a/io/src/test/scala/sbt/io/FileUtilitiesSpecification.scala +++ b/io/src/test/scala/sbt/io/FileUtilitiesSpecification.scala @@ -18,10 +18,12 @@ object WriteContentSpecification extends Properties("Write content") { property("Unzip doesn't stack overflow") = largeUnzip() implicit lazy val validChar: Arbitrary[Char] = Arbitrary( - for (i <- Gen.choose(0, 0xd7ff)) yield i.toChar) + for (i <- Gen.choose(0, 0xd7ff)) yield i.toChar + ) implicit lazy val validString: Arbitrary[String] = Arbitrary( - arbitrary[List[Char]] map (_.mkString)) + arbitrary[List[Char]] map (_.mkString) + ) private def largeUnzip() = { testUnzip[Product] diff --git a/io/src/test/scala/sbt/io/IOSpec.scala b/io/src/test/scala/sbt/io/IOSpec.scala index 31e996b7..b107983b 100644 --- a/io/src/test/scala/sbt/io/IOSpec.scala +++ b/io/src/test/scala/sbt/io/IOSpec.scala @@ -23,9 +23,11 @@ class IOSpec extends FunSuite { val relativeRootDir = new File(nestedDir, "..") assert( IO.relativize(rootDir.toFile, nestedFile) - .map(normalizeForWindows) === Option("meh.file")) + .map(normalizeForWindows) === Option("meh.file") + ) assert( - IO.relativize(relativeRootDir, nestedFile).map(normalizeForWindows) === Option("meh.file")) + IO.relativize(relativeRootDir, nestedFile).map(normalizeForWindows) === Option("meh.file") + ) IO.delete(rootDir.toFile) } @@ -101,15 +103,18 @@ class IOSpec extends FunSuite { val u = IO.classLocation[java.lang.Integer] assert( (u.toString == "jrt:/java.base") || - (u.toString.startsWith("file:") && u.toString.endsWith("rt.jar") && IO.asFile(u).isFile)) + (u.toString.startsWith("file:") && u.toString.endsWith("rt.jar") && IO.asFile(u).isFile) + ) } test( - "classLocation[AbstractMap.SimpleEntry] should return a URL pointing to the rt.jar or java.base") { + "classLocation[AbstractMap.SimpleEntry] should return a URL pointing to the rt.jar or java.base" + ) { val u = IO.classLocation[java.util.AbstractMap.SimpleEntry[String, String]] assert( (u.toString == "jrt:/java.base") || - (u.toString.startsWith("file:") && u.toString.endsWith("rt.jar") && IO.asFile(u).isFile)) + (u.toString.startsWith("file:") && u.toString.endsWith("rt.jar") && IO.asFile(u).isFile) + ) } test("classLocation[this.type] should return a URL pointing to a directory or a JAR") { @@ -128,7 +133,8 @@ class IOSpec extends FunSuite { } test( - "classLocationPath[AbstractMap.SimpleEntry] should return NIO path pointing to the rt.jar or java.base") { + "classLocationPath[AbstractMap.SimpleEntry] should return NIO path pointing to the rt.jar or java.base" + ) { val p = IO.classLocationPath[java.util.AbstractMap.SimpleEntry[String, String]] assert( ((p.toString == "/java.base") && (p.getFileSystem.toString == "jrt:/")) @@ -154,7 +160,8 @@ class IOSpec extends FunSuite { } test( - "classLocationFileOption[AbstractMap.SimpleEntry] should return File pointing to the rt.jar or None") { + "classLocationFileOption[AbstractMap.SimpleEntry] should return File pointing to the rt.jar or None" + ) { val opt = IO.classLocationFileOption[java.util.AbstractMap.SimpleEntry[String, String]] assert( opt match { @@ -175,14 +182,16 @@ class IOSpec extends FunSuite { val s = IO.classfileLocation[java.lang.Integer].toString assert( (s == "jrt:/java.base/java/lang/Integer.class") || - (s.startsWith("jar:file:") && s.endsWith("!/java/lang/Integer.class"))) + (s.startsWith("jar:file:") && s.endsWith("!/java/lang/Integer.class")) + ) } test("classfileLocation[AbstractMap.SimpleEntry] should return a URL pointing to *.class") { val s = IO.classfileLocation[java.util.AbstractMap.SimpleEntry[String, String]].toString assert( (s == "jrt:/java.base/java/util/AbstractMap$SimpleEntry.class") || - (s.startsWith("jar:file:") && s.endsWith("!/java/util/AbstractMap$SimpleEntry.class"))) + (s.startsWith("jar:file:") && s.endsWith("!/java/util/AbstractMap$SimpleEntry.class")) + ) } test("classfileLocation[this.type] should return a URL pointing to *.class") { diff --git a/io/src/test/scala/sbt/io/NameFilterSpecification.scala b/io/src/test/scala/sbt/io/NameFilterSpecification.scala index 943d8889..10525011 100644 --- a/io/src/test/scala/sbt/io/NameFilterSpecification.scala +++ b/io/src/test/scala/sbt/io/NameFilterSpecification.scala @@ -8,10 +8,12 @@ object NameFilterSpecification extends Properties("NameFilter") { property("All pass accepts everything") = forAll((s: String) => AllPassFilter.accept(s)) property("Exact filter matches provided string") = forAll( - (s1: String, s2: String) => (new ExactFilter(s1)).accept(s2) == (s1 == s2)) + (s1: String, s2: String) => (new ExactFilter(s1)).accept(s2) == (s1 == s2) + ) property("Exact filter matches valid string") = forAll( - (s: String) => (new ExactFilter(s)).accept(s)) + (s: String) => (new ExactFilter(s)).accept(s) + ) property("Glob filter matches provided string if no *s") = forAll { (s1: String, s2: String) => val stripped = stripAsterisksAndControl(s1) diff --git a/io/src/test/scala/sbt/io/PathMapperSpec.scala b/io/src/test/scala/sbt/io/PathMapperSpec.scala index 6e8786e6..10abfe5f 100644 --- a/io/src/test/scala/sbt/io/PathMapperSpec.scala +++ b/io/src/test/scala/sbt/io/PathMapperSpec.scala @@ -20,8 +20,9 @@ class PathMapperSpec extends fixture.FlatSpec with Matchers { ) val target = base / "target" / "scala-2.11" / "classes" - val mappings = (files --- dirs) pair (file => - rebase(dirs, target)(file) orElse (flat(target): File => Option[File])(file)) + val mappings = (files --- dirs) pair ( + file => rebase(dirs, target)(file) orElse (flat(target): File => Option[File])(file) + ) mappings shouldBe Seq( base / "src" / "main" / "resources" / "scalac-plugin.xml" -> diff --git a/io/src/test/scala/sbt/nio/FileTreeViewSpec.scala b/io/src/test/scala/sbt/nio/FileTreeViewSpec.scala index c6f8f05d..c8f13714 100644 --- a/io/src/test/scala/sbt/nio/FileTreeViewSpec.scala +++ b/io/src/test/scala/sbt/nio/FileTreeViewSpec.scala @@ -22,7 +22,9 @@ class FileTreeViewSpec extends FlatSpec { val file = Files.createFile(nestedSubdir.resolve("file")) assert( view.list(Glob(dir, RecursiveGlob)).collect { case (p, a) if !a.isDirectory => p } == Seq( - file)) + file + ) + ) } "iterator" should "be lazy" in IO.withTemporaryDirectory { dir => val firstSubdir = Files.createDirectory(dir.toPath.resolve("first")) diff --git a/io/src/test/scala/sbt/nio/GlobFilterSpec.scala b/io/src/test/scala/sbt/nio/GlobFilterSpec.scala index dc87a615..be13e4b8 100644 --- a/io/src/test/scala/sbt/nio/GlobFilterSpec.scala +++ b/io/src/test/scala/sbt/nio/GlobFilterSpec.scala @@ -51,9 +51,11 @@ class GlobFilterSpec extends FlatSpec { assert(Glob(base, p"*/**/*.txt").matches(base.resolve("foo").resolve("bar.txt"))) assert( Glob(base, p"*/**/*.txt") - .matches(base.resolve("foo").resolve("bar").resolve("baz").resolve("bar.txt"))) + .matches(base.resolve("foo").resolve("bar").resolve("baz").resolve("bar.txt")) + ) assert( !Glob(base, p"*/**/*.txt") - .matches(base.resolve("foo").resolve("bar").resolve("baz").resolve("bar.tx"))) + .matches(base.resolve("foo").resolve("bar").resolve("baz").resolve("bar.tx")) + ) } } diff --git a/io/src/test/scala/sbt/nio/GlobPathFinderSpec.scala b/io/src/test/scala/sbt/nio/GlobPathFinderSpec.scala index 2247cb9d..a4e1e15b 100644 --- a/io/src/test/scala/sbt/nio/GlobPathFinderSpec.scala +++ b/io/src/test/scala/sbt/nio/GlobPathFinderSpec.scala @@ -40,7 +40,8 @@ class GlobPathFinderSpec extends FlatSpec { assert((dir ** "bar.txt").get() == Nil) assert( dir.descendantsExcept(AllPassFilter, NothingFilter).get().toSet == - PathFinder(dir).descendantsExcept(AllPassFilter, NothingFilter).get().toSet) + PathFinder(dir).descendantsExcept(AllPassFilter, NothingFilter).get().toSet + ) } it should "work with combiners" in IO.withTemporaryDirectory { dir => val subdir = Files.createDirectories(dir.toPath.resolve("subdir")).toFile diff --git a/io/src/test/scala/sbt/nio/GlobSyntaxSpec.scala b/io/src/test/scala/sbt/nio/GlobSyntaxSpec.scala index 102b788f..39983b84 100644 --- a/io/src/test/scala/sbt/nio/GlobSyntaxSpec.scala +++ b/io/src/test/scala/sbt/nio/GlobSyntaxSpec.scala @@ -45,10 +45,12 @@ class GlobSyntaxSpec extends FlatSpec { assert(!Glob(basePath, "foo[a-d]b").matches(basePath.resolve("abcdefooeb"))) assert(Glob(basePath, p"**/*foo[a-d]b").matches(basePath.resolve("abcdefooab"))) assert( - Glob(basePath, p"**/*/*foo[a-d]b").matches(basePath.resolve("bar").resolve("abcdefooab"))) + Glob(basePath, p"**/*/*foo[a-d]b").matches(basePath.resolve("bar").resolve("abcdefooab")) + ) assert( Glob(basePath, p"**/*/*foo[a-d]b") - .matches(basePath.resolve("bar").resolve("baz").resolve("buzz").resolve("abcdefooab"))) + .matches(basePath.resolve("bar").resolve("baz").resolve("buzz").resolve("abcdefooab")) + ) } they should "apply extension filters" in { assert(Glob(basePath, "*.txt").matches(basePath.resolve("foo.txt"))) @@ -59,8 +61,8 @@ class GlobSyntaxSpec extends FlatSpec { assert(!Glob(basePath, "*.{txt,md}").matches(basePath.resolve("foo.scala"))) val complexGlob = Glob(basePath, AnyPath / RecursiveGlob / AnyPath / "*.{txt,md}") assert( - complexGlob.matches( - basePath.resolve("foo").resolve("bar").resolve("buzz").resolve("foo.txt"))) + complexGlob.matches(basePath.resolve("foo").resolve("bar").resolve("buzz").resolve("foo.txt")) + ) assert(complexGlob.matches(basePath.resolve("foo").resolve("bar").resolve("foo.txt"))) assert(!complexGlob.matches(basePath.resolve("bar").resolve("foo.txt"))) } @@ -71,8 +73,8 @@ class GlobSyntaxSpec extends FlatSpec { assert(!Glob(basePath, "foo*").matches(basePath.resolve("bar").resolve("foo.txt"))) val complexGlob = Glob(basePath, AnyPath / RecursiveGlob / AnyPath / "foo*") assert( - complexGlob.matches( - basePath.resolve("foo").resolve("bar").resolve("buzz").resolve("foo.txt"))) + complexGlob.matches(basePath.resolve("foo").resolve("bar").resolve("buzz").resolve("foo.txt")) + ) assert(complexGlob.matches(basePath.resolve("foo").resolve("bar").resolve("foo.txt"))) assert(!complexGlob.matches(basePath.resolve("bar").resolve("foo.txt"))) } @@ -82,8 +84,8 @@ class GlobSyntaxSpec extends FlatSpec { assert(!Glob(basePath, "*foo").matches(basePath.resolve("bar").resolve("abcdfoo"))) val complexGlob = Glob(basePath, AnyPath / RecursiveGlob / AnyPath / "*foo") assert( - complexGlob.matches( - basePath.resolve("foo").resolve("bar").resolve("buzz").resolve("abcdfoo"))) + complexGlob.matches(basePath.resolve("foo").resolve("bar").resolve("buzz").resolve("abcdfoo")) + ) assert(complexGlob.matches(basePath.resolve("foo").resolve("bar").resolve("abcdfoo"))) assert(!complexGlob.matches(basePath.resolve("bar").resolve("abcdfoo"))) } @@ -94,7 +96,8 @@ class GlobSyntaxSpec extends FlatSpec { assert(Glob(basePath, RecursiveGlob / "foo*bar").matches(basePath.resolve("fooabcbar"))) assert( Glob(basePath, RecursiveGlob / "foo*bar") - .matches(basePath.resolve("baz").resolve("buzz").resolve("fooabcbar"))) + .matches(basePath.resolve("baz").resolve("buzz").resolve("fooabcbar")) + ) } they should "work with file syntax" in IO.withTemporaryDirectory { dir => val file = basePath.toFile @@ -163,7 +166,9 @@ class GlobSyntaxSpec extends FlatSpec { assert( basePath.toGlob / RecursiveGlob / AnyPath / "*.txt" == Glob( basePath, - RecursiveGlob / AnyPath / "*.txt")) + RecursiveGlob / AnyPath / "*.txt" + ) + ) assert(basePath.toGlob / * == Glob(basePath, AnyPath)) assert(basePath.toGlob / ** / * / "*.txt" == Glob(basePath, RecursiveGlob / AnyPath / "*.txt")) } @@ -171,6 +176,7 @@ class GlobSyntaxSpec extends FlatSpec { implicit val option: RelativeGlobViewOption = RelativeGlobViewOption.Ignore assert(Glob(p"./foo").fileTreeViewListParameters._3.matches(Paths.get("foo").toAbsolutePath)) assert( - Glob(p"./foo/*").fileTreeViewListParameters._3.matches(Paths.get(p"foo/bar").toAbsolutePath)) + Glob(p"./foo/*").fileTreeViewListParameters._3.matches(Paths.get(p"foo/bar").toAbsolutePath) + ) } } From aa27a9552336907cbb657876d76df8e2d3675b22 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 4 May 2019 01:46:39 -0400 Subject: [PATCH 3/3] Scalafmt 2.0.0-RC7 --- .scalafmt.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 718ce5ae..91c7f99c 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 2.0.0-RC6 +version = 2.0.0-RC7 maxColumn = 100 project.git = true project.excludeFilters = [ /sbt-test/, /input_sources/, /contraband-scala/ ]