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
This commit is contained in:
Ethan Atkins 2019-01-13 16:04:58 -08:00
parent f7f7addff7
commit 03cb79bbfc
1 changed files with 7 additions and 3 deletions

View File

@ -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
}