private void internalParseGeneralOptions()

in odps-console-mr/src/main/java/com/aliyun/openservices/odps/console/mr/MapReduceCommand.java [140:248]


  private void internalParseGeneralOptions(String commandText) throws ODPSConsoleException,
      IOException {
    // split command by whitespace chars (space, tab, newline)
    String[] ss = StringUtils.splitPreserveAllTokens(commandText.trim());
    int idx = 1; // skip 'jar' command
    while (idx < ss.length) {
      // skip empty tokens;
      while (idx < ss.length && ss[idx].isEmpty()) {
        idx++;
      }
      if (idx >= ss.length) {
        break;
      }

      String token = ss[idx];

      if (token.equalsIgnoreCase(OPT_CONF)) {
        // skip empty tokens
        do {
          idx++;
        } while (idx < ss.length && ss[idx].isEmpty());

        if (idx < ss.length && isNotOpt(ss[idx])) {
          this.conf = ss[idx];
        } else {
          throw new IOException("Argument for conf can't be empty");
        }
        validateFiles(this.conf);

      } else if (token.equalsIgnoreCase(OPT_RESOURCES)) {
        // skip empty tokens
        do {
          idx++;
        } while (idx < ss.length && ss[idx].isEmpty());

        if (idx < ss.length && isNotOpt(ss[idx])) {
          this.resources = formatSeparator(ss[idx], false);
        } else {
          throw new IOException("Argument for resources can't be empty");
        }

      } else if (token.equalsIgnoreCase(OPT_LIBJARS)) {
        // skip empty tokens
        do {
          idx++;
        } while (idx < ss.length && ss[idx].isEmpty());

        if (idx < ss.length && isNotOpt(ss[idx])) {
          this.libjars = formatSeparator(ss[idx], true);
        } else {
          throw new IOException("Argument for libjars can't be empty");
        }

      } else if (token.equalsIgnoreCase(OPT_CLASSPATH) || token.equalsIgnoreCase(OPT_CP)) {
        // skip empty tokens
        do {
          idx++;
        } while (idx < ss.length && ss[idx].isEmpty());

        if (idx < ss.length && isNotOpt(ss[idx])) {
          this.classpath = formatSeparator(ss[idx], false);
        } else {
          throw new IOException("Argument for classpath can't be empty");
        }
        this.classpath = validateFiles(this.classpath);

      } else if (token.equals(OPT_L)) {
        localMode = true;
      } else if (token.startsWith(OPT_D)) {
        String[] kv = token.substring(OPT_D.length()).split("=", 2);
        if (kv.length == 2) {
          this.jvmOptions.add(token);
        } else {
          throw new IOException("Incorrect property: " + token);
        }

      } else if (token.startsWith(OPT_X)) {
        String xparam = token.substring(OPT_X.length());
        if (xparam.isEmpty()) {
          throw new IOException("Incorrect -X option, should not be empty");
        }
        this.jvmOptions.add(token);

      } else if (token.startsWith(OPT_COST)) {
        String costParam = token.substring(OPT_COST.length());
        if (!costParam.isEmpty()) {
          throw new IOException("Incorrect -cost option , remain it just a single flag , no suffix or kv");
        }
        this.isCostMode =true;

      } else if (!token.isEmpty()) {
        // find main class
        // NOTE: tab and newline will be replaced with space
        StringBuilder builder = new StringBuilder();
        for (int i = idx; i < ss.length; i++) {
          if (i != idx) {
            builder.append(' ');
          }
          builder.append(ss[i]);
        }
        remainderArgs = builder.toString();

        break;

      }

      idx++;
    }
  }