translate mapper to use VirtualFile

This commit is contained in:
João Ferreira 2024-12-10 19:22:24 +00:00 committed by Eugene Yokota
parent f4ae48bf72
commit a2b046e0c3
2 changed files with 10 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package sbt
import sbt.io.{ AllPassFilter, FileFilter, PathFinder }
import sbt.io.Path.*
import xsbti.{ FileConverter, VirtualFile }
import java.io.File
@ -11,16 +12,19 @@ object Mapper {
* Selects all descendants of `base` directory and maps them to a path relative to `base`.
* `base` itself is not included.
*/
def allSubpaths(base: File): Seq[(File, String)] =
def allSubpaths(base: File)(implicit conv: FileConverter): Seq[(VirtualFile, String)] =
selectSubpaths(base, AllPassFilter)
/**
* Selects descendants of `base` directory matching `filter` and maps them to a path relative to `base`.
* `base` itself is not included.
*/
def selectSubpaths(base: File, filter: FileFilter): Seq[(File, String)] =
def selectSubpaths(base: File, filter: FileFilter)(implicit
conv: FileConverter
): Seq[(VirtualFile, String)] =
PathFinder(base).globRecursive(filter).get().collect {
case f if f != base => f -> base.toPath.relativize(f.toPath).toString
case f if f != base =>
conv.toVirtualFile(f.toPath) -> base.toPath.relativize(f.toPath).toString
}
/**
@ -43,10 +47,11 @@ object Mapper {
* @param baseDirectory The directory that should be turned into a mappings sequence.
* @return mappings The `baseDirectory` and all of its contents
*/
def directory(baseDirectory: File): Seq[(File, String)] =
def directory(baseDirectory: File)(implicit conv: FileConverter): Seq[(VirtualFile, String)] =
Option(baseDirectory.getParentFile)
.map(parent => PathFinder(baseDirectory).allPaths pair relativeTo(parent))
.getOrElse(PathFinder(baseDirectory).allPaths pair basic)
.map { case (f, s) => conv.toVirtualFile(f.toPath) -> s }
/**
* return a Seq of mappings excluding the directory itself.

View File

@ -5,7 +5,7 @@ version := "0.2"
Compile / packageBin / mappings ++= {
val converter = fileConverter.value
Path.directory(file("test")).map { case (f,s) => converter.toVirtualFile(f.toPath) -> s }
Mapper.directory(file("test"))(using converter)
}
lazy val unzipPackage = taskKey[Unit]("extract jar file")