|
| 1 | +package com.typesafe.sbt |
| 2 | + |
| 3 | +import java.nio.file.{ Path => NioPath } |
| 4 | +import java.io.{ File => IoFile } |
| 5 | +import sbt.* |
| 6 | +import sbt.Keys.Classpath |
| 7 | +import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFile } |
| 8 | + |
| 9 | +private[sbt] object PluginCompat: |
| 10 | + type FileRef = HashedVirtualFileRef |
| 11 | + type Out = VirtualFile |
| 12 | + |
| 13 | + def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath = |
| 14 | + conv.toPath(a.data) |
| 15 | + inline def toFile(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): File = |
| 16 | + toNioPath(a).toFile |
| 17 | + def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[NioPath] = |
| 18 | + cp.map(toNioPath).toVector |
| 19 | + inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[File] = |
| 20 | + toNioPaths(cp).map(_.toFile) |
| 21 | + def toSet[A](iterable: Iterable[A]): Set[A] = iterable.to(Set) |
| 22 | + inline def classpathToFiles(classpath: Classpath)(using conv: FileConverter): Seq[File] = |
| 23 | + toFiles(classpath.to(Seq)) |
| 24 | + inline def toKey(settingKey: SettingKey[String]): StringAttributeKey = StringAttributeKey(settingKey.key.label) |
| 25 | + def toNioPath(hvf: HashedVirtualFileRef)(using conv: FileConverter): NioPath = |
| 26 | + conv.toPath(hvf) |
| 27 | + def toFile(hvf: HashedVirtualFileRef)(using conv: FileConverter): File = |
| 28 | + toNioPath(hvf).toFile |
| 29 | + inline def toFileRef(file: File)(using conv: FileConverter): FileRef = |
| 30 | + conv.toVirtualFile(file.toPath) |
| 31 | + inline def selectFirstPredicate(using conv: FileConverter): Seq[FileRef] => Boolean = files => |
| 32 | + files.forall(toFile(_).isFile) && files.map(_.contentHashStr).distinct.size == 1 |
| 33 | +end PluginCompat |
0 commit comments