From eac193762c5de683d55d63f5415353f8b0de82fc Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 11 Oct 2017 18:42:39 +0100 Subject: [PATCH] Add a recursive property to Source Required to fix sbt/sbt#3501. --- .../internal/io/SourceModificationWatch.scala | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala b/io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala index 92243925..3a369630 100644 --- a/io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala +++ b/io/src/main/scala/sbt/internal/io/SourceModificationWatch.scala @@ -130,8 +130,17 @@ private[sbt] final class WatchState private ( * @param base Where to start looking for files. * @param includeFilter Filter to apply to determine whether to include a file. * @param excludeFilter Filter to apply to determine whether to ignore a file. + * @param recursive Whether the lists is recursive or immediate children. */ -final class Source(base: File, includeFilter: FileFilter, excludeFilter: FileFilter) { +final class Source( + base: File, + includeFilter: FileFilter, + excludeFilter: FileFilter, + recursive: Boolean +) { + + def this(base: File, includeFilter: FileFilter, excludeFilter: FileFilter) = + this(base, includeFilter, excludeFilter, true) /** * Determine whether `p` should be included in this source. @@ -151,8 +160,13 @@ final class Source(base: File, includeFilter: FileFilter, excludeFilter: FileFil * Gathers all the paths from this source without applying filters. * @return A sequence of all the paths collected from this source. */ - private[sbt] def getUnfilteredPaths(): Seq[Path] = - base.allPaths.get.map(_.toPath) + private[sbt] def getUnfilteredPaths(): Seq[Path] = { + val pathFinder = if (recursive) base.allPaths else base.glob(AllPassFilter) + pathFinder.get.map(_.toPath) + } + + def withRecursive(recursive: Boolean): Source = + new Source(base, includeFilter, excludeFilter, recursive) }