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