-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream Mill's
dist.launcherScript
into `mill.util.Jvm.launcherUni…
…versalScript` (#4333) Fixes #4302 We largely copy the existing implementation `dist/package.mill`. Once we rebootstrap, we can cut over to the new `Jvm.*` implementation and remove the version in `dist/`. Added some unit tests to exercise the `JAVA_HOME`/`JAVA_OPTS` handling
- Loading branch information
Showing
5 changed files
with
130 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package launcher; | ||
public class Main { | ||
public static void main(String[] args) { | ||
System.out.println("test.property " + System.getProperty("test.property")); | ||
System.out.println("java.home " + System.getProperty("java.home")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package mill.scalalib | ||
|
||
import mill.testkit.{TestBaseModule, UnitTester} | ||
import utest._ | ||
|
||
object LauncherTests extends TestSuite { | ||
|
||
val customJavaVersion = "19.0.2" | ||
object HelloJava extends TestBaseModule with JavaModule { | ||
object ZincWorkerJava extends ZincWorkerModule { | ||
def jvmId = s"temurin:$customJavaVersion" | ||
} | ||
|
||
def javacOptions = Seq("-target", "1.8", "-source", "1.8") | ||
} | ||
|
||
val resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "launcher" | ||
|
||
def tests: Tests = Tests { | ||
def check(executableTask: mill.define.Target[mill.api.PathRef], copyBat: Boolean = false) = { | ||
val eval = UnitTester(HelloJava, resourcePath) | ||
|
||
val Right(result1) = eval.apply(executableTask) | ||
|
||
val executable = | ||
if (mill.util.Util.windowsPlatform && copyBat) { | ||
val prev = result1.value.path | ||
val next = prev / ".." / s"${prev.baseName}.bat" | ||
os.copy(prev, next) | ||
next | ||
} else result1.value.path | ||
|
||
val text = os.call(executable).out.text() | ||
assert(text.contains("test.property null")) | ||
assert(text.contains("java.home")) | ||
assert(!text.contains(customJavaVersion)) | ||
|
||
val text2 = os | ||
.call(executable, env = Map("JAVA_OPTS" -> "-Dtest.property=123")) | ||
.out.text() | ||
assert(text2.contains("test.property 123")) | ||
assert(!text2.contains(customJavaVersion)) | ||
val Right(javaHome) = eval.apply(HelloJava.ZincWorkerJava.javaHome) | ||
|
||
val text3 = os | ||
.call(executable, env = Map("JAVA_HOME" -> javaHome.value.get.path.toString)) | ||
.out.text() | ||
assert(text3.contains("java.home")) | ||
assert(text3.contains(customJavaVersion)) | ||
} | ||
|
||
test("launcher") - check(HelloJava.launcher) | ||
// Windows requires that you copy the `.jar` file to a `.bat` extension before running it | ||
test("assembly") - check(HelloJava.assembly, copyBat = true) | ||
} | ||
} |