Skip to content

Commit 576d80f

Browse files
authored
init: copy .jvmopts to .mill-jvm-opts when converting a sbt project (#5339)
Fix #5335 Pull request: #5339
1 parent adeea8f commit 576d80f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

integration/migrating/init/src/MillInitSbtTests.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,33 @@ object MillInitScala3ExampleProjectTests extends BuildGenTestSuite {
4646
}
4747
}
4848

49+
object MillInitScala3ExampleProjectWithJvmOptsTests extends BuildGenTestSuite {
50+
def tests: Tests = Tests {
51+
/*
52+
- 17 KB
53+
- `sbt` 1.10.7
54+
*/
55+
val url =
56+
"https://github.com/scala/scala3-example-project/archive/853808c50601e88edaa7272bcfb887b96be0e22a.zip"
57+
58+
test - integrationTest(url)(it =>
59+
os.write(it.workspacePath / ".jvmopts", "-Ddummy=prop -Ddummy2=prop2")
60+
testMillInit(
61+
it,
62+
expectedAllSourceFileNums = Map("allSourceFiles" -> 13, "test.allSourceFiles" -> 1),
63+
expectedCompileTaskResults = Some(SplitTaskResults(
64+
successful = SortedSet("compile", "test.compile"),
65+
failed = SortedSet.empty
66+
)),
67+
expectedTestTaskResults =
68+
Some(SplitTaskResults(successful = SortedSet("test"), failed = SortedSet.empty))
69+
)
70+
assert(os.exists(it.workspacePath / ".mill-jvm-opts"))
71+
assert(os.read(it.workspacePath / ".mill-jvm-opts") == "-Ddummy=prop -Ddummy2=prop2")
72+
)
73+
}
74+
}
75+
4976
object MillInitSbtScalaCsv200Tests extends BuildGenTestSuite {
5077
def tests: Tests = Tests {
5178
/*

libs/init/sbt/src/mill/main/sbt/SbtBuildGenMain.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,32 @@ object SbtBuildGenMain
157157
convertWriteOut(cfg, cfg.shared, (buildExport.defaultBuildInfo, projectNodeTree))
158158

159159
println("converted sbt build to Mill")
160+
161+
{
162+
val jvmOptsSbt = workspace / ".jvmopts"
163+
val jvmOptsMill = workspace / ".mill-jvm-opts"
164+
165+
if (os.exists(jvmOptsSbt)) {
166+
println(s"copying ${jvmOptsSbt.last} to ${jvmOptsMill.last}")
167+
if (os.exists(jvmOptsMill)) {
168+
val backup = jvmOptsMill / os.up / s"${jvmOptsMill.last}.bak"
169+
println(s"creating backup ${backup.last}")
170+
os.move.over(jvmOptsMill, backup)
171+
}
172+
var reportOnce = true
173+
// Since .jvmopts may contain multiple args per line, we warn the user
174+
// as Mill wants each arg on a separate line
175+
os.read.lines(jvmOptsSbt).collectFirst {
176+
// Warn the user once when we find spaces, but ignore comments
177+
case x if reportOnce && !x.trim().startsWith("#") && x.trim().contains(" ") =>
178+
reportOnce = false
179+
println(
180+
s"${jvmOptsMill.last}: Please check that each arguments is on a separate line!"
181+
)
182+
}
183+
os.copy(jvmOptsSbt, jvmOptsMill)
184+
}
185+
}
160186
}
161187

162188
/**

0 commit comments

Comments
 (0)