Skip to content

Commit

Permalink
Get scalafix working, mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
earldouglas committed Oct 10, 2024
1 parent 2760852 commit 251c02d
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- uses: actions/setup-java@v1
with:
java-version: 11
- run: sbt scalafmtCheckAll test scripted
- run: sbt scalafmtCheckAll "scalafixAll --check" test scripted
1 change: 1 addition & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rules = [
OrganizeImports
RemoveUnused
]
18 changes: 2 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,12 @@ scriptedBatchExecution := true
scriptedParallelInstances := 8

// Scalafix
/*
semanticdbEnabled := true
semanticdbVersion := scalafixSemanticdb.revision
scalacOptions ++= {
scalaBinaryVersion.value match {
case "2.12" =>
Seq(
"-Ywarn-unused-import",
s"-P:semanticdb:sourceroot:${baseDirectory.value}"
)
case _ =>
Seq("-Wunused:imports")
}
}
*/

scalacOptions ++= {
scalaBinaryVersion.value match {
case "2.12" => Nil
case _ => Seq("-language:implicitConversions")
case "2.12" => Seq("-Ywarn-unused-import")
case _ => Seq.empty // ("-Wunused:imports")
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/scala-2/com/earldouglas/sbt/war/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.earldouglas.sbt.war

import sbt.Keys._
import sbt.Keys.{`package` => pkg}
import sbt._

object Compat {
val Compile_pkg_artifact = Compile / pkg / artifact
val Compile_sourceDirectory = Compile / sourceDirectory
val Compile_target = Compile / target
val Global_onLoad = Global / onLoad
val pkg_artifact = pkg / artifact
}
16 changes: 16 additions & 0 deletions src/main/scala-3/com/earldouglas/sbt/war/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.earldouglas.sbt.war

import sbt.Keys._
import sbt.Keys.{`package` => pkg}
import sbt._
import sbt.given

import scala.language.implicitConversions

object Compat {
val Compile_pkg_artifact = Compile / pkg / artifact
val Compile_sourceDirectory = Compile / sourceDirectory
val Compile_target = Compile / target
val Global_onLoad = Global / onLoad
val pkg_artifact = pkg / artifact
}
10 changes: 4 additions & 6 deletions src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.earldouglas.sbt.war

import sbt.Keys.artifact
import sbt.Keys.moduleName
import sbt.Keys._
import sbt.Keys.{`package` => pkg}
import sbt.{given, _}
import sbt._

/** Identifies the files that compose the .war file (resources, .class
* files in the classes/ directory, and .jar files in the lib/
Expand All @@ -15,7 +14,6 @@ import sbt.{given, _}
*/
object WarPackagePlugin extends AutoPlugin {


override def requires = WebappComponentsPlugin

override lazy val projectSettings: Seq[Setting[_]] = {
Expand All @@ -27,10 +25,10 @@ object WarPackagePlugin extends AutoPlugin {
)

val packageArtifactSetting: Setting[_] =
pkg / artifact := Artifact(moduleName.value, "war", "war")
Compat.pkg_artifact := Artifact(moduleName.value, "war", "war")

val artifactSettings: Seq[Setting[_]] =
addArtifact(Compile / pkg / artifact, pkg)
addArtifact(Compat.Compile_pkg_artifact, pkg)

Seq(
packageTaskSettings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.earldouglas.sbt.war

import sbt.Def.Initialize
import sbt.Def.settingKey
import sbt.Keys._
import sbt.Keys.{`package` => pkg}
import sbt.{given, _}
import sbt._

import java.util.concurrent.atomic.AtomicReference
import scala.sys.process.{Process => ScalaProcess}
Expand Down Expand Up @@ -58,7 +57,7 @@ object WarPackageRunnerPlugin extends AutoPlugin {
warForkOptions.value,
Seq(
"-jar",
runner.file.getPath(),
runner.getPath(),
"--port",
warPort.value.toString(),
WarPackageRunnerPluginCompat
Expand Down Expand Up @@ -88,7 +87,7 @@ object WarPackageRunnerPlugin extends AutoPlugin {

val onLoadSetting: Initialize[State => State] =
Def.setting {
(Global / onLoad).value
Compat.Global_onLoad.value
.compose(_.addExitHook(stopContainerInstance()))
}

Expand All @@ -100,8 +99,11 @@ object WarPackageRunnerPlugin extends AutoPlugin {

val runnerLibrary: Initialize[ModuleID] =
Def.setting {
("com.heroku" % "webapp-runner" % webappRunnerVersion.value)
.intransitive() % War
ModuleID(
organization = "com.heroku",
name = "webapp-runner",
revision = webappRunnerVersion.value
).intransitive() % War
}

Seq(
Expand All @@ -110,7 +112,7 @@ object WarPackageRunnerPlugin extends AutoPlugin {
warJoin := joinWar.value,
warStop := stopWar.value,
warForkOptions := forkOptions.value,
Global / onLoad := onLoadSetting.value,
Compat.Global_onLoad := onLoadSetting.value,
libraryDependencies += runnerLibrary.value
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.earldouglas.sbt.war

import sbt.Def.Initialize
import sbt.Def.taskKey
import sbt.Keys._
import sbt.{given, _}
import sbt._

/** Identifies the files that compose the webapp (resources, .class
* files, and .jar files). This is used by user-facing plugins
Expand Down Expand Up @@ -52,7 +51,7 @@ object WebappComponentsPlugin extends AutoPlugin {
override val projectSettings: Seq[Setting[_]] = {

val webappResourcesTask: Initialize[Task[Map[String, File]]] =
(Compile / sourceDirectory)
(Compat.Compile_sourceDirectory)
.map(_ / "webapp")
.map(WebappComponents.getResources(_))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.earldouglas.sbt.war
import sbt.Def.Initialize
import sbt.Def.settingKey
import sbt.Keys._
import sbt.{given, _}
import sbt._

import java.nio.file.Files
import java.nio.file.Paths
Expand Down Expand Up @@ -50,7 +50,7 @@ object WebappComponentsRunnerPlugin extends AutoPlugin {
val runnerConfigFile: Initialize[Task[File]] =
Def.task {

val emptyDir: File = (Compile / target).value / "empty"
val emptyDir: File = Compat.Compile_target.value / "empty"

val resourceMapString =
WebappComponentsPlugin.webappContents.value
Expand All @@ -60,7 +60,7 @@ object WebappComponentsRunnerPlugin extends AutoPlugin {
.mkString(",")

val configurationFile: File =
(Compile / target).value / "webapp-components.properties"
Compat.Compile_target.value / "webapp-components.properties"

Files
.writeString(
Expand Down Expand Up @@ -111,7 +111,7 @@ object WebappComponentsRunnerPlugin extends AutoPlugin {

val onLoadSetting: Initialize[State => State] =
Def.setting {
(Global / onLoad).value
(Compat.Global_onLoad).value
.compose(_.addExitHook(stopContainerInstance()))
}

Expand All @@ -129,7 +129,7 @@ object WebappComponentsRunnerPlugin extends AutoPlugin {
webappJoin := joinWebapp.value,
webappStop := stopWebapp.value,
webappForkOptions := forkOptions.value,
Global / onLoad := onLoadSetting.value,
Compat.Global_onLoad := onLoadSetting.value,
webappComponentsRunnerVersion := BuildInfo.webappComponentsRunnerVersion,
libraryDependencies ++= runnerLibraries.value
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.earldouglas.sbt.war

import sbt.Def.settingKey
import sbt.{given, _}
import sbt._

/** Launches a webapp composed of in-place resources, classes, and
* libraries.
Expand Down

0 comments on commit 251c02d

Please sign in to comment.