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