Skip to content

Commit

Permalink
Merge pull request #261 from BillyAutrey/scripted-sbt2-compatibility-…
Browse files Browse the repository at this point in the history
…part-2

Scripted sbt2 compatibility part 2
  • Loading branch information
mkurz authored Oct 24, 2024
2 parents b92d20e + 99b81eb commit 9455eaa
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 70 deletions.
121 changes: 121 additions & 0 deletions src/sbt-test/sbt-web/multi-module/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import FileAssertions.*

lazy val a = (project in file("."))
.enablePlugins(SbtWeb)
.dependsOn(b)
Expand Down Expand Up @@ -27,3 +29,122 @@ lazy val e = (project in file("modules/e"))
)

lazy val x = (project in file("modules/x"))

// Check for files

//$ exists target/web/public/main/js/a.js
//$ exists target/web/public/main/lib/b/js/b.js
//$ exists target/web/public/main/lib/c/js/c.js
//$ exists target/web/public/main/lib/d/js/d.js
//$ exists target/web/public/main/lib/e/js/e.js
//$ exists target/web/public/main/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckA") := {
assertLibrary(target.value, "a", Root())
assertLibrary(target.value, "b")
assertLibrary(target.value, "c")
assertLibrary(target.value, "d")
assertLibrary(target.value, "e")
assertLibrary(target.value, "jquery", External())
}

//$ exists modules/b/target/web/public/main/js/b.js
//$ exists modules/b/target/web/public/main/lib/c/js/c.js
//$ exists modules/b/target/web/public/main/lib/d/js/d.js
//$ exists modules/b/target/web/public/main/lib/e/js/e.js
//$ exists modules/b/target/web/public/main/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckB") := {
assertLibrary((b / target).value, "b", Root())
assertLibrary((b / target).value, "c")
assertLibrary((b / target).value, "d")
assertLibrary((b / target).value, "e")
assertLibrary((b / target).value, "jquery", External())
}

//$ exists modules/c/target/web/public/main/js/c.js
//$ exists modules/c/target/web/public/main/js/e.js
//$ exists modules/c/target/web/public/main/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckC") := {
assertLibrary((c / target).value, "c", Root())
assertLibrary((c / target).value, "e", Root())
assertLibrary((c / target).value, "jquery", External())
}

//$ exists modules/d/target/web/public/main/js/d.js
//$ exists modules/d/target/web/public/main/lib/e/js/e.js
//$ exists modules/d/target/web/public/main/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckD") := {
assertLibrary((d / target).value, "d", Root())
assertLibrary((d / target).value, "e")
assertLibrary((d / target).value, "jquery", External())
}

//$ exists modules/e/target/web/public/main/js/e.js
//$ exists modules/e/target/web/public/main/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckE") := {
assertLibrary((e / target).value, "e", Root())
assertLibrary((e / target).value, "jquery", External())
}

//$ exists modules/b/target/web/public/test/lib/c/js/c.js
//$ exists modules/b/target/web/public/test/lib/c/js/u.js
//$ exists modules/b/target/web/public/test/lib/d/js/d.js
//$ exists modules/b/target/web/public/test/lib/d/js/u.js
//$ exists modules/b/target/web/public/test/lib/e/js/e.js
//$ exists modules/b/target/web/public/test/lib/e/js/t.js
//$ exists modules/b/target/web/public/test/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckBTest") := {
assertLibrary((b / target).value, "b", Library("test"))
assertLibrary((b / target).value, "c", Library("test"))
assertLibrary((b / target).value, "c", Library("test"), Some("u"))
assertLibrary((b / target).value, "d", Library("test"))
assertLibrary((b / target).value, "d", Library("test"), Some("u"))
assertLibrary((b / target).value, "e", Library("test"))
assertLibrary((b / target).value, "e", Library("test"), Some("t"))
assertLibrary((b / target).value, "jquery", External("test"))
}

//# c has set import directly
//$ exists modules/c/target/web/public/test/js/c.js
//$ exists modules/c/target/web/public/test/js/u.js
//$ exists modules/c/target/web/public/test/js/e.js
//$ exists modules/c/target/web/public/test/js/t.js
//$ exists modules/c/target/web/public/test/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckCTest") := {
assertLibrary((c / target).value, "c", Root("test"))
assertLibrary((c / target).value, "c", Root("test"), Some("u"))
assertLibrary((c / target).value, "e", Root("test"))
assertLibrary((c / target).value, "e", Root("test"), Some("t"))
assertLibrary((c / target).value, "jquery", External("test"))
}

//$ exists modules/d/target/web/public/test/js/d.js
//$ exists modules/d/target/web/public/test/js/u.js
//$ exists modules/d/target/web/public/test/lib/e/js/e.js
//$ exists modules/d/target/web/public/test/lib/e/js/t.js
//$ exists modules/d/target/web/public/test/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckDTest") := {
assertLibrary((d / target).value, "d", Root("test"))
assertLibrary((d / target).value, "d", Root("test"), Some("u"))
assertLibrary((d / target).value, "e", Library("test"))
assertLibrary((d / target).value, "e", Library("test"), Some("t"))
assertLibrary((d / target).value, "jquery", External("test"))
}

//$ exists modules/e/target/web/public/test/js/e.js
//$ exists modules/e/target/web/public/test/js/t.js
//$ exists modules/e/target/web/public/test/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckETest") := {
assertLibrary((e / target).value, "e", Root("test"))
assertLibrary((e / target).value, "e", Root("test"), Some("t"))
assertLibrary((e / target).value, "jquery", External("test"))
}

//$ exists target/web/public/main/lib/e/js/e.js
TaskKey[Unit]("fileCheckATracked") := {
assertLibrary(target.value, "e")
}

//$ exists target/web/public/main/lib/e/js/e.js
TaskKey[Unit]("fileCheckETracked") := {
assertLibrary(target.value, "e")
}
26 changes: 26 additions & 0 deletions src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sbt.*

object FileAssertions {
def assertLibrary(
target: File,
id: String,
location: LibraryLocation = Library(),
altName: Option[String] = None
): Unit = {
val filename = altName.getOrElse(id)
val fileToVerify = location match {
case Root(stage) =>
target / "web" / "public" / stage / "js" / s"$filename.js"
case Library(stage) =>
target / "web" / "public" / stage / "lib" / id / "js" / s"$filename.js"
case External(path) =>
target / "web" / "public" / path / "lib" / id / s"$filename.js"
}
assert(fileToVerify.exists(), s"Could not find $filename.js")
}
}

sealed trait LibraryLocation
case class Root(stage: String = "main") extends LibraryLocation
case class Library(stage: String = "main") extends LibraryLocation
case class External(stage: String = "main") extends LibraryLocation
70 changes: 15 additions & 55 deletions src/sbt-test/sbt-web/multi-module/test
Original file line number Diff line number Diff line change
@@ -1,83 +1,43 @@
> a/assets

$ exists target/web/public/main/js/a.js
$ exists target/web/public/main/lib/b/js/b.js
$ exists target/web/public/main/lib/c/js/c.js
$ exists target/web/public/main/lib/d/js/d.js
$ exists target/web/public/main/lib/e/js/e.js
$ exists target/web/public/main/lib/jquery/jquery.js
> fileCheckA

> b/assets

$ exists modules/b/target/web/public/main/js/b.js
$ exists modules/b/target/web/public/main/lib/c/js/c.js
$ exists modules/b/target/web/public/main/lib/d/js/d.js
$ exists modules/b/target/web/public/main/lib/e/js/e.js
$ exists modules/b/target/web/public/main/lib/jquery/jquery.js
> fileCheckB

> c/assets

# c has set import directly
$ exists modules/c/target/web/public/main/js/c.js
$ exists modules/c/target/web/public/main/js/e.js
$ exists modules/c/target/web/public/main/lib/jquery/jquery.js
> fileCheckC

> d/assets

$ exists modules/d/target/web/public/main/js/d.js
$ exists modules/d/target/web/public/main/lib/e/js/e.js
$ exists modules/d/target/web/public/main/lib/jquery/jquery.js
> fileCheckD

> e/assets
> fileCheckE

$ exists modules/e/target/web/public/main/js/e.js
$ exists modules/e/target/web/public/main/lib/jquery/jquery.js

> b/web-assets-test:assets

> b/TestAssets/assets
# b has disabled direct modules so we expect lib/b here
$ exists modules/b/target/web/public/test/lib/b/js/b.js

$ exists modules/b/target/web/public/test/lib/c/js/c.js
$ exists modules/b/target/web/public/test/lib/c/js/u.js
$ exists modules/b/target/web/public/test/lib/d/js/d.js
$ exists modules/b/target/web/public/test/lib/d/js/u.js
$ exists modules/b/target/web/public/test/lib/e/js/e.js
$ exists modules/b/target/web/public/test/lib/e/js/t.js
$ exists modules/b/target/web/public/test/lib/jquery/jquery.js
> fileCheckBTest

> c/web-assets-test:assets
> c/TestAssets/assets

# c has set import directly
$ exists modules/c/target/web/public/test/js/c.js
$ exists modules/c/target/web/public/test/js/u.js
$ exists modules/c/target/web/public/test/js/e.js
$ exists modules/c/target/web/public/test/js/t.js
$ exists modules/c/target/web/public/test/lib/jquery/jquery.js

> d/web-assets-test:assets

$ exists modules/d/target/web/public/test/js/d.js
$ exists modules/d/target/web/public/test/js/u.js
$ exists modules/d/target/web/public/test/lib/e/js/e.js
$ exists modules/d/target/web/public/test/lib/e/js/t.js
$ exists modules/d/target/web/public/test/lib/jquery/jquery.js
> fileCheckCTest

> e/web-assets-test:assets
> d/TestAssets/assets
> fileCheckDTest

$ exists modules/e/target/web/public/test/js/e.js
$ exists modules/e/target/web/public/test/js/t.js
$ exists modules/e/target/web/public/test/lib/jquery/jquery.js
> e/TestAssets/assets
> fileCheckETest

# Let's optimize the syncing

> set ThisBuild / trackInternalDependencies := TrackLevel.TrackIfMissing

> a/assets

$ exists target/web/public/main/lib/e/js/e.js
> fileCheckATracked

> e/clean
> a/assets

$ exists target/web/public/main/lib/e/js/e.js
> fileCheckETracked
26 changes: 25 additions & 1 deletion src/sbt-test/sbt-web/package/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import FileAssertions.*

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

name := "Web Project"
Expand All @@ -8,4 +10,26 @@ crossPaths := false

libraryDependencies += "org.webjars" % "jquery" % "2.0.3-1"

TaskKey[Unit]("extractAssets") := IO.unzip((artifactPath in (Assets, packageBin)).value, file("extracted"))
TaskKey[Unit]("extractAssets") := IO.unzip(
SbtWeb.asFile(((Assets / packageBin) / artifactPath).value, fileConverter.value),
file("extracted")
)

// $ exists target/web-project-0.1-web-assets.jar
TaskKey[Unit]("fileCheckAssets") := {
assertExists(target.value / "web-project-0.1-web-assets.jar")
}

// $ exists extracted/js/a.js
// $ exists extracted/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckExtracted") := {
assertExists(baseDirectory.value / "extracted" / "js" / "a.js")
assertExists(baseDirectory.value / "extracted" / "lib" / "jquery" / "jquery.js")
}

// $ exists extracted/public/js/a.js
// $ exists extracted/public/lib/jquery/jquery.js
TaskKey[Unit]("fileCheckPublic") := {
assertExists(baseDirectory.value / "extracted" / "public" / "js" / "a.js")
assertExists(baseDirectory.value / "extracted" / "public" / "lib" / "jquery" / "jquery.js")
}
6 changes: 6 additions & 0 deletions src/sbt-test/sbt-web/package/project/FileAssertions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sbt.*

object FileAssertions {
def assertExists(file: File): Unit =
assert(file.exists(), s"Could not find ${file.getName}")
}
12 changes: 5 additions & 7 deletions src/sbt-test/sbt-web/package/test
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
> web-assets:package
$ exists target/web-project-0.1-web-assets.jar
> Assets/package
> fileCheckAssets

> extractAssets
$ exists extracted/js/a.js
$ exists extracted/lib/jquery/jquery.js
> fileCheckExtracted

> 'set Assets / WebKeys.packagePrefix := "public/"'
> web-assets:package
> Assets/package

$ delete extracted
> extractAssets
$ exists extracted/public/js/a.js
$ exists extracted/public/lib/jquery/jquery.js
> fileCheckPublic
18 changes: 18 additions & 0 deletions src/sbt-test/sbt-web/publish-webjar/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import FileAssertions.*

lazy val a = (project in file("module/a"))
.enablePlugins(SbtWeb)
.settings(
Expand All @@ -21,3 +23,19 @@ lazy val c = (project in file("."))
.settings(
libraryDependencies += "com.github.sbt.web.test" %% "web-module-b" % "0.1-SNAPSHOT"
)

//$ exists target/web/web-modules/main/webjars/lib/jquery/jquery.js
//$ exists target/web/web-modules/main/webjars/lib/web-module-a/js/a.js
//$ exists target/web/web-modules/main/webjars/lib/web-module-b/js/b.js
//
//$ exists target/web/public/main/lib/jquery/jquery.js
//$ exists target/web/public/main/lib/web-module-a/js/a.js
//$ exists target/web/public/main/lib/web-module-b/js/b.js
TaskKey[Unit]("fileCheck") := {
assertExists(target.value / "web" / "web-modules" / "main" / "webjars" / "lib" / "jquery" / "jquery.js")
assertExists(target.value / "web" / "web-modules" / "main" / "webjars" / "lib" / "web-module-a" / "js" / "a.js")
assertExists(target.value / "web" / "web-modules" / "main" / "webjars" / "lib" / "web-module-b" / "js" / "b.js")
assertExists(target.value / "web" / "public" / "main" / "lib" / "jquery" / "jquery.js")
assertExists(target.value / "web" / "public" / "main" / "lib" / "web-module-a" / "js" / "a.js")
assertExists(target.value / "web" / "public" / "main" / "lib" / "web-module-b" / "js" / "b.js")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sbt.*

object FileAssertions {
def assertExists(file: File): Unit =
assert(file.exists(), s"Could not find ${file.getName}")
}
8 changes: 1 addition & 7 deletions src/sbt-test/sbt-web/publish-webjar/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@

> assets

$ exists target/web/web-modules/main/webjars/lib/jquery/jquery.js
$ exists target/web/web-modules/main/webjars/lib/web-module-a/js/a.js
$ exists target/web/web-modules/main/webjars/lib/web-module-b/js/b.js

$ exists target/web/public/main/lib/jquery/jquery.js
$ exists target/web/public/main/lib/web-module-a/js/a.js
$ exists target/web/public/main/lib/web-module-b/js/b.js
> fileCheck

0 comments on commit 9455eaa

Please sign in to comment.