diff --git a/src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala b/src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala index e1ac30f..a519b1b 100644 --- a/src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala +++ b/src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala @@ -8,7 +8,7 @@ import java.nio.file.{ Path => NioPath } private[sbt] object PluginCompat { type FileRef = java.io.File - type Out = java.io.File + type UnhashedFileRef = java.io.File def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath = a.data.toPath diff --git a/src/main/scala-3/com/typesafe/sbt/PluginCompat.scala b/src/main/scala-3/com/typesafe/sbt/PluginCompat.scala index 6205cdf..e780167 100644 --- a/src/main/scala-3/com/typesafe/sbt/PluginCompat.scala +++ b/src/main/scala-3/com/typesafe/sbt/PluginCompat.scala @@ -4,11 +4,11 @@ import java.nio.file.{ Path => NioPath } import java.io.{ File => IoFile } import sbt.* import sbt.Keys.Classpath -import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFile } +import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFileRef } private[sbt] object PluginCompat: type FileRef = HashedVirtualFileRef - type Out = VirtualFile + type UnhashedFileRef = VirtualFileRef def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath = conv.toPath(a.data) @@ -22,9 +22,9 @@ private[sbt] object PluginCompat: inline def classpathToFiles(classpath: Classpath)(using conv: FileConverter): Seq[File] = toFiles(classpath.to(Seq)) inline def toKey(settingKey: SettingKey[String]): StringAttributeKey = StringAttributeKey(settingKey.key.label) - def toNioPath(hvf: HashedVirtualFileRef)(using conv: FileConverter): NioPath = + def toNioPath(hvf: VirtualFileRef)(using conv: FileConverter): NioPath = conv.toPath(hvf) - def toFile(hvf: HashedVirtualFileRef)(using conv: FileConverter): File = + def toFile(hvf: VirtualFileRef)(using conv: FileConverter): File = toNioPath(hvf).toFile inline def toFileRef(file: File)(using conv: FileConverter): FileRef = conv.toVirtualFile(file.toPath) diff --git a/src/main/scala/com/typesafe/sbt/web/SbtWeb.scala b/src/main/scala/com/typesafe/sbt/web/SbtWeb.scala index 6135360..25981ea 100644 --- a/src/main/scala/com/typesafe/sbt/web/SbtWeb.scala +++ b/src/main/scala/com/typesafe/sbt/web/SbtWeb.scala @@ -585,6 +585,20 @@ object SbtWeb extends AutoPlugin { toFileRef(file) } + /** + * Convert a FileRef to a File, for compatibility usage in user sbt files/tasks + * @param fileRef + * The file ref to convert + * @param conv + * A valid FileConverter. Usually fileConverter.value, in Task scope + * @return + * The file converted to a usable File type. + */ + def asFile(fileRef: UnhashedFileRef, conv: FileConverter): File = { + implicit val fc: FileConverter = conv + toFile(fileRef) + } + /** * Deduplicator that selects the first file contained in the base directory. * diff --git a/src/sbt-test/sbt-web/extract-web-jars/build.sbt b/src/sbt-test/sbt-web/extract-web-jars/build.sbt index dd16f24..ebf9acc 100644 --- a/src/sbt-test/sbt-web/extract-web-jars/build.sbt +++ b/src/sbt-test/sbt-web/extract-web-jars/build.sbt @@ -38,8 +38,8 @@ TaskKey[Unit]("fileCheckNode") := { //$ newer target/foo target/web/public/main/lib/jquery/jquery.js TaskKey[Unit]("checkJqueryTimestamp") := { assert( - ( target.value / "web" / "public" / "main" / "lib" / "jquery" / "jquery.js" ).exists(), - "Could not find jquery" + (baseDirectory.value / "target" / "foo" ).lastModified() > (target.value / "web" / "public" / "main" / "lib" / "jquery" / "jquery.js" ).lastModified(), + "target/foo was not newer than jquery.js" ) } diff --git a/src/sbt-test/sbt-web/extract-web-jars/test b/src/sbt-test/sbt-web/extract-web-jars/test index 36db452..873e919 100644 --- a/src/sbt-test/sbt-web/extract-web-jars/test +++ b/src/sbt-test/sbt-web/extract-web-jars/test @@ -4,7 +4,6 @@ # Extract node modules > Assets/webNodeModules -$ exists target/web/node-modules/main/webjars/less/package.json > fileCheckNode > clean