From 03cb79bbfc534a2d7befe1374a695e3e84fd9613 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sun, 13 Jan 2019 16:04:58 -0800 Subject: [PATCH] Stop using ---/pair in SbtLauncherPlugin I'd like to remove '---' and 'pair' in sbt 2 so I'm inlining the logic where I find it. The '---' method is trivially implemented with a filter on the sequence of files and filtering the output will not require io, unlike '---'. For pair, I get confused every time I see it in the code and it is rarely saving more than a line. While I understand that it may have been convenient when the code using pair was originally written, I don't think it is worth the maintenance cost. My specific issue is that to me pair means tuple2, full stop. The definition of pair is: def pair[T](mapper: File => Option[T], errorIfNone: Boolean = true): Seq[(File, T)] First of all, it's not at all obvious when seen inline in the code that it has the side effect of evaluating PathFinder.get. Moreover, it doesn't return a general pair, it's a very specific pair with a File in the first position. I just don't see how using pair improves upon, say: val func: File => Option[(File, String)] = ??? globs.all.flatMap(func) or val func: File => Option[(File, String)] = ??? globs.all.map(f => func(f) match { case Some(r) => r case None => throw new IllegalStateException("Couldn't evaluate func for $f") }) // or just define `func = File => (File, String)` and throw on an error --- project/SbtLauncherPlugin.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/project/SbtLauncherPlugin.scala b/project/SbtLauncherPlugin.scala index c3b5f229b..7386b79cc 100644 --- a/project/SbtLauncherPlugin.scala +++ b/project/SbtLauncherPlugin.scala @@ -1,6 +1,5 @@ -import sbt.io.Path._ +import sbt.Keys._ import sbt._ -import Keys._ import sbt.io.CopyOptions object SbtLauncherPlugin extends AutoPlugin { @@ -43,7 +42,12 @@ object SbtLauncherPlugin extends AutoPlugin { IO.unzip(jar, dir) IO.copy(overrides.map({ case (n, f) => (f, dir / n) }), CopyOptions().withOverwrite(true)) // TODO - is the ok for creating a jar? - IO.zip((dir.allPaths --- dir) pair relativeTo(dir), target) + val rebase: File => Seq[(File, String)] = { + val path = dir.toPath + f => + if (f != dir) f -> path.relativize(f.toPath).toString :: Nil else Nil + } + IO.zip(dir.allPaths.get().flatMap(rebase), target) } target }