Skip to content

Commit 757f9bb

Browse files
authored
Use Order[Version] to simplify MillAlg.content (#3540)
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.
1 parent fbf5c4b commit 757f9bb

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

modules/core/src/main/scala/org/scalasteward/core/buildtool/mill/MillAlg.scala

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,19 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
110110
}
111111

112112
object MillAlg {
113-
private[mill] def millMinVersion(millVersion: Option[Version]): Option[String] =
114-
millVersion.flatMap(_.value.trim.split("[.]", 3).take(2).lastOption)
115-
116113
private[mill] val cliPluginCoordinate: String =
117114
s"ivy:${org.scalasteward.core.BuildInfo.organization}::${org.scalasteward.core.BuildInfo.millPluginArtifactName}::${org.scalasteward.core.BuildInfo.millPluginVersion}"
118115

119-
private[mill] def content(millVersion: Option[Version]) = {
120-
def rawContent(millBinPlatform: String) =
121-
s"""|import $$ivy.`${org.scalasteward.core.BuildInfo.organization}::${org.scalasteward.core.BuildInfo.millPluginArtifactName}_mill${millBinPlatform}:${org.scalasteward.core.BuildInfo.millPluginVersion}`
122-
|""".stripMargin
123-
124-
millMinVersion(millVersion) match {
125-
case None => rawContent("$MILL_BIN_PLATFORM")
126-
// We support these platforms, but we can't take the $MILL_BIN_PLATFORM support for granted
127-
case Some("6") => rawContent("0.6")
128-
case Some("7") | Some("8") => rawContent("0.7")
129-
case Some("9") => rawContent("0.9")
130-
case _ => rawContent("$MILL_BIN_PLATFORM")
116+
private[mill] def content(millVersion: Option[Version]): String = {
117+
// We support these platforms, but we can't take the $MILL_BIN_PLATFORM support for granted
118+
val millBinPlatform = millVersion match {
119+
case Some(v) if v >= Version("0.10") => "$MILL_BIN_PLATFORM"
120+
case Some(v) if v >= Version("0.9") => "0.9"
121+
case Some(v) if v >= Version("0.7") => "0.7"
122+
case Some(v) if v >= Version("0.6") => "0.6"
123+
case _ => "$MILL_BIN_PLATFORM"
131124
}
125+
s"""import $$ivy.`${org.scalasteward.core.BuildInfo.organization}::${org.scalasteward.core.BuildInfo.millPluginArtifactName}_mill${millBinPlatform}:${org.scalasteward.core.BuildInfo.millPluginVersion}`"""
132126
}
133127

134128
val extractDeps: String = "org.scalasteward.mill.plugin.StewardPlugin/extractDeps"

modules/core/src/test/scala/org/scalasteward/core/buildtool/mill/MillAlgTest.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,4 @@ class MillAlgTest extends FunSuite {
100100
assert(MillAlg.content(Some(Version("0.9.14"))).contains("_mill0.9"))
101101
assert(MillAlg.content(Some(Version("0.10.0"))).contains("_mill$MILL_BIN_PLATFORM"))
102102
}
103-
104-
test("mill version") {
105-
assert(MillAlg.millMinVersion(None).isEmpty)
106-
assert(MillAlg.millMinVersion(Some(Version("0.6.1"))).contains("6"))
107-
assert(MillAlg.millMinVersion(Some(Version("0.7.0"))).contains("7"))
108-
assert(MillAlg.millMinVersion(Some(Version("0.8.0"))).contains("8"))
109-
assert(MillAlg.millMinVersion(Some(Version("0.9.14"))).contains("9"))
110-
assert(MillAlg.millMinVersion(Some(Version("0.10.0"))).contains("10"))
111-
assert(MillAlg.millMinVersion(Some(Version("0.11.0"))).contains("11"))
112-
}
113103
}

0 commit comments

Comments
 (0)