Newer
Older
gitbucket_jkp / build.sbt
@Naoki Takezoe Naoki Takezoe on 14 Jan 2021 10 KB Release GitBucket 4.35.3 (#2626)
  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.35.3"
  7. val ScalatraVersion = "2.7.1"
  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.3"
  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" % "8.29.1",
  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. "org.kohsuke" % "github-api" % "1.116" % "test"
  75. )
  76.  
  77. // Compiler settings
  78. scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method", "-feature")
  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. // Run package task before test to generate target/webapp for integration test
  125. test in Test := {
  126. _root_.sbt.Keys.`package`.value
  127. (test in Test).value
  128. }
  129.  
  130. val executableKey = TaskKey[File]("executable")
  131. executableKey := {
  132. import java.util.jar.Attributes.{Name => AttrName}
  133. import java.util.jar.{Manifest => JarManifest}
  134.  
  135. val workDir = Keys.target.value / "executable"
  136. val warName = Keys.name.value + ".war"
  137.  
  138. val log = streams.value.log
  139. log info s"building executable webapp in ${workDir}"
  140.  
  141. // initialize temp directory
  142. val temp = workDir / "webapp"
  143. IO delete temp
  144.  
  145. // include jetty classes
  146. val jettyJars = Keys.update.value select configurationFilter(name = ExecutableConfig.name)
  147. jettyJars foreach { jar =>
  148. IO unzip (jar, temp, (name: String) =>
  149. (name startsWith "javax/") ||
  150. (name startsWith "org/"))
  151. }
  152.  
  153. // include original war file
  154. val warFile = (Keys.`package`).value
  155. IO unzip (warFile, temp)
  156.  
  157. // include launcher classes
  158. val classDir = (Keys.classDirectory in Compile).value
  159. val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
  160. launchClasses foreach { name =>
  161. IO copyFile (classDir / name, temp / name)
  162. }
  163.  
  164. // include plugins
  165. val pluginsDir = temp / "WEB-INF" / "classes" / "plugins"
  166. IO createDirectory (pluginsDir)
  167.  
  168. val plugins = IO readLines (Keys.baseDirectory.value / "src" / "main" / "resources" / "bundle-plugins.txt")
  169. plugins.foreach { plugin =>
  170. plugin.trim.split(":") match {
  171. case Array(pluginId, pluginVersion) =>
  172. val url = "https://github.com/" +
  173. s"gitbucket/gitbucket-${pluginId}-plugin/releases/download/${pluginVersion}/gitbucket-${pluginId}-plugin-${pluginVersion}.jar"
  174. log info s"Download: ${url}"
  175. IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
  176. case _ => ()
  177. }
  178. }
  179.  
  180. // zip it up
  181. IO delete (temp / "META-INF" / "MANIFEST.MF")
  182. val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file =>
  183. IO.relativizeFile(temp, file)
  184. }
  185. val manifest = new JarManifest
  186. manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
  187. manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
  188. val outputFile = workDir / warName
  189. IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest, Some(
  190. System.currentTimeMillis()
  191. ))
  192.  
  193. // generate checksums
  194. Seq(
  195. "md5" -> "MD5",
  196. "sha1" -> "SHA-1",
  197. "sha256" -> "SHA-256"
  198. ).foreach {
  199. case (extension, algorithm) =>
  200. val checksumFile = workDir / (warName + "." + extension)
  201. Checksums generate (outputFile, checksumFile, algorithm)
  202. }
  203.  
  204. // done
  205. log info s"built executable webapp ${outputFile}"
  206. outputFile
  207. }
  208. publishTo := {
  209. val nexus = "https://oss.sonatype.org/"
  210. if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
  211. else Some("releases" at nexus + "service/local/staging/deploy/maven2")
  212. }
  213. publishMavenStyle := true
  214. pomIncludeRepository := { _ =>
  215. false
  216. }
  217. pomExtra := (
  218. <url>https://github.com/gitbucket/gitbucket</url>
  219. <licenses>
  220. <license>
  221. <name>The Apache Software License, Version 2.0</name>
  222. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  223. </license>
  224. </licenses>
  225. <scm>
  226. <url>https://github.com/gitbucket/gitbucket</url>
  227. <connection>scm:git:https://github.com/gitbucket/gitbucket.git</connection>
  228. </scm>
  229. <developers>
  230. <developer>
  231. <id>takezoe</id>
  232. <name>Naoki Takezoe</name>
  233. <url>https://github.com/takezoe</url>
  234. </developer>
  235. <developer>
  236. <id>shimamoto</id>
  237. <name>Takako Shimamoto</name>
  238. <url>https://github.com/shimamoto</url>
  239. </developer>
  240. <developer>
  241. <id>tanacasino</id>
  242. <name>Tomofumi Tanaka</name>
  243. <url>https://github.com/tanacasino</url>
  244. </developer>
  245. <developer>
  246. <id>mrkm4ntr</id>
  247. <name>Shintaro Murakami</name>
  248. <url>https://github.com/mrkm4ntr</url>
  249. </developer>
  250. <developer>
  251. <id>nazoking</id>
  252. <name>nazoking</name>
  253. <url>https://github.com/nazoking</url>
  254. </developer>
  255. <developer>
  256. <id>McFoggy</id>
  257. <name>Matthieu Brouillard</name>
  258. <url>https://github.com/McFoggy</url>
  259. </developer>
  260. </developers>
  261. )
  262.  
  263. licenseOverrides := {
  264. case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
  265. LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
  266. }
  267.  
  268. testOptions in Test ++= {
  269. if (scala.util.Properties.isWin) {
  270. Seq(
  271. Tests.Exclude(
  272. Set(
  273. "gitbucket.core.GitBucketCoreModuleSpec"
  274. )
  275. )
  276. )
  277. } else {
  278. Nil
  279. }
  280. }