jdk/src/share/classes/sun/launcher/LauncherHelper.java
changeset 13411 224a28370893
parent 12538 211d6e82fe51
child 14518 f4b1adde53b3
equal deleted inserted replaced
13410:e667545511c7 13411:224a28370893
    46 import java.lang.reflect.Method;
    46 import java.lang.reflect.Method;
    47 import java.lang.reflect.Modifier;
    47 import java.lang.reflect.Modifier;
    48 import java.math.BigDecimal;
    48 import java.math.BigDecimal;
    49 import java.math.RoundingMode;
    49 import java.math.RoundingMode;
    50 import java.nio.charset.Charset;
    50 import java.nio.charset.Charset;
       
    51 import java.nio.file.DirectoryStream;
       
    52 import java.nio.file.Files;
       
    53 import java.nio.file.Path;
    51 import java.util.ResourceBundle;
    54 import java.util.ResourceBundle;
    52 import java.text.MessageFormat;
    55 import java.text.MessageFormat;
    53 import java.util.ArrayList;
    56 import java.util.ArrayList;
    54 import java.util.Collections;
    57 import java.util.Collections;
    55 import java.util.Iterator;
    58 import java.util.Iterator;
    67     INSTANCE;
    70     INSTANCE;
    68     private static final String MAIN_CLASS = "Main-Class";
    71     private static final String MAIN_CLASS = "Main-Class";
    69 
    72 
    70     private static StringBuilder outBuf = new StringBuilder();
    73     private static StringBuilder outBuf = new StringBuilder();
    71 
    74 
    72     private static ResourceBundle javarb = null;
       
    73 
       
    74     private static final String INDENT = "    ";
    75     private static final String INDENT = "    ";
    75     private static final String VM_SETTINGS     = "VM settings:";
    76     private static final String VM_SETTINGS     = "VM settings:";
    76     private static final String PROP_SETTINGS   = "Property settings:";
    77     private static final String PROP_SETTINGS   = "Property settings:";
    77     private static final String LOCALE_SETTINGS = "Locale settings:";
    78     private static final String LOCALE_SETTINGS = "Locale settings:";
    78 
    79 
    79     // sync with java.c and sun.misc.VM
    80     // sync with java.c and sun.misc.VM
    80     private static final String diagprop = "sun.java.launcher.diag";
    81     private static final String diagprop = "sun.java.launcher.diag";
       
    82     final static boolean trace = sun.misc.VM.getSavedProperty(diagprop) != null;
    81 
    83 
    82     private static final String defaultBundleName =
    84     private static final String defaultBundleName =
    83             "sun.launcher.resources.launcher";
    85             "sun.launcher.resources.launcher";
    84     private static class ResourceBundleHolder {
    86     private static class ResourceBundleHolder {
    85         private static final ResourceBundle RB =
    87         private static final ResourceBundle RB =
   426 
   428 
   427     static void abort(PrintStream ostream, Throwable t, String msgKey, Object... args) {
   429     static void abort(PrintStream ostream, Throwable t, String msgKey, Object... args) {
   428         if (msgKey != null) {
   430         if (msgKey != null) {
   429             ostream.println(getLocalizedMessage(msgKey, args));
   431             ostream.println(getLocalizedMessage(msgKey, args));
   430         }
   432         }
   431         if (sun.misc.VM.getSavedProperty(diagprop) != null) {
   433         if (trace) {
   432             if (t != null) {
   434             if (t != null) {
   433                 t.printStackTrace();
   435                 t.printStackTrace();
   434             } else {
   436             } else {
   435                 Thread.dumpStack();
   437                 Thread.dumpStack();
   436             }
   438             }
   530         } catch (UnsupportedEncodingException uee) {
   532         } catch (UnsupportedEncodingException uee) {
   531             abort(ostream, uee, null);
   533             abort(ostream, uee, null);
   532         }
   534         }
   533         return null; // keep the compiler happy
   535         return null; // keep the compiler happy
   534     }
   536     }
       
   537 
       
   538     static String[] expandArgs(String[] argArray) {
       
   539         List<StdArg> aList = new ArrayList<>();
       
   540         for (String x : argArray) {
       
   541             aList.add(new StdArg(x));
       
   542         }
       
   543         return expandArgs(aList);
       
   544     }
       
   545 
       
   546     static String[] expandArgs(List<StdArg> argList) {
       
   547         ArrayList<String> out = new ArrayList<>();
       
   548         if (trace) {
       
   549             System.err.println("Incoming arguments:");
       
   550         }
       
   551         for (StdArg a : argList) {
       
   552             if (trace) {
       
   553                 System.err.println(a);
       
   554             }
       
   555             if (a.needsExpansion) {
       
   556                 File x = new File(a.arg);
       
   557                 File parent = x.getParentFile();
       
   558                 String glob = x.getName();
       
   559                 if (parent == null) {
       
   560                     parent = new File(".");
       
   561                 }
       
   562                 try (DirectoryStream<Path> dstream =
       
   563                         Files.newDirectoryStream(parent.toPath(), glob)) {
       
   564                     int entries = 0;
       
   565                     for (Path p : dstream) {
       
   566                         out.add(p.normalize().toString());
       
   567                         entries++;
       
   568                     }
       
   569                     if (entries == 0) {
       
   570                         out.add(a.arg);
       
   571                     }
       
   572                 } catch (Exception e) {
       
   573                     out.add(a.arg);
       
   574                     if (trace) {
       
   575                         System.err.println("Warning: passing argument as-is " + a);
       
   576                         System.err.print(e);
       
   577                     }
       
   578                 }
       
   579             } else {
       
   580                 out.add(a.arg);
       
   581             }
       
   582         }
       
   583         String[] oarray = new String[out.size()];
       
   584         out.toArray(oarray);
       
   585 
       
   586         if (trace) {
       
   587             System.err.println("Expanded arguments:");
       
   588             for (String x : oarray) {
       
   589                 System.err.println(x);
       
   590             }
       
   591         }
       
   592         return oarray;
       
   593     }
       
   594 
       
   595     /* duplicate of the native StdArg struct */
       
   596     private static class StdArg {
       
   597         final String arg;
       
   598         final boolean needsExpansion;
       
   599         StdArg(String arg, boolean expand) {
       
   600             this.arg = arg;
       
   601             this.needsExpansion = expand;
       
   602         }
       
   603         // protocol: first char indicates whether expansion is required
       
   604         // 'T' = true ; needs expansion
       
   605         // 'F' = false; needs no expansion
       
   606         StdArg(String in) {
       
   607             this.arg = in.substring(1);
       
   608             needsExpansion = in.charAt(0) == 'T';
       
   609         }
       
   610         public String toString() {
       
   611             return "StdArg{" + "arg=" + arg + ", needsExpansion=" + needsExpansion + '}';
       
   612         }
       
   613     }
   535 }
   614 }
       
   615