Skip to content

Commit

Permalink
Fix timestamp check on extract-web-jars, add asFile to SbtWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyAutrey committed Oct 17, 2024
1 parent 521089c commit 76c6b7a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala-3/com/typesafe/sbt/PluginCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/main/scala/com/typesafe/sbt/web/SbtWeb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/sbt-web/extract-web-jars/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}

Expand Down
1 change: 0 additions & 1 deletion src/sbt-test/sbt-web/extract-web-jars/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

# Extract node modules
> Assets/webNodeModules
$ exists target/web/node-modules/main/webjars/less/package.json
> fileCheckNode

> clean
Expand Down

0 comments on commit 76c6b7a

Please sign in to comment.