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