< prev index next >

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

Print this page




  30 import java.util.Map;
  31 import java.util.Set;
  32 import jdk.jpackage.internal.Arguments.CLIOptions;
  33 
  34 /**
  35  * ValidOptions
  36  *
  37  * Two basic methods for validating command line options.
  38  *
  39  * initArgs()
  40  *      Computes the Map of valid options for each mode on this Platform.
  41  *
  42  * checkIfSupported(CLIOptions mode, CLIOptions arg)
  43  *      Determine if the given arg is valid in the given mode.
  44  *
  45  * checkIfOtherSupported(CLIOptions mode, CLIOptions arg)
  46  *      Determine if the given arg is valid in the a different mode.
  47  */
  48 class ValidOptions {
  49 
  50     private ValidOptions() {};




  51 
  52     // multimap that contains pairs of (mode, supported args)
  53     private static final Map<CLIOptions, Set<CLIOptions>> options =
  54             new HashMap<>();
  55 
  56     private static boolean argsInitialized = false;
  57 
  58     // initializing list of mandatory arguments
  59     private static void initArgs() {
  60         if (argsInitialized) {
  61             return;
  62         }
  63 
  64         // add options for CREATE_IMAGE
  65         add(CLIOptions.CREATE_IMAGE, CLIOptions.INPUT);
  66         add(CLIOptions.CREATE_IMAGE, CLIOptions.OUTPUT);
  67         add(CLIOptions.CREATE_IMAGE, CLIOptions.APPCLASS);
  68         add(CLIOptions.CREATE_IMAGE, CLIOptions.NAME);
  69         add(CLIOptions.CREATE_IMAGE, CLIOptions.IDENTIFIER);
  70         add(CLIOptions.CREATE_IMAGE, CLIOptions.VERBOSE);
  71         add(CLIOptions.CREATE_IMAGE, CLIOptions.OVERWRITE);
  72         add(CLIOptions.CREATE_IMAGE, CLIOptions.FILES);
  73         add(CLIOptions.CREATE_IMAGE, CLIOptions.ARGUMENTS);
  74         add(CLIOptions.CREATE_IMAGE, CLIOptions.STRIP_NATIVE_COMMANDS);
  75         add(CLIOptions.CREATE_IMAGE, CLIOptions.ICON);
  76         add(CLIOptions.CREATE_IMAGE, CLIOptions.VERSION);
  77         add(CLIOptions.CREATE_IMAGE, CLIOptions.JVM_ARGS);
  78         add(CLIOptions.CREATE_IMAGE, CLIOptions.SECONDARY_LAUNCHER);
  79         add(CLIOptions.CREATE_IMAGE, CLIOptions.BUILD_ROOT);
  80         add(CLIOptions.CREATE_IMAGE, CLIOptions.PREDEFINED_RUNTIME_IMAGE);
  81         add(CLIOptions.CREATE_IMAGE, CLIOptions.MAIN_JAR);
  82         add(CLIOptions.CREATE_IMAGE, CLIOptions.MODULE);
  83         add(CLIOptions.CREATE_IMAGE, CLIOptions.ADD_MODULES);
  84         add(CLIOptions.CREATE_IMAGE, CLIOptions.MODULE_PATH);
  85         add(CLIOptions.CREATE_IMAGE, CLIOptions.RESOURCE_DIR);
  86 
  87         if (Platform.getPlatform() == Platform.MAC) {
  88             add(CLIOptions.CREATE_IMAGE, CLIOptions.MAC_SIGN);
  89             add(CLIOptions.CREATE_IMAGE, CLIOptions.MAC_BUNDLE_NAME);
  90             add(CLIOptions.CREATE_IMAGE, CLIOptions.MAC_BUNDLE_IDENTIFIER);
  91             add(CLIOptions.CREATE_IMAGE, CLIOptions.MAC_BUNDLE_SIGNING_PREFIX);
  92             add(CLIOptions.CREATE_IMAGE, CLIOptions.MAC_SIGNING_KEY_NAME);
  93             add(CLIOptions.CREATE_IMAGE, CLIOptions.MAC_SIGNING_KEYCHAIN);
  94             add(CLIOptions.CREATE_IMAGE, CLIOptions.CATEGORY);
  95             add(CLIOptions.CREATE_IMAGE, CLIOptions.COPYRIGHT);
  96         }
  97 
  98         if (Platform.getPlatform() == Platform.WINDOWS) {
  99             add(CLIOptions.CREATE_IMAGE, CLIOptions.DESCRIPTION);
 100             add(CLIOptions.CREATE_IMAGE, CLIOptions.VENDOR);
 101             add(CLIOptions.CREATE_IMAGE, CLIOptions.COPYRIGHT);
 102             add(CLIOptions.CREATE_IMAGE, CLIOptions.WIN_CONSOLE_HINT);
 103         }
 104 
 105         // add options for CREATE_INSTALLER
 106         // (start with all options for CREATE_IMAGE)
 107         Set<CLIOptions> imageOptions = options.get(CLIOptions.CREATE_IMAGE);
 108         imageOptions.forEach(o -> add(CLIOptions.CREATE_INSTALLER, o));
 109 
 110         add(CLIOptions.CREATE_INSTALLER, CLIOptions.RUNTIME_INSTALLER);
 111         add(CLIOptions.CREATE_INSTALLER, CLIOptions.INSTALLER_TYPE);
 112         add(CLIOptions.CREATE_INSTALLER, CLIOptions.LICENSE_FILE);
 113         add(CLIOptions.CREATE_INSTALLER, CLIOptions.FILE_ASSOCIATIONS);
 114         add(CLIOptions.CREATE_INSTALLER, CLIOptions.INSTALL_DIR);
 115         add(CLIOptions.CREATE_INSTALLER, CLIOptions.PREDEFINED_APP_IMAGE);
 116         add(CLIOptions.CREATE_INSTALLER, CLIOptions.INSTALLER_TYPE);
 117 
 118         if (Platform.getPlatform() == Platform.MAC) {
 119             add(CLIOptions.CREATE_INSTALLER, CLIOptions.MAC_APP_STORE_CATEGORY);
 120             add(CLIOptions.CREATE_INSTALLER,
 121                     CLIOptions.MAC_APP_STORE_ENTITLEMENTS);




 122         }
 123 
 124         if (Platform.getPlatform() == Platform.LINUX) {
 125             add(CLIOptions.CREATE_INSTALLER, CLIOptions.LINUX_BUNDLE_NAME);
 126             add(CLIOptions.CREATE_INSTALLER, CLIOptions.LINUX_DEB_MAINTAINER);
 127             add(CLIOptions.CREATE_INSTALLER, CLIOptions.LINUX_RPM_LICENSE_TYPE);
 128             add(CLIOptions.CREATE_INSTALLER,
 129                     CLIOptions.LINUX_PACKAGE_DEPENDENCIES);
 130             add(CLIOptions.CREATE_INSTALLER, CLIOptions.DESCRIPTION);
 131             add(CLIOptions.CREATE_INSTALLER, CLIOptions.VENDOR);
 132             add(CLIOptions.CREATE_INSTALLER, CLIOptions.CATEGORY);
 133             add(CLIOptions.CREATE_INSTALLER, CLIOptions.COPYRIGHT);
 134         }
 135 
 136         if (Platform.getPlatform() == Platform.WINDOWS) {
 137             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_MENU_HINT);
 138             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_MENU_GROUP);
 139             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_SHORTCUT_HINT);
 140             add(CLIOptions.CREATE_INSTALLER,
 141                     CLIOptions.WIN_PER_USER_INSTALLATION);
 142             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_DIR_CHOOSER);
 143             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_REGISTRY_NAME);
 144             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_UPGRADE_UUID);
 145             add(CLIOptions.CREATE_INSTALLER, CLIOptions.CATEGORY);
 146             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_CONSOLE_HINT);
 147         }
 148 
 149         argsInitialized = true;
 150     }
 151 
 152     static void add(CLIOptions mode, CLIOptions arg) {
 153         if (mode.equals(arg)) {
 154             return;




 155         }
 156         options.computeIfAbsent(mode,
 157                     k -> new HashSet<>()).add(arg);
 158     }
 159 
 160     static boolean checkIfSupported(CLIOptions mode, CLIOptions arg) {
 161         if (mode.equals(arg)) {
 162             return true;
 163         }
 164 
 165         initArgs();
 166         Set<CLIOptions> set = options.get(mode);
 167         if (set != null) {
 168             return set.contains(arg);
 169         }
 170         return false;
 171     }
 172 
 173     static boolean checkIfOtherSupported(CLIOptions mode, CLIOptions arg) {
 174         for (CLIOptions other : options.keySet()) {
 175             if (!other.equals(mode)) {
 176                 if (checkIfSupported(other, arg)) {
 177                     return true;
 178                 }
 179             }
 180         }
 181         return false;
 182     }
 183 }


  30 import java.util.Map;
  31 import java.util.Set;
  32 import jdk.jpackage.internal.Arguments.CLIOptions;
  33 
  34 /**
  35  * ValidOptions
  36  *
  37  * Two basic methods for validating command line options.
  38  *
  39  * initArgs()
  40  *      Computes the Map of valid options for each mode on this Platform.
  41  *
  42  * checkIfSupported(CLIOptions mode, CLIOptions arg)
  43  *      Determine if the given arg is valid in the given mode.
  44  *
  45  * checkIfOtherSupported(CLIOptions mode, CLIOptions arg)
  46  *      Determine if the given arg is valid in the a different mode.
  47  */
  48 class ValidOptions {
  49 
  50     enum USE {
  51         ALL,        // valid in all cases
  52         LAUNCHER,   // valid when creating a launcher
  53         INSTALL     // valid when creating an installer
  54     }
  55         
  56     private static final HashMap<String, USE> options = new HashMap<>();


  57 

  58 
  59     // initializing list of mandatory arguments
  60     static {
  61         options.put(CLIOptions.CREATE_IMAGE.getId(), USE.ALL);
  62         options.put(CLIOptions.CREATE_INSTALLER.getId(), USE.ALL);
  63         options.put(CLIOptions.NAME.getId(), USE.ALL);
  64         options.put(CLIOptions.VERSION.getId(), USE.ALL);
  65         options.put(CLIOptions.OUTPUT.getId(), USE.ALL);
  66         options.put(CLIOptions.TEMP_ROOT.getId(), USE.ALL);
  67         options.put(CLIOptions.VERBOSE.getId(), USE.ALL);
  68         options.put(CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId(), USE.ALL);
  69         options.put(CLIOptions.RESOURCE_DIR.getId(), USE.ALL);
  70         options.put(CLIOptions.IDENTIFIER.getId(), USE.ALL);
  71         options.put(CLIOptions.DESCRIPTION.getId(), USE.ALL);
  72         options.put(CLIOptions.VENDOR.getId(), USE.ALL);
  73         options.put(CLIOptions.COPYRIGHT.getId(), USE.ALL);
  74 
  75         options.put(CLIOptions.INPUT.getId(), USE.LAUNCHER);
  76         options.put(CLIOptions.FILES.getId(), USE.LAUNCHER);
  77         options.put(CLIOptions.MODULE.getId(), USE.LAUNCHER);
  78         options.put(CLIOptions.MODULE_PATH.getId(), USE.LAUNCHER);
  79         options.put(CLIOptions.ADD_MODULES.getId(), USE.LAUNCHER);
  80         options.put(CLIOptions.MAIN_JAR.getId(), USE.LAUNCHER);
  81         options.put(CLIOptions.APPCLASS.getId(), USE.LAUNCHER);
  82         options.put(CLIOptions.ICON.getId(), USE.LAUNCHER);
  83         options.put(CLIOptions.ARGUMENTS.getId(), USE.LAUNCHER);
  84         options.put(CLIOptions.JVM_ARGS.getId(), USE.LAUNCHER);
  85         options.put(CLIOptions.ADD_LAUNCHER.getId(), USE.LAUNCHER);
  86 
  87         options.put(CLIOptions.INSTALLER_TYPE.getId(), USE.INSTALL);
  88         options.put(CLIOptions.LICENSE_FILE.getId(), USE.INSTALL);
  89         options.put(CLIOptions.FILE_ASSOCIATIONS.getId(), USE.INSTALL);
  90         options.put(CLIOptions.INSTALL_DIR.getId(), USE.INSTALL);
  91         options.put(CLIOptions.PREDEFINED_APP_IMAGE.getId(), USE.INSTALL);
  92         options.put(CLIOptions.INSTALLER_TYPE.getId(), USE.INSTALL);





  93 
  94         if (Platform.getPlatform() == Platform.WINDOWS) {
  95             options.put(CLIOptions.WIN_CONSOLE_HINT.getId(), USE.LAUNCHER);

















  96 
  97             options.put(CLIOptions.WIN_MENU_HINT.getId(), USE.INSTALL);
  98             options.put(CLIOptions.WIN_MENU_GROUP.getId(), USE.INSTALL);
  99             options.put(CLIOptions.WIN_SHORTCUT_HINT.getId(), USE.INSTALL);
 100             options.put(CLIOptions.WIN_DIR_CHOOSER.getId(), USE.INSTALL);
 101             options.put(CLIOptions.WIN_REGISTRY_NAME.getId(), USE.INSTALL);
 102             options.put(CLIOptions.WIN_UPGRADE_UUID.getId(), USE.INSTALL);
 103             options.put(CLIOptions.WIN_PER_USER_INSTALLATION.getId(),
 104                         USE.INSTALL);
 105         }
 106 
 107         if (Platform.getPlatform() == Platform.MAC) {
 108             options.put(CLIOptions.MAC_SIGN.getId(), USE.INSTALL);
 109             options.put(CLIOptions.MAC_BUNDLE_NAME.getId(), USE.INSTALL);
 110             options.put(CLIOptions.MAC_BUNDLE_IDENTIFIER.getId(), USE.INSTALL);
 111             options.put(CLIOptions.MAC_BUNDLE_SIGNING_PREFIX.getId(),
 112                         USE.INSTALL);
 113             options.put(CLIOptions.MAC_SIGNING_KEY_NAME.getId(), USE.INSTALL);
 114             options.put(CLIOptions.MAC_SIGNING_KEYCHAIN.getId(), USE.INSTALL);
 115             options.put(CLIOptions.MAC_APP_STORE_CATEGORY.getId(), USE.INSTALL);
 116             options.put(CLIOptions.MAC_APP_STORE_ENTITLEMENTS.getId(),
 117                         USE.INSTALL);















 118         }
 119 
 120         if (Platform.getPlatform() == Platform.LINUX) {
 121             options.put(CLIOptions.LINUX_BUNDLE_NAME.getId(), USE.INSTALL);
 122             options.put(CLIOptions.LINUX_DEB_MAINTAINER.getId(), USE.INSTALL);
 123             options.put(CLIOptions.LINUX_RPM_LICENSE_TYPE.getId(), USE.INSTALL);
 124             options.put(CLIOptions.LINUX_PACKAGE_DEPENDENCIES.getId(),
 125                         USE.INSTALL);
 126             options.put(CLIOptions.LINUX_MENU_GROUP.getId(), USE.INSTALL);
 127         }


 128     }
 129 
 130     static boolean checkIfSupported(CLIOptions arg) {
 131         return options.containsKey(arg.getId());

 132     }
 133 
 134     static boolean checkIfImageSupported(CLIOptions arg) {
 135         USE use = options.get(arg.getId());
 136         return USE.ALL == use || USE.LAUNCHER == use;



 137     }
 138 
 139     static boolean checkIfInstallerSupported(CLIOptions arg) {
 140         USE use = options.get(arg.getId());
 141         return USE.ALL == use || USE.INSTALL == use;






 142     }
 143 }
< prev index next >