Skip to content

Commit

Permalink
Use Order[Version] to simplify MillAlg.content (#3540)
Browse files Browse the repository at this point in the history
With our `Version` data type and its `Order` instance we can simplify
`MillAlg.content` because we can just check if a Mill version is >= 0.7
and < 0.9 for example without extracting the minor version number.
  • Loading branch information
fthomas authored Jan 13, 2025
1 parent fbf5c4b commit 757f9bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,19 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
}

object MillAlg {
private[mill] def millMinVersion(millVersion: Option[Version]): Option[String] =
millVersion.flatMap(_.value.trim.split("[.]", 3).take(2).lastOption)

private[mill] val cliPluginCoordinate: String =
s"ivy:${org.scalasteward.core.BuildInfo.organization}::${org.scalasteward.core.BuildInfo.millPluginArtifactName}::${org.scalasteward.core.BuildInfo.millPluginVersion}"

private[mill] def content(millVersion: Option[Version]) = {
def rawContent(millBinPlatform: String) =
s"""|import $$ivy.`${org.scalasteward.core.BuildInfo.organization}::${org.scalasteward.core.BuildInfo.millPluginArtifactName}_mill${millBinPlatform}:${org.scalasteward.core.BuildInfo.millPluginVersion}`
|""".stripMargin

millMinVersion(millVersion) match {
case None => rawContent("$MILL_BIN_PLATFORM")
// We support these platforms, but we can't take the $MILL_BIN_PLATFORM support for granted
case Some("6") => rawContent("0.6")
case Some("7") | Some("8") => rawContent("0.7")
case Some("9") => rawContent("0.9")
case _ => rawContent("$MILL_BIN_PLATFORM")
private[mill] def content(millVersion: Option[Version]): String = {
// We support these platforms, but we can't take the $MILL_BIN_PLATFORM support for granted
val millBinPlatform = millVersion match {
case Some(v) if v >= Version("0.10") => "$MILL_BIN_PLATFORM"
case Some(v) if v >= Version("0.9") => "0.9"
case Some(v) if v >= Version("0.7") => "0.7"
case Some(v) if v >= Version("0.6") => "0.6"
case _ => "$MILL_BIN_PLATFORM"
}
s"""import $$ivy.`${org.scalasteward.core.BuildInfo.organization}::${org.scalasteward.core.BuildInfo.millPluginArtifactName}_mill${millBinPlatform}:${org.scalasteward.core.BuildInfo.millPluginVersion}`"""
}

val extractDeps: String = "org.scalasteward.mill.plugin.StewardPlugin/extractDeps"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,4 @@ class MillAlgTest extends FunSuite {
assert(MillAlg.content(Some(Version("0.9.14"))).contains("_mill0.9"))
assert(MillAlg.content(Some(Version("0.10.0"))).contains("_mill$MILL_BIN_PLATFORM"))
}

test("mill version") {
assert(MillAlg.millMinVersion(None).isEmpty)
assert(MillAlg.millMinVersion(Some(Version("0.6.1"))).contains("6"))
assert(MillAlg.millMinVersion(Some(Version("0.7.0"))).contains("7"))
assert(MillAlg.millMinVersion(Some(Version("0.8.0"))).contains("8"))
assert(MillAlg.millMinVersion(Some(Version("0.9.14"))).contains("9"))
assert(MillAlg.millMinVersion(Some(Version("0.10.0"))).contains("10"))
assert(MillAlg.millMinVersion(Some(Version("0.11.0"))).contains("11"))
}
}

0 comments on commit 757f9bb

Please sign in to comment.