-
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
16ea987
commit 3ff7b5d
Showing
37 changed files
with
691 additions
and
99 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
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,62 @@ | ||
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,49 @@ | ||
package v5 | ||
|
||
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 | ||
|
||
override def projectSettings: Seq[Setting[_]] = | ||
Seq( | ||
webappResources := { | ||
val srcDir: File = | ||
(sourceDirectory in Compile).value / "webapp" | ||
WebappComponents.getWebappResources(srcDir) | ||
}, | ||
webappClasses := { | ||
val classpath: Seq[File] = | ||
(fullClasspath in Runtime).value | ||
.map(_.data) | ||
WebappComponents.getWebappClasses(classpath) | ||
}, | ||
webappLib := { | ||
val classpath: Seq[File] = | ||
(fullClasspath in Runtime).value | ||
.map(_.data) | ||
WebappComponents.getWebappLib(classpath) | ||
} | ||
) | ||
} |
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.