Package org.arquillian.spacelift.process

Examples of org.arquillian.spacelift.process.ProcessResult


        // handle IO of spawned process
        Execution<ProcessResult> processConsumer = Tasks.chain(spawnedProcess, ConsumeProcessOutputTask.class)
            .programName(command.getProgramName()).interaction(interaction).execute();

        // wait for process to finish IO
        ProcessResult result = processConsumer.await();

        if (spawnedProcess.hasFailed()) {
            throw new ExecutionException("Invocation of \"{0}\" failed with {1}", new Object[] {
                command,
                result.exitValue() });
        }

        return result;
    }
View Full Code Here


    protected ProcessResult process(Execution<Process> runningProcess) throws Exception {

        Process process = runningProcess.await();

        final List<String> output = new ArrayList<String>();
        final ProcessResult result = new ProcessResultImpl(process, programName, output);
        final ProcessInteractionApplicator interaction = new ProcessInteractionApplicator(interactionDefinition, programName);
        final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        final OutputStream writer = new BufferedOutputStream(process.getOutputStream());

        // close process input stream if we don't need it
        // closed input stream is a requirement for process not to hang on windows
        if (!interaction.requiresInputInteraction()) {
            try {
                writer.close();
            } catch (IOException ignore) {
            }
        }

        try {
            // read character by character
            int i;
            boolean reachedEOF = false;

            // write initial text if any
            if (interaction.typesInitialText() != null) {
                writer.flush();
                writer.write(interaction.typesInitialText().getBytes());
                writer.flush();
                output.add(interaction.typesInitialText());
            }

            Sentence sentence = new SentenceImpl();
            // we have an extra check to figure out whether EOF was reached - using last expected response
            while (!reachedEOF && (i = reader.read()) != -1) {
                // add the character
                sentence.append((char) i);

                boolean shouldTerminate = interaction.shouldTerminate(sentence);
                String answer = interaction.repliesTo(sentence);
                // sentence was not empty, reply
                if (answer != null) {
                    sentence.append(answer);
                    writer.flush();
                    writer.write(answer.getBytes());
                    writer.flush();
                }
                if (shouldTerminate) {
                    runningProcess.markAsFinished();
                    runningProcess.terminate();
                }

                reachedEOF = runningProcess.isMarkedAsFinished();

                // save and print output
                if (sentence.isFinished()) {
                    sentence.trim();
                    log.log(Level.FINEST, "({0}): {1}", new Object[] { result.processName(), sentence });

                    output.add(sentence.toString());
                    // propagate output/error to user
                    if (interaction.shouldOutput(sentence)) {
                        System.out.println(interaction.transform(sentence));
                    }
                    if (interaction.shouldOutputToErr(sentence)) {
                        System.err.println(interaction.transform(sentence));
                    }
                    sentence.reset();
                }
            }

            // handle last line
            if (!sentence.isEmpty()) {
                log.log(Level.FINEST, "{0} outputs: {1}", new Object[] { result.processName(), sentence });

                output.add(sentence.toString());
                // propagate output/error to user
                if (interaction.shouldOutput(sentence)) {
                    System.out.println(interaction.transform(sentence));
View Full Code Here

TOP

Related Classes of org.arquillian.spacelift.process.ProcessResult

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.