Newer
Older
gitbucket_jkp / build.sbt
@Scala Steward Scala Steward on 18 Mar 2024 10 KB Update github-api to 1.320
  1. import sbtlicensereport.license.{DepModuleInfo, LicenseInfo}
  2. import com.jsuereth.sbtpgp.PgpKeys._
  3.  
  4. val Organization = "io.github.gitbucket"
  5. val Name = "gitbucket"
  6. val GitBucketVersion = "4.40.0"
  7. val ScalatraVersion = "3.0.0"
  8. val JettyVersion = "10.0.20"
  9. val JgitVersion = "6.9.0.202403050737-r"
  10.  
  11. lazy val root = (project in file("."))
  12. .enablePlugins(SbtTwirl, ScalatraPlugin)
  13.  
  14. sourcesInBase := false
  15. organization := Organization
  16. name := Name
  17. version := GitBucketVersion
  18. scalaVersion := "2.13.13"
  19.  
  20. crossScalaVersions += "3.4.0"
  21.  
  22. // scalafmtOnCompile := true
  23.  
  24. coverageExcludedPackages := ".*\\.html\\..*"
  25.  
  26. libraryDependencies ++= Seq(
  27. "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
  28. "org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
  29. "org.scalatra" %% "scalatra-javax" % ScalatraVersion,
  30. "org.scalatra" %% "scalatra-json-javax" % ScalatraVersion,
  31. "org.scalatra" %% "scalatra-forms-javax" % ScalatraVersion,
  32. "org.json4s" %% "json4s-jackson" % "4.0.7",
  33. "commons-io" % "commons-io" % "2.15.1",
  34. "io.github.gitbucket" % "solidbase" % "1.0.5",
  35. "io.github.gitbucket" % "markedj" % "1.0.20",
  36. "org.apache.commons" % "commons-compress" % "1.26.1",
  37. "org.apache.commons" % "commons-email" % "1.6.0",
  38. "commons-net" % "commons-net" % "3.10.0",
  39. "org.apache.httpcomponents" % "httpclient" % "4.5.14",
  40. "org.apache.sshd" % "apache-sshd" % "2.12.1" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
  41. "org.apache.tika" % "tika-core" % "2.9.1",
  42. "com.github.takezoe" %% "blocking-slick" % "0.0.14",
  43. "com.novell.ldap" % "jldap" % "2009-10-07",
  44. "com.h2database" % "h2" % "1.4.199",
  45. "org.mariadb.jdbc" % "mariadb-java-client" % "2.7.6",
  46. "org.postgresql" % "postgresql" % "42.7.3",
  47. "ch.qos.logback" % "logback-classic" % "1.5.3",
  48. "com.zaxxer" % "HikariCP" % "5.1.0" exclude ("org.slf4j", "slf4j-api"),
  49. "com.typesafe" % "config" % "1.4.3",
  50. "fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
  51. "io.github.java-diff-utils" % "java-diff-utils" % "4.12",
  52. "org.cache2k" % "cache2k-all" % "1.6.0.Final",
  53. "net.coobird" % "thumbnailator" % "0.4.20",
  54. "com.github.zafarkhaja" % "java-semver" % "0.10.2",
  55. "com.nimbusds" % "oauth2-oidc-sdk" % "11.10.1",
  56. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
  57. "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
  58. "junit" % "junit" % "4.13.2" % "test",
  59. "org.scalatra" %% "scalatra-scalatest-javax" % ScalatraVersion % "test",
  60. "org.mockito" % "mockito-core" % "5.11.0" % "test",
  61. "com.dimafeng" %% "testcontainers-scala" % "0.41.3" % "test",
  62. "org.testcontainers" % "mysql" % "1.19.7" % "test",
  63. "org.testcontainers" % "postgresql" % "1.19.7" % "test",
  64. "net.i2p.crypto" % "eddsa" % "0.3.0",
  65. "is.tagomor.woothee" % "woothee-java" % "1.11.0",
  66. "org.ec4j.core" % "ec4j-core" % "0.3.0",
  67. "org.kohsuke" % "github-api" % "1.320" % "test"
  68. )
  69.  
  70. // Compiler settings
  71. scalacOptions := Seq(
  72. "-deprecation",
  73. "-language:postfixOps",
  74. "-opt:l:method",
  75. "-feature",
  76. "-Wunused:imports",
  77. "-Wconf:cat=unused&src=twirl/.*:s,cat=unused&src=scala/gitbucket/core/model/[^/]+\\.scala:s"
  78. )
  79. scalacOptions ++= {
  80. scalaBinaryVersion.value match {
  81. case "2.13" =>
  82. Seq("-Xsource:3")
  83. case _ =>
  84. Nil
  85. }
  86. }
  87. compile / javacOptions ++= Seq("-target", "11", "-source", "11")
  88. Jetty / javaOptions += "-Dlogback.configurationFile=/logback-dev.xml"
  89.  
  90. // Test settings
  91. //testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
  92. Test / javaOptions += "-Dgitbucket.home=target/gitbucket_home_for_test"
  93. Test / testOptions += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
  94. Test / fork := true
  95.  
  96. // Packaging options
  97. packageOptions += Package.MainClass("JettyLauncher")
  98.  
  99. // Assembly settings
  100. assembly / test := {}
  101. assembly / assemblyMergeStrategy := {
  102. case PathList("META-INF", xs @ _*) =>
  103. (xs map { _.toLowerCase }) match {
  104. case ("manifest.mf" :: Nil) => MergeStrategy.discard
  105. case _ => MergeStrategy.discard
  106. }
  107. case x => MergeStrategy.first
  108. }
  109.  
  110. // Exclude a war file from published artifacts
  111. signedArtifacts := {
  112. signedArtifacts.value.filterNot { case (_, file) =>
  113. file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
  114. }
  115. }
  116.  
  117. // Create executable war file
  118. val ExecutableConfig = config("executable").hide
  119. Keys.ivyConfigurations += ExecutableConfig
  120. libraryDependencies ++= Seq(
  121. "org.eclipse.jetty" % "jetty-security" % JettyVersion % "executable",
  122. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "executable",
  123. "org.eclipse.jetty" % "jetty-server" % JettyVersion % "executable",
  124. "org.eclipse.jetty" % "jetty-xml" % JettyVersion % "executable",
  125. "org.eclipse.jetty" % "jetty-http" % JettyVersion % "executable",
  126. "org.eclipse.jetty" % "jetty-servlet" % JettyVersion % "executable",
  127. "org.eclipse.jetty" % "jetty-io" % JettyVersion % "executable",
  128. "org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
  129. )
  130.  
  131. // Run package task before test to generate target/webapp for integration test
  132. Test / test := {
  133. _root_.sbt.Keys.`package`.value
  134. (Test / test).value
  135. }
  136.  
  137. val executableKey = TaskKey[File]("executable")
  138. executableKey := {
  139. import java.util.jar.Attributes.{Name => AttrName}
  140. import java.util.jar.{Manifest => JarManifest}
  141.  
  142. val workDir = Keys.target.value / "executable"
  143. val warName = Keys.name.value + ".war"
  144.  
  145. val log = streams.value.log
  146. log info s"building executable webapp in ${workDir}"
  147.  
  148. // initialize temp directory
  149. val temp = workDir / "webapp"
  150. IO delete temp
  151.  
  152. // include jetty classes
  153. val jettyJars = Keys.update.value select configurationFilter(name = ExecutableConfig.name)
  154. jettyJars foreach { jar =>
  155. IO unzip (jar, temp, (name: String) =>
  156. (name startsWith "javax/") || (name startsWith "org/") || (name startsWith "META-INF/services/"))
  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 = (Compile / Keys.classDirectory).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://github.com/" +
  179. s"gitbucket/gitbucket-${pluginId}-plugin/releases/download/${pluginVersion}/gitbucket-${pluginId}-plugin-${pluginVersion}.jar"
  180. log info s"Download: ${url}"
  181. IO transfer (new java.net.URI(url).toURL.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, None)
  196.  
  197. // generate checksums
  198. Seq(
  199. "md5" -> "MD5",
  200. "sha1" -> "SHA-1",
  201. "sha256" -> "SHA-256"
  202. ).foreach { case (extension, algorithm) =>
  203. val checksumFile = workDir / (warName + "." + extension)
  204. Checksums generate (outputFile, checksumFile, algorithm)
  205. }
  206.  
  207. // done
  208. log info s"built executable webapp ${outputFile}"
  209. outputFile
  210. }
  211. publishTo := {
  212. val nexus = "https://oss.sonatype.org/"
  213. if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
  214. else Some("releases" at nexus + "service/local/staging/deploy/maven2")
  215. }
  216. publishMavenStyle := true
  217. pomIncludeRepository := { _ =>
  218. false
  219. }
  220. pomExtra := (
  221. <url>https://github.com/gitbucket/gitbucket</url>
  222. <licenses>
  223. <license>
  224. <name>The Apache Software License, Version 2.0</name>
  225. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  226. </license>
  227. </licenses>
  228. <scm>
  229. <url>https://github.com/gitbucket/gitbucket</url>
  230. <connection>scm:git:https://github.com/gitbucket/gitbucket.git</connection>
  231. </scm>
  232. <developers>
  233. <developer>
  234. <id>takezoe</id>
  235. <name>Naoki Takezoe</name>
  236. <url>https://github.com/takezoe</url>
  237. </developer>
  238. <developer>
  239. <id>shimamoto</id>
  240. <name>Takako Shimamoto</name>
  241. <url>https://github.com/shimamoto</url>
  242. </developer>
  243. <developer>
  244. <id>tanacasino</id>
  245. <name>Tomofumi Tanaka</name>
  246. <url>https://github.com/tanacasino</url>
  247. </developer>
  248. <developer>
  249. <id>mrkm4ntr</id>
  250. <name>Shintaro Murakami</name>
  251. <url>https://github.com/mrkm4ntr</url>
  252. </developer>
  253. <developer>
  254. <id>nazoking</id>
  255. <name>nazoking</name>
  256. <url>https://github.com/nazoking</url>
  257. </developer>
  258. <developer>
  259. <id>McFoggy</id>
  260. <name>Matthieu Brouillard</name>
  261. <url>https://github.com/McFoggy</url>
  262. </developer>
  263. </developers>
  264. )
  265.  
  266. Test / testOptions ++= {
  267. if (scala.util.Properties.isWin) {
  268. Seq(
  269. Tests.Exclude(
  270. Set(
  271. "gitbucket.core.GitBucketCoreModuleSpec"
  272. )
  273. )
  274. )
  275. } else {
  276. Nil
  277. }
  278. }
  279.  
  280. Jetty / javaOptions ++= Seq(
  281. "-Dlogback.configurationFile=/logback-dev.xml",
  282. "-Xdebug",
  283. "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000",
  284. "-Dorg.eclipse.jetty.annotations.AnnotationParser.LEVEL=OFF",
  285. // "-Ddev-features=keep-session"
  286. )