Search in sources :

Example 1 with LoggedDataInputStream

use of org.netbeans.lib.cvsclient.util.LoggedDataInputStream in project maven-scm by apache.

the class ExtConnection method open.

/**
 * {@inheritDoc}
 */
public void open() throws AuthenticationException, CommandAbortedException {
    connection = new Connection(host, port);
    try {
        // TODO: connection timeout?
        connection.connect();
    } catch (IOException e) {
        String message = "Cannot connect. Reason: " + e.getMessage();
        throw new AuthenticationException(message, e, message);
    }
    File privateKey = getPrivateKey();
    try {
        boolean authenticated;
        if (privateKey != null && privateKey.exists()) {
            authenticated = connection.authenticateWithPublicKey(userName, privateKey, getPassphrase());
        } else {
            authenticated = connection.authenticateWithPassword(userName, password);
        }
        if (!authenticated) {
            String message = "Authentication failed.";
            throw new AuthenticationException(message, message);
        }
    } catch (IOException e) {
        closeConnection();
        String message = "Cannot authenticate. Reason: " + e.getMessage();
        throw new AuthenticationException(message, e, message);
    }
    try {
        session = connection.openSession();
    } catch (IOException e) {
        String message = "Cannot open session. Reason: " + e.getMessage();
        throw new CommandAbortedException(message, message);
    }
    String command = "cvs server";
    try {
        session.execCommand(command);
    } catch (IOException e) {
        String message = "Cannot execute remote command: " + command;
        throw new CommandAbortedException(message, message);
    }
    InputStream stdout = new StreamGobbler(session.getStdout());
    InputStream stderr = new StreamGobbler(session.getStderr());
    stderrReader = new BufferedReader(new InputStreamReader(stderr));
    setInputStream(new LoggedDataInputStream(stdout));
    setOutputStream(new LoggedDataOutputStream(session.getStdin()));
}
Also used : StreamGobbler(ch.ethz.ssh2.StreamGobbler) CommandAbortedException(org.netbeans.lib.cvsclient.command.CommandAbortedException) InputStreamReader(java.io.InputStreamReader) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) LoggedDataInputStream(org.netbeans.lib.cvsclient.util.LoggedDataInputStream) InputStream(java.io.InputStream) Connection(ch.ethz.ssh2.Connection) AbstractConnection(org.netbeans.lib.cvsclient.connection.AbstractConnection) IOException(java.io.IOException) LoggedDataOutputStream(org.netbeans.lib.cvsclient.util.LoggedDataOutputStream) BufferedReader(java.io.BufferedReader) File(java.io.File) LoggedDataInputStream(org.netbeans.lib.cvsclient.util.LoggedDataInputStream)

Aggregations

Connection (ch.ethz.ssh2.Connection)1 StreamGobbler (ch.ethz.ssh2.StreamGobbler)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 CommandAbortedException (org.netbeans.lib.cvsclient.command.CommandAbortedException)1 AbstractConnection (org.netbeans.lib.cvsclient.connection.AbstractConnection)1 AuthenticationException (org.netbeans.lib.cvsclient.connection.AuthenticationException)1 LoggedDataInputStream (org.netbeans.lib.cvsclient.util.LoggedDataInputStream)1 LoggedDataOutputStream (org.netbeans.lib.cvsclient.util.LoggedDataOutputStream)1