Skip to content

Commit

Permalink
Merge pull request #236 from eed3si9n/wip/plugins
Browse files Browse the repository at this point in the history
Bump plugins
  • Loading branch information
eed3si9n authored May 4, 2019
2 parents ade240d + aa27a95 commit e5f1ece
Show file tree
Hide file tree
Showing 42 changed files with 509 additions and 307 deletions.
11 changes: 11 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version = 2.0.0-RC7
maxColumn = 100
project.git = true
project.excludeFilters = [ /sbt-test/, /input_sources/, /contraband-scala/ ]
Expand All @@ -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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
[email protected]
os: linux
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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"))
Expand All @@ -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("."))
Expand Down
12 changes: 9 additions & 3 deletions io/src/main/scala/sbt/internal/io/ErrorHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
79 changes: 48 additions & 31 deletions io/src/main/scala/sbt/internal/io/Milli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
)
}
}

Expand Down Expand Up @@ -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
)
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions io/src/main/scala/sbt/internal/io/Retry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down
27 changes: 16 additions & 11 deletions io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

/**
Expand Down
10 changes: 6 additions & 4 deletions io/src/main/scala/sbt/internal/nio/DefaultFileTreeView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 11 additions & 9 deletions io/src/main/scala/sbt/internal/nio/FileCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 15 additions & 11 deletions io/src/main/scala/sbt/internal/nio/FileEvent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit e5f1ece

Please sign in to comment.