Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add directory filter compatibility shim #264

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.typesafe.sbt

import sbt.*
import sbt.Keys.Classpath
import com.typesafe.sbt.web.PathMapping
import xsbti.FileConverter

import java.nio.file.{ Path => NioPath }
Expand All @@ -28,4 +29,5 @@ private[sbt] object PluginCompat {
def toFileRef(f: File)(implicit conv: FileConverter): FileRef = f
def selectFirstPredicate: Seq[FileRef] => Boolean = files =>
files.forall(_.isFile) && files.map(_.hashString).distinct.size == 1
def fileRefCompatible(path: PathMapping)(implicit conv: FileConverter): Boolean = true
}
3 changes: 3 additions & 0 deletions src/main/scala-3/com/typesafe/sbt/PluginCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.io.{ File => IoFile }
import sbt.*
import sbt.Keys.Classpath
import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFileRef }
import com.typesafe.sbt.web.PathMapping

private[sbt] object PluginCompat:
type FileRef = HashedVirtualFileRef
Expand All @@ -30,4 +31,6 @@ private[sbt] object PluginCompat:
conv.toVirtualFile(file.toPath)
inline def selectFirstPredicate(using conv: FileConverter): Seq[FileRef] => Boolean = files =>
files.forall(toFile(_).isFile) && files.map(_.contentHashStr).distinct.size == 1
inline def fileRefCompatible(path: PathMapping)(using conv: FileConverter): Boolean =
!toFile(path._1).isDirectory
end PluginCompat
11 changes: 7 additions & 4 deletions src/main/scala/com/typesafe/sbt/web/SbtWeb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,11 @@ object SbtWeb extends AutoPlugin {
* Create package mappings for assets in the webjar format. Use the webjars path prefix and exclude all web module
* assets.
*/
def createWebJarMappings: Def.Initialize[Task[Seq[(FileRef, String)]]] = Def.task {
def createWebJarMappings: Def.Initialize[Task[Seq[PathMapping]]] = Def.task {
def webModule(file: File) = webModuleDirectories.value.exists(dir => IO.relativize(dir, file).isDefined)
implicit val fc: FileConverter = fileConverter.value
mappings.value flatMap {
case mapping if !fileRefCompatible(mapping) => None
case (file, path) if webModule(toFile(file)) => None
case (file, path) => Some(file -> (webJarsPathPrefix.value + path))
}
Expand Down Expand Up @@ -450,10 +451,12 @@ object SbtWeb extends AutoPlugin {
/**
* Create package mappings for all assets, adding the optional prefix.
*/
def packageAssetsMappings: Def.Initialize[Task[Seq[(FileRef, String)]]] = Def.task {
def packageAssetsMappings: Def.Initialize[Task[Seq[PathMapping]]] = Def.task {
implicit val fc: FileConverter = fileConverter.value
val prefix = packagePrefix.value
(Defaults.ConfigGlobal / pipeline).value map { case (file, path) =>
file -> (prefix + path)
(Defaults.ConfigGlobal / pipeline).value collect {
case (file, path) if fileRefCompatible((file, path)) =>
file -> (prefix + path)
}
}

Expand Down
Loading