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