8209963: source file mode for JVM should provide a hook to locate the source file

Reviewed-by: darcy
This commit is contained in:
Jonathan Gibbons 2018-09-26 16:23:31 -07:00
parent 065fdac559
commit db6295f8a2
2 changed files with 17 additions and 0 deletions

View File

@ -399,6 +399,7 @@ public class Main {
*/
private void execute(String mainClassName, String[] appArgs, Context context)
throws Fault, InvocationTargetException {
System.setProperty("jdk.launcher.sourcefile", context.file.toString());
ClassLoader cl = context.getClassLoader(ClassLoader.getSystemClassLoader());
try {
Class<?> appClass = Class.forName(mainClassName, true, cl);

View File

@ -250,6 +250,22 @@ public class SourceLauncherTest extends TestRunner {
"access denied (\"java.util.PropertyPermission\" \"user.dir\" \"write\")");
}
public void testSystemProperty(Path base) throws IOException {
tb.writeJavaFiles(base,
"class ShowProperty {\n" +
" public static void main(String... args) {\n" +
" System.out.println(System.getProperty(\"jdk.launcher.sourcefile\"));\n" +
" }\n" +
"}");
Path file = base.resolve("ShowProperty.java");
String log = new JavaTask(tb)
.className(file.toString())
.run(Task.Expect.SUCCESS)
.getOutput(Task.OutputKind.STDOUT);
checkEqual("stdout", log.trim(), file.toAbsolutePath().toString());
}
void testSuccess(Path file, String expect) throws IOException {
Result r = run(file, Collections.emptyList(), List.of("1", "2", "3"));
checkEqual("stdout", r.stdOut, expect);