Skip to content

Commit

Permalink
Add default implementation for BuildToolAlg#runMigration
Browse files Browse the repository at this point in the history
This adds a default implementation for `BuildToolAlg#runMigration` that
logs a warning that Scalafix migrations are not supported by the build
tool. It prevents some repeated text that is used for every build tool
except sbt.
  • Loading branch information
fthomas committed Dec 13, 2023
1 parent 29dcd58 commit 6998d77
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package org.scalasteward.core.buildtool

import org.scalasteward.core.data.Scope
import org.scalasteward.core.edit.scalafix.ScalafixMigration
import org.typelevel.log4cats.Logger
import scala.annotation.nowarn

trait BuildToolAlg[F[_]] {
def name: String
Expand All @@ -26,5 +28,13 @@ trait BuildToolAlg[F[_]] {

def getDependencies(buildRoot: BuildRoot): F[List[Scope.Dependencies]]

def runMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit]
def runMigration(@nowarn buildRoot: BuildRoot, @nowarn migration: ScalafixMigration): F[Unit] =
logger.warn(
s"Scalafix migrations are currently not supported in $name projects" +
scalafixIssue.fold("")(issue => s", see $issue for details")
)

protected def logger: Logger[F]

protected def scalafixIssue: Option[String] = None

Check warning on line 39 in modules/core/src/main/scala/org/scalasteward/core/buildtool/BuildToolAlg.scala

View check run for this annotation

Codecov / codecov/patch

modules/core/src/main/scala/org/scalasteward/core/buildtool/BuildToolAlg.scala#L39

Added line #L39 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import cats.syntax.all._
import org.scalasteward.core.application.Config
import org.scalasteward.core.buildtool.{BuildRoot, BuildToolAlg}
import org.scalasteward.core.data._
import org.scalasteward.core.edit.scalafix.ScalafixMigration
import org.scalasteward.core.io.{FileAlg, ProcessAlg, WorkspaceAlg}
import org.scalasteward.core.util.Nel
import org.typelevel.log4cats.Logger

final class MavenAlg[F[_]](config: Config)(implicit
fileAlg: FileAlg[F],
logger: Logger[F],
override protected val logger: Logger[F],
processAlg: ProcessAlg[F],
workspaceAlg: WorkspaceAlg[F],
F: MonadCancelThrow[F]
Expand All @@ -56,10 +55,8 @@ final class MavenAlg[F[_]](config: Config)(implicit
resolvers = parser.parseResolvers(repositoriesRaw).distinct
} yield List(Scope(dependencies, resolvers))

override def runMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit] =
logger.warn(
s"Scalafix migrations are currently not supported in $name projects, see https://github.com/scala-steward-org/scala-steward/issues/2839 for details"
)
override protected val scalafixIssue: Option[String] =
Some("https://github.com/scala-steward-org/scala-steward/issues/2839")

private def exec(command: Nel[String], repoDir: File): F[List[String]] =
maybeIgnoreOptsFiles(repoDir).surround(processAlg.execSandboxed(command, repoDir))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import cats.syntax.all._
import org.scalasteward.core.buildtool.mill.MillAlg._
import org.scalasteward.core.buildtool.{BuildRoot, BuildToolAlg}
import org.scalasteward.core.data._
import org.scalasteward.core.edit.scalafix.ScalafixMigration
import org.scalasteward.core.io.{FileAlg, ProcessAlg, WorkspaceAlg}
import org.scalasteward.core.util.Nel
import org.typelevel.log4cats.Logger

final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
fileAlg: FileAlg[F],
logger: Logger[F],
override protected val logger: Logger[F],
processAlg: ProcessAlg[F],
workspaceAlg: WorkspaceAlg[F],
F: MonadCancelThrow[F]
Expand Down Expand Up @@ -82,10 +81,8 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
dependencies = parsed.map(module => Scope(module.dependencies, module.repositories))
} yield dependencies

override def runMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit] =
logger.warn(
s"Scalafix migrations are currently not supported in $name projects, see https://github.com/scala-steward-org/scala-steward/issues/2838 for details"
)
override protected val scalafixIssue: Option[String] =
Some("https://github.com/scala-steward-org/scala-steward/issues/2838")

private def getMillVersion(buildRootDir: File): F[Option[Version]] =
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import org.scalasteward.core.edit.scalafix.{ScalafixCli, ScalafixMigration}
import org.scalasteward.core.io.process.SlurpOptions
import org.scalasteward.core.io.{FileAlg, FileData, ProcessAlg, WorkspaceAlg}
import org.scalasteward.core.util.Nel
import org.typelevel.log4cats.Logger

final class SbtAlg[F[_]](config: Config)(implicit
fileAlg: FileAlg[F],
override protected val logger: Logger[F],
processAlg: ProcessAlg[F],
scalafixCli: ScalafixCli[F],
workspaceAlg: WorkspaceAlg[F],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import cats.syntax.all._
import org.scalasteward.core.buildtool.sbt.SbtAlg
import org.scalasteward.core.buildtool.{BuildRoot, BuildToolAlg}
import org.scalasteward.core.data.Scope
import org.scalasteward.core.edit.scalafix.ScalafixMigration
import org.scalasteward.core.git.GitAlg
import org.scalasteward.core.io.process.SlurpOptions
import org.scalasteward.core.io.{FileAlg, ProcessAlg, WorkspaceAlg}
Expand Down Expand Up @@ -53,7 +52,7 @@ object ScalaCliAlg {
final class ScalaCliAlg[F[_]](implicit
fileAlg: FileAlg[F],
gitAlg: GitAlg[F],
logger: Logger[F],
override protected val logger: Logger[F],
processAlg: ProcessAlg[F],
sbtAlg: SbtAlg[F],
workspaceAlg: WorkspaceAlg[F],
Expand Down Expand Up @@ -92,8 +91,6 @@ final class ScalaCliAlg[F[_]](implicit
_ <- fileAlg.deleteForce(buildRootDir / exportDir)
} yield dependencies

override def runMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit] =
logger.warn(
s"Scalafix migrations are currently not supported in $name projects, see https://github.com/VirtusLab/scala-cli/issues/647 for details"
)
override protected val scalafixIssue: Option[String] =
Some("https://github.com/VirtusLab/scala-cli/issues/647")
}

0 comments on commit 6998d77

Please sign in to comment.