1 /* |
1 /* |
2 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
500 } |
500 } |
501 } |
501 } |
502 } |
502 } |
503 |
503 |
504 // From src/share/bin/java.c: |
504 // From src/share/bin/java.c: |
505 // enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR, LM_MODULE } |
505 // enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR, LM_MODULE, LM_SOURCE } |
506 |
506 |
507 private static final int LM_UNKNOWN = 0; |
507 private static final int LM_UNKNOWN = 0; |
508 private static final int LM_CLASS = 1; |
508 private static final int LM_CLASS = 1; |
509 private static final int LM_JAR = 2; |
509 private static final int LM_JAR = 2; |
510 private static final int LM_MODULE = 3; |
510 private static final int LM_MODULE = 3; |
|
511 private static final int LM_SOURCE = 4; |
511 |
512 |
512 static void abort(Throwable t, String msgKey, Object... args) { |
513 static void abort(Throwable t, String msgKey, Object... args) { |
513 if (msgKey != null) { |
514 if (msgKey != null) { |
514 ostream.println(getLocalizedMessage(msgKey, args)); |
515 ostream.println(getLocalizedMessage(msgKey, args)); |
515 } |
516 } |
536 * @param what the module name[/class], JAR file, or the main class |
537 * @param what the module name[/class], JAR file, or the main class |
537 * depending on the mode |
538 * depending on the mode |
538 * |
539 * |
539 * @return the application's main class |
540 * @return the application's main class |
540 */ |
541 */ |
|
542 @SuppressWarnings("fallthrough") |
541 public static Class<?> checkAndLoadMain(boolean printToStderr, |
543 public static Class<?> checkAndLoadMain(boolean printToStderr, |
542 int mode, |
544 int mode, |
543 String what) { |
545 String what) { |
544 initOutput(printToStderr); |
546 initOutput(printToStderr); |
545 |
547 |
546 Class<?> mainClass = (mode == LM_MODULE) ? loadModuleMainClass(what) |
548 Class<?> mainClass = null; |
547 : loadMainClass(mode, what); |
549 switch (mode) { |
|
550 case LM_MODULE: case LM_SOURCE: |
|
551 mainClass = loadModuleMainClass(what); |
|
552 break; |
|
553 default: |
|
554 mainClass = loadMainClass(mode, what); |
|
555 break; |
|
556 } |
548 |
557 |
549 // record the real main class for UI purposes |
558 // record the real main class for UI purposes |
550 // neither method above can return null, they will abort() |
559 // neither method above can return null, they will abort() |
551 appClass = mainClass; |
560 appClass = mainClass; |
552 |
561 |