Skip to content

Commit

Permalink
Merge branch 'develop' into remove-sbt-whitesource
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored Nov 15, 2021
2 parents e6a5555 + ff50334 commit b88ee1e
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 21 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
env:
SCALA212: 2.12.14
SCALA213: 2.13.6
SCALA3: 3.1.0

jobs:
test:
Expand Down Expand Up @@ -46,11 +47,11 @@ jobs:
case ${{ matrix.jobtype }} in
1)
sbt -v -Dfile.encoding=UTF8 -Dsbt.test.fork=true ++$SCALA212! mimaReportBinaryIssues scalafmtCheckAll headerCheck Test/headerCheck test doc
sbt -v -Dfile.encoding=UTF8 -Dsbt.test.fork=false ++$SCALA213! test
sbt -v -Dfile.encoding=UTF8 -Dsbt.test.fork=false ++$SCALA213! test ++$SCALA3! test
;;
2)
sbt -v -Dfile.encoding=UTF8 -Dsbt.test.fork=true ++$SCALA212! mimaReportBinaryIssues test
sbt -v -Dfile.encoding=UTF8 -Dsbt.test.fork=false ++$SCALA213! test
sbt -v -Dfile.encoding=UTF8 -Dsbt.test.fork=false ++$SCALA213! test ++$SCALA3! test
;;
*)
echo unknown jobtype
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ThisBuild / publishTo := {
def commonSettings: Seq[Setting[_]] = Seq(
scalaVersion := scala212,
compile / javacOptions ++= Seq("-Xlint", "-Xlint:-serial"),
crossScalaVersions := Seq(scala212, scala213),
crossScalaVersions := Seq(scala212, scala213, scala3),
headerLicense := (ThisBuild / headerLicense).value,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import sbt.internal.nio._
import sbt.io._
import sbt.io.syntax._
import sbt.nio.file.{ AnyPath, FileAttributes, FileTreeView, Glob, RecursiveGlob }
import sbt.nio.file.Glob.GlobOps

import scala.annotation.tailrec
import scala.collection.JavaConverters._
Expand Down
2 changes: 2 additions & 0 deletions io/src/main/scala/sbt/internal/nio/FileCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import java.util.Collections
import java.util.concurrent.{ ConcurrentHashMap, ConcurrentSkipListMap }

import sbt.internal.nio.FileEvent.{ Creation, Deletion, Update }
import sbt.internal.nio.FileCache.{ GlobOps => FileCacheGlobOps }
import sbt.nio.file.FileAttributes.NonExistent
import sbt.nio.file.{ AnyPath, FileAttributes, FileTreeView, Glob, RecursiveGlob }
import sbt.nio.file.Glob.{ GlobOps => GlobGlobOps }

import scala.collection.JavaConverters._
import scala.collection.mutable
Expand Down
10 changes: 7 additions & 3 deletions io/src/main/scala/sbt/internal/nio/FileEventMonitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,14 @@ private[sbt] object FileEventMonitor {
val waits = quarantinedEvents.map(_._2.occurredAt + quarantinePeriod - now).toVector
if (waits.isEmpty) None else Some(waits.min)
}
@tailrec
override final def poll(
duration: Duration,
filter: FileEvent[T] => Boolean
): Seq[FileEvent[T]] = pollImpl(duration, filter)
@tailrec
private[this] final def pollImpl(
duration: Duration,
filter: FileEvent[T] => Boolean
): Seq[FileEvent[T]] = {
val start = Deadline.now
val adjustedDuration = quarantineDuration.map(Seq(duration, _).min).getOrElse(duration)
Expand Down Expand Up @@ -292,7 +296,7 @@ private[sbt] object FileEventMonitor {
quarantinedEvents.remove(path)
antiEntropyDeadlines.put(path, event.occurredAt + period)
logger.debug(s"Triggering event for previously quarantined deleted file: $path")
event
event: FileEvent[T]
}
// Keep old anti entropy events around for a while in case there are still unhandled
// events that occurred between polls. This is necessary because there is no background
Expand All @@ -304,7 +308,7 @@ private[sbt] object FileEventMonitor {
case s: Seq[FileEvent[T]] if s.nonEmpty => s
case _ =>
val limit = duration - (Deadline.now - start)
if (limit > 0.millis) poll(limit, filter) else Nil
if (limit > 0.millis) pollImpl(limit, filter) else Nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.swoval.functional.Filters
import sbt.internal.nio.FileEvent.{ Creation, Deletion, Update }
import sbt.internal.nio.SwovalConverters._
import sbt.nio.file.{ FileAttributes, Glob }
import sbt.nio.file.Glob.GlobOps

import scala.collection.JavaConverters._
import scala.collection.immutable.VectorBuilder
Expand Down
1 change: 1 addition & 0 deletions io/src/main/scala/sbt/internal/nio/Observers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger

import sbt.nio.file.Glob
import sbt.nio.file.Glob.GlobOps

import scala.util.control.NonFatal

Expand Down
2 changes: 1 addition & 1 deletion io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ object IO {
* See `sbt.io.IO$.move(java.io.File,java.io.File):Unit` for the behavior of the individual move operations.
*/
def move(files: Traversable[(File, File)]): Unit =
files.foreach(Function.tupled(move))
files.foreach(Function.tupled(move(_, _)))

/**
* Moves the contents of `a` to the location specified by `b`.
Expand Down
1 change: 1 addition & 0 deletions io/src/main/scala/sbt/io/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import java.nio.file.{

import sbt.io.PathFinder.GlobPathFinder
import sbt.nio.file.{ AnyPath, FileAttributes, FileTreeView, Glob }
import sbt.nio.file.Glob.GlobOps

import scala.collection.JavaConverters._
import scala.collection.mutable
Expand Down
5 changes: 3 additions & 2 deletions io/src/main/scala/sbt/nio/file/FileTreeView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap

import sbt.internal.io.Retry
import sbt.internal.nio.SwovalFileTreeView
import sbt.nio.file.Glob.GlobOps
import sbt.nio.file.Glob.Root

import scala.annotation.tailrec
Expand Down Expand Up @@ -249,13 +250,13 @@ 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(_))
}
}

Expand Down
1 change: 1 addition & 0 deletions io/src/test/scala/sbt/internal/nio/PathSyntaxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import sbt.nio.TestHelpers._
import sbt.nio.file.RelativeGlob
import sbt.nio.file.syntax._
import sbt.nio.file._
import sbt.nio.file.Glob.GlobOps

class PathSyntaxSpec extends AnyFlatSpec {
"toGlob" should "work with absolute paths" in {
Expand Down
3 changes: 1 addition & 2 deletions io/src/test/scala/sbt/io/CopyDirectorySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
package sbt.io

import java.nio.file._
import org.scalatest.diagrams.Diagrams
import org.scalatest.flatspec.AnyFlatSpec
import sbt.io.syntax._

class CopyDirectorySpec extends AnyFlatSpec with Diagrams {
class CopyDirectorySpec extends AnyFlatSpec {
it should "copy symlinks" in IO.withTemporaryDirectory { dir =>
// Given:
// src/
Expand Down
4 changes: 2 additions & 2 deletions io/src/test/scala/sbt/nio/FileTreeViewSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import sbt.nio.file.{
}
import sbt.nio.file.syntax._

import scala.annotation.tailrec
import scala.collection.mutable

class FileTreeViewSpec extends AnyFlatSpec {
Expand Down Expand Up @@ -110,7 +109,8 @@ class FileTreeViewSpec extends AnyFlatSpec {
val random = new scala.util.Random()
val n = 2000
val nested = Files.createDirectories(dir.toPath / "subdir" / "nested")
@tailrec
// TODO https://github.com/lampepfl/dotty/issues/13941
// @tailrec
def newRandomFile(): Path =
try Files.createFile(nested / s"a${1 + random.nextInt(n)}")
catch { case _: FileAlreadyExistsException => newRandomFile() }
Expand Down
1 change: 1 addition & 0 deletions io/src/test/scala/sbt/nio/GlobFilterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.scalatest.flatspec.AnyFlatSpec
import sbt.io.IO
import sbt.io.syntax._
import sbt.nio.file.{ AnyPath, Glob, RecursiveGlob }
import sbt.nio.file.Glob.GlobOps

class GlobFilterSpec extends AnyFlatSpec {
"GlobAsFilter" should "work with simple files" in IO.withTemporaryDirectory { dir =>
Expand Down
3 changes: 2 additions & 1 deletion io/src/test/scala/sbt/nio/GlobSyntaxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import java.nio.file.Paths

import org.scalatest.flatspec.AnyFlatSpec
import sbt.nio.TestHelpers._
import sbt.nio.file.Glob.GlobOps
import sbt.nio.file.Glob.RelativeGlobViewOption
import sbt.nio.file.RelativeGlob.{ *, ** }
import sbt.nio.file.RelativeGlob._
import sbt.nio.file.syntax._
import sbt.nio.file.{ AnyPath, Glob, RecursiveGlob, RelativeGlob }

Expand Down
1 change: 1 addition & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Keys._
object Dependencies {
val scala212 = "2.12.15"
val scala213 = "2.13.6"
val scala3 = "3.1.0"

val scalaCompiler = Def.setting {
val v = if (scalaBinaryVersion.value == "3") scala213 else scalaVersion.value
Expand Down
18 changes: 11 additions & 7 deletions project/HouseRulesPluglin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ object HouseRulesPlugin extends AutoPlugin {

lazy val baseSettings: Seq[Def.Setting[_]] = Seq(
scalacOptions ++= Seq("-encoding", "utf8"),
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-Xlint"),
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked"),
scalacOptions += "-language:higherKinds",
scalacOptions += "-language:implicitConversions",
scalacOptions ++= "-Xfuture".ifScala213OrMinus.value.toList,
scalacOptions += "-Xlint",
scalacOptions ++= "-Xfatal-warnings"
.ifScala(v => {
sys.props.get("sbt.build.fatal") match {
Expand All @@ -27,10 +26,9 @@ object HouseRulesPlugin extends AutoPlugin {
.toList,
scalacOptions ++= "-Yinline-warnings".ifScala211OrMinus.value.toList,
scalacOptions ++= "-Yno-adapted-args".ifScala212OrMinus.value.toList,
scalacOptions += "-Ywarn-dead-code",
scalacOptions += "-Ywarn-numeric-widen",
scalacOptions += "-Ywarn-value-discard",
scalacOptions ++= "-Ywarn-unused-import".ifScala(v => 11 <= v && v <= 12).value.toList
scalacOptions ++= "-Ywarn-dead-code".ifScala213OrMinus.value.toList,
scalacOptions ++= "-Ywarn-numeric-widen".ifScala213OrMinus.value.toList,
scalacOptions ++= "-Ywarn-value-discard".ifScala213OrMinus.value.toList,
) ++ Seq(Compile, Test).flatMap(
c => (c / console / scalacOptions) --= Seq("-Ywarn-unused-import", "-Xlint")
)
Expand All @@ -41,7 +39,13 @@ object HouseRulesPlugin extends AutoPlugin {
def ifScala(p: Long => Boolean) =
Def setting (scalaPartV.value collect { case (2, y) if p(y) => __x })
def ifScalaLte(v: Long) = ifScala(_ <= v)
def ifScalaGte(v: Long) = ifScala(_ >= v)
def ifScalaGte(v: Long) =
Def.setting(
scalaPartV.value.collect {
case (2, y) if y >= v => __x
case (n, _) if n >= 3 => __x
}
)
def ifScala211OrMinus = ifScalaLte(11)
def ifScala211OrPlus = ifScalaGte(11)
def ifScala212OrMinus = ifScalaLte(12)
Expand Down

0 comments on commit b88ee1e

Please sign in to comment.