Newer
Older
gitbucket_jkp / build.sbt
@kenji yoshida kenji yoshida on 24 Oct 2019 10 KB Update jetty to 9.4.22.v20191022
  1. import com.typesafe.sbt.license.{DepModuleInfo, LicenseInfo}
  2. import com.typesafe.sbt.pgp.PgpKeys._
  3.  
  4. val Organization = "io.github.gitbucket"
  5. val Name = "gitbucket"
  6. val GitBucketVersion = "4.32.0"
  7. val ScalatraVersion = "2.7.0-RC1"
  8. val JettyVersion = "9.4.22.v20191022"
  9. val JgitVersion = "5.5.1.201910021850-r"
  10.  
  11. lazy val root = (project in file("."))
  12. .enablePlugins(SbtTwirl, ScalatraPlugin)
  13. .settings(
  14. )
  15.  
  16. sourcesInBase := false
  17. organization := Organization
  18. name := Name
  19. version := GitBucketVersion
  20. scalaVersion := "2.13.1"
  21.  
  22. scalafmtOnCompile := true
  23.  
  24. coverageExcludedPackages := ".*\\.html\\..*"
  25.  
  26. // dependency settings
  27. resolvers ++= Seq(
  28. Classpaths.typesafeReleases,
  29. Resolver.jcenterRepo,
  30. "sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/"
  31. )
  32.  
  33. libraryDependencies ++= Seq(
  34. "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
  35. "org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
  36. "org.scalatra" %% "scalatra" % ScalatraVersion,
  37. "org.scalatra" %% "scalatra-json" % ScalatraVersion,
  38. "org.scalatra" %% "scalatra-forms" % ScalatraVersion,
  39. "org.json4s" %% "json4s-jackson" % "3.6.7",
  40. "commons-io" % "commons-io" % "2.6",
  41. "io.github.gitbucket" % "solidbase" % "1.0.3",
  42. "io.github.gitbucket" % "markedj" % "1.0.16",
  43. "org.apache.commons" % "commons-compress" % "1.19",
  44. "org.apache.commons" % "commons-email" % "1.5",
  45. "org.apache.httpcomponents" % "httpclient" % "4.5.10",
  46. "org.apache.sshd" % "apache-sshd" % "2.1.0" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
  47. "org.apache.tika" % "tika-core" % "1.22",
  48. "com.github.takezoe" %% "blocking-slick-32" % "0.0.12",
  49. "com.novell.ldap" % "jldap" % "2009-10-07",
  50. "com.h2database" % "h2" % "1.4.199",
  51. "org.mariadb.jdbc" % "mariadb-java-client" % "2.5.1",
  52. "org.postgresql" % "postgresql" % "42.2.6",
  53. "ch.qos.logback" % "logback-classic" % "1.2.3",
  54. "com.zaxxer" % "HikariCP" % "3.4.1",
  55. "com.typesafe" % "config" % "1.4.0",
  56. "com.typesafe.akka" %% "akka-actor" % "2.5.26",
  57. "fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
  58. "com.github.bkromhout" % "java-diff-utils" % "2.1.1",
  59. "org.cache2k" % "cache2k-all" % "1.2.4.Final",
  60. "com.enragedginger" %% "akka-quartz-scheduler" % "1.8.1-akka-2.5.x" exclude ("com.mchange", "c3p0") exclude ("com.zaxxer", "HikariCP-java6"),
  61. "net.coobird" % "thumbnailator" % "0.4.8",
  62. "com.github.zafarkhaja" % "java-semver" % "0.9.0",
  63. "com.nimbusds" % "oauth2-oidc-sdk" % "5.64.4",
  64. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
  65. "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
  66. "junit" % "junit" % "4.12" % "test",
  67. "org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
  68. "org.mockito" % "mockito-core" % "3.1.0" % "test",
  69. "com.dimafeng" %% "testcontainers-scala" % "0.33.0" % "test",
  70. "org.testcontainers" % "mysql" % "1.12.2" % "test",
  71. "org.testcontainers" % "postgresql" % "1.12.2" % "test",
  72. "net.i2p.crypto" % "eddsa" % "0.3.0",
  73. "is.tagomor.woothee" % "woothee-java" % "1.10.1",
  74. "org.ec4j.core" % "ec4j-core" % "0.0.3"
  75. )
  76.  
  77. // Compiler settings
  78. scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method")
  79. javacOptions in compile ++= Seq("-target", "8", "-source", "8")
  80. javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
  81.  
  82. // Test settings
  83. //testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
  84. javaOptions in Test += "-Dgitbucket.home=target/gitbucket_home_for_test"
  85. testOptions in Test += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
  86. fork in Test := true
  87.  
  88. // Packaging options
  89. packageOptions += Package.MainClass("JettyLauncher")
  90.  
  91. // Assembly settings
  92. test in assembly := {}
  93. assemblyMergeStrategy in assembly := {
  94. case PathList("META-INF", xs @ _*) =>
  95. (xs map { _.toLowerCase }) match {
  96. case ("manifest.mf" :: Nil) => MergeStrategy.discard
  97. case _ => MergeStrategy.discard
  98. }
  99. case x => MergeStrategy.first
  100. }
  101.  
  102. // Exclude a war file from published artifacts
  103. signedArtifacts := {
  104. signedArtifacts.value.filterNot {
  105. case (_, file) => file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
  106. }
  107. }
  108.  
  109. // Create executable war file
  110. val ExecutableConfig = config("executable").hide
  111. Keys.ivyConfigurations += ExecutableConfig
  112. libraryDependencies ++= Seq(
  113. "org.eclipse.jetty" % "jetty-security" % JettyVersion % "executable",
  114. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "executable",
  115. "org.eclipse.jetty" % "jetty-continuation" % JettyVersion % "executable",
  116. "org.eclipse.jetty" % "jetty-server" % JettyVersion % "executable",
  117. "org.eclipse.jetty" % "jetty-xml" % JettyVersion % "executable",
  118. "org.eclipse.jetty" % "jetty-http" % JettyVersion % "executable",
  119. "org.eclipse.jetty" % "jetty-servlet" % JettyVersion % "executable",
  120. "org.eclipse.jetty" % "jetty-io" % JettyVersion % "executable",
  121. "org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
  122. )
  123.  
  124. val executableKey = TaskKey[File]("executable")
  125. executableKey := {
  126. import java.util.jar.Attributes.{Name => AttrName}
  127. import java.util.jar.{Manifest => JarManifest}
  128.  
  129. val workDir = Keys.target.value / "executable"
  130. val warName = Keys.name.value + ".war"
  131.  
  132. val log = streams.value.log
  133. log info s"building executable webapp in ${workDir}"
  134.  
  135. // initialize temp directory
  136. val temp = workDir / "webapp"
  137. IO delete temp
  138.  
  139. // include jetty classes
  140. val jettyJars = Keys.update.value select configurationFilter(name = ExecutableConfig.name)
  141. jettyJars foreach { jar =>
  142. IO unzip (jar, temp, (name: String) =>
  143. (name startsWith "javax/") ||
  144. (name startsWith "org/"))
  145. }
  146.  
  147. // include original war file
  148. val warFile = (Keys.`package`).value
  149. IO unzip (warFile, temp)
  150.  
  151. // include launcher classes
  152. val classDir = (Keys.classDirectory in Compile).value
  153. val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
  154. launchClasses foreach { name =>
  155. IO copyFile (classDir / name, temp / name)
  156. }
  157.  
  158. // include plugins
  159. val pluginsDir = temp / "WEB-INF" / "classes" / "plugins"
  160. IO createDirectory (pluginsDir)
  161.  
  162. val plugins = IO readLines (Keys.baseDirectory.value / "src" / "main" / "resources" / "bundle-plugins.txt")
  163. plugins.foreach { plugin =>
  164. plugin.trim.split(":") match {
  165. case Array(pluginId, pluginVersion) =>
  166. val url = "https://github.com/" +
  167. s"gitbucket/gitbucket-${pluginId}-plugin/releases/download/${pluginVersion}/gitbucket-${pluginId}-plugin-${pluginVersion}.jar"
  168. log info s"Download: ${url}"
  169. IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
  170. case _ => ()
  171. }
  172. }
  173.  
  174. // zip it up
  175. IO delete (temp / "META-INF" / "MANIFEST.MF")
  176. val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file =>
  177. IO.relativizeFile(temp, file)
  178. }
  179. val manifest = new JarManifest
  180. manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
  181. manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
  182. val outputFile = workDir / warName
  183. IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest)
  184.  
  185. // generate checksums
  186. Seq(
  187. "md5" -> "MD5",
  188. "sha1" -> "SHA-1",
  189. "sha256" -> "SHA-256"
  190. ).foreach {
  191. case (extension, algorithm) =>
  192. val checksumFile = workDir / (warName + "." + extension)
  193. Checksums generate (outputFile, checksumFile, algorithm)
  194. }
  195.  
  196. // done
  197. log info s"built executable webapp ${outputFile}"
  198. outputFile
  199. }
  200. publishTo := {
  201. val nexus = "https://oss.sonatype.org/"
  202. if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
  203. else Some("releases" at nexus + "service/local/staging/deploy/maven2")
  204. }
  205. publishMavenStyle := true
  206. pomIncludeRepository := { _ =>
  207. false
  208. }
  209. pomExtra := (
  210. <url>https://github.com/gitbucket/gitbucket</url>
  211. <licenses>
  212. <license>
  213. <name>The Apache Software License, Version 2.0</name>
  214. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  215. </license>
  216. </licenses>
  217. <scm>
  218. <url>https://github.com/gitbucket/gitbucket</url>
  219. <connection>scm:git:https://github.com/gitbucket/gitbucket.git</connection>
  220. </scm>
  221. <developers>
  222. <developer>
  223. <id>takezoe</id>
  224. <name>Naoki Takezoe</name>
  225. <url>https://github.com/takezoe</url>
  226. </developer>
  227. <developer>
  228. <id>shimamoto</id>
  229. <name>Takako Shimamoto</name>
  230. <url>https://github.com/shimamoto</url>
  231. </developer>
  232. <developer>
  233. <id>tanacasino</id>
  234. <name>Tomofumi Tanaka</name>
  235. <url>https://github.com/tanacasino</url>
  236. </developer>
  237. <developer>
  238. <id>mrkm4ntr</id>
  239. <name>Shintaro Murakami</name>
  240. <url>https://github.com/mrkm4ntr</url>
  241. </developer>
  242. <developer>
  243. <id>nazoking</id>
  244. <name>nazoking</name>
  245. <url>https://github.com/nazoking</url>
  246. </developer>
  247. <developer>
  248. <id>McFoggy</id>
  249. <name>Matthieu Brouillard</name>
  250. <url>https://github.com/McFoggy</url>
  251. </developer>
  252. </developers>
  253. )
  254.  
  255. licenseOverrides := {
  256. case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
  257. LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
  258. }
  259.  
  260. testOptions in Test ++= {
  261. if (scala.util.Properties.isWin) {
  262. Seq(
  263. Tests.Exclude(
  264. Set(
  265. "gitbucket.core.GitBucketCoreModuleSpec"
  266. )
  267. )
  268. )
  269. } else {
  270. Nil
  271. }
  272. }