< prev index next >

src/java.base/share/classes/sun/launcher/LauncherHelper.java

Print this page
rev 14279 : [mq]: 8140281-deprecation-optional.get


 512      */
 513     private static Class<?> loadModuleMainClass(String what) {
 514         int i = what.indexOf('/');
 515         String mainModule;
 516         String mainClass;
 517         if (i == -1) {
 518             mainModule = what;
 519             mainClass = null;
 520         } else {
 521             mainModule = what.substring(0, i);
 522             mainClass = what.substring(i+1);
 523         }
 524 
 525         // main module is in the boot layer
 526         Layer layer = Layer.boot();
 527         Optional<Module> om = layer.findModule(mainModule);
 528         if (!om.isPresent()) {
 529             // should not happen
 530             throw new InternalError("Module " + mainModule + " not in boot Layer");
 531         }
 532         Module m = om.get();
 533 
 534         // get main class
 535         if (mainClass == null) {
 536             Optional<String> omc = m.getDescriptor().mainClass();
 537             if (!omc.isPresent()) {
 538                 abort(null, "java.launcher.module.error1", mainModule);
 539             }
 540             mainClass = omc.get();
 541         }
 542 
 543         // load the class from the module
 544         Class<?> c = Class.forName(m, mainClass);
 545         if (c == null &&  System.getProperty("os.name", "").contains("OS X")
 546                 && Normalizer.isNormalized(mainClass, Normalizer.Form.NFD)) {
 547 
 548             String cn = Normalizer.normalize(mainClass, Normalizer.Form.NFC);
 549             c = Class.forName(m, cn);
 550 
 551         }
 552         if (c == null) {
 553             abort(null, "java.launcher.module.error2", mainClass, mainModule);
 554         }
 555 
 556         System.setProperty("jdk.module.main.class", c.getName());
 557         return c;
 558     }
 559 
 560     /**


 799         private static String fxLaunchName = null;
 800         private static String fxLaunchMode = null;
 801 
 802         private static Class<?> fxLauncherClass    = null;
 803         private static Method   fxLauncherMethod   = null;
 804 
 805         /*
 806          * Set the launch params according to what was passed to LauncherHelper
 807          * so we can use the same launch mode for FX. Abort if there is any
 808          * issue with loading the FX runtime or with the launcher method.
 809          */
 810         private static void setFXLaunchParameters(String what, int mode) {
 811 
 812             // find the module with the FX launcher
 813             Optional<Module> om = Layer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME);
 814             if (!om.isPresent()) {
 815                 abort(null, "java.launcher.cls.error5");
 816             }
 817 
 818             // load the FX launcher class
 819             fxLauncherClass = Class.forName(om.get(), JAVAFX_LAUNCHER_CLASS_NAME);
 820             if (fxLauncherClass == null) {
 821                 abort(null, "java.launcher.cls.error5");
 822             }
 823 
 824             try {
 825                 /*
 826                  * signature must be:
 827                  * public static void launchApplication(String launchName,
 828                  *     String launchMode, String[] args);
 829                  */
 830                 fxLauncherMethod = fxLauncherClass.getMethod("launchApplication",
 831                         String.class, String.class, String[].class);
 832 
 833                 // verify launcher signature as we do when validating the main method
 834                 int mod = fxLauncherMethod.getModifiers();
 835                 if (!Modifier.isStatic(mod)) {
 836                     abort(null, "java.launcher.javafx.error1");
 837                 }
 838                 if (fxLauncherMethod.getReturnType() != java.lang.Void.TYPE) {
 839                     abort(null, "java.launcher.javafx.error1");




 512      */
 513     private static Class<?> loadModuleMainClass(String what) {
 514         int i = what.indexOf('/');
 515         String mainModule;
 516         String mainClass;
 517         if (i == -1) {
 518             mainModule = what;
 519             mainClass = null;
 520         } else {
 521             mainModule = what.substring(0, i);
 522             mainClass = what.substring(i+1);
 523         }
 524 
 525         // main module is in the boot layer
 526         Layer layer = Layer.boot();
 527         Optional<Module> om = layer.findModule(mainModule);
 528         if (!om.isPresent()) {
 529             // should not happen
 530             throw new InternalError("Module " + mainModule + " not in boot Layer");
 531         }
 532         Module m = om.getWhenPresent();
 533 
 534         // get main class
 535         if (mainClass == null) {
 536             Optional<String> omc = m.getDescriptor().mainClass();
 537             if (!omc.isPresent()) {
 538                 abort(null, "java.launcher.module.error1", mainModule);
 539             }
 540             mainClass = omc.getWhenPresent();
 541         }
 542 
 543         // load the class from the module
 544         Class<?> c = Class.forName(m, mainClass);
 545         if (c == null &&  System.getProperty("os.name", "").contains("OS X")
 546                 && Normalizer.isNormalized(mainClass, Normalizer.Form.NFD)) {
 547 
 548             String cn = Normalizer.normalize(mainClass, Normalizer.Form.NFC);
 549             c = Class.forName(m, cn);
 550 
 551         }
 552         if (c == null) {
 553             abort(null, "java.launcher.module.error2", mainClass, mainModule);
 554         }
 555 
 556         System.setProperty("jdk.module.main.class", c.getName());
 557         return c;
 558     }
 559 
 560     /**


 799         private static String fxLaunchName = null;
 800         private static String fxLaunchMode = null;
 801 
 802         private static Class<?> fxLauncherClass    = null;
 803         private static Method   fxLauncherMethod   = null;
 804 
 805         /*
 806          * Set the launch params according to what was passed to LauncherHelper
 807          * so we can use the same launch mode for FX. Abort if there is any
 808          * issue with loading the FX runtime or with the launcher method.
 809          */
 810         private static void setFXLaunchParameters(String what, int mode) {
 811 
 812             // find the module with the FX launcher
 813             Optional<Module> om = Layer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME);
 814             if (!om.isPresent()) {
 815                 abort(null, "java.launcher.cls.error5");
 816             }
 817 
 818             // load the FX launcher class
 819             fxLauncherClass = Class.forName(om.getWhenPresent(), JAVAFX_LAUNCHER_CLASS_NAME);
 820             if (fxLauncherClass == null) {
 821                 abort(null, "java.launcher.cls.error5");
 822             }
 823 
 824             try {
 825                 /*
 826                  * signature must be:
 827                  * public static void launchApplication(String launchName,
 828                  *     String launchMode, String[] args);
 829                  */
 830                 fxLauncherMethod = fxLauncherClass.getMethod("launchApplication",
 831                         String.class, String.class, String[].class);
 832 
 833                 // verify launcher signature as we do when validating the main method
 834                 int mod = fxLauncherMethod.getModifiers();
 835                 if (!Modifier.isStatic(mod)) {
 836                     abort(null, "java.launcher.javafx.error1");
 837                 }
 838                 if (fxLauncherMethod.getReturnType() != java.lang.Void.TYPE) {
 839                     abort(null, "java.launcher.javafx.error1");


< prev index next >