< prev index next >

src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java

Print this page




  34 /*
  35  * AddLauncherArguments
  36  *
  37  * Processes a add-launcher properties file to create the Map of
  38  * bundle params applicable to the add-launcher:
  39  *
  40  * BundlerParams p = (new AddLauncherArguments(file)).getLauncherMap();
  41  *
  42  * A add-launcher is another executable program generated by either the
  43  * create-app-image mode or the create-installer mode.
  44  * The add-launcher may be the same program with different configuration,
  45  * or a completely different program created from the same files.
  46  *
  47  * There may be multiple add-launchers, each created by using the
  48  * command line arg "--add-launcher <file path>
  49  *
  50  * The add-launcher properties file may have any of:
  51  *
  52  * appVersion
  53  * module
  54  * add-modules
  55  * main-jar
  56  * main-class
  57  * icon
  58  * arguments
  59  * java-options
  60  * win-console
  61  *
  62  */
  63 class AddLauncherArguments {
  64 
  65     private final String name;
  66     private final String filename;
  67     private Map<String, String> allArgs;
  68     private Map<String, ? super Object> bundleParams;
  69 
  70     AddLauncherArguments(String name, String filename) {
  71         this.name = name;
  72         this.filename = filename;
  73     }
  74 


  88         if (module != null && mainClass != null) {
  89             putUnlessNull(bundleParams, CLIOptions.MODULE.getId(),
  90                     module + "/" + mainClass);
  91         } else if (module != null) {
  92             putUnlessNull(bundleParams, CLIOptions.MODULE.getId(),
  93                     module);
  94         } else {
  95             putUnlessNull(bundleParams, CLIOptions.MAIN_JAR.getId(),
  96                     mainJar);
  97             putUnlessNull(bundleParams, CLIOptions.APPCLASS.getId(),
  98                     mainClass);
  99         }
 100 
 101         putUnlessNull(bundleParams, CLIOptions.NAME.getId(),
 102                 getOptionValue(CLIOptions.NAME));
 103 
 104         putUnlessNull(bundleParams, CLIOptions.VERSION.getId(),
 105                 getOptionValue(CLIOptions.VERSION));
 106 
 107         putUnlessNull(bundleParams,
 108                 CLIOptions.ADD_MODULES.getId(),
 109                 getOptionValue(CLIOptions.ADD_MODULES));
 110 
 111         putUnlessNull(bundleParams,
 112                 CLIOptions.WIN_CONSOLE_HINT.getId(),
 113                 getOptionValue(CLIOptions.WIN_CONSOLE_HINT));
 114 
 115         String value = getOptionValue(CLIOptions.ICON);
 116         putUnlessNull(bundleParams, CLIOptions.ICON.getId(),
 117                 (value == null) ? null : new File(value));
 118 
 119         String argumentStr = getOptionValue(CLIOptions.ARGUMENTS);
 120         putUnlessNullOrEmpty(bundleParams,
 121                 CLIOptions.ARGUMENTS.getId(),
 122                 Arguments.getArgumentList(argumentStr));
 123 
 124         String jvmargsStr = getOptionValue(CLIOptions.JAVA_OPTIONS);
 125         putUnlessNullOrEmpty(bundleParams,
 126                 CLIOptions.JAVA_OPTIONS.getId(),
 127                 Arguments.getArgumentList(jvmargsStr));
 128     }
 129 
 130     private String getOptionValue(CLIOptions option) {
 131         if (option == null || allArgs == null) {


 159             params.put(param, value);
 160         }
 161     }
 162 
 163     private void putUnlessNullOrEmpty(Map<String, ? super Object> params,
 164             String param, Map<?, ?> value) {
 165         if (value != null && !value.isEmpty()) {
 166             params.put(param, value);
 167         }
 168     }
 169 
 170     static Map<String, ? super Object> merge(
 171             Map<String, ? super Object> original,
 172             Map<String, ? super Object> additional) {
 173         Map<String, ? super Object> tmp = new HashMap<>(original);
 174         if (additional.containsKey("module")) {
 175             tmp.remove("main-jar");
 176             tmp.remove("main-class");
 177         } else if (additional.containsKey("main-jar")) {
 178             tmp.remove("module");
 179             // should we only remove add-modules when it wasn't actually passed
 180             // but was inferred or empty ?
 181             tmp.remove("add-modules");
 182         }
 183         tmp.putAll(additional);
 184         return tmp;
 185     }
 186 
 187 }


  34 /*
  35  * AddLauncherArguments
  36  *
  37  * Processes a add-launcher properties file to create the Map of
  38  * bundle params applicable to the add-launcher:
  39  *
  40  * BundlerParams p = (new AddLauncherArguments(file)).getLauncherMap();
  41  *
  42  * A add-launcher is another executable program generated by either the
  43  * create-app-image mode or the create-installer mode.
  44  * The add-launcher may be the same program with different configuration,
  45  * or a completely different program created from the same files.
  46  *
  47  * There may be multiple add-launchers, each created by using the
  48  * command line arg "--add-launcher <file path>
  49  *
  50  * The add-launcher properties file may have any of:
  51  *
  52  * appVersion
  53  * module

  54  * main-jar
  55  * main-class
  56  * icon
  57  * arguments
  58  * java-options
  59  * win-console
  60  *
  61  */
  62 class AddLauncherArguments {
  63 
  64     private final String name;
  65     private final String filename;
  66     private Map<String, String> allArgs;
  67     private Map<String, ? super Object> bundleParams;
  68 
  69     AddLauncherArguments(String name, String filename) {
  70         this.name = name;
  71         this.filename = filename;
  72     }
  73 


  87         if (module != null && mainClass != null) {
  88             putUnlessNull(bundleParams, CLIOptions.MODULE.getId(),
  89                     module + "/" + mainClass);
  90         } else if (module != null) {
  91             putUnlessNull(bundleParams, CLIOptions.MODULE.getId(),
  92                     module);
  93         } else {
  94             putUnlessNull(bundleParams, CLIOptions.MAIN_JAR.getId(),
  95                     mainJar);
  96             putUnlessNull(bundleParams, CLIOptions.APPCLASS.getId(),
  97                     mainClass);
  98         }
  99 
 100         putUnlessNull(bundleParams, CLIOptions.NAME.getId(),
 101                 getOptionValue(CLIOptions.NAME));
 102 
 103         putUnlessNull(bundleParams, CLIOptions.VERSION.getId(),
 104                 getOptionValue(CLIOptions.VERSION));
 105 
 106         putUnlessNull(bundleParams,




 107                 CLIOptions.WIN_CONSOLE_HINT.getId(),
 108                 getOptionValue(CLIOptions.WIN_CONSOLE_HINT));
 109 
 110         String value = getOptionValue(CLIOptions.ICON);
 111         putUnlessNull(bundleParams, CLIOptions.ICON.getId(),
 112                 (value == null) ? null : new File(value));
 113 
 114         String argumentStr = getOptionValue(CLIOptions.ARGUMENTS);
 115         putUnlessNullOrEmpty(bundleParams,
 116                 CLIOptions.ARGUMENTS.getId(),
 117                 Arguments.getArgumentList(argumentStr));
 118 
 119         String jvmargsStr = getOptionValue(CLIOptions.JAVA_OPTIONS);
 120         putUnlessNullOrEmpty(bundleParams,
 121                 CLIOptions.JAVA_OPTIONS.getId(),
 122                 Arguments.getArgumentList(jvmargsStr));
 123     }
 124 
 125     private String getOptionValue(CLIOptions option) {
 126         if (option == null || allArgs == null) {


 154             params.put(param, value);
 155         }
 156     }
 157 
 158     private void putUnlessNullOrEmpty(Map<String, ? super Object> params,
 159             String param, Map<?, ?> value) {
 160         if (value != null && !value.isEmpty()) {
 161             params.put(param, value);
 162         }
 163     }
 164 
 165     static Map<String, ? super Object> merge(
 166             Map<String, ? super Object> original,
 167             Map<String, ? super Object> additional) {
 168         Map<String, ? super Object> tmp = new HashMap<>(original);
 169         if (additional.containsKey("module")) {
 170             tmp.remove("main-jar");
 171             tmp.remove("main-class");
 172         } else if (additional.containsKey("main-jar")) {
 173             tmp.remove("module");



 174         }
 175         tmp.putAll(additional);
 176         return tmp;
 177     }
 178 
 179 }
< prev index next >