static Server openConnection()

in command.line/java/com/jetbrains/teamcity/command/CommandRunner.java [164:200]


  static Server openConnection(final Args args, final IProgressMonitor monitor) throws MalformedURLException, ECommunicationException, EAuthorizationException {
    final String host = getHost(args);
    if (host != null) {
      String user;
      String password;
      if (args.hasArgument(USER_ARG, PASSWORD_ARG)) {
        user = args.getArgument(USER_ARG);
        password = args.getArgument(PASSWORD_ARG);

      } else {
        // try to load from saved
        final ICredential credential = TCAccess.getInstance().findCredential(host);
        if (credential != null) {
          user = credential.getUser();
          try {
            password = EncryptUtil.unscramble(credential.getPassword());
          } catch (Throwable t) {
            // the EncryptUtil raises exception if decoding string was not
            // scrambled
            password = credential.getPassword();
          }
        } else {
          throw new IllegalArgumentException(MessageFormat.format(Messages.getString("CommandRunner.not.logged.in.error.pattern"), host)); //$NON-NLS-1$
        }
      }
      final Server server = new Server(new URL(host));
      monitor.beginTask(MessageFormat.format(Messages.getString("CommandRunner.connecting.step.name"), host)); //$NON-NLS-1$
      server.connect();
      monitor.done();
      monitor.beginTask(Messages.getString("CommandRunner.logging.step.name")); //$NON-NLS-1$
      server.logon(user, password);
      monitor.done();
      return server;
    } else {
      throw new IllegalArgumentException(MessageFormat.format(Messages.getString("CommandRunner.no.default.host.error.pattern"), HOST_ARG)); //$NON-NLS-1$
    }
  }