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.25.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, JRebelPlugin)
  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.0.201806131550-r",
  34. "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "5.0.0.201806131550-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. )
  73.  
  74. // Compiler settings
  75. scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method", "-Xfuture")
  76. javacOptions in compile ++= Seq("-target", "8", "-source", "8")
  77. javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
  78.  
  79. // Test settings
  80. //testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
  81. javaOptions in Test += "-Dgitbucket.home=target/gitbucket_home_for_test"
  82. testOptions in Test += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
  83. fork in Test := true
  84.  
  85. // Packaging options
  86. packageOptions += Package.MainClass("JettyLauncher")
  87.  
  88. // Assembly settings
  89. test in assembly := {}
  90. assemblyMergeStrategy in assembly := {
  91. case PathList("META-INF", xs @ _*) =>
  92. (xs map { _.toLowerCase }) match {
  93. case ("manifest.mf" :: Nil) => MergeStrategy.discard
  94. case _ => MergeStrategy.discard
  95. }
  96. case x => MergeStrategy.first
  97. }
  98.  
  99. // JRebel
  100. //Seq(jrebelSettings: _*)
  101.  
  102. //jrebel.webLinks += (target in webappPrepare).value
  103. //jrebel.enabled := System.getenv().get("JREBEL") != null
  104. javaOptions in Jetty ++= Option(System.getenv().get("JREBEL")).toSeq.flatMap { path =>
  105. if (path.endsWith(".jar")) {
  106. // Legacy JRebel agent
  107. Seq("-noverify", "-XX:+UseConcMarkSweepGC", "-XX:+CMSClassUnloadingEnabled", s"-javaagent:${path}")
  108. } else {
  109. // New JRebel agent
  110. Seq(s"-agentpath:${path}")
  111. }
  112. }
  113.  
  114. // Exclude a war file from published artifacts
  115. signedArtifacts := {
  116. signedArtifacts.value.filterNot {
  117. case (_, file) => file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
  118. }
  119. }
  120.  
  121. // Create executable war file
  122. val ExecutableConfig = config("executable").hide
  123. Keys.ivyConfigurations += ExecutableConfig
  124. libraryDependencies ++= Seq(
  125. "org.eclipse.jetty" % "jetty-security" % JettyVersion % "executable",
  126. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "executable",
  127. "org.eclipse.jetty" % "jetty-continuation" % JettyVersion % "executable",
  128. "org.eclipse.jetty" % "jetty-server" % JettyVersion % "executable",
  129. "org.eclipse.jetty" % "jetty-xml" % JettyVersion % "executable",
  130. "org.eclipse.jetty" % "jetty-http" % JettyVersion % "executable",
  131. "org.eclipse.jetty" % "jetty-servlet" % JettyVersion % "executable",
  132. "org.eclipse.jetty" % "jetty-io" % JettyVersion % "executable",
  133. "org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
  134. )
  135.  
  136. val executableKey = TaskKey[File]("executable")
  137. executableKey := {
  138. import java.util.jar.Attributes.{Name => AttrName}
  139. import java.util.jar.{Manifest => JarManifest}
  140.  
  141. val workDir = Keys.target.value / "executable"
  142. val warName = Keys.name.value + ".war"
  143.  
  144. val log = streams.value.log
  145. log info s"building executable webapp in ${workDir}"
  146.  
  147. // initialize temp directory
  148. val temp = workDir / "webapp"
  149. IO delete temp
  150.  
  151. // include jetty classes
  152. val jettyJars = Keys.update.value select configurationFilter(name = ExecutableConfig.name)
  153. jettyJars foreach { jar =>
  154. IO unzip (jar, temp, (name: String) =>
  155. (name startsWith "javax/") ||
  156. (name startsWith "org/"))
  157. }
  158.  
  159. // include original war file
  160. val warFile = (Keys.`package`).value
  161. IO unzip (warFile, temp)
  162.  
  163. // include launcher classes
  164. val classDir = (Keys.classDirectory in Compile).value
  165. val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
  166. launchClasses foreach { name =>
  167. IO copyFile (classDir / name, temp / name)
  168. }
  169.  
  170. // include plugins
  171. val pluginsDir = temp / "WEB-INF" / "classes" / "plugins"
  172. IO createDirectory (pluginsDir)
  173.  
  174. val plugins = IO readLines (Keys.baseDirectory.value / "src" / "main" / "resources" / "bundle-plugins.txt")
  175. plugins.foreach { plugin =>
  176. plugin.trim.split(":") match {
  177. case Array(pluginId, pluginVersion) =>
  178. val url = "https://plugins.gitbucket-community.org/releases/" +
  179. s"gitbucket-${pluginId}-plugin/gitbucket-${pluginId}-plugin-gitbucket_${version.value}-${pluginVersion}.jar"
  180. log info s"Download: ${url}"
  181. IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
  182. case _ => ()
  183. }
  184. }
  185.  
  186. // zip it up
  187. IO delete (temp / "META-INF" / "MANIFEST.MF")
  188. val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file =>
  189. IO.relativizeFile(temp, file)
  190. }
  191. val manifest = new JarManifest
  192. manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
  193. manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
  194. val outputFile = workDir / warName
  195. IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest)
  196.  
  197. // generate checksums
  198. Seq(
  199. "md5" -> "MD5",
  200. "sha1" -> "SHA-1",
  201. "sha256" -> "SHA-256"
  202. ).foreach {
  203. case (extension, algorithm) =>
  204. val checksumFile = workDir / (warName + "." + extension)
  205. Checksums generate (outputFile, checksumFile, algorithm)
  206. }
  207.  
  208. // done
  209. log info s"built executable webapp ${outputFile}"
  210. outputFile
  211. }
  212. publishTo := {
  213. val nexus = "https://oss.sonatype.org/"
  214. if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
  215. else Some("releases" at nexus + "service/local/staging/deploy/maven2")
  216. }
  217. publishMavenStyle := true
  218. pomIncludeRepository := { _ =>
  219. false
  220. }
  221. pomExtra := (
  222. <url>https://github.com/gitbucket/gitbucket</url>
  223. <licenses>
  224. <license>
  225. <name>The Apache Software License, Version 2.0</name>
  226. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  227. </license>
  228. </licenses>
  229. <scm>
  230. <url>https://github.com/gitbucket/gitbucket</url>
  231. <connection>scm:git:https://github.com/gitbucket/gitbucket.git</connection>
  232. </scm>
  233. <developers>
  234. <developer>
  235. <id>takezoe</id>
  236. <name>Naoki Takezoe</name>
  237. <url>https://github.com/takezoe</url>
  238. </developer>
  239. <developer>
  240. <id>shimamoto</id>
  241. <name>Takako Shimamoto</name>
  242. <url>https://github.com/shimamoto</url>
  243. </developer>
  244. <developer>
  245. <id>tanacasino</id>
  246. <name>Tomofumi Tanaka</name>
  247. <url>https://github.com/tanacasino</url>
  248. </developer>
  249. <developer>
  250. <id>mrkm4ntr</id>
  251. <name>Shintaro Murakami</name>
  252. <url>https://github.com/mrkm4ntr</url>
  253. </developer>
  254. <developer>
  255. <id>nazoking</id>
  256. <name>nazoking</name>
  257. <url>https://github.com/nazoking</url>
  258. </developer>
  259. <developer>
  260. <id>McFoggy</id>
  261. <name>Matthieu Brouillard</name>
  262. <url>https://github.com/McFoggy</url>
  263. </developer>
  264. </developers>
  265. )
  266.  
  267. licenseOverrides := {
  268. case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
  269. LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
  270. }