Newer
Older
gitbucket_jkp / build.sbt
@João Costa João Costa on 28 Oct 2017 10 KB Replace joda-time with java.time
  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.3"
  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. "com.novell.ldap" % "jldap" % "2009-10-07",
  45. "com.h2database" % "h2" % "1.4.195",
  46. "org.mariadb.jdbc" % "mariadb-java-client" % "2.1.2",
  47. "org.postgresql" % "postgresql" % "42.0.0",
  48. "ch.qos.logback" % "logback-classic" % "1.2.3",
  49. "com.zaxxer" % "HikariCP" % "2.6.1",
  50. "com.typesafe" % "config" % "1.3.1",
  51. "com.typesafe.akka" %% "akka-actor" % "2.5.0",
  52. "fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.0.0",
  53. "com.github.bkromhout" % "java-diff-utils" % "2.1.1",
  54. "org.cache2k" % "cache2k-all" % "1.0.0.CR1",
  55. "com.enragedginger" %% "akka-quartz-scheduler" % "1.6.0-akka-2.4.x" exclude("c3p0","c3p0"),
  56. "net.coobird" % "thumbnailator" % "0.4.8",
  57. "com.github.zafarkhaja" % "java-semver" % "0.9.0",
  58. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
  59. "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
  60. "junit" % "junit" % "4.12" % "test",
  61. "org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
  62. "org.mockito" % "mockito-core" % "2.7.22" % "test",
  63. "com.wix" % "wix-embedded-mysql" % "2.1.4" % "test",
  64. "ru.yandex.qatools.embed" % "postgresql-embedded" % "2.0" % "test",
  65. "net.i2p.crypto" % "eddsa" % "0.1.0"
  66. )
  67.  
  68. // Compiler settings
  69. scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method")
  70. javacOptions in compile ++= Seq("-target", "8", "-source", "8")
  71. javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
  72.  
  73. // Test settings
  74. //testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
  75. javaOptions in Test += "-Dgitbucket.home=target/gitbucket_home_for_test"
  76. testOptions in Test += Tests.Setup( () => new java.io.File("target/gitbucket_home_for_test").mkdir() )
  77. fork in Test := true
  78.  
  79. // Packaging options
  80. packageOptions += Package.MainClass("JettyLauncher")
  81.  
  82. // Assembly settings
  83. test in assembly := {}
  84. assemblyMergeStrategy in assembly := {
  85. case PathList("META-INF", xs @ _*) =>
  86. (xs map {_.toLowerCase}) match {
  87. case ("manifest.mf" :: Nil) => MergeStrategy.discard
  88. case _ => MergeStrategy.discard
  89. }
  90. case x => MergeStrategy.first
  91. }
  92.  
  93. // JRebel
  94. //Seq(jrebelSettings: _*)
  95.  
  96. //jrebel.webLinks += (target in webappPrepare).value
  97. //jrebel.enabled := System.getenv().get("JREBEL") != null
  98. javaOptions in Jetty ++= Option(System.getenv().get("JREBEL")).toSeq.flatMap { path =>
  99. Seq("-noverify", "-XX:+UseConcMarkSweepGC", "-XX:+CMSClassUnloadingEnabled", s"-javaagent:${path}")
  100. }
  101.  
  102. // Exclude a war file from published artifacts
  103. signedArtifacts := {
  104. packagedArtifacts.value.filterNot { case (artifact, file) => file.getName.endsWith(".war") }
  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.{ Manifest => JarManifest }
  125. import java.util.jar.Attributes.{ Name => AttrName }
  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.  
  146. // include original war file
  147. val warFile = (Keys.`package`).value
  148. IO unzip (warFile, temp)
  149.  
  150. // include launcher classes
  151. val classDir = (Keys.classDirectory in Compile).value
  152. val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */)
  153. launchClasses foreach { name =>
  154. IO copyFile (classDir / name, temp / name)
  155. }
  156.  
  157. // include plugins
  158. val pluginsDir = temp / "WEB-INF" / "classes" / "plugins"
  159. IO createDirectory (pluginsDir)
  160. IO copyFile(Keys.baseDirectory.value / "plugins.json", pluginsDir / "plugins.json")
  161.  
  162. val json = IO read(Keys.baseDirectory.value / "plugins.json")
  163. PluginsJson.parse(json).foreach { case (plugin, version) =>
  164. val url = if(plugin == "gitbucket-pages-plugin"){
  165. s"https://github.com/gitbucket/${plugin}/releases/download/v${version}/${plugin}_${scalaBinaryVersion.value}-${version}.jar"
  166. } else {
  167. s"https://github.com/gitbucket/${plugin}/releases/download/${version}/${plugin}_${scalaBinaryVersion.value}-${version}.jar"
  168. }
  169. log info s"Download: ${url}"
  170. IO transfer(new java.net.URL(url).openStream, pluginsDir / s"${plugin}_${scalaBinaryVersion.value}-${version}.jar")
  171. }
  172.  
  173. // zip it up
  174. IO delete (temp / "META-INF" / "MANIFEST.MF")
  175. val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file => IO.relativizeFile(temp, file) }
  176. val manifest = new JarManifest
  177. manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
  178. manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
  179. val outputFile = workDir / warName
  180. IO jar (contentMappings.map { case (file, path) => (file, path.toString) } , outputFile, manifest)
  181.  
  182. // generate checksums
  183. Seq(
  184. "md5" -> "MD5",
  185. "sha1" -> "SHA-1",
  186. "sha256" -> "SHA-256"
  187. )
  188. .foreach { case (extension, algorithm) =>
  189. val checksumFile = workDir / (warName + "." + extension)
  190. Checksums generate (outputFile, checksumFile, algorithm)
  191. }
  192.  
  193. // done
  194. log info s"built executable webapp ${outputFile}"
  195. outputFile
  196. }
  197. publishTo := {
  198. val nexus = "https://oss.sonatype.org/"
  199. if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
  200. else Some("releases" at nexus + "service/local/staging/deploy/maven2")
  201. }
  202. publishMavenStyle := true
  203. pomIncludeRepository := { _ => false }
  204. pomExtra := (
  205. <url>https://github.com/gitbucket/gitbucket</url>
  206. <licenses>
  207. <license>
  208. <name>The Apache Software License, Version 2.0</name>
  209. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  210. </license>
  211. </licenses>
  212. <scm>
  213. <url>https://github.com/gitbucket/gitbucket</url>
  214. <connection>scm:git:https://github.com/gitbucket/gitbucket.git</connection>
  215. </scm>
  216. <developers>
  217. <developer>
  218. <id>takezoe</id>
  219. <name>Naoki Takezoe</name>
  220. <url>https://github.com/takezoe</url>
  221. </developer>
  222. <developer>
  223. <id>shimamoto</id>
  224. <name>Takako Shimamoto</name>
  225. <url>https://github.com/shimamoto</url>
  226. </developer>
  227. <developer>
  228. <id>tanacasino</id>
  229. <name>Tomofumi Tanaka</name>
  230. <url>https://github.com/tanacasino</url>
  231. </developer>
  232. <developer>
  233. <id>mrkm4ntr</id>
  234. <name>Shintaro Murakami</name>
  235. <url>https://github.com/mrkm4ntr</url>
  236. </developer>
  237. <developer>
  238. <id>nazoking</id>
  239. <name>nazoking</name>
  240. <url>https://github.com/nazoking</url>
  241. </developer>
  242. <developer>
  243. <id>McFoggy</id>
  244. <name>Matthieu Brouillard</name>
  245. <url>https://github.com/McFoggy</url>
  246. </developer>
  247. </developers>
  248. )
  249.  
  250. licenseOverrides := {
  251. case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
  252. LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
  253. }