diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..fd91c81 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,2 @@ +version = 3.8.3 +runner.dialect=scala212source3 diff --git a/build.sbt b/build.sbt index 90bd4d1..f9368ab 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,3 @@ -import scalariform.formatter.preferences._ - lazy val root = (project in file(".")).settings( organization := "org.scalatra.sbt", name := "sbt-scalatra", @@ -14,7 +12,8 @@ lazy val root = (project in file(".")).settings( ) }, publishTo := { - if (version.value.trim.endsWith("SNAPSHOT")) Some(Opts.resolver.sonatypeSnapshots) + if (version.value.trim.endsWith("SNAPSHOT")) + Some(Opts.resolver.sonatypeSnapshots) else Some(Opts.resolver.sonatypeStaging) }, publishMavenStyle := true, @@ -45,12 +44,9 @@ lazy val root = (project in file(".")).settings( ) -scalariformPreferences := scalariformPreferences.value - .setPreference(DanglingCloseParenthesis, Force) - enablePlugins(ScriptedPlugin) scriptedLaunchOpts ++= Seq( "scalatra_version" -> "2.8.4", - "scala_version" -> "2.13.15", -).map{ case (k, v) => s"-D$k=$v" } + "scala_version" -> "2.13.15" +).map { case (k, v) => s"-D$k=$v" } diff --git a/project/plugin.sbt b/project/plugin.sbt index 268d212..4aff3db 100644 --- a/project/plugin.sbt +++ b/project/plugin.sbt @@ -1,7 +1,9 @@ -addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3") -addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1") +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature") // scripted for plugin testing -libraryDependencies += { "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value } +libraryDependencies += { + "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value +} diff --git a/scripted.sbt b/scripted.sbt index 2a89e38..d0b4f85 100644 --- a/scripted.sbt +++ b/scripted.sbt @@ -1,4 +1,5 @@ -scriptedLaunchOpts := { scriptedLaunchOpts.value ++ - Seq("-Xmx1024M", "-Dplugin.version=" + version.value) +scriptedLaunchOpts := { + scriptedLaunchOpts.value ++ + Seq("-Xmx1024M", "-Dplugin.version=" + version.value) } scriptedBufferLog := false diff --git a/src/main/scala/org/scalatra/sbt/DistPlugin.scala b/src/main/scala/org/scalatra/sbt/DistPlugin.scala index ae72f06..2ec206e 100644 --- a/src/main/scala/org/scalatra/sbt/DistPlugin.scala +++ b/src/main/scala/org/scalatra/sbt/DistPlugin.scala @@ -11,13 +11,19 @@ import com.earldouglas.xwp.WebappPlugin.autoImport.webappPrepare object DistPlugin extends AutoPlugin { object DistKeys { - val dist = taskKey[File]("Build a distribution, assemble the files, create a launcher and make an archive.") - val stage = taskKey[Seq[File]]("Build a distribution, assemble the files and create a launcher.") + val dist = taskKey[File]( + "Build a distribution, assemble the files, create a launcher and make an archive." + ) + val stage = taskKey[Seq[File]]( + "Build a distribution, assemble the files and create a launcher." + ) val assembleJarsAndClasses = taskKey[Seq[File]]("Assemble jars and classes") val memSetting = settingKey[String]("The maximium and initial heap size.") @deprecated("there is no effect. will be removed", "") val permGenSetting = settingKey[String]("The PermGen size.") - val envExports = settingKey[Seq[String]]("The exports which will be expored in the launcher script.") + val envExports = settingKey[Seq[String]]( + "The exports which will be expored in the launcher script." + ) val runScriptName = settingKey[String]("The name of the service runscript.") } @@ -33,8 +39,12 @@ object DistPlugin extends AutoPlugin { Def.task { IO.delete(tgt.value) - val (libs, dirs) = cp.value.files partition Compat.ClasspathUtilities.isArchive - val jars = libs.descendantsExcept(GlobFilter("*"), excl.value) pair Path.flat(tgt.value / "lib") + val (libs, dirs) = + cp.value.files partition Compat.ClasspathUtilities.isArchive + val jars = + libs.descendantsExcept(GlobFilter("*"), excl.value) pair Path.flat( + tgt.value / "lib" + ) val classesAndResources = dirs flatMap { dir => val files = dir.descendantsExcept(GlobFilter("*"), excl.value) files pair Path.rebase(dir, tgt.value / "lib") @@ -44,15 +54,40 @@ object DistPlugin extends AutoPlugin { } } - private def createLauncherScriptTask(base: File, name: String, libFiles: Seq[File], mainClass: Option[String], javaOptions: Seq[String], envExports: Seq[String], logger: Logger): File = { + private def createLauncherScriptTask( + base: File, + name: String, + libFiles: Seq[File], + mainClass: Option[String], + javaOptions: Seq[String], + envExports: Seq[String], + logger: Logger + ): File = { val f = base / "bin" / name if (!f.getParentFile.exists()) f.getParentFile.mkdirs() - IO.write(f, createScriptString(base, name, libFiles, mainClass, javaOptions, envExports)) + IO.write( + f, + createScriptString( + base, + name, + libFiles, + mainClass, + javaOptions, + envExports + ) + ) Compat.executeProccess("chmod +x %s".format(f.getAbsolutePath), logger) f } - private def createScriptString(base: File, name: String, libFiles: Seq[File], mainClass: Option[String], javaOptions: Seq[String], envExports: Seq[String]): String = { + private def createScriptString( + base: File, + name: String, + libFiles: Seq[File], + mainClass: Option[String], + javaOptions: Seq[String], + envExports: Seq[String] + ): String = { """#!/bin/env bash | |export CLASSPATH="lib:%s" @@ -60,11 +95,18 @@ object DistPlugin extends AutoPlugin { |%s | |java $JAVA_OPTS -cp $CLASSPATH %s - |""".stripMargin.format(classPathString(base, libFiles), javaOptions.mkString(" "), envExports.map(e => "export %s".format(e)).mkString("\n"), mainClass.getOrElse("")) + |""".stripMargin.format( + classPathString(base, libFiles), + javaOptions.mkString(" "), + envExports.map(e => "export %s".format(e)).mkString("\n"), + mainClass.getOrElse("") + ) } private def classPathString(base: File, libFiles: Seq[File]) = { - (libFiles filter Compat.ClasspathUtilities.isArchive map (_.relativeTo(base))).flatten mkString java.io.File.pathSeparator + (libFiles filter Compat.ClasspathUtilities.isArchive map (_.relativeTo( + base + ))).flatten mkString java.io.File.pathSeparator } private def stageTask: Initialize[Task[Seq[File]]] = { @@ -79,13 +121,26 @@ object DistPlugin extends AutoPlugin { val s = streams Def.task { - val launch = createLauncherScriptTask(tgt.value, nm.value, libFiles.value, mc.value, jo.value, ee.value, s.value.log) + val launch = createLauncherScriptTask( + tgt.value, + nm.value, + libFiles.value, + mc.value, + jo.value, + ee.value, + s.value.log + ) val logsDir = tgt.value / "logs" if (!logsDir.exists()) logsDir.mkdirs() - s.value.log.info("Adding " + webRes.value + " to dist in " + tgt.value + "/webapp") - val resourceFilesFinder = webRes.value.descendantsExcept(GlobFilter("*"), excl.value) - val resourceFiles = IO.copy(resourceFilesFinder pair Path.rebase(webRes.value, tgt.value / "webapp")) + s.value.log.info( + "Adding " + webRes.value + " to dist in " + tgt.value + "/webapp" + ) + val resourceFilesFinder = + webRes.value.descendantsExcept(GlobFilter("*"), excl.value) + val resourceFiles = IO.copy( + resourceFilesFinder pair Path.rebase(webRes.value, tgt.value / "webapp") + ) libFiles.value ++ Seq(launch, logsDir) ++ resourceFiles } @@ -113,12 +168,16 @@ object DistPlugin extends AutoPlugin { } private object PatternFileFilter { - def apply(expression: String): PatternFileFilter = new PatternFileFilter(Pattern.compile(expression)) + def apply(expression: String): PatternFileFilter = new PatternFileFilter( + Pattern.compile(expression) + ) } val distSettings = Seq( Dist / excludeFilter := { - HiddenFileFilter || PatternFileFilter(".*/WEB-INF/classes") || PatternFileFilter(".*/WEB-INF/lib") + HiddenFileFilter || PatternFileFilter( + ".*/WEB-INF/classes" + ) || PatternFileFilter(".*/WEB-INF/lib") // could use (webappDest in webapp).value.getCanonicalPath instead of .*, but webappDest is a task and SBT settings cant depend on tasks }, Dist / target := (Compile / target)(_ / "dist").value, diff --git a/src/main/scala/org/scalatra/sbt/PluginKeys.scala b/src/main/scala/org/scalatra/sbt/PluginKeys.scala index 2451cec..64713d1 100644 --- a/src/main/scala/org/scalatra/sbt/PluginKeys.scala +++ b/src/main/scala/org/scalatra/sbt/PluginKeys.scala @@ -4,5 +4,6 @@ import sbt._ import Keys._ object PluginKeys { - val browse = taskKey[Unit]("Open a web browser to localhost on container:port") + val browse = + taskKey[Unit]("Open a web browser to localhost on container:port") } diff --git a/src/main/scala/org/scalatra/sbt/ScalatraPlugin.scala b/src/main/scala/org/scalatra/sbt/ScalatraPlugin.scala index cf4d9fd..10e8a92 100644 --- a/src/main/scala/org/scalatra/sbt/ScalatraPlugin.scala +++ b/src/main/scala/org/scalatra/sbt/ScalatraPlugin.scala @@ -5,7 +5,7 @@ import Keys._ import java.net.URI import com.earldouglas.xwp.ContainerPlugin.autoImport.containerPort import com.earldouglas.xwp.JettyPlugin -import com.earldouglas.xwp.JettyPlugin.{ projectSettings => jettySettings } +import com.earldouglas.xwp.JettyPlugin.{projectSettings => jettySettings} import com.earldouglas.xwp.JettyPlugin.autoImport.Jetty object ScalatraPlugin extends AutoPlugin { @@ -30,14 +30,17 @@ object ScalatraPlugin extends AutoPlugin { java.awt.Desktop.getDesktop.browse(url) } catch { case _: Throwable => { - log.info(f"Could not open browser, sorry. Open manually to ${url.toASCIIString}") + log.info( + f"Could not open browser, sorry. Open manually to ${url.toASCIIString}" + ) } } } val scalatraSettings: Seq[Def.Setting[_]] = jettySettings ++ Seq(browseTask) - val scalatraWithDist: Seq[Def.Setting[_]] = scalatraSettings ++ DistPlugin.distSettings + val scalatraWithDist: Seq[Def.Setting[_]] = + scalatraSettings ++ DistPlugin.distSettings override lazy val projectSettings = scalatraSettings } diff --git a/src/sbt-test/DistPlugin/dist/project/plugin.sbt b/src/sbt-test/DistPlugin/dist/project/plugin.sbt index f44d05b..7252dca 100644 --- a/src/sbt-test/DistPlugin/dist/project/plugin.sbt +++ b/src/sbt-test/DistPlugin/dist/project/plugin.sbt @@ -1,5 +1,8 @@ sys.props.get("plugin.version") match { case Some(x) => addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + case _ => + sys.error( + """|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin + ) } diff --git a/src/sbt-test/ScalatraPlugin/browse/build.sbt b/src/sbt-test/ScalatraPlugin/browse/build.sbt index 3bb4913..bcf42db 100644 --- a/src/sbt-test/ScalatraPlugin/browse/build.sbt +++ b/src/sbt-test/ScalatraPlugin/browse/build.sbt @@ -19,19 +19,23 @@ Jetty / containerPort := 8090 lazy val check = taskKey[Unit]("check if / is available") - check := { import org.http4s.implicits._ import cats.effect.unsafe.implicits.global - org.http4s.blaze.client.BlazeClientBuilder[cats.effect.IO].resource.use { - client => + org.http4s.blaze.client + .BlazeClientBuilder[cats.effect.IO] + .resource + .use { client => val uri = uri"http://localhost:8090/" - client.expect[String](uri).map( - res => if (res != "hey") sys.error("unexpected output: " + res) else () - ) - }.unsafeRunSync() + client + .expect[String](uri) + .map(res => + if (res != "hey") sys.error("unexpected output: " + res) else () + ) + } + .unsafeRunSync() } diff --git a/src/sbt-test/ScalatraPlugin/browse/project/plugin.sbt b/src/sbt-test/ScalatraPlugin/browse/project/plugin.sbt index 858bf4d..98d67f6 100644 --- a/src/sbt-test/ScalatraPlugin/browse/project/plugin.sbt +++ b/src/sbt-test/ScalatraPlugin/browse/project/plugin.sbt @@ -2,6 +2,9 @@ libraryDependencies += "org.http4s" %% "http4s-blaze-client" % "0.23.16" sys.props.get("plugin.version") match { case Some(x) => addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + case _ => + sys.error( + """|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin + ) } diff --git a/src/sbt-test/ScalatraPlugin/jetty-start/build.sbt b/src/sbt-test/ScalatraPlugin/jetty-start/build.sbt index 8960403..01971ab 100644 --- a/src/sbt-test/ScalatraPlugin/jetty-start/build.sbt +++ b/src/sbt-test/ScalatraPlugin/jetty-start/build.sbt @@ -19,19 +19,23 @@ Jetty / containerPort := 8090 lazy val check = taskKey[Unit]("check if / is available") - check := { import org.http4s.implicits._ import cats.effect.unsafe.implicits.global - org.http4s.blaze.client.BlazeClientBuilder[cats.effect.IO].resource.use { - client => + org.http4s.blaze.client + .BlazeClientBuilder[cats.effect.IO] + .resource + .use { client => val uri = uri"http://localhost:8090/" - client.expect[String](uri).map( - res => if (res != "hey") sys.error("unexpected output: " + res) else () - ) - }.unsafeRunSync() + client + .expect[String](uri) + .map(res => + if (res != "hey") sys.error("unexpected output: " + res) else () + ) + } + .unsafeRunSync() } diff --git a/src/sbt-test/ScalatraPlugin/jetty-start/project/plugin.sbt b/src/sbt-test/ScalatraPlugin/jetty-start/project/plugin.sbt index 858bf4d..98d67f6 100644 --- a/src/sbt-test/ScalatraPlugin/jetty-start/project/plugin.sbt +++ b/src/sbt-test/ScalatraPlugin/jetty-start/project/plugin.sbt @@ -2,6 +2,9 @@ libraryDependencies += "org.http4s" %% "http4s-blaze-client" % "0.23.16" sys.props.get("plugin.version") match { case Some(x) => addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + case _ => + sys.error( + """|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin + ) }