Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add welcome message + prefix internal commands + stop filtering scala-reflect out #430

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion migrate/src/main/scala/migrate/internal/InitialLib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ object InitialLib {
("org.scala-js", "scalajs-compiler"),
("org.scala-js", "scalajs-library"),
("org.scala-js", "scalajs-test-bridge"),
("org.scala-lang", "scala-reflect"),
("org.scala-lang", "scala-library"),
("org.scoverage", "scalac-scoverage-plugin"),
("org.scalameta", "semanticdb-scalac")
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/scala/migrate/CommandStrings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ object CommandStrings {
|- Unclassified: sbt-scala3-migrate does not know how to migrate this dependency
|""".stripMargin

val migrateFallback = "migrateFallback"
val migrateFallback = "internalMigrateFallback"
}
44 changes: 40 additions & 4 deletions plugin/src/main/scala/migrate/ScalaMigratePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import sbt.internal.util.complete.Parser
import sbt.internal.util.complete.Parser.token
import sbt.internal.util.complete.Parsers.Space
import sbt.plugins.JvmPlugin
import scala.Console._

import java.nio.file.Path
import scala.collection.mutable
Expand Down Expand Up @@ -68,6 +69,41 @@ object ScalaMigratePlugin extends AutoPlugin {

override def trigger = AllRequirements

override def globalSettings: Seq[Setting[_]] = Def.settings(
onLoad := {
val previousOnLoad = onLoad.value
state0 => {
val state1 = previousOnLoad(state0)
if (state1.currentCommand.exists(e => e.commandLine == "loadp")) {
state1.log.info(
s"""|
|$GREEN${BOLD}sbt-scala3-migrate ${BuildInfo.version} detected!$RESET
|It can assist you during the migration to Scala 3.
|Run the following commands, to start migrating to Scala 3:
| - ${BOLD}migrateDependencies <project>$RESET
| - ${BOLD}migrateScalacOptions <project>$RESET
| - ${BOLD}migrateSyntax <project>$RESET
| - ${BOLD}migrateTypes <project>$RESET
|Learn more about them on https://docs.scala-lang.org/scala3/guides/migration/scala3-migrate.html
|Remove sbt-scala3-migrate from your project/plugins.sbt to clear this message out.
|
|""".stripMargin
)
}
state1
}
},
commands ++= Seq(
migrateSyntax,
migrateScalacOptions,
migrateLibDependencies,
migrateTypes,
fallback,
fallbackAndFail,
migrateFail
)
)

override def projectSettings: Seq[Setting[_]] = Def.settings(
semanticdbEnabled := {
val sv = scalaVersion.value
Expand Down Expand Up @@ -125,7 +161,7 @@ object ScalaMigratePlugin extends AutoPlugin {
val classpath = dependencyClasspath.value.map(_.data.toPath())
val scala3Lib = scalaInstance.value.libraryJars.toSeq.map(_.toPath)
val scala3ClassDirectory = (compile / classDirectory).value.toPath
val scalac3Options = sanitazeScala3Options(sOptions)
val scalac3Options = sanitizeScala3Options(sOptions)
val semanticdbTarget = semanticdbTargetRoot.value.toPath
Scala3Inputs(projectId, sv, scalac3Options, scala3Lib ++ classpath, scala3ClassDirectory, semanticdbTarget)
},
Expand Down Expand Up @@ -232,20 +268,20 @@ object ScalaMigratePlugin extends AutoPlugin {
}

lazy val fallbackAndFail: Command =
Command("migrateFallbackAndFail")(idParser) { (state, projectId) =>
Command("internalMigrateFallbackAndFail")(idParser) { (state, projectId) =>
PopOnFailure :: s"migrateFallback $projectId" :: s"migrateFail $projectId" :: Nil ::: state
}

lazy val migrateFail: Command =
Command("migrateFail")(idParser) { (state, projectId) =>
Command("internalMigrateFail")(idParser) { (state, projectId) =>
state.log.error(s"Migration of $projectId failed.")
state.fail
}

private def setScalaVersion(projectId: String, scalaVersion: String): String =
s"""set LocalProject("$projectId") / scalaVersion := "$scalaVersion""""

private def sanitazeScala3Options(options: Seq[String]) = {
private def sanitizeScala3Options(options: Seq[String]) = {
val nonWorkingOptions = Set(syntheticsOn)
options.filterNot(nonWorkingOptions)
}
Expand Down
Loading