-
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
7733d3b
commit 737636d
Showing
34 changed files
with
701 additions
and
98 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
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,63 @@ | ||
package v5 | ||
|
||
import sbt._ | ||
|
||
/** */ | ||
object WebappComponents { | ||
|
||
/** Given a resources directory, e.g. src/main/webapp, traverse to | ||
* find all the files it contains. | ||
* | ||
* @return | ||
* a mapping from source to destination of webapp resources | ||
*/ | ||
def getWebappResources(resourcesDir: File): Map[File, String] = { | ||
(resourcesDir ** "*").get | ||
.filter(_.isFile()) | ||
.flatMap(src => | ||
IO | ||
.relativize(resourcesDir, src) | ||
.map(dst => src -> dst) | ||
) | ||
.toMap | ||
} | ||
|
||
/** Given a classpath (potentially with both .jar files and classes | ||
* directories), traverse to find all the .class files. | ||
* | ||
* @return | ||
* a mapping from source to destination of .class files | ||
*/ | ||
def getWebappClasses(classpath: Seq[File]): Map[File, String] = { | ||
|
||
val classpathDirs: Seq[File] = | ||
classpath | ||
.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 | ||
} | ||
|
||
/** 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 | ||
*/ | ||
def getWebappLib(classpath: Seq[File]): Map[File, String] = { | ||
classpath | ||
.filter(f => f.isFile()) | ||
.filter(f => f.getName().endsWith(".jar")) | ||
.map(src => src -> src.getName()) | ||
.toMap | ||
} | ||
} |
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,59 @@ | ||
package v5 | ||
|
||
import sbt.Def.Initialize | ||
import sbt.Def.settingKey | ||
import sbt.Def.taskKey | ||
import sbt.Keys._ | ||
import sbt._ | ||
|
||
/** Finds webapp components (resources, .class files, and .jar files). | ||
* This is used by WarPlugin and WebappRunnerPlugin. | ||
*/ | ||
object WebappPluginV5 extends AutoPlugin { | ||
|
||
object autoImport { | ||
|
||
lazy val webappResources = | ||
settingKey[Map[File, String]]("webapp resources") | ||
|
||
lazy val webappClasses = | ||
taskKey[Map[File, String]]("webapp classes") | ||
|
||
lazy val webappLib = | ||
taskKey[Map[File, String]]("webapp lib") | ||
} | ||
|
||
import autoImport._ | ||
|
||
override def requires = plugins.JvmPlugin | ||
|
||
val webappResourcesSetting: Initialize[Map[File, String]] = | ||
Def.setting { | ||
val resourcesDir: File = | ||
(Compile / sourceDirectory).value / "webapp" | ||
WebappComponents.getWebappResources(resourcesDir) | ||
} | ||
|
||
val webappClassesTask: Initialize[Task[Map[File, String]]] = | ||
Def.task { | ||
val classpath: Seq[File] = | ||
(Runtime / fullClasspath).value | ||
.map(_.data) | ||
WebappComponents.getWebappClasses(classpath) | ||
} | ||
|
||
val webappLibTask: Initialize[Task[Map[File, String]]] = | ||
Def.task { | ||
val classpath: Seq[File] = | ||
(Runtime / fullClasspath).value | ||
.map(_.data) | ||
WebappComponents.getWebappLib(classpath) | ||
} | ||
|
||
override def projectSettings: Seq[Setting[_]] = | ||
Seq( | ||
webappResources := webappResourcesSetting.value, | ||
webappClasses := webappClassesTask.value, | ||
webappLib := webappLibTask.value | ||
) | ||
} |
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,13 @@ | ||
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(WebappPluginV5) | ||
|
||
scalaVersion := "3.5.0" | ||
semanticdbEnabled := true | ||
semanticdbVersion := scalafixSemanticdb.revision | ||
|
||
scalacOptions += "-Wunused:all" |
Oops, something went wrong.