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.201805301535-rc2",
  34. "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "5.0.0.201805301535-rc2",
  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. IO copyFile (Keys.baseDirectory.value / "plugins.json", pluginsDir / "plugins.json")
  174.  
  175. val json = IO read (Keys.baseDirectory.value / "plugins.json")
  176. PluginsJson.getUrls(json).foreach { url =>
  177. log info s"Download: ${url}"
  178. IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
  179. }
  180.  
  181. // zip it up
  182. IO delete (temp / "META-INF" / "MANIFEST.MF")
  183. val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file =>
  184. IO.relativizeFile(temp, file)
  185. }
  186. val manifest = new JarManifest
  187. manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
  188. manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
  189. val outputFile = workDir / warName
  190. IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest)
  191.  
  192. // generate checksums
  193. Seq(
  194. "md5" -> "MD5",
  195. "sha1" -> "SHA-1",
  196. "sha256" -> "SHA-256"
  197. ).foreach {
  198. case (extension, algorithm) =>
  199. val checksumFile = workDir / (warName + "." + extension)
  200. Checksums generate (outputFile, checksumFile, algorithm)
  201. }
  202.  
  203. // done
  204. log info s"built executable webapp ${outputFile}"
  205. outputFile
  206. }
  207. publishTo := {
  208. val nexus = "https://oss.sonatype.org/"
  209. if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
  210. else Some("releases" at nexus + "service/local/staging/deploy/maven2")
  211. }
  212. publishMavenStyle := true
  213. pomIncludeRepository := { _ =>
  214. false
  215. }
  216. pomExtra := (
  217. <url>https://github.com/gitbucket/gitbucket</url>
  218. <licenses>
  219. <license>
  220. <name>The Apache Software License, Version 2.0</name>
  221. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  222. </license>
  223. </licenses>
  224. <scm>
  225. <url>https://github.com/gitbucket/gitbucket</url>
  226. <connection>scm:git:https://github.com/gitbucket/gitbucket.git</connection>
  227. </scm>
  228. <developers>
  229. <developer>
  230. <id>takezoe</id>
  231. <name>Naoki Takezoe</name>
  232. <url>https://github.com/takezoe</url>
  233. </developer>
  234. <developer>
  235. <id>shimamoto</id>
  236. <name>Takako Shimamoto</name>
  237. <url>https://github.com/shimamoto</url>
  238. </developer>
  239. <developer>
  240. <id>tanacasino</id>
  241. <name>Tomofumi Tanaka</name>
  242. <url>https://github.com/tanacasino</url>
  243. </developer>
  244. <developer>
  245. <id>mrkm4ntr</id>
  246. <name>Shintaro Murakami</name>
  247. <url>https://github.com/mrkm4ntr</url>
  248. </developer>
  249. <developer>
  250. <id>nazoking</id>
  251. <name>nazoking</name>
  252. <url>https://github.com/nazoking</url>
  253. </developer>
  254. <developer>
  255. <id>McFoggy</id>
  256. <name>Matthieu Brouillard</name>
  257. <url>https://github.com/McFoggy</url>
  258. </developer>
  259. </developers>
  260. )
  261.  
  262. licenseOverrides := {
  263. case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
  264. LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
  265. }