JScratch
Loading...
Searching...
No Matches
ProjectRunner.java
Go to the documentation of this file.
1
package
com.jscratch.compiler;
2
3
import
com.jscratch.Stage;
4
import
java.io.File;
5
import
java.lang.reflect.Method;
6
7
public
class
ProjectRunner
{
8
private
static
java.net.URLClassLoader
projectClassLoader
;
9
10
public
static
void
mount
(File buildDir) {
11
try
{
12
projectClassLoader
=
new
java.net.URLClassLoader(
13
new
java.net.URL[]{buildDir.toURI().toURL()},
14
ProjectRunner
.class.getClassLoader()
15
);
16
}
catch
(Exception e) {
17
e.printStackTrace();
18
}
19
}
20
21
public
static
java.net.URLClassLoader
getProjectClassLoader
() {
22
return
projectClassLoader
;
23
}
24
25
public
static
void
run
(File buildDir, String mainClassName) {
26
// Kill existing stage if it exists
27
if
(
Stage
.
instance
!=
null
) {
28
Stage
.
instance
.
disposeStage
();
29
}
30
31
// Create a completely new stage instance
32
Stage
newStage =
new
Stage
();
33
34
Stage
.
run
(newStage, () -> {
35
try
{
36
if
(
projectClassLoader
==
null
)
mount
(buildDir);
37
38
Class<?> clazz =
projectClassLoader
.loadClass(
"generated."
+ mainClassName);
39
Method mainMethod = clazz.getMethod(
"main"
, String[].
class
);
40
41
// Execute Main.main(new String[0])
42
mainMethod.invoke(
null
, (Object)
new
String[0]);
43
44
}
catch
(Exception e) {
45
e.printStackTrace();
46
}
47
});
48
}
49
}
com.jscratch.Stage
Definition
Stage.java:26
com.jscratch.Stage.instance
static Stage instance
Definition
Stage.java:27
com.jscratch.Stage.run
static void run(Runnable setup)
Definition
Stage.java:270
com.jscratch.Stage.disposeStage
void disposeStage()
Definition
Stage.java:316
com.jscratch.compiler.ProjectRunner
Definition
ProjectRunner.java:7
com.jscratch.compiler.ProjectRunner.getProjectClassLoader
static java.net.URLClassLoader getProjectClassLoader()
Definition
ProjectRunner.java:21
com.jscratch.compiler.ProjectRunner.mount
static void mount(File buildDir)
Definition
ProjectRunner.java:10
com.jscratch.compiler.ProjectRunner.projectClassLoader
static java.net.URLClassLoader projectClassLoader
Definition
ProjectRunner.java:8
com.jscratch.compiler.ProjectRunner.run
static void run(File buildDir, String mainClassName)
Definition
ProjectRunner.java:25
src
main
java
com
jscratch
compiler
ProjectRunner.java
Generated by
1.16.1