@Test public void stdoutAndStderrShouldBeLogged() throws Exception { myContext.checking(new Expectations() {{ allowing(myChannel).connect(with(any(Integer.class))); oneOf(myChannel).getInputStream(); will(returnValue(new ByteArrayInputStream("standard output\n".getBytes()))); oneOf(myChannel).getErrStream(); will(returnValue(new ByteArrayInputStream("standard error\n".getBytes()))); oneOf(myChannel).isConnected(); will(returnValue(true)); oneOf(myChannel).isEOF(); will(returnValue(false)); oneOf(myLogger).message("Executing commands:\n" + DEFAULT_COMMAND + "\non host []"); oneOf(myLogger).message("standard output"); oneOf(myLogger).message("standard error"); oneOf(myLogger).message("SSH exit-code [0]"); }}); myAdapter.runProcess(); myContext.assertIsSatisfied(); }
@Override public BuildFinishedStatus runProcess() { JSch.setLogger(new JSchBuildLogger(myLogger)); Session session = null; try { session = myProvider.getSession(); return executeCommand(session, myPty, myCommands); } catch (JSchException e) { logBuildProblem(myLogger, e.getMessage()); LOG.warnAndDebugDetails("Error executing SSH command", e); return BuildFinishedStatus.FINISHED_FAILED; } finally { if (session != null) { session.disconnect(); } } }
SSHExecProcessAdapter extends SyncBuildProcessAdapter { @Override public BuildFinishedStatus runProcess() { JSch.setLogger(new JSchBuildLogger(myLogger)); Session session = null; try { session = myProvider.getSession(); return executeCommand(session, myPty, myCommands); } catch (JSchException e) { logBuildProblem(myLogger, e.getMessage()); LOG.warnAndDebugDetails("Error executing SSH command", e); return BuildFinishedStatus.FINISHED_FAILED; } finally { if (session != null) { session.disconnect(); } } } }
SSHExecProcessAdapter extends SyncBuildProcessAdapter { @Override public BuildFinishedStatus runProcess() { JSch.setLogger(new JSchBuildLogger(myLogger)); Session session = null; try { session = myProvider.getSession(); return executeCommand(session, myPty, myCommands); } catch (JSchException e) { logBuildProblem(myLogger, e.getMessage()); LOG.warnAndDebugDetails("Error executing SSH command", e); return BuildFinishedStatus.FINISHED_FAILED; } finally { if (session != null) { session.disconnect(); } } } SSHExecProcessAdapter(@NotNull final SSHSessionProvider provider,
                               @NotNull final String commands,
                               @NotNull final String pty,
                               @NotNull final BuildProgressLogger buildLogger,
                               @NotNull final SSHProcessAdapterOptions options); }
SSHExecProcessAdapter extends SyncBuildProcessAdapter { @Override public BuildFinishedStatus runProcess() { JSch.setLogger(new JSchBuildLogger(myLogger)); Session session = null; try { session = myProvider.getSession(); return executeCommand(session, myPty, myCommands); } catch (JSchException e) { logBuildProblem(myLogger, e.getMessage()); LOG.warnAndDebugDetails("Error executing SSH command", e); return BuildFinishedStatus.FINISHED_FAILED; } finally { if (session != null) { session.disconnect(); } } } SSHExecProcessAdapter(@NotNull final SSHSessionProvider provider,
                               @NotNull final String commands,
                               @NotNull final String pty,
                               @NotNull final BuildProgressLogger buildLogger,
                               @NotNull final SSHProcessAdapterOptions options); @Override BuildFinishedStatus runProcess(); }
SSHExecProcessAdapter extends SyncBuildProcessAdapter { @Override public BuildFinishedStatus runProcess() { JSch.setLogger(new JSchBuildLogger(myLogger)); Session session = null; try { session = myProvider.getSession(); return executeCommand(session, myPty, myCommands); } catch (JSchException e) { logBuildProblem(myLogger, e.getMessage()); LOG.warnAndDebugDetails("Error executing SSH command", e); return BuildFinishedStatus.FINISHED_FAILED; } finally { if (session != null) { session.disconnect(); } } } SSHExecProcessAdapter(@NotNull final SSHSessionProvider provider,
                               @NotNull final String commands,
                               @NotNull final String pty,
                               @NotNull final BuildProgressLogger buildLogger,
                               @NotNull final SSHProcessAdapterOptions options); @Override BuildFinishedStatus runProcess();  }