Example #1
0
  /**
   * Extract any command-line properties and their corresponding values.
   *
   * <p>May print out usage information if a badly formatted {@literal "property=value"} pair is
   * encountered, or when an unknown argument is found (depending on value of the {@code
   * ignoreUnknown} parameter).
   *
   * <p><b>NOTE:</b> {@code null} is not a permitted value for any parameter.
   *
   * @param ignoreUnknown Whether or not to handle unknown arguments.
   * @param fromStartupManager Whether or not this call originated from {@code startupmanager.jar}.
   * @param args Array containing command-line arguments.
   * @param defaults Default parameter values.
   * @return Command-line arguments as a collection of property identifiers and values.
   */
  public static Properties getArgs(
      final boolean ignoreUnknown,
      final boolean fromStartupManager,
      final String[] args,
      final Properties defaults) {
    Properties props = new Properties(defaults);
    for (int i = 0; i < args.length; i++) {

      // handle property definitions
      if (args[i].startsWith("-D")) {
        List<String> l = StringUtil.split(args[i].substring(2), "=");
        if (l.size() == 2) {
          props.setProperty(l.get(0), l.get(1));
        } else {
          usage("Invalid property:" + args[i]);
        }
      }

      // handle userpath changes
      else if (ARG_USERPATH.equals(args[i]) && (i + 1) < args.length) {
        props.setProperty("userpath", args[++i]);
      }

      // handle help requests
      else if (ARG_HELP.equals(args[i]) && (fromStartupManager)) {
        System.err.println(USAGE_MESSAGE);
        System.err.println(getUsageMessage());
        System.exit(1);
      }

      // bail out for unknown args, unless we don't care!
      else if (!ignoreUnknown) {
        usage("Unknown argument: " + args[i]);
      }
    }
    return props;
  }
Example #2
0
  /**
   * Currently we're only handling the {@code -forceaqua} flag so we can mitigate some overlay
   * issues we've been seeing on OS X Leopard.
   *
   * @param arg The current argument we're examining.
   * @param args The actual array of arguments.
   * @param idx The index of {@code arg} within {@code args}.
   * @return The idx of the last value in the args array we look at. i.e., if the flag arg does not
   *     require any further values in the args array then don't increment idx. If arg requires one
   *     more value then increment idx by one. etc.
   * @throws Exception Throw bad things off to something that can handle 'em!
   */
  protected int parseArg(String arg, String[] args, int idx) throws Exception {

    if ("-forceaqua".equals(arg)) {
      // unfortunately we can't simply set the look and feel here. If I
      // were to do so, the loadLookAndFeel in the IdvUIManager would
      // eventually get loaded and then set the look and feel to whatever
      // the preferences dictate.
      // instead I use the boolean toggle to signal to McV's
      // UIManager.loadLookAndFeel that it should simply ignore the user's
      // preference is and load the Aqua L&F from there.
      McIDASV.useAquaLookAndFeel = true;
    } else if (ARG_HELP.equals(arg)) {
      String msg = USAGE_MESSAGE + "\n" + getUsageMessage();
      if (McIDASV.isWindows() && !GraphicsEnvironment.isHeadless()) {
        userMessage(msg, false);
      } else {
        helpLogger.info(System.getProperty("line.separator") + msg);
      }
      ((McIDASV) getIdv()).exit(1);
    } else if (checkArg(arg, "-script", args, idx, 1) || checkArg(arg, "-pyfile", args, idx, 1)) {
      String scriptArg = args[idx++];
      jythonScript = scriptArg;
      scriptingFiles.add(scriptArg);
      if (!getIslInteractive()) {
        setIsOffScreen(true);
      }
    } else if ("-welcomewindow".equals(arg)) {
      // do nothing

    } else if (checkArg(arg, "-autoquit", args, idx, 1)) {
      // do nothing besides skip the next parameter
      // (which should be the autoquit delay)
      idx++;
    } else if ("-console".equals(arg)) {
      System.err.println("*** WARNING: console flag is likely to go away soon!");
    } else if (ARG_JYTHONARGS.equals(arg)) {
      if (scriptingFiles.isEmpty()) {
        System.err.println(
            "*** WARNING: Jython script arguments will be ignored unless you provide a Jython script to execute!");
      } else {
        jythonArguments.addAll(extractJythonArgs(idx, args));

        // jump to end of args to halt further idv processing.
        return args.length;
      }
    } else if (checkArg(arg, ARG_LOGPATH, args, idx, 1)) {
      String argValue = args[idx++];
      persistentCommandLineArgs.add(ARG_LOGPATH);
      persistentCommandLineArgs.add(argValue);
    } else if (checkArg(arg, ARG_BUNDLE, args, idx, 1)) {
      String argValue = args[idx++];
      String[] results = FileOption.parseFormat(argValue);
      if (FileOption.booleanFromFormat(results[0])) {
        argXidvFiles.add(results[1]);
      }
      System.err.println("result[0]: " + FileOption.booleanFromFormat(results[0]));
      System.err.println("result[1]: '" + results[1] + '\'');
    } else if (checkArg(arg, ARG_DOACTION, args, idx, 1)) {
      startupAction = args[idx++];
    } else {
      if (ARG_ISLINTERACTIVE.equals(arg)
          || ARG_B64ISL.equals(arg)
          || ARG_ISLFILE.equals(arg)
          || isIslFile(arg)) {
        System.err.println("*** WARNING: ISL is being deprecated!");
      } else if (arg.startsWith("-D")) {
        List<String> l = StringUtil.split(arg.substring(2), "=");
        if (l.size() == 2) {
          System.setProperty(l.get(0), l.get(1));
        }
      }
      return super.parseArg(arg, args, idx);
    }
    return idx;
  }