< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2007, 2017, 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


 485         for (String moduleAndPackage : value.split(" ")) {
 486             String[] s = moduleAndPackage.trim().split("/");
 487             if (s.length == 2) {
 488                 String mn = s[0];
 489                 String pn = s[1];
 490                 ModuleLayer.boot()
 491                     .findModule(mn)
 492                     .filter(m -> m.getDescriptor().packages().contains(pn))
 493                     .ifPresent(m -> {
 494                         if (open) {
 495                             Modules.addOpensToAllUnnamed(m, pn);
 496                         } else {
 497                             Modules.addExportsToAllUnnamed(m, pn);
 498                         }
 499                     });
 500             }
 501         }
 502     }
 503 
 504     // From src/share/bin/java.c:
 505     //   enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR, LM_MODULE }
 506 
 507     private static final int LM_UNKNOWN = 0;
 508     private static final int LM_CLASS   = 1;
 509     private static final int LM_JAR     = 2;
 510     private static final int LM_MODULE  = 3;

 511 
 512     static void abort(Throwable t, String msgKey, Object... args) {
 513         if (msgKey != null) {
 514             ostream.println(getLocalizedMessage(msgKey, args));
 515         }
 516         if (trace) {
 517             if (t != null) {
 518                 t.printStackTrace();
 519             } else {
 520                 Thread.dumpStack();
 521             }
 522         }
 523         System.exit(1);
 524     }
 525 
 526     /**
 527      * This method:
 528      * 1. Loads the main class from the module or class path
 529      * 2. Checks the public static void main method.
 530      * 3. If the main class extends FX Application then call on FXHelper to
 531      * perform the launch.
 532      *
 533      * @param printToStderr if set, all output will be routed to stderr
 534      * @param mode LaunchMode as determined by the arguments passed on the
 535      *             command line
 536      * @param what the module name[/class], JAR file, or the main class
 537      *             depending on the mode
 538      *
 539      * @return the application's main class
 540      */

 541     public static Class<?> checkAndLoadMain(boolean printToStderr,
 542                                             int mode,
 543                                             String what) {
 544         initOutput(printToStderr);
 545 
 546         Class<?> mainClass = (mode == LM_MODULE) ? loadModuleMainClass(what)
 547                                                  : loadMainClass(mode, what);







 548 
 549         // record the real main class for UI purposes
 550         // neither method above can return null, they will abort()
 551         appClass = mainClass;
 552 
 553         /*
 554          * Check if FXHelper can launch it using the FX launcher. In an FX app,
 555          * the main class may or may not have a main method, so do this before
 556          * validating the main class.
 557          */
 558         if (JAVAFX_FXHELPER_CLASS_NAME_SUFFIX.equals(mainClass.getName()) ||
 559             doesExtendFXApplication(mainClass)) {
 560             // Will abort() if there are problems with FX runtime
 561             FXHelper.setFXLaunchParameters(what, mode);
 562             mainClass = FXHelper.class;
 563         }
 564 
 565         validateMainClass(mainClass);
 566         return mainClass;
 567     }


   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


 485         for (String moduleAndPackage : value.split(" ")) {
 486             String[] s = moduleAndPackage.trim().split("/");
 487             if (s.length == 2) {
 488                 String mn = s[0];
 489                 String pn = s[1];
 490                 ModuleLayer.boot()
 491                     .findModule(mn)
 492                     .filter(m -> m.getDescriptor().packages().contains(pn))
 493                     .ifPresent(m -> {
 494                         if (open) {
 495                             Modules.addOpensToAllUnnamed(m, pn);
 496                         } else {
 497                             Modules.addExportsToAllUnnamed(m, pn);
 498                         }
 499                     });
 500             }
 501         }
 502     }
 503 
 504     // From src/share/bin/java.c:
 505     //   enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR, LM_MODULE, LM_SOURCE }
 506 
 507     private static final int LM_UNKNOWN = 0;
 508     private static final int LM_CLASS   = 1;
 509     private static final int LM_JAR     = 2;
 510     private static final int LM_MODULE  = 3;
 511     private static final int LM_SOURCE  = 4;
 512 
 513     static void abort(Throwable t, String msgKey, Object... args) {
 514         if (msgKey != null) {
 515             ostream.println(getLocalizedMessage(msgKey, args));
 516         }
 517         if (trace) {
 518             if (t != null) {
 519                 t.printStackTrace();
 520             } else {
 521                 Thread.dumpStack();
 522             }
 523         }
 524         System.exit(1);
 525     }
 526 
 527     /**
 528      * This method:
 529      * 1. Loads the main class from the module or class path
 530      * 2. Checks the public static void main method.
 531      * 3. If the main class extends FX Application then call on FXHelper to
 532      * perform the launch.
 533      *
 534      * @param printToStderr if set, all output will be routed to stderr
 535      * @param mode LaunchMode as determined by the arguments passed on the
 536      *             command line
 537      * @param what the module name[/class], JAR file, or the main class
 538      *             depending on the mode
 539      *
 540      * @return the application's main class
 541      */
 542     @SuppressWarnings("fallthrough")
 543     public static Class<?> checkAndLoadMain(boolean printToStderr,
 544                                             int mode,
 545                                             String what) {
 546         initOutput(printToStderr);
 547 
 548         Class<?> mainClass = null;
 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         }
 557 
 558         // record the real main class for UI purposes
 559         // neither method above can return null, they will abort()
 560         appClass = mainClass;
 561 
 562         /*
 563          * Check if FXHelper can launch it using the FX launcher. In an FX app,
 564          * the main class may or may not have a main method, so do this before
 565          * validating the main class.
 566          */
 567         if (JAVAFX_FXHELPER_CLASS_NAME_SUFFIX.equals(mainClass.getName()) ||
 568             doesExtendFXApplication(mainClass)) {
 569             // Will abort() if there are problems with FX runtime
 570             FXHelper.setFXLaunchParameters(what, mode);
 571             mainClass = FXHelper.class;
 572         }
 573 
 574         validateMainClass(mainClass);
 575         return mainClass;
 576     }


< prev index next >