Package com.xebialabs.overthere.util

Examples of com.xebialabs.overthere.util.CapturingOverthereExecutionOutputHandler


            default:
                throw new IllegalArgumentException(format("Unknown operating system [%s]", source.getConnection().getHostOperatingSystem()));
        }
        CmdLine cmdLine = new CmdLine().addTemplatedFragment(copyCommandTemplate, source.getPath(), getPath());

        CapturingOverthereExecutionOutputHandler capturedStderr = capturingHandler();
        int errno = source.getConnection().execute(loggingOutputHandler(logger), multiHandler(loggingErrorHandler(logger), capturedStderr), cmdLine);
        if (errno != 0) {
            throw new RuntimeIOException(format("Cannot copy [%s] to [%s] on [%s]: %s (errno=%d)", source.getPath(), getPath(), getConnection(), capturedStderr.getOutput(), errno));
        }
    }
View Full Code Here


    public LsResults getFileInfo() throws RuntimeIOException {
        logger.debug("Retrieving file info of {}", this);

        CmdLine lsCmdLine = CmdLine.build(NOCD_PSEUDO_COMMAND).addTemplatedFragment(connection.getFileInfoCommand, getPath());
        LsResults results = new LsResults();
        CapturingOverthereExecutionOutputHandler capturedOutput = capturingHandler();
        int errno = executeCommand(capturedOutput, swallow(), lsCmdLine);
        if (errno == 0) {
            for (int i = capturedOutput.getOutputLines().size() - 1; i >= 0; i--) {
                if (parseLsOutputLine(results, capturedOutput.getOutputLines().get(i))) {
                    results.exists = true;
                    break;
                }
            }

            if (!results.exists) {
                throw new RuntimeIOException("ls -ld " + getPath() + " returned " + errno + " but its output is unparseable: " + capturedOutput.getOutput());
            }
        } else {
            results.exists = false;
        }
View Full Code Here

    public List<OverthereFile> listFiles() {
        logger.debug("Listing directory {}", this);

        CmdLine lsCmdLine = build(NOCD_PSEUDO_COMMAND).addTemplatedFragment(connection.listFilesCommand, getPath());

        CapturingOverthereExecutionOutputHandler capturedStdout = capturingHandler();
        CapturingOverthereExecutionOutputHandler capturedStderr = capturingHandler();
        int errno = executeCommand(multiHandler(loggingOutputHandler(logger), capturedStdout), multiHandler(loggingErrorHandler(logger), capturedStderr), lsCmdLine);
        if (errno != 0) {
            throw new RuntimeIOException("Cannot list directory " + this + ": " + capturedStderr.getOutput() + " (errno=" + errno + ")");
        }

        List<OverthereFile> files = new ArrayList<OverthereFile>();
        for (String lsLine : capturedStdout.getOutputLines()) {
            // Filter out the '.' and '..'
View Full Code Here

            throw new RuntimeIOException("Cannot copy " + source + " to " + this + ": " + e.toString(), e);
        }
    }

    private void executeAndThrowOnErrorCode(CmdLine mkdirCmdLine, String message) {
        CapturingOverthereExecutionOutputHandler capturedStderr = capturingHandler();
        int errno = executeCommand(loggingOutputHandler(logger), multiHandler(loggingErrorHandler(logger), capturedStderr), mkdirCmdLine);
        if (errno != 0) {
            throw new RuntimeIOException(format("%s: %s (errno=%d)", message, capturedStderr.getOutput(), errno));
        }
    }
View Full Code Here

            logger.debug("Overriding umask by recursively setting permissions on files and/or directories copied with scp to be readable and executable (if needed) by group and other");

            CmdLine chmodCmdLine = CmdLine.build(NOELEVATION_PSEUDO_COMMAND, NOCD_PSEUDO_COMMAND)
                    .addTemplatedFragment(((SshElevatedUserConnection) connection).overrideUmaskCommand, remoteFile.getPath());

            CapturingOverthereExecutionOutputHandler capturedOutput = capturingHandler();
            int errno = connection.execute(loggingOutputHandler(logger), multiHandler(loggingErrorHandler(logger), capturedOutput), chmodCmdLine);
            if (errno != 0) {
                throw new RuntimeIOException("Cannot set permissions on file " + this + " to go+rX: " + capturedOutput.getOutput() + " (errno=" + errno + ")");
            }
        }
    }
View Full Code Here

        logger.debug("Copying actual file {} to temporary file {} before download", this, tempFile);

        CmdLine cpCmdLine = CmdLine.build(NOCD_PSEUDO_COMMAND)
                .addTemplatedFragment(((SshElevatedUserConnection) connection).copyToTempFileCommand, this.getPath(), tempFile.getPath());

        CapturingOverthereExecutionOutputHandler cpCapturedOutput = capturingHandler();
        int cpResult = getConnection().execute(multiHandler(loggingOutputHandler(logger), cpCapturedOutput), multiHandler(loggingErrorHandler(logger), cpCapturedOutput), cpCmdLine);
        if (cpResult != 0) {
            String errorMessage = cpCapturedOutput.getOutput();
            throw new RuntimeIOException("Cannot copy actual file " + this + " to temporary file " + tempFile + " before download: " + errorMessage);
        }

        CmdLine chmodCmdLine = CmdLine.build(NOCD_PSEUDO_COMMAND)
                .addTemplatedFragment(((SshElevatedUserConnection) connection).overrideUmaskCommand, tempFile.getPath());

        CapturingOverthereExecutionOutputHandler chmodCapturedOutput = capturingHandler();
        int chmodResult = getConnection().execute(multiHandler(loggingOutputHandler(logger), chmodCapturedOutput), multiHandler(loggingErrorHandler(logger), chmodCapturedOutput), chmodCmdLine);
        if (chmodResult != 0) {
            String errorMessage = chmodCapturedOutput.getOutput();
            throw new RuntimeIOException("Cannot grant group and other read and execute permissions (chmod -R go+rX) to file " + tempFile
                    + " before download: " + errorMessage);
        }
    }
View Full Code Here

        }

        CmdLine cpCmdLine = CmdLine.build(NOCD_PSEUDO_COMMAND)
                .addTemplatedFragment(((SshElevatedUserConnection) connection).copyFromTempFileCommand, tempFile.getPath(), targetPath);

        CapturingOverthereExecutionOutputHandler cpCapturedOutput = capturingHandler();
        int cpResult = getConnection().execute(multiHandler(loggingOutputHandler(logger), cpCapturedOutput), multiHandler(loggingErrorHandler(logger), cpCapturedOutput), cpCmdLine);

        if (cpResult != 0) {
            String errorMessage = cpCapturedOutput.getOutput();
            throw new RuntimeIOException("Cannot copy temporary file " + tempFile + " to actual file " + this + " after upload: " + errorMessage);
        }
    }
View Full Code Here

    }

    @Test
    @Assumption(methods = "onUnix")
    public void shouldExecuteSimpleCommandOnUnix() {
        CapturingOverthereExecutionOutputHandler captured = capturingHandler();
        int res = connection.execute(multiHandler(sysoutHandler(), captured), syserrHandler(), CmdLine.build("ls", "-ld", "/tmp/."));
        assertThat(res, equalTo(0));
        assertThat(captured.getOutput(), containsString("drwxrwxrwt"));
    }
View Full Code Here

    }

    @Test
    @Assumption(methods = "onUnix")
    public void shouldExecuteCommandWithSpecialCharactersOnUnix() {
        CapturingOverthereExecutionOutputHandler captured = capturingHandler();
        int res = connection.execute(multiHandler(sysoutHandler(), captured), syserrHandler(), CmdLine.build("echo", SPECIAL_CHARS_UNIX));
        assertThat(res, equalTo(0));
        for (int i = 0; i < SPECIAL_CHARS_UNIX.length(); i++) {
            assertThat(captured.getOutput().indexOf(SPECIAL_CHARS_UNIX.charAt(i)) >= 0, is(true));
        }
    }
View Full Code Here

    @Test
    @Assumption(methods = "onUnix")
    public void shouldExecuteSimpleCommandInWorkingDirectoryOnUnix() {
        connection.setWorkingDirectory(connection.getFile("/etc"));
        CapturingOverthereExecutionOutputHandler captured = capturingHandler();
        int res = connection.execute(multiHandler(sysoutHandler(), captured), syserrHandler(), CmdLine.build("pwd"));
        assertThat(res, equalTo(0));
        assertThat(captured.getOutput(), containsString("/etc"));
    }
View Full Code Here

TOP

Related Classes of com.xebialabs.overthere.util.CapturingOverthereExecutionOutputHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.