private static void checkUseProject()

in odps-console-basic/src/main/java/com/aliyun/openservices/odps/console/utils/CommandParserUtils.java [303:357]


  private static void checkUseProject(
      List<AbstractCommand> commandList,
      ExecutionContext sessionContext) {
    if (StringUtils.isNullOrEmpty(sessionContext.getProjectName())) {
      return;
    }
    boolean useProjectFlag = false;
    for (AbstractCommand command : commandList) {
      if (command instanceof UseProjectCommand || command instanceof InteractiveCommand) {
        useProjectFlag = true;
      }
    }
    if (!useProjectFlag) {
      String commandText = "--project=" + sessionContext.getProjectName();
      UseProjectCommand useProjectCommand = new UseProjectCommand(
          commandText,
          sessionContext,
          sessionContext.getProjectName());
      int index = 0;
      boolean loginCommandExist = false;
      for (AbstractCommand command : commandList) {
        index++;
        if (command instanceof LoginCommand) {
          loginCommandExist = true;
          break;
        }

      }
      if (loginCommandExist) {
        commandList.add(index, useProjectCommand);
      } else {
        commandList.add(0, useProjectCommand);
      }
    }

    // 因为第一次启动,use project可能把设置的priority值给设置为默认值
    // 所以需要用初始值创建一个 InstancePriorityCommand
    boolean ipcExist = false;
    int useCommandIndex = 0;
    for (int i = 0; i < commandList.size(); i++) {
      AbstractCommand command = commandList.get(i);
      if (command instanceof InstancePriorityCommand) {
        ipcExist = true;
      } else if (command instanceof UseProjectCommand) {
        useCommandIndex = i + 1;
      }
    }
    if (!ipcExist) {
      // 如果不存在,则需要加一个InstancePriorityCommand来设置Priority的值,存在就不管了
      InstancePriorityCommand ipc = new InstancePriorityCommand(sessionContext.getPriority(),
                                                                "--instance_priority",
                                                                sessionContext);
      commandList.add(useCommandIndex, ipc);
    }
  }