Newer
Older
gitbucket_jkp / build.sbt
@Scala Steward Scala Steward on 2 Jun 2023 11 KB Update scala-library to 2.13.11
  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-SNAPSHOT"
  7. val ScalatraVersion = "3.0.0-M3"
  8. val JettyVersion = "10.0.15"
  9. val JgitVersion = "6.5.0.202303070854-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.11"
  19.  
  20. crossScalaVersions += "3.3.0"
  21.  
  22. conflictWarning := {
  23. if (scalaBinaryVersion.value == "3") {
  24. // TODO remove this workaround
  25. ConflictWarning("warn", Level.Warn, false)
  26. } else {
  27. conflictWarning.value
  28. }
  29. }
  30.  
  31. // scalafmtOnCompile := true
  32.  
  33. coverageExcludedPackages := ".*\\.html\\..*"
  34.  
  35. // dependency settings
  36. resolvers ++= Seq(
  37. Classpaths.typesafeReleases,
  38. "sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/"
  39. )
  40.  
  41. libraryDependencies ++= Seq(
  42. "org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
  43. "org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
  44. "org.scalatra" %% "scalatra" % ScalatraVersion,
  45. "org.scalatra" %% "scalatra-json" % ScalatraVersion,
  46. "org.scalatra" %% "scalatra-forms" % ScalatraVersion,
  47. "org.json4s" %% "json4s-jackson" % "4.0.6",
  48. "commons-io" % "commons-io" % "2.12.0",
  49. "io.github.gitbucket" % "solidbase" % "1.0.5",
  50. "io.github.gitbucket" % "markedj" % "1.0.17",
  51. "org.apache.commons" % "commons-compress" % "1.23.0",
  52. "org.apache.commons" % "commons-email" % "1.5",
  53. "commons-net" % "commons-net" % "3.9.0",
  54. "org.apache.httpcomponents" % "httpclient" % "4.5.14",
  55. "org.apache.sshd" % "apache-sshd" % "2.10.0" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
  56. "org.apache.tika" % "tika-core" % "2.8.0",
  57. "com.github.takezoe" %% "blocking-slick-32" % "0.0.12" cross CrossVersion.for3Use2_13,
  58. "com.novell.ldap" % "jldap" % "2009-10-07",
  59. "com.h2database" % "h2" % "1.4.199",
  60. "org.mariadb.jdbc" % "mariadb-java-client" % "2.7.6",
  61. "org.postgresql" % "postgresql" % "42.6.0",
  62. "ch.qos.logback" % "logback-classic" % "1.4.7",
  63. "com.zaxxer" % "HikariCP" % "4.0.3" exclude ("org.slf4j", "slf4j-api"),
  64. "com.typesafe" % "config" % "1.4.2",
  65. "fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
  66. "io.github.java-diff-utils" % "java-diff-utils" % "4.12",
  67. "org.cache2k" % "cache2k-all" % "1.6.0.Final",
  68. "net.coobird" % "thumbnailator" % "0.4.19",
  69. "com.github.zafarkhaja" % "java-semver" % "0.9.0",
  70. "com.nimbusds" % "oauth2-oidc-sdk" % "10.9.1",
  71. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
  72. "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
  73. "junit" % "junit" % "4.13.2" % "test",
  74. "org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
  75. "org.mockito" % "mockito-core" % "5.3.1" % "test",
  76. "com.dimafeng" %% "testcontainers-scala" % "0.40.16" % "test",
  77. "org.testcontainers" % "mysql" % "1.18.3" % "test",
  78. "org.testcontainers" % "postgresql" % "1.18.3" % "test",
  79. "net.i2p.crypto" % "eddsa" % "0.3.0",
  80. "is.tagomor.woothee" % "woothee-java" % "1.11.0",
  81. "org.ec4j.core" % "ec4j-core" % "0.3.0",
  82. "org.kohsuke" % "github-api" % "1.315" % "test"
  83. )
  84.  
  85. libraryDependencies ~= {
  86. _.map {
  87. case x if x.name == "twirl-api" =>
  88. x cross CrossVersion.for3Use2_13
  89. case x =>
  90. x
  91. }
  92. }
  93.  
  94. // Compiler settings
  95. scalacOptions := Seq(
  96. "-deprecation",
  97. "-language:postfixOps",
  98. "-opt:l:method",
  99. "-feature",
  100. "-Wunused:imports",
  101. "-Wconf:cat=unused&src=twirl/.*:s,cat=unused&src=scala/gitbucket/core/model/[^/]+\\.scala:s"
  102. )
  103. compile / javacOptions ++= Seq("-target", "11", "-source", "11")
  104. Jetty / javaOptions += "-Dlogback.configurationFile=/logback-dev.xml"
  105.  
  106. // Test settings
  107. //testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
  108. Test / javaOptions += "-Dgitbucket.home=target/gitbucket_home_for_test"
  109. Test / testOptions += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
  110. Test / fork := true
  111.  
  112. // Packaging options
  113. packageOptions += Package.MainClass("JettyLauncher")
  114.  
  115. // Assembly settings
  116. assembly / test := {}
  117. assembly / assemblyMergeStrategy := {
  118. case PathList("META-INF", xs @ _*) =>
  119. (xs map { _.toLowerCase }) match {
  120. case ("manifest.mf" :: Nil) => MergeStrategy.discard
  121. case _ => MergeStrategy.discard
  122. }
  123. case x => MergeStrategy.first
  124. }
  125.  
  126. // Exclude a war file from published artifacts
  127. signedArtifacts := {
  128. signedArtifacts.value.filterNot {
  129. case (_, file) => file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
  130. }
  131. }
  132.  
  133. // Create executable war file
  134. val ExecutableConfig = config("executable").hide
  135. Keys.ivyConfigurations += ExecutableConfig
  136. libraryDependencies ++= Seq(
  137. "org.eclipse.jetty" % "jetty-security" % JettyVersion % "executable",
  138. "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "executable",
  139. "org.eclipse.jetty" % "jetty-server" % JettyVersion % "executable",
  140. "org.eclipse.jetty" % "jetty-xml" % JettyVersion % "executable",
  141. "org.eclipse.jetty" % "jetty-http" % JettyVersion % "executable",
  142. "org.eclipse.jetty" % "jetty-servlet" % JettyVersion % "executable",
  143. "org.eclipse.jetty" % "jetty-io" % JettyVersion % "executable",
  144. "org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
  145. )
  146.  
  147. // Run package task before test to generate target/webapp for integration test
  148. Test / test := {
  149. _root_.sbt.Keys.`package`.value
  150. (Test / test).value
  151. }
  152.  
  153. val executableKey = TaskKey[File]("executable")
  154. executableKey := {
  155. import java.util.jar.Attributes.{Name => AttrName}
  156. import java.util.jar.{Manifest => JarManifest}
  157.  
  158. val workDir = Keys.target.value / "executable"
  159. val warName = Keys.name.value + ".war"
  160.  
  161. val log = streams.value.log
  162. log info s"building executable webapp in ${workDir}"
  163.  
  164. // initialize temp directory
  165. val temp = workDir / "webapp"
  166. IO delete temp
  167.  
  168. // include jetty classes
  169. val jettyJars = Keys.update.value select configurationFilter(name = ExecutableConfig.name)
  170. jettyJars foreach { jar =>
  171. IO unzip (jar, temp, (name: String) =>
  172. (name startsWith "javax/") ||
  173. (name startsWith "org/"))
  174. }
  175.  
  176. // include original war file
  177. val warFile = (Keys.`package`).value
  178. IO unzip (warFile, temp)
  179.  
  180. // include launcher classes
  181. val classDir = (Compile / Keys.classDirectory).value
  182. val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
  183. launchClasses foreach { name =>
  184. IO copyFile (classDir / name, temp / name)
  185. }
  186.  
  187. // include plugins
  188. val pluginsDir = temp / "WEB-INF" / "classes" / "plugins"
  189. IO createDirectory (pluginsDir)
  190.  
  191. val plugins = IO readLines (Keys.baseDirectory.value / "src" / "main" / "resources" / "bundle-plugins.txt")
  192. plugins.foreach { plugin =>
  193. plugin.trim.split(":") match {
  194. case Array(pluginId, pluginVersion) =>
  195. val url = "https://github.com/" +
  196. s"gitbucket/gitbucket-${pluginId}-plugin/releases/download/${pluginVersion}/gitbucket-${pluginId}-plugin-${pluginVersion}.jar"
  197. log info s"Download: ${url}"
  198. IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
  199. case _ => ()
  200. }
  201. }
  202.  
  203. // zip it up
  204. IO delete (temp / "META-INF" / "MANIFEST.MF")
  205. val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file =>
  206. IO.relativizeFile(temp, file)
  207. }
  208. val manifest = new JarManifest
  209. manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
  210. manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
  211. val outputFile = workDir / warName
  212. IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest, None)
  213.  
  214. // generate checksums
  215. Seq(
  216. "md5" -> "MD5",
  217. "sha1" -> "SHA-1",
  218. "sha256" -> "SHA-256"
  219. ).foreach {
  220. case (extension, algorithm) =>
  221. val checksumFile = workDir / (warName + "." + extension)
  222. Checksums generate (outputFile, checksumFile, algorithm)
  223. }
  224.  
  225. // done
  226. log info s"built executable webapp ${outputFile}"
  227. outputFile
  228. }
  229. publishTo := {
  230. val nexus = "https://oss.sonatype.org/"
  231. if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
  232. else Some("releases" at nexus + "service/local/staging/deploy/maven2")
  233. }
  234. publishMavenStyle := true
  235. pomIncludeRepository := { _ =>
  236. false
  237. }
  238. pomExtra := (
  239. <url>https://github.com/gitbucket/gitbucket</url>
  240. <licenses>
  241. <license>
  242. <name>The Apache Software License, Version 2.0</name>
  243. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  244. </license>
  245. </licenses>
  246. <scm>
  247. <url>https://github.com/gitbucket/gitbucket</url>
  248. <connection>scm:git:https://github.com/gitbucket/gitbucket.git</connection>
  249. </scm>
  250. <developers>
  251. <developer>
  252. <id>takezoe</id>
  253. <name>Naoki Takezoe</name>
  254. <url>https://github.com/takezoe</url>
  255. </developer>
  256. <developer>
  257. <id>shimamoto</id>
  258. <name>Takako Shimamoto</name>
  259. <url>https://github.com/shimamoto</url>
  260. </developer>
  261. <developer>
  262. <id>tanacasino</id>
  263. <name>Tomofumi Tanaka</name>
  264. <url>https://github.com/tanacasino</url>
  265. </developer>
  266. <developer>
  267. <id>mrkm4ntr</id>
  268. <name>Shintaro Murakami</name>
  269. <url>https://github.com/mrkm4ntr</url>
  270. </developer>
  271. <developer>
  272. <id>nazoking</id>
  273. <name>nazoking</name>
  274. <url>https://github.com/nazoking</url>
  275. </developer>
  276. <developer>
  277. <id>McFoggy</id>
  278. <name>Matthieu Brouillard</name>
  279. <url>https://github.com/McFoggy</url>
  280. </developer>
  281. </developers>
  282. )
  283.  
  284. Test / testOptions ++= {
  285. if (scala.util.Properties.isWin) {
  286. Seq(
  287. Tests.Exclude(
  288. Set(
  289. "gitbucket.core.GitBucketCoreModuleSpec"
  290. )
  291. )
  292. )
  293. } else {
  294. Nil
  295. }
  296. }
  297.  
  298. Jetty / javaOptions ++= Seq(
  299. "-Dlogback.configurationFile=/logback-dev.xml",
  300. "-Xdebug",
  301. "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000",
  302. "-Dorg.eclipse.jetty.annotations.AnnotationParser.LEVEL=OFF",
  303. //"-Ddev-features=keep-session"
  304. )