mirror of https://github.com/sbt/sbt.git
Merge pull request #8269 from xuwei-k/try-with-resources
use try-with-resources syntax in WorkerMain.java
This commit is contained in:
commit
36f3dfbaaf
|
|
@ -126,14 +126,11 @@ public final class WorkerMain {
|
||||||
throw new RuntimeException("missing jvmRunInfo element");
|
throw new RuntimeException("missing jvmRunInfo element");
|
||||||
}
|
}
|
||||||
RunInfo.JvmRunInfo jvmRunInfo = info.jvmRunInfo;
|
RunInfo.JvmRunInfo jvmRunInfo = info.jvmRunInfo;
|
||||||
URLClassLoader cl = createClassLoader(jvmRunInfo, ClassLoader.getSystemClassLoader());
|
try (URLClassLoader cl = createClassLoader(jvmRunInfo, ClassLoader.getSystemClassLoader())) {
|
||||||
try {
|
|
||||||
Class<?> mainClass = cl.loadClass(jvmRunInfo.mainClass);
|
Class<?> mainClass = cl.loadClass(jvmRunInfo.mainClass);
|
||||||
Method mainMethod = mainClass.getMethod("main", String[].class);
|
Method mainMethod = mainClass.getMethod("main", String[].class);
|
||||||
String[] mainArgs = jvmRunInfo.args.stream().toArray(String[]::new);
|
String[] mainArgs = jvmRunInfo.args.stream().toArray(String[]::new);
|
||||||
mainMethod.invoke(null, (Object) mainArgs);
|
mainMethod.invoke(null, (Object) mainArgs);
|
||||||
} finally {
|
|
||||||
cl.close();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("only jvm is supported");
|
throw new RuntimeException("only jvm is supported");
|
||||||
|
|
@ -144,13 +141,8 @@ public final class WorkerMain {
|
||||||
if (info.jvm) {
|
if (info.jvm) {
|
||||||
RunInfo.JvmRunInfo jvmRunInfo = info.jvmRunInfo;
|
RunInfo.JvmRunInfo jvmRunInfo = info.jvmRunInfo;
|
||||||
ClassLoader parent = new ForkTestMain().getClass().getClassLoader();
|
ClassLoader parent = new ForkTestMain().getClass().getClassLoader();
|
||||||
ClassLoader cl = createClassLoader(jvmRunInfo, parent);
|
try (URLClassLoader cl = createClassLoader(jvmRunInfo, parent)) {
|
||||||
try {
|
|
||||||
ForkTestMain.main(id, info, this.originalOut, cl);
|
ForkTestMain.main(id, info, this.originalOut, cl);
|
||||||
} finally {
|
|
||||||
if (cl instanceof URLClassLoader) {
|
|
||||||
((URLClassLoader) cl).close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("only jvm is supported");
|
throw new RuntimeException("only jvm is supported");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue