Newer
Older
gitbucket_jkp / build.sbt
@Uli Heller Uli Heller on 22 Oct 2017 10 KB Updated to jetty-9.4.7
  1. import com.typesafe.sbt.license.{LicenseInfo, DepModuleInfo}
  2. import com.typesafe.sbt.pgp.PgpKeys._
  3.  
  4. val Organization = "io.github.gitbucket"
  5. val Name = "gitbucket"
  6. val GitBucketVersion = "4.19.0-SNAPSHOT"
  7. val ScalatraVersion = "2.5.0"
  8. val JettyVersion = "9.4.7.v20170914"
  9.  
  10. lazy val root = (project in file(".")).enablePlugins(SbtTwirl, ScalatraPlugin, JRebelPlugin).settings(
  11.  
  12. )
  13.  
  14. sourcesInBase := false
  15. organization := Organization
  16. name := Name
  17. version := GitBucketVersion
  18. scalaVersion := "2.12.4"
  19.  
  20. // dependency settings
  21. resolvers ++= Seq(
  22. Classpaths.typesafeReleases,
  23. Resolver.jcenterRepo,
  24. "amateras" at "http://amateras.sourceforge.jp/mvn/",
  25. "sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/",
  26. "amateras-snapshot" at "http://amateras.sourceforge.jp/mvn-snapshot/"
  27. )
  28. libraryDependencies ++= Seq(
  29. "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.9.0.201710071750-r",
  30. "org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.9.0.201710071750-r",
  31. "org.scalatra" %% "scalatra" % ScalatraVersion,
  32. "org.scalatra" %% "scalatra-json" % ScalatraVersion,
  33. "org.json4s" %% "json4s-jackson" % "3.5.1",
  34. "io.github.gitbucket" %% "scalatra-forms" % "1.1.0",
  35. "commons-io" % "commons-io" % "2.5",
  36. "io.github.gitbucket" % "solidbase" % "1.0.2",
  37. "io.github.gitbucket" % "markedj" % "1.0.15",
  38. "org.apache.commons" % "commons-compress" % "1.13",
  39. "org.apache.commons" % "commons-email" % "1.4",
  40. "org.apache.httpcomponents" % "httpclient" % "4.5.3",
  41. "org.apache.sshd" % "apache-sshd" % "1.4.0" exclude("org.slf4j","slf4j-jdk14"),
  42. "org.apache.tika" % "tika-core" % "1.14",
  43. "com.github.takezoe" %% "blocking-slick-32" % "0.0.10",
  44. "joda-time" % "joda-time" % "2.9.9",
  45. "com.novell.ldap" % "jldap" % "2009-10-07",
  46. "com.h2database" % "h2" % "1.4.195",
  47. "org.mariadb.jdbc" % "mariadb-java-client" % "2.0.3",
  48. "org.postgresql" % "postgresql" % "42.0.0",
  49. "ch.qos.logback" % "logback-classic" % "1.2.3",
  50. "com.zaxxer" % "HikariCP" % "2.6.1",
  51. "com.typesafe" % "config" % "1.3.1",
  52. "com.typesafe.akka" %% "akka-actor" % "2.5.0",
  53. "fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.0.0",
  54. "com.github.bkromhout" % "java-diff-utils" % "2.1.1",
  55. "org.cache2k" % "cache2k-all" % "1.0.0.CR1",
  56. "com.enragedginger" %% "akka-quartz-scheduler" % "1.6.0-akka-2.4.x" exclude("c3p0","c3p0"),
  57. "net.coobird" % "thumbnailator" % "0.4.8",
  58. "com.github.zafarkhaja" % "java-semver" % "0.9.0",
  59. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
  60. "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
  61. "junit" % "junit" % "4.12" % "test",
  62. "org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
  63. "org.mockito" % "mockito-core" % "2.7.22" % "test",
  64. "com.wix" % "wix-embedded-mysql" % "2.1.4" % "test",
  65. "ru.yandex.qatools.embed" % "postgresql-embedded" % "2.0" % "test",
  66. "net.i2p.crypto" % "eddsa" % "0.1.0"
  67. )
  68.  
  69. // Compiler settings
  70. scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method")
  71. javacOptions in compile ++= Seq("-target", "8", "-source", "8")
  72. javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
  73.  
  74. // Test settings
  75. //testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
  76. javaOptions in Test += "-Dgitbucket.home=target/gitbucket_home_for_test"
  77. testOptions in Test += Tests.Setup( () => new java.io.File("target/gitbucket_home_for_test").mkdir() )
  78. fork in Test := true
  79.  
  80. // Packaging options
  81. packageOptions += Package.MainClass("JettyLauncher")
  82.  
  83. // Assembly settings
  84. test in assembly := {}
  85. assemblyMergeStrategy in assembly := {
  86. case PathList("META-INF", xs @ _*) =>
  87. (xs map {_.toLowerCase}) match {
  88. case ("manifest.mf" :: Nil) => MergeStrategy.discard
  89. case _ => MergeStrategy.discard
  90. }
  91. case x => MergeStrategy.first
  92. }
  93.  
  94. // JRebel
  95. //Seq(jrebelSettings: _*)
  96.  
  97. //jrebel.webLinks += (target in webappPrepare).value
  98. //jrebel.enabled := System.getenv().get("JREBEL") != null
  99. javaOptions in Jetty ++= Option(System.getenv().get("JREBEL")).toSeq.flatMap { path =>
  100. Seq("-noverify", "-XX:+UseConcMarkSweepGC", "-XX:+CMSClassUnloadingEnabled", s"-javaagent:${path}")
  101. }
  102.  
  103. // Exclude a war file from published artifacts
  104. signedArtifacts := {
  105. packagedArtifacts.value.filterNot { case (artifact, file) => file.getName.endsWith(".war") }
  106. }
  107.  
  108. // Create executable war file
  109. val ExecutableConfig = config("executable").hide
  110. Keys.ivyConfigurations += ExecutableConfig
  111. libraryDependencies ++= Seq(
  112. "org.eclipse.jetty" % "jetty-security" % JettyVersion % "executable",
  113. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "executable",
  114. "org.eclipse.jetty" % "jetty-continuation" % JettyVersion % "executable",
  115. "org.eclipse.jetty" % "jetty-server" % JettyVersion % "executable",
  116. "org.eclipse.jetty" % "jetty-xml" % JettyVersion % "executable",
  117. "org.eclipse.jetty" % "jetty-http" % JettyVersion % "executable",
  118. "org.eclipse.jetty" % "jetty-servlet" % JettyVersion % "executable",
  119. "org.eclipse.jetty" % "jetty-io" % JettyVersion % "executable",
  120. "org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
  121. )
  122.  
  123. val executableKey = TaskKey[File]("executable")
  124. executableKey := {
  125. import java.util.jar.{ Manifest => JarManifest }
  126. import java.util.jar.Attributes.{ Name => AttrName }
  127.  
  128. val workDir = Keys.target.value / "executable"
  129. val warName = Keys.name.value + ".war"
  130.  
  131. val log = streams.value.log
  132. log info s"building executable webapp in ${workDir}"
  133.  
  134. // initialize temp directory
  135. val temp = workDir / "webapp"
  136. IO delete temp
  137.  
  138. // include jetty classes
  139. val jettyJars = Keys.update.value select configurationFilter(name = ExecutableConfig.name)
  140. jettyJars foreach { jar =>
  141. IO unzip (jar, temp, (name:String) =>
  142. (name startsWith "javax/") ||
  143. (name startsWith "org/")
  144. )
  145. }
  146.  
  147. // include original war file
  148. val warFile = (Keys.`package`).value
  149. IO unzip (warFile, temp)
  150.  
  151. // include launcher classes
  152. val classDir = (Keys.classDirectory in Compile).value
  153. val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */)
  154. launchClasses foreach { name =>
  155. IO copyFile (classDir / name, temp / name)
  156. }
  157.  
  158. // include plugins
  159. val pluginsDir = temp / "WEB-INF" / "classes" / "plugins"
  160. IO createDirectory (pluginsDir)
  161. IO copyFile(Keys.baseDirectory.value / "plugins.json", pluginsDir / "plugins.json")
  162.  
  163. val json = IO read(Keys.baseDirectory.value / "plugins.json")
  164. PluginsJson.parse(json).foreach { case (plugin, version) =>
  165. val url = if(plugin == "gitbucket-pages-plugin"){
  166. s"https://github.com/gitbucket/${plugin}/releases/download/v${version}/${plugin}_${scalaBinaryVersion.value}-${version}.jar"
  167. } else {
  168. s"https://github.com/gitbucket/${plugin}/releases/download/${version}/${plugin}_${scalaBinaryVersion.value}-${version}.jar"
  169. }
  170. log info s"Download: ${url}"
  171. IO transfer(new java.net.URL(url).openStream, pluginsDir / s"${plugin}_${scalaBinaryVersion.value}-${version}.jar")
  172. }
  173.  
  174. // zip it up
  175. IO delete (temp / "META-INF" / "MANIFEST.MF")
  176. val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file => IO.relativizeFile(temp, file) }
  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. )
  189. .foreach { 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 := { _ => false }
  205. pomExtra := (
  206. <url>https://github.com/gitbucket/gitbucket</url>
  207. <licenses>
  208. <license>
  209. <name>The Apache Software License, Version 2.0</name>
  210. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  211. </license>
  212. </licenses>
  213. <scm>
  214. <url>https://github.com/gitbucket/gitbucket</url>
  215. <connection>scm:git:https://github.com/gitbucket/gitbucket.git</connection>
  216. </scm>
  217. <developers>
  218. <developer>
  219. <id>takezoe</id>
  220. <name>Naoki Takezoe</name>
  221. <url>https://github.com/takezoe</url>
  222. </developer>
  223. <developer>
  224. <id>shimamoto</id>
  225. <name>Takako Shimamoto</name>
  226. <url>https://github.com/shimamoto</url>
  227. </developer>
  228. <developer>
  229. <id>tanacasino</id>
  230. <name>Tomofumi Tanaka</name>
  231. <url>https://github.com/tanacasino</url>
  232. </developer>
  233. <developer>
  234. <id>mrkm4ntr</id>
  235. <name>Shintaro Murakami</name>
  236. <url>https://github.com/mrkm4ntr</url>
  237. </developer>
  238. <developer>
  239. <id>nazoking</id>
  240. <name>nazoking</name>
  241. <url>https://github.com/nazoking</url>
  242. </developer>
  243. <developer>
  244. <id>McFoggy</id>
  245. <name>Matthieu Brouillard</name>
  246. <url>https://github.com/McFoggy</url>
  247. </developer>
  248. </developers>
  249. )
  250.  
  251. licenseOverrides := {
  252. case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
  253. LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
  254. }