22
33import pro .gravit .launcher .base .Launcher ;
44import pro .gravit .launcher .base .LauncherConfig ;
5+ import pro .gravit .launcher .core .LauncherInject ;
56import pro .gravit .launcher .core .LauncherNetworkAPI ;
67import pro .gravit .launcher .start .ClientLauncherWrapper ;
78import pro .gravit .utils .helper .IOHelper ;
9+ import pro .gravit .utils .launch .ClassLoaderControl ;
810import pro .gravit .utils .launch .LaunchOptions ;
911import pro .gravit .utils .launch .ModuleLaunch ;
1012
1820@ LauncherNetworkAPI
1921public class LauncherEngineWrapper {
2022 private static final List <String > modules = new ArrayList <>();
23+ @ LauncherInject ("launcher.alwaysUseRelauncher" )
24+ public static boolean alwaysUseRelauncher ;
2125
2226
2327
@@ -62,9 +66,10 @@ public static Map<String, String> applyLoggerSettings(String[] arguments) {
6266 modules .add ("javafx.controls" );
6367 modules .add ("javafx.media" );
6468 modules .add ("javafx.web" );
69+ modules .add ("jdk.jsobject" ); // https://bugs.openjdk.org/browse/JDK-8338249
6570 }
6671 public static void main (String [] args ) throws Throwable {
67- if (!Boolean .getBoolean (ClientLauncherWrapper .WRAPPED_LAUNCH_PROPERTY )) {
72+ if (alwaysUseRelauncher && !Boolean .getBoolean (ClientLauncherWrapper .WRAPPED_LAUNCH_PROPERTY )) {
6873 System .setProperty (ClientLauncherWrapper .BRIDGED_FROM_ENGINE_PROPERTY , "true" );
6974 ClientLauncherWrapper .main (args );
7075 return ;
@@ -77,14 +82,38 @@ public static void main(String[] args) throws Throwable {
7782 List <Path > classpath = new ArrayList <>();
7883 classpath .add (IOHelper .getCodeSource (LauncherEngine .class ));
7984 var libDirectory = Path .of (System .getProperty ("java.home" )).resolve ("lib" );
85+ int failedModules = 0 ;
8086 for (var moduleName : modules ) {
8187 var path = libDirectory .resolve (moduleName .concat (".jar" ));
8288 if (Files .exists (path )) {
8389 options .moduleConf .modules .add (moduleName );
8490 options .moduleConf .modulePath .add (path .toAbsolutePath ().toString ());
91+ } else {
92+ failedModules ++;
93+ }
94+ }
95+ ClassLoaderControl control ;
96+ try {
97+ control = launch .init (classpath , null , options );
98+ ModuleLayer .Controller controller = (ModuleLayer .Controller ) control .getJava9ModuleController ();
99+ var javafxModule = controller .layer ().findModule ("javafx.base" );
100+ if (javafxModule .isEmpty ()) {
101+ // We probably failed to resolve javafx modules, try re-launch
102+ if (!Boolean .getBoolean (ClientLauncherWrapper .WRAPPED_LAUNCH_PROPERTY )) {
103+ System .setProperty (ClientLauncherWrapper .BRIDGED_FROM_ENGINE_PROPERTY , "true" );
104+ ClientLauncherWrapper .main (args );
105+ return ;
106+ }
107+ }
108+ } catch (Throwable e ) {
109+ // We probably failed to resolve javafx modules, try re-launch
110+ if (!Boolean .getBoolean (ClientLauncherWrapper .WRAPPED_LAUNCH_PROPERTY )) {
111+ System .setProperty (ClientLauncherWrapper .BRIDGED_FROM_ENGINE_PROPERTY , "true" );
112+ ClientLauncherWrapper .main (args );
113+ return ;
85114 }
115+ throw e ;
86116 }
87- var control = launch .init (classpath , null , options );
88117 launch .launch (LauncherEngine .class .getName (), null , List .of (args ));
89118 }
90119}
0 commit comments