-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebappPlugin: Initial V5 implementation
- Loading branch information
1 parent
2df016c
commit 03c0c8d
Showing
27 changed files
with
589 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
version = 3.8.3 // https://scalameta.org/scalafmt/docs/installation.html#sbt | ||
runner.dialect = scala212 // https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects | ||
runner.dialect = scala212source3 // https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects | ||
maxColumn = 72 // RFC 678: https://datatracker.ietf.org/doc/html/rfc678 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package v5 | ||
|
||
import java.util.jar.Manifest | ||
|
||
import sbt._ | ||
import sbt.Def.taskKey | ||
import sbt.Def.settingKey | ||
import sbt.Keys._ | ||
import sbt.FilesInfo.lastModified | ||
import sbt.FilesInfo.exists | ||
import sbt.FileFunction.cached | ||
|
||
object V5WebappPlugin extends AutoPlugin { | ||
|
||
object autoImport { | ||
|
||
lazy val Webapp = | ||
config("webapp").hide | ||
|
||
lazy val assets = | ||
settingKey[Map[File, String]]("assets") | ||
|
||
lazy val classes = | ||
taskKey[Map[File, String]]("classes") | ||
|
||
lazy val lib = | ||
taskKey[Map[File, String]]("lib") | ||
} | ||
|
||
import autoImport._ | ||
|
||
override def requires = plugins.JvmPlugin | ||
|
||
def webappAssets(srcDir: File): Map[File, String] = { | ||
(srcDir ** "*").get | ||
.filter(_.isFile()) | ||
.flatMap(src => | ||
IO | ||
.relativize(srcDir, src) | ||
.map(dst => src -> dst) | ||
) | ||
.toMap | ||
} | ||
|
||
val webappClasses: Def.Initialize[Task[Map[File, String]]] = | ||
Def.task { | ||
|
||
val classpathDirs: Seq[File] = | ||
(fullClasspath in Runtime).value | ||
.map(_.data) | ||
.filter(_.isDirectory()) | ||
|
||
val classesMappings: Seq[(File, File)] = | ||
for { | ||
classpathDir <- classpathDirs | ||
classFile <- (classpathDir ** "*").get | ||
if classFile.isFile() | ||
relativeFile <- IO.relativizeFile(classpathDir, classFile) | ||
} yield (classFile, relativeFile) | ||
|
||
classesMappings | ||
.map({ case (src, dst) => src -> dst.getPath() }) | ||
.toMap | ||
} | ||
|
||
val webappLib: Def.Initialize[Task[Map[File, String]]] = | ||
Def.task { | ||
val cp: Keys.Classpath = | ||
(fullClasspath in Runtime).value | ||
cp | ||
.map(_.data) | ||
.filter(f => f.isFile()) | ||
.filter(f => f.getName().endsWith(".jar")) | ||
.map(src => src -> src.getName()) | ||
.toMap | ||
} | ||
|
||
override def projectSettings: Seq[Setting[_]] = | ||
inConfig(Webapp)( | ||
Seq( | ||
assets := { | ||
val srcDir: File = | ||
(sourceDirectory in Compile).value / "webapp" | ||
webappAssets(srcDir) | ||
}, | ||
classes := webappClasses.value.mapValues(d => s"classes/$d"), | ||
lib := webappLib.value.mapValues(d => s"lib/$d") | ||
) | ||
) | ||
} |
25 changes: 0 additions & 25 deletions
25
src/sbt-test/container/multi-module-multi-webapp/remoteweb/src/main/scala/remote.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rules = [ | ||
OrganizeImports | ||
RemoveUnused | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version=3.7.13 | ||
runner.dialect=scala3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.5.4" | ||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.19" % "test" | ||
|
||
libraryDependencies += "com.h2database" % "h2" % "2.2.224" | ||
libraryDependencies += "javax.servlet" % "javax.servlet-api" % "4.0.1" % "provided" | ||
|
||
enablePlugins(V5WebappPlugin) | ||
enablePlugins(TomcatPlugin) | ||
|
||
scalaVersion := "3.5.0" | ||
semanticdbEnabled := true | ||
semanticdbVersion := scalafixSemanticdb.revision | ||
|
||
scalacOptions += "-Wunused:all" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
TaskKey[Unit]("check-assets") := { | ||
|
||
def assertEquals( | ||
name: String, | ||
expected: Map[File, String], | ||
obtained: Map[File, String] | ||
): Unit = { | ||
|
||
val sizesDoNotMatch = expected.size != obtained.size | ||
val mappingsDoNotMatch = expected != obtained | ||
|
||
if (sizesDoNotMatch || mappingsDoNotMatch) { | ||
sys.error( | ||
s"""|${name}: | ||
| expected: | ||
|${expected.mkString(" - ", "\n - ", "")} | ||
| obtained: | ||
|${obtained.mkString(" - ", "\n - ", "")} | ||
|""".stripMargin | ||
) | ||
} | ||
} | ||
|
||
val expected: List[String] = | ||
List( | ||
"WEB-INF/web.xml", | ||
"favicon.ico", | ||
"index.html", | ||
"styles/theme.css" | ||
) | ||
|
||
assertEquals( | ||
name = "assets", | ||
expected = { | ||
val root: File = (Compile / sourceDirectory).value | ||
expected | ||
.map(x => root / "webapp" / x -> x) | ||
.toMap | ||
}, | ||
obtained = (Webapp / assets).value | ||
) | ||
} |
Oops, something went wrong.