Skip to content

Commit e80bc74

Browse files
committed
No more type errors, yay!
1 parent 8158c60 commit e80bc74

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala

+5
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ private[sbt] object PluginCompat {
2525
def toNioPath(f: File)(implicit conv: FileConverter): NioPath =
2626
f.toPath
2727
def toFile(f: File)(implicit conv: FileConverter): File = f
28+
29+
def toFileRef(f: File)(implicit conv: FileConverter): FileRef = f
30+
31+
def selectFirstPredicate: Seq[FileRef] => Boolean = files =>
32+
files.forall(_.isFile) && files.map(_.hashString).distinct.size == 1
2833
}

src/main/scala-3/com/typesafe/sbt/PluginCompat.scala

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ private[sbt] object PluginCompat:
1313
def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath =
1414
conv.toPath(a.data)
1515
inline def toFile(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): File =
16-
toNioPath(a).toFile()
16+
toNioPath(a).toFile
1717
def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[NioPath] =
1818
cp.map(toNioPath).toVector
1919
inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[File] =
20-
toNioPaths(cp).map(_.toFile())
20+
toNioPaths(cp).map(_.toFile)
2121
def toSet[A](iterable: Iterable[A]): Set[A] = iterable.to(Set)
2222
inline def classpathToFiles(classpath: Classpath)(using conv: FileConverter): Seq[File] =
2323
toFiles(classpath.to(Seq))
2424
inline def toKey( settingKey: SettingKey[String] ): StringAttributeKey = StringAttributeKey(settingKey.key.label)
2525
def toNioPath(hvf: HashedVirtualFileRef)(using conv: FileConverter): NioPath =
2626
conv.toPath(hvf)
2727
def toFile(hvf: HashedVirtualFileRef)(using conv: FileConverter): File =
28-
toNioPath(hvf).toFile()
28+
toNioPath(hvf).toFile
29+
30+
def toFileRef(file: File)(using conv: FileConverter): FileRef =
31+
conv.toVirtualFile(file.toPath)
32+
33+
inline def selectFirstPredicate(using conv: FileConverter): Seq[FileRef] => Boolean = files =>
34+
files.forall(toFile(_).isFile) && files.map(_.contentHashStr).distinct.size == 1
2935
end PluginCompat

src/main/scala/com/typesafe/sbt/web/SbtWeb.scala

+7-17
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,11 @@ object SbtWeb extends AutoPlugin {
402402
* Create package mappings for assets in the webjar format. Use the webjars path prefix and exclude all web module
403403
* assets.
404404
*/
405-
def createWebJarMappings: Def.Initialize[Task[Seq[(File, String)]]] = Def.task {
405+
def createWebJarMappings: Def.Initialize[Task[Seq[(FileRef, String)]]] = Def.task {
406406
def webModule(file: File) = webModuleDirectories.value.exists(dir => IO.relativize(dir, file).isDefined)
407+
implicit val fc: FileConverter = fileConverter.value
407408
mappings.value flatMap {
408-
case (file, path) if webModule(file) => None
409+
case (file, path) if webModule(toFile(file)) => None
409410
case (file, path) => Some(file -> (webJarsPathPrefix.value + path))
410411
}
411412
}
@@ -434,7 +435,8 @@ object SbtWeb extends AutoPlugin {
434435
if (state.value.get(disableExportedProducts).getOrElse(false)) {
435436
Seq.empty
436437
} else {
437-
Seq(Attributed.blank(exportTask.value).put(toKey(webModulesLib), moduleName.value))
438+
implicit val fc: FileConverter = fileConverter.value
439+
Seq(Attributed.blank(toFileRef(exportTask.value)).put(toKey(webModulesLib), moduleName.value))
438440
}
439441
}
440442

@@ -546,9 +548,9 @@ object SbtWeb extends AutoPlugin {
546548
mappings.groupBy(_._2 /*path*/ ).toSeq flatMap { grouped =>
547549
val (path, group) = grouped
548550
if (group.size > 1) {
549-
val files = group.map(_._1)
551+
val files = group.map(mapping => toFile(mapping._1))
550552
val deduplicated = firstResult(deduplicators)(files)
551-
deduplicated.fold(group)(file => Seq((file, path)))
553+
deduplicated.fold(group)(file => Seq((toFileRef(file), path)))
552554
} else {
553555
group
554556
}
@@ -563,18 +565,6 @@ object SbtWeb extends AutoPlugin {
563565
(fs.toStream flatMap { f => f(a).toSeq }).headOption
564566
}
565567

566-
/**
567-
* Deduplicator that selects the first file contained in the base directory.
568-
*
569-
* @param base
570-
* the base directory to check against
571-
* @return
572-
* a deduplicator function that prefers files in the base directory
573-
*/
574-
def selectFileFrom(base: File): Deduplicator = { (files: Seq[File]) =>
575-
files.find(_.relativeTo(base).isDefined)
576-
}
577-
578568
/**
579569
* Deduplicator that checks whether all duplicates are directories and if so will simply select the first one.
580570
*

src/main/scala/com/typesafe/sbt/web/package.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ package object web {
1414
/**
1515
* A function for possibly selecting a single file from a sequence.
1616
*/
17-
type Deduplicator = Seq[FileRef] => Option[FileRef]
17+
type Deduplicator = Seq[File] => Option[File]
1818
}

0 commit comments

Comments
 (0)