From 9df0c9dada9c7b2eb96b019a81d9d7c9df2b9150 Mon Sep 17 00:00:00 2001 From: James Earl Douglas Date: Thu, 26 Sep 2024 16:51:50 -0700 Subject: [PATCH] Refactor a bunch of stuff (#938) This helps prepare for WebappComponentsRunnerPlugin. * Move webapp-runner version number to the outer build configuration * Use sbt-buildinfo to propagate it it to WarPackageRunnerPlugin * Fork tests * Move .war contents concatenation from WarPackagePlugin to WebappComponentsPlugin * Prefix WarPackageRunnerPlugin keys with `war` * Move WarPackageRunnerPlugin settings out of War configuration * Flip webapp contents map from `src -> dest` to `dest -> src` --- build.sbt | 12 ++++ project/plugins.sbt | 1 + .../com/earldouglas/sbt/war/WarPackage.scala | 32 ---------- .../sbt/war/WarPackagePlugin.scala | 18 ++---- .../sbt/war/WarPackageRunnerPlugin.scala | 61 +++++++++---------- .../sbt/war/WebappComponents.scala | 33 +++++----- .../sbt/war/WebappComponentsPlugin.scala | 19 ++++-- .../com/earldouglas/xwp/WebappPlugin.scala | 24 +++++--- .../combined/scenarios/war-runner-plugin.sbt | 22 +++---- .../combined/scenarios/webapp-plugin.sbt | 21 ++++--- src/sbt-test/sbt-war/combined/test | 4 +- .../earldouglas/sbt/war/WarPackageTest.scala | 42 ------------- .../sbt/war/WebappComponentsTest.scala | 32 +++++----- 13 files changed, 131 insertions(+), 190 deletions(-) delete mode 100644 src/main/scala/com/earldouglas/sbt/war/WarPackage.scala delete mode 100644 src/test/scala/com/earldouglas/sbt/war/WarPackageTest.scala diff --git a/build.sbt b/build.sbt index b2026a2e..6c95d1cf 100644 --- a/build.sbt +++ b/build.sbt @@ -20,8 +20,20 @@ semanticdbEnabled := true semanticdbVersion := scalafixSemanticdb.revision scalacOptions += "-Ywarn-unused-import" +// webapp-runner +lazy val webappRunnerVersion = + settingKey[String]("webapp-runner version") +webappRunnerVersion := "9.0.68.1" +libraryDependencies += "com.heroku" % "webapp-runner" % webappRunnerVersion.value intransitive () + +// sbt-buildinfo +enablePlugins(BuildInfoPlugin) +buildInfoKeys := Seq[BuildInfoKey](webappRunnerVersion) +buildInfoPackage := "com.earldouglas.sbt.war" + // Testing libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.19" % "test" +Test / fork := true // Publish to Sonatype, https://www.scala-sbt.org/release/docs/Using-Sonatype.html credentials := List( diff --git a/project/plugins.sbt b/project/plugins.sbt index 85e0ab84..e3bf4ad9 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,3 +2,4 @@ libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0") diff --git a/src/main/scala/com/earldouglas/sbt/war/WarPackage.scala b/src/main/scala/com/earldouglas/sbt/war/WarPackage.scala deleted file mode 100644 index d9897d73..00000000 --- a/src/main/scala/com/earldouglas/sbt/war/WarPackage.scala +++ /dev/null @@ -1,32 +0,0 @@ -package com.earldouglas.sbt.war - -import sbt.File - -/** Identifies the files that get bundled in the .war file: - * - * - Resources - * - HTML/JS/CSS files, images, etc. - * - Optional WEB-INF/web.xml deployment descriptor - * - Anything else that isn't a .class file or .jar file - * - .class files in the classes/ directory - * - .jar files in the lib/ directory - */ -object WarPackage { - - /** Given the resources, classes, and .jar files of a webapp, put them - * all together in the right subdirectories for the .war file. - * - * @return - * a mapping from source to destination of war contents - */ - def getWarContents( - webappResources: Map[File, String], - webappClasses: Map[File, String], - webappLib: Map[File, String] - ): Seq[(File, String)] = - Seq( - webappResources, - webappClasses.map { case (k, v) => k -> s"WEB-INF/classes/${v}" }, - webappLib.map { case (k, v) => k -> s"WEB-INF/lib/${v}" } - ).flatten -} diff --git a/src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala b/src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala index 1e295bc3..bfbbf67a 100644 --- a/src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala +++ b/src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala @@ -18,22 +18,14 @@ object WarPackagePlugin extends AutoPlugin { override def requires = WebappComponentsPlugin - val warContents: Initialize[Task[Seq[(File, String)]]] = - Def.task { - - import WebappComponentsPlugin.autoImport._ - - WarPackage.getWarContents( - webappResources = webappResources.value, - webappClasses = webappClasses.value, - webappLib = webappLib.value - ) - } - override lazy val projectSettings: Seq[Setting[_]] = { + val packageContents: Initialize[Task[Seq[(java.io.File, String)]]] = + WebappComponentsPlugin.webappContents + .map(_.toSeq.map({ case (k, v) => (v, k) })) + val packageTaskSettings: Seq[Setting[_]] = - Defaults.packageTaskSettings(pkg, warContents) + Defaults.packageTaskSettings(pkg, packageContents) val packageArtifactSetting: Setting[_] = pkg / artifact := Artifact(moduleName.value, "war", "war") diff --git a/src/main/scala/com/earldouglas/sbt/war/WarPackageRunnerPlugin.scala b/src/main/scala/com/earldouglas/sbt/war/WarPackageRunnerPlugin.scala index 51ebd7ef..a9eea43b 100644 --- a/src/main/scala/com/earldouglas/sbt/war/WarPackageRunnerPlugin.scala +++ b/src/main/scala/com/earldouglas/sbt/war/WarPackageRunnerPlugin.scala @@ -1,5 +1,6 @@ package com.earldouglas.sbt.war +import sbt.Def.Initialize import sbt.Def.settingKey import sbt.Def.taskKey import sbt.Keys._ @@ -16,10 +17,12 @@ object WarPackageRunnerPlugin extends AutoPlugin { object autoImport { lazy val War = config("war").hide - lazy val port = settingKey[Int]("container port") - lazy val start = taskKey[Unit]("start container") - lazy val join = taskKey[Option[Int]]("join container") - lazy val stop = taskKey[Unit]("stop container") + lazy val warPort = settingKey[Int]("container port") + lazy val warStart = taskKey[Unit]("start container") + lazy val warJoin = taskKey[Option[Int]]("join container") + lazy val warStop = taskKey[Unit]("stop container") + lazy val warForkOptions = + settingKey[ForkOptions]("container fork options") lazy val webappRunnerVersion = settingKey[String]("webapp-runner version") } @@ -30,16 +33,16 @@ object WarPackageRunnerPlugin extends AutoPlugin { override val projectConfigurations: Seq[Configuration] = Seq(War) private lazy val containerInstance = - new AtomicReference[Option[ScalaProcess]]( - Option.empty[ScalaProcess] - ) + new AtomicReference[Option[ScalaProcess]](None) - private val startTask: Def.Initialize[Task[Unit]] = + private val startWar: Initialize[Task[Unit]] = Def.task { + stopContainerInstance() + val runners: Seq[File] = Classpaths .managedJars( - configuration.value, + War, classpathTypes.value, update.value ) @@ -51,8 +54,8 @@ object WarPackageRunnerPlugin extends AutoPlugin { streams.value.log.info("[sbt-war] Starting server") val process: ScalaProcess = Fork.java.fork( - (War / forkOptions).value, - Seq("-jar", r.file.getPath(), (War / pkg).value.getPath()) + warForkOptions.value, + Seq("-jar", r.file.getPath(), pkg.value.getPath()) ) containerInstance.set(Some(process)) case _ :: _ => @@ -67,24 +70,22 @@ object WarPackageRunnerPlugin extends AutoPlugin { } } - private val joinTask: Def.Initialize[Task[Option[Int]]] = + private val joinWar: Initialize[Task[Option[Int]]] = Def.task { containerInstance.get.map { _.exitValue } } private def stopContainerInstance(): Unit = { - val oldProcess = - containerInstance - .getAndSet(Option.empty[ScalaProcess]) + val oldProcess = containerInstance.getAndSet(None) oldProcess.foreach(_.destroy()) } - private val stopTask: Def.Initialize[Task[Unit]] = + private val stopWar: Initialize[Task[Unit]] = Def.task { stopContainerInstance() } - private val onLoadSetting: Def.Initialize[State => State] = + private val onLoadSetting: Initialize[State => State] = Def.setting { (Global / onLoad).value compose { state: State => state.addExitHook(stopContainerInstance()) @@ -93,20 +94,14 @@ object WarPackageRunnerPlugin extends AutoPlugin { override lazy val projectSettings = Seq( - inConfig(War)( - Seq( - port := 8080, - start := startTask.value, - join := joinTask.value, - stop := stopTask.value, - forkOptions := ForkOptions(), - webappRunnerVersion := "9.0.68.1" - ) - ), - Seq( - Global / onLoad := onLoadSetting.value, - libraryDependencies += - ("com.heroku" % "webapp-runner" % (War / webappRunnerVersion).value intransitive ()) % War - ) - ).flatten + warPort := 8080, + warStart := startWar.value, + warJoin := joinWar.value, + warStop := stopWar.value, + warForkOptions := ForkOptions(), + webappRunnerVersion := BuildInfo.webappRunnerVersion, + Global / onLoad := onLoadSetting.value, + libraryDependencies += + ("com.heroku" % "webapp-runner" % webappRunnerVersion.value intransitive ()) % War + ) } diff --git a/src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala b/src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala index c7e96406..27ded17b 100644 --- a/src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala +++ b/src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala @@ -17,15 +17,16 @@ object WebappComponents { * find all the files it contains. * * @return - * a mapping from source to destination of webapp resources + * a mapping from destination to source of webapp resources */ - def getResources(resourcesDir: File): Map[File, String] = { + def getResources(resourcesDir: File): Map[String, File] = { (resourcesDir ** "*").get + .filter(_.exists()) .filter(_.isFile()) - .flatMap(src => + .flatMap(file => IO - .relativize(resourcesDir, src) - .map(dst => src -> dst) + .relativize(resourcesDir, file) + .map(path => path -> file) ) .toMap } @@ -34,38 +35,40 @@ object WebappComponents { * directories), traverse to find all the .class files. * * @return - * a mapping from source to destination of .class files + * a mapping from destination to source of .class files */ - def getClasses(classpath: Seq[File]): Map[File, String] = { + def getClasses(classpath: Seq[File]): Map[String, File] = { val classpathDirs: Seq[File] = classpath + .filter(_.exists()) .filter(_.isDirectory()) - val classesMappings: Seq[(File, File)] = + val classesMappings: Seq[(String, File)] = for { classpathDir <- classpathDirs classFile <- (classpathDir ** "*").get + if classFile.exists() if classFile.isFile() relativeFile <- IO.relativizeFile(classpathDir, classFile) - } yield (classFile, relativeFile) + relativePath = s"WEB-INF/classes/${relativeFile.getPath()}" + } yield (relativePath, classFile) - classesMappings - .map({ case (src, dst) => src -> dst.getPath() }) - .toMap + classesMappings.toMap } /** Given a classpath (potentially with both .jar files and classes * directories), traverse to find all the .jar files. * * @return - * a mapping from source to destination of .jar files + * a mapping from destination to source of .jar files */ - def getLib(classpath: Seq[File]): Map[File, String] = { + def getLib(classpath: Seq[File]): Map[String, File] = { classpath + .filter(f => f.exists()) .filter(f => f.isFile()) .filter(f => f.getName().endsWith(".jar")) - .map(src => src -> src.getName()) + .map(file => s"WEB-INF/lib/${file.getName()}" -> file) .toMap } } diff --git a/src/main/scala/com/earldouglas/sbt/war/WebappComponentsPlugin.scala b/src/main/scala/com/earldouglas/sbt/war/WebappComponentsPlugin.scala index f916ea6b..8f564f81 100644 --- a/src/main/scala/com/earldouglas/sbt/war/WebappComponentsPlugin.scala +++ b/src/main/scala/com/earldouglas/sbt/war/WebappComponentsPlugin.scala @@ -14,13 +14,13 @@ object WebappComponentsPlugin extends AutoPlugin { object autoImport { lazy val webappResources = - taskKey[Map[File, String]]("webapp resources") + taskKey[Map[String, File]]("webapp resources") lazy val webappClasses = - taskKey[Map[File, String]]("webapp classes") + taskKey[Map[String, File]]("webapp classes") lazy val webappLib = - taskKey[Map[File, String]]("webapp lib") + taskKey[Map[String, File]]("webapp lib") } import autoImport._ @@ -32,16 +32,16 @@ object WebappComponentsPlugin extends AutoPlugin { val webappResourcesDir: Initialize[File] = Def.setting((Compile / sourceDirectory).value / "webapp") - val webappResourcesTask: Initialize[Task[Map[File, String]]] = + val webappResourcesTask: Initialize[Task[Map[String, File]]] = Def.task(WebappComponents.getResources(webappResourcesDir.value)) val classpathFiles: Initialize[Task[Seq[File]]] = Def.task((Runtime / fullClasspath).value.files) - val webappClassesTask: Initialize[Task[Map[File, String]]] = + val webappClassesTask: Initialize[Task[Map[String, File]]] = Def.task(WebappComponents.getClasses(classpathFiles.value)) - val webappLibTask: Initialize[Task[Map[File, String]]] = + val webappLibTask: Initialize[Task[Map[String, File]]] = Def.task(WebappComponents.getLib(classpathFiles.value)) Seq( @@ -50,4 +50,11 @@ object WebappComponentsPlugin extends AutoPlugin { webappLib := webappLibTask.value ) } + + lazy val webappContents: Initialize[Task[Map[String, File]]] = + Def.task { + webappResources.value ++ + webappClasses.value ++ + webappLib.value + } } diff --git a/src/main/scala/com/earldouglas/xwp/WebappPlugin.scala b/src/main/scala/com/earldouglas/xwp/WebappPlugin.scala index 5549ecf9..25de8d37 100644 --- a/src/main/scala/com/earldouglas/xwp/WebappPlugin.scala +++ b/src/main/scala/com/earldouglas/xwp/WebappPlugin.scala @@ -105,8 +105,8 @@ object WebappPlugin extends AutoPlugin { val resourceFiles: Set[File] = WebappComponents .getResources(webappResourcesDir) - .filterNot(x => x._1.isDirectory()) - .map(_._1) + .map(_._2) + .filter(_.isFile()) .toSet cacheify( @@ -156,8 +156,12 @@ object WebappPlugin extends AutoPlugin { (Runtime / fullClasspath).value .map(_.data) - val webappClasses: Map[File, String] = - WebappComponents.getClasses(classpath) + val webappClasses: Map[String, File] = + WebappComponents + .getClasses(classpath) + .map({ case (path, file) => + (path.replaceAll("^WEB-INF/classes/", ""), file) + }) // copy this project's classes directly to WEB-INF/classes def classesAsClasses(): Set[File] = { @@ -166,12 +170,12 @@ object WebappPlugin extends AutoPlugin { "classes", { in => webappClasses - .find { case (src, dest) => src == in } - .map { case (src, dest) => webInfDir / "classes" / dest } + .find { case (_, file) => file == in } + .map { case (path, _) => webInfDir / "classes" / path } }, webappClasses - .filter { case (src, dest) => !src.isDirectory } - .map { case (src, dest) => src } + .filter { case (_, file) => file.isFile() } + .map { case (_, file) => file } .toSet, taskStreams ) @@ -186,7 +190,7 @@ object WebappPlugin extends AutoPlugin { val outputJar = webappLibDir / jarFilename Compat.jar( - sources = webappClasses, + sources = webappClasses.map({ case (k, v) => (v, k) }).toMap, outputJar = outputJar, manifest = new Manifest ) @@ -204,7 +208,7 @@ object WebappPlugin extends AutoPlugin { cacheify( "lib-deps", { in => Some(webappTarget / "WEB-INF" / "lib" / in.getName()) }, - WebappComponents.getLib(classpath).keySet, + WebappComponents.getLib(classpath).values.toSet, taskStreams ) diff --git a/src/sbt-test/sbt-war/combined/scenarios/war-runner-plugin.sbt b/src/sbt-test/sbt-war/combined/scenarios/war-runner-plugin.sbt index b45c6b77..80b94482 100644 --- a/src/sbt-test/sbt-war/combined/scenarios/war-runner-plugin.sbt +++ b/src/sbt-test/sbt-war/combined/scenarios/war-runner-plugin.sbt @@ -24,7 +24,7 @@ TaskKey[Unit]("await-open") := { } } - awaitOpen((War / port).value) + awaitOpen(warPort.value) } TaskKey[Unit]("await-closed") := { @@ -51,7 +51,7 @@ TaskKey[Unit]("await-closed") := { } } - awaitClosed((War / port).value) + awaitClosed(warPort.value) } TaskKey[Unit]("check") := { @@ -114,14 +114,14 @@ TaskKey[Unit]("check") := { | * status: ${expectedStatus} | * body: | > ${expectedBody - .toString() - .replaceAll("\n", "\n > ")} + .toString() + .replaceAll("\n", "\n > ")} | obtained: | * status: ${obtainedStatus} | * body: | > ${obtainedBody - .toString() - .replaceAll("\n", "\n > ")} + .toString() + .replaceAll("\n", "\n > ")} |""".stripMargin ) } else { @@ -133,14 +133,14 @@ TaskKey[Unit]("check") := { } assertEquals( - url = s"http://localhost:${(War / port).value}/", + url = s"http://localhost:${warPort.value}/", expectedBody = Source .fromFile((Compile / sourceDirectory).value / "webapp" / "index.html") .mkString ) assertEquals( - url = s"http://localhost:${(War / port).value}/count", + url = s"http://localhost:${warPort.value}/count", expectedBody = """|{ | "count": 1 |} @@ -148,7 +148,7 @@ TaskKey[Unit]("check") := { ) assertEquals( - url = s"http://localhost:${(War / port).value}/count", + url = s"http://localhost:${warPort.value}/count", expectedBody = """|{ | "count": 2 |} @@ -156,7 +156,7 @@ TaskKey[Unit]("check") := { ) assertEquals( - url = s"http://localhost:${(War / port).value}/count", + url = s"http://localhost:${warPort.value}/count", expectedBody = """|{ | "count": 3 |} @@ -164,7 +164,7 @@ TaskKey[Unit]("check") := { ) assertEquals( - url = s"http://localhost:${(War / port).value}/count", + url = s"http://localhost:${warPort.value}/count", expectedBody = """|{ | "count": 4 |} diff --git a/src/sbt-test/sbt-war/combined/scenarios/webapp-plugin.sbt b/src/sbt-test/sbt-war/combined/scenarios/webapp-plugin.sbt index 2f29cb0e..9a60f355 100644 --- a/src/sbt-test/sbt-war/combined/scenarios/webapp-plugin.sbt +++ b/src/sbt-test/sbt-war/combined/scenarios/webapp-plugin.sbt @@ -13,8 +13,8 @@ val checkClasses: Def.Initialize[Task[Unit]] = def assertEquals( name: String, - expected: Map[File, String], - obtained: Map[File, String] + expected: Map[String, File], + obtained: Map[String, File] ): Unit = { val sizesDoNotMatch = expected.size != obtained.size @@ -69,7 +69,7 @@ val checkClasses: Def.Initialize[Task[Unit]] = expected = { val root: File = (Compile / classDirectory).value expected - .map(x => root / x -> x) + .map(x => s"WEB-INF/classes/${x}" -> root / x) .toMap }, obtained = webappClasses.value @@ -84,17 +84,18 @@ val checkLib: Def.Initialize[Task[Unit]] = def assertContains( name: String, expected: Set[String], - obtained: Map[File, String] + obtained: Map[String, File] ): Unit = { val sizesDoNotMatch = expected.size != obtained.size - val mappingsDoNotMatch = expected != obtained.values.toSet + val mappingsDoNotMatch = expected != obtained.keys.toSet if (sizesDoNotMatch || mappingsDoNotMatch) { log.error(name) sys.error( s"""|${name}: - | expected: ${expected} + | expected: + |${expected.mkString(" - ", "\n - ", "")} | obtained: |${obtained.mkString(" - ", "\n - ", "")} |""".stripMargin @@ -119,7 +120,7 @@ val checkLib: Def.Initialize[Task[Unit]] = assertContains( name = "WebappComponentsPlugin: checkLib", - expected = expected, + expected = expected.map(x => s"WEB-INF/lib/${x}"), obtained = webappLib.value ) } @@ -131,8 +132,8 @@ lazy val checkResources: Def.Initialize[Task[Unit]] = def assertEquals( name: String, - expected: Map[File, String], - obtained: Map[File, String] + expected: Map[String, File], + obtained: Map[String, File] ): Unit = { val sizesDoNotMatch = expected.size != obtained.size @@ -167,7 +168,7 @@ lazy val checkResources: Def.Initialize[Task[Unit]] = expected = { val root: File = (Compile / sourceDirectory).value expected - .map(x => root / "webapp" / x -> x) + .map(x => x -> root / "webapp" / x) .toMap }, obtained = webappResources.value diff --git a/src/sbt-test/sbt-war/combined/test b/src/sbt-test/sbt-war/combined/test index 9f6dbf23..73a608a3 100644 --- a/src/sbt-test/sbt-war/combined/test +++ b/src/sbt-test/sbt-war/combined/test @@ -26,9 +26,9 @@ $ delete war-package-plugin.sbt $ copy-file scenarios/war-runner-plugin.sbt war-runner-plugin.sbt > reload -> War / start +> warStart > awaitOpen > check -> War / stop +> warStop > awaitClosed $ delete war-runner-plugin.sbt diff --git a/src/test/scala/com/earldouglas/sbt/war/WarPackageTest.scala b/src/test/scala/com/earldouglas/sbt/war/WarPackageTest.scala deleted file mode 100644 index 1b1d665c..00000000 --- a/src/test/scala/com/earldouglas/sbt/war/WarPackageTest.scala +++ /dev/null @@ -1,42 +0,0 @@ -package com.earldouglas.sbt.war - -import org.scalatest.funsuite.AnyFunSuite -import org.scalatest.matchers.should.Matchers - -import java.io.File - -class WarPackageTest extends AnyFunSuite with Matchers { - - val fakeproject: File = - new File("src/test/fakeproject/src/main/webapp") - - val fakeClasspath: Seq[File] = - Seq( - "src/test/fakeproject/classes", - "src/test/fakeproject/lib/baz.jar", - "src/test/fakeproject/lib/raz.jar" - ).map(new File(_)) - - test("getWarContents") { - - val expected: Seq[(File, String)] = - Seq( - "src/test/fakeproject/src/main/webapp/foo.html" -> "foo.html", - "src/test/fakeproject/src/main/webapp/bar.html" -> "bar.html", - "src/test/fakeproject/src/main/webapp/baz/raz.css" -> "baz/raz.css", - "src/test/fakeproject/classes/foo.class" -> "WEB-INF/classes/foo.class", - "src/test/fakeproject/classes/bar.class" -> "WEB-INF/classes/bar.class", - "src/test/fakeproject/lib/baz.jar" -> "WEB-INF/lib/baz.jar", - "src/test/fakeproject/lib/raz.jar" -> "WEB-INF/lib/raz.jar" - ).map { case (src, dst) => new File(src) -> dst } - - val obtained: Seq[(File, String)] = - WarPackage.getWarContents( - webappResources = WebappComponents.getResources(fakeproject), - webappClasses = WebappComponents.getClasses(fakeClasspath), - webappLib = WebappComponents.getLib(fakeClasspath) - ) - - obtained.sorted shouldBe expected.sorted - } -} diff --git a/src/test/scala/com/earldouglas/sbt/war/WebappComponentsTest.scala b/src/test/scala/com/earldouglas/sbt/war/WebappComponentsTest.scala index 205f85aa..b7fcdd32 100644 --- a/src/test/scala/com/earldouglas/sbt/war/WebappComponentsTest.scala +++ b/src/test/scala/com/earldouglas/sbt/war/WebappComponentsTest.scala @@ -19,14 +19,14 @@ class WebappComponentsTest extends AnyFunSuite with Matchers { test("getResources") { - val expected: Map[File, String] = + val expected: Map[String, File] = Map( - "src/test/fakeproject/src/main/webapp/foo.html" -> "foo.html", - "src/test/fakeproject/src/main/webapp/bar.html" -> "bar.html", - "src/test/fakeproject/src/main/webapp/baz/raz.css" -> "baz/raz.css" - ).map { case (src, dst) => new File(src) -> dst } + "bar.html" -> "src/test/fakeproject/src/main/webapp/bar.html", + "baz/raz.css" -> "src/test/fakeproject/src/main/webapp/baz/raz.css", + "foo.html" -> "src/test/fakeproject/src/main/webapp/foo.html" + ).map { case (path, file) => path -> new File(file) } - val obtained: Map[File, String] = + val obtained: Map[String, File] = WebappComponents.getResources(fakeproject) obtained shouldBe expected @@ -34,13 +34,13 @@ class WebappComponentsTest extends AnyFunSuite with Matchers { test("getClasses") { - val expected: Map[File, String] = + val expected: Map[String, File] = Map( - "src/test/fakeproject/classes/foo.class" -> "foo.class", - "src/test/fakeproject/classes/bar.class" -> "bar.class" - ).map { case (src, dst) => new File(src) -> dst } + "WEB-INF/classes/bar.class" -> "src/test/fakeproject/classes/bar.class", + "WEB-INF/classes/foo.class" -> "src/test/fakeproject/classes/foo.class" + ).map { case (path, file) => path -> new File(file) } - val obtained: Map[File, String] = + val obtained: Map[String, File] = WebappComponents.getClasses(fakeClasspath) obtained shouldBe expected @@ -48,13 +48,13 @@ class WebappComponentsTest extends AnyFunSuite with Matchers { test("getLib") { - val expected: Map[File, String] = + val expected: Map[String, File] = Map( - "src/test/fakeproject/lib/baz.jar" -> "baz.jar", - "src/test/fakeproject/lib/raz.jar" -> "raz.jar" - ).map { case (src, dst) => new File(src) -> dst } + "WEB-INF/lib/baz.jar" -> "src/test/fakeproject/lib/baz.jar", + "WEB-INF/lib/raz.jar" -> "src/test/fakeproject/lib/raz.jar" + ).map { case (path, file) => path -> new File(file) } - val obtained: Map[File, String] = + val obtained: Map[String, File] = WebappComponents.getLib(fakeClasspath) obtained shouldBe expected