Skip to content

Commit 721a674

Browse files
authored
Merge pull request #3538 from scala-steward-org/topic/use-disable-ticker-mill-0.11
Run Mill 0.11 with `--disable-ticker` instead of `--ticker false`
2 parents 092736c + 1391af1 commit 721a674

File tree

2 files changed

+50
-21
lines changed

2 files changed

+50
-21
lines changed

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,23 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
4545
.map(_.nonEmpty)
4646
)
4747

48-
private def runMill(buildRootDir: File) = {
49-
val options =
50-
List("--no-server", "--ticker=false", "--import", cliPluginCoordinate, "show", extractDeps)
51-
val command = Nel("mill", options)
52-
processAlg.execSandboxed(command, buildRootDir)
53-
}
54-
private def runMillUnder011(buildRootDir: File, millBuildVersion: Option[Version]) = {
55-
val predef = buildRootDir / "scala-steward.sc"
56-
val predefContent = content(millBuildVersion)
57-
val command = Nel("mill", List("-i", "-p", predef.toString, "show", extractDeps))
58-
fileAlg.createTemporarily(predef, predefContent).surround {
59-
processAlg.execSandboxed(command, buildRootDir)
48+
private def runMill(buildRootDir: File, millBuildVersion: Option[Version]): F[List[String]] =
49+
millBuildVersion match {
50+
case Some(v) if v >= Version("0.11") =>
51+
val noTicker =
52+
if (v >= Version("0.12")) List("--ticker", "false") else List("--disable-ticker")
53+
val options =
54+
"--no-server" :: noTicker ++ List("--import", cliPluginCoordinate, "show", extractDeps)
55+
val command = Nel("mill", options)
56+
processAlg.execSandboxed(command, buildRootDir)
57+
case _ =>
58+
val predef = buildRootDir / "scala-steward.sc"
59+
val predefContent = content(millBuildVersion)
60+
val command = Nel("mill", List("-i", "-p", predef.toString, "show", extractDeps))
61+
fileAlg.createTemporarily(predef, predefContent).surround {
62+
processAlg.execSandboxed(command, buildRootDir)
63+
}
6064
}
61-
}
6265

6366
override def getDependencies(buildRoot: BuildRoot): F[List[Scope.Dependencies]] =
6467
for {
@@ -79,9 +82,7 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
7982
millBuildVersion: Option[Version]
8083
): F[List[Scope.Dependencies]] =
8184
for {
82-
extracted <-
83-
if (isMillVersionGreaterOrEqual011(millBuildVersion)) runMill(buildRootDir)
84-
else runMillUnder011(buildRootDir, millBuildVersion)
85+
extracted <- runMill(buildRootDir, millBuildVersion)
8586
parsed <- F.fromEither(
8687
parser.parseModules(extracted.dropWhile(!_.startsWith("{")).mkString("\n"))
8788
)
@@ -110,9 +111,6 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
110111
}
111112

112113
object MillAlg {
113-
private[mill] def isMillVersionGreaterOrEqual011(millVersion: Option[Version]): Boolean =
114-
millMinVersion(millVersion).flatMap(_.toIntOption).exists(_ >= 11)
115-
116114
private[mill] def millMinVersion(millVersion: Option[Version]): Option[String] =
117115
millVersion.flatMap(_.value.trim.split("[.]", 3).take(2).lastOption)
118116

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MillAlgTest extends FunSuite {
3131
assertEquals(state, expected)
3232
}
3333

34-
test("getDependencies, version >= 0.11") {
34+
test("getDependencies, 0.11 <= version < 0.12") {
3535
val repo = Repo("lihaoyi", "fastparse")
3636
val buildRoot = BuildRoot(repo, ".")
3737
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
@@ -40,7 +40,7 @@ class MillAlgTest extends FunSuite {
4040
repoDir,
4141
"mill",
4242
"--no-server",
43-
"--ticker=false",
43+
"--disable-ticker",
4444
"--import",
4545
"ivy:org.scala-steward::scala-steward-mill-plugin::0.18.0",
4646
"show",
@@ -64,6 +64,37 @@ class MillAlgTest extends FunSuite {
6464
assertEquals(state, expected)
6565
}
6666

67+
test("getDependencies, 0.12 <= version") {
68+
val repo = Repo("mill-alg", "test-3")
69+
val buildRoot = BuildRoot(repo, ".")
70+
val buildRootDir = workspaceAlg.buildRootDir(buildRoot).unsafeRunSync()
71+
val millCmd = Cmd.execSandboxed(
72+
buildRootDir,
73+
"mill",
74+
"--no-server",
75+
"--ticker",
76+
"false",
77+
"--import",
78+
"ivy:org.scala-steward::scala-steward-mill-plugin::0.18.0",
79+
"show",
80+
extractDeps
81+
)
82+
val initial = MockState.empty
83+
.copy(commandOutputs = Map(millCmd -> Right(List("""{"modules":[]}"""))))
84+
.addFiles(buildRootDir / ".mill-version" -> "0.12.5", buildRootDir / "build.sc" -> "")
85+
.unsafeRunSync()
86+
val state = millAlg.getDependencies(buildRoot).runS(initial).unsafeRunSync()
87+
val expected = initial.copy(
88+
trace = Vector(
89+
Cmd("read", s"$buildRootDir/.mill-version"),
90+
Cmd("read", s"$buildRootDir/.config/mill-version"),
91+
millCmd,
92+
Cmd("read", s"$buildRootDir/build.sc")
93+
)
94+
)
95+
assertEquals(state, expected)
96+
}
97+
6798
test("predef-content") {
6899
assert(MillAlg.content(None).contains("_mill$MILL_BIN_PLATFORM"))
69100
assert(MillAlg.content(Some(Version("0.6.1"))).contains("_mill0.6"))

0 commit comments

Comments
 (0)