1 /*
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
45 import java.io.UnsupportedEncodingException;
46 import java.lang.module.Configuration;
47 import java.lang.module.ModuleDescriptor;
48 import java.lang.module.ModuleDescriptor.Requires;
49 import java.lang.module.ModuleDescriptor.Exports;
50 import java.lang.module.ModuleDescriptor.Opens;
51 import java.lang.module.ModuleDescriptor.Provides;
52 import java.lang.module.ModuleFinder;
53 import java.lang.module.ModuleReference;
54 import java.lang.module.ResolvedModule;
55 import java.lang.reflect.InvocationTargetException;
56 import java.lang.reflect.Method;
57 import java.lang.reflect.Modifier;
58 import java.math.BigDecimal;
59 import java.math.RoundingMode;
60 import java.net.URI;
61 import java.nio.charset.Charset;
62 import java.nio.file.DirectoryStream;
63 import java.nio.file.Files;
64 import java.nio.file.Path;
65 import java.text.Normalizer;
66 import java.text.MessageFormat;
67 import java.util.ArrayList;
68 import java.util.Collections;
69 import java.util.Comparator;
70 import java.util.Iterator;
71 import java.util.List;
72 import java.util.Locale;
73 import java.util.Locale.Category;
74 import java.util.Optional;
75 import java.util.Properties;
76 import java.util.ResourceBundle;
77 import java.util.Set;
78 import java.util.TreeSet;
79 import java.util.jar.Attributes;
80 import java.util.jar.JarFile;
81 import java.util.jar.Manifest;
82 import java.util.stream.Collectors;
83 import java.util.stream.Stream;
84
707 Optional<String> omc = m.getDescriptor().mainClass();
708 if (!omc.isPresent()) {
709 abort(null, "java.launcher.module.error1", mainModule);
710 }
711 mainClass = omc.get();
712 }
713
714 // load the class from the module
715 Class<?> c = null;
716 try {
717 c = Class.forName(m, mainClass);
718 if (c == null && System.getProperty("os.name", "").contains("OS X")
719 && Normalizer.isNormalized(mainClass, Normalizer.Form.NFD)) {
720
721 String cn = Normalizer.normalize(mainClass, Normalizer.Form.NFC);
722 c = Class.forName(m, cn);
723 }
724 } catch (LinkageError le) {
725 abort(null, "java.launcher.module.error3", mainClass, m.getName(),
726 le.getClass().getName() + ": " + le.getLocalizedMessage());
727 }
728 if (c == null) {
729 abort(null, "java.launcher.module.error2", mainClass, mainModule);
730 }
731
732 System.setProperty("jdk.module.main.class", c.getName());
733 return c;
734 }
735
736 /**
737 * Loads the main class from the class path (LM_CLASS or LM_JAR).
738 */
739 private static Class<?> loadMainClass(int mode, String what) {
740 // get the class name
741 String cn;
742 switch (mode) {
743 case LM_CLASS:
744 cn = what;
745 break;
746 case LM_JAR:
763 && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
764 try {
765 // On Mac OS X since all names with diacritical marks are
766 // given as decomposed it is possible that main class name
767 // comes incorrectly from the command line and we have
768 // to re-compose it
769 String ncn = Normalizer.normalize(cn, Normalizer.Form.NFC);
770 mainClass = Class.forName(ncn, false, scl);
771 } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
772 abort(cnfe1, "java.launcher.cls.error1", cn,
773 cnfe1.getClass().getCanonicalName(), cnfe1.getMessage());
774 }
775 } else {
776 abort(cnfe, "java.launcher.cls.error1", cn,
777 cnfe.getClass().getCanonicalName(), cnfe.getMessage());
778 }
779 }
780 } catch (LinkageError le) {
781 abort(le, "java.launcher.cls.error6", cn,
782 le.getClass().getName() + ": " + le.getLocalizedMessage());
783 }
784 return mainClass;
785 }
786
787 /*
788 * Accessor method called by the launcher after getting the main class via
789 * checkAndLoadMain(). The "application class" is the class that is finally
790 * executed to start the application and in this case is used to report
791 * the correct application name, typically for UI purposes.
792 */
793 public static Class<?> getApplicationClass() {
794 return appClass;
795 }
796
797 /*
798 * Check if the given class is a JavaFX Application class. This is done
799 * in a way that does not cause the Application class to load or throw
800 * ClassNotFoundException if the JavaFX runtime is not available.
801 */
802 private static boolean doesExtendFXApplication(Class<?> mainClass) {
|
1 /*
2 * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
45 import java.io.UnsupportedEncodingException;
46 import java.lang.module.Configuration;
47 import java.lang.module.ModuleDescriptor;
48 import java.lang.module.ModuleDescriptor.Requires;
49 import java.lang.module.ModuleDescriptor.Exports;
50 import java.lang.module.ModuleDescriptor.Opens;
51 import java.lang.module.ModuleDescriptor.Provides;
52 import java.lang.module.ModuleFinder;
53 import java.lang.module.ModuleReference;
54 import java.lang.module.ResolvedModule;
55 import java.lang.reflect.InvocationTargetException;
56 import java.lang.reflect.Method;
57 import java.lang.reflect.Modifier;
58 import java.math.BigDecimal;
59 import java.math.RoundingMode;
60 import java.net.URI;
61 import java.nio.charset.Charset;
62 import java.nio.file.DirectoryStream;
63 import java.nio.file.Files;
64 import java.nio.file.Path;
65 import java.security.AccessControlException;
66 import java.text.Normalizer;
67 import java.text.MessageFormat;
68 import java.util.ArrayList;
69 import java.util.Collections;
70 import java.util.Comparator;
71 import java.util.Iterator;
72 import java.util.List;
73 import java.util.Locale;
74 import java.util.Locale.Category;
75 import java.util.Optional;
76 import java.util.Properties;
77 import java.util.ResourceBundle;
78 import java.util.Set;
79 import java.util.TreeSet;
80 import java.util.jar.Attributes;
81 import java.util.jar.JarFile;
82 import java.util.jar.Manifest;
83 import java.util.stream.Collectors;
84 import java.util.stream.Stream;
85
708 Optional<String> omc = m.getDescriptor().mainClass();
709 if (!omc.isPresent()) {
710 abort(null, "java.launcher.module.error1", mainModule);
711 }
712 mainClass = omc.get();
713 }
714
715 // load the class from the module
716 Class<?> c = null;
717 try {
718 c = Class.forName(m, mainClass);
719 if (c == null && System.getProperty("os.name", "").contains("OS X")
720 && Normalizer.isNormalized(mainClass, Normalizer.Form.NFD)) {
721
722 String cn = Normalizer.normalize(mainClass, Normalizer.Form.NFC);
723 c = Class.forName(m, cn);
724 }
725 } catch (LinkageError le) {
726 abort(null, "java.launcher.module.error3", mainClass, m.getName(),
727 le.getClass().getName() + ": " + le.getLocalizedMessage());
728 } catch (AccessControlException ace) {
729 abort(ace, "java.launcher.module.error5", mainClass, m.getName(),
730 ace.getClass().getName(), ace.getLocalizedMessage());
731 }
732 if (c == null) {
733 abort(null, "java.launcher.module.error2", mainClass, mainModule);
734 }
735
736 System.setProperty("jdk.module.main.class", c.getName());
737 return c;
738 }
739
740 /**
741 * Loads the main class from the class path (LM_CLASS or LM_JAR).
742 */
743 private static Class<?> loadMainClass(int mode, String what) {
744 // get the class name
745 String cn;
746 switch (mode) {
747 case LM_CLASS:
748 cn = what;
749 break;
750 case LM_JAR:
767 && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
768 try {
769 // On Mac OS X since all names with diacritical marks are
770 // given as decomposed it is possible that main class name
771 // comes incorrectly from the command line and we have
772 // to re-compose it
773 String ncn = Normalizer.normalize(cn, Normalizer.Form.NFC);
774 mainClass = Class.forName(ncn, false, scl);
775 } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
776 abort(cnfe1, "java.launcher.cls.error1", cn,
777 cnfe1.getClass().getCanonicalName(), cnfe1.getMessage());
778 }
779 } else {
780 abort(cnfe, "java.launcher.cls.error1", cn,
781 cnfe.getClass().getCanonicalName(), cnfe.getMessage());
782 }
783 }
784 } catch (LinkageError le) {
785 abort(le, "java.launcher.cls.error6", cn,
786 le.getClass().getName() + ": " + le.getLocalizedMessage());
787 } catch (AccessControlException ace) {
788 abort(ace, "java.launcher.cls.error7", cn,
789 ace.getClass().getName(), ace.getLocalizedMessage());
790 }
791 return mainClass;
792 }
793
794 /*
795 * Accessor method called by the launcher after getting the main class via
796 * checkAndLoadMain(). The "application class" is the class that is finally
797 * executed to start the application and in this case is used to report
798 * the correct application name, typically for UI purposes.
799 */
800 public static Class<?> getApplicationClass() {
801 return appClass;
802 }
803
804 /*
805 * Check if the given class is a JavaFX Application class. This is done
806 * in a way that does not cause the Application class to load or throw
807 * ClassNotFoundException if the JavaFX runtime is not available.
808 */
809 private static boolean doesExtendFXApplication(Class<?> mainClass) {
|