src/main/java/com/digitalglobe/util/maven/plugin/ExecuteCommand.java
/**
     * Use this method to execute the command.
     */
Use this method to execute the command.
Use this method to execute the command .
void executeCommand()
    {
        List<Exception> errors = new ArrayList<>();
        try {
            ProcessBuilder pb = new ProcessBuilder(this.commandInformation);
            pb.environment().clear();
            pb.environment().putAll(this.environmentMap);
            Process process = pb.start();
            InputStream inputStream = process.getInputStream();
            InputStream errorStream = process.getErrorStream();
            this.inputStreamHandler = new StreamHandler(inputStream);
            this.errorStreamHandler = new StreamHandler(errorStream);
            this.inputStreamHandler.start();
            this.errorStreamHandler.start();
            process.waitFor();
            this.inputStreamHandler.join();
            this.errorStreamHandler.join();
            if(this.inputStreamHandler.getException() != null)
                errors.add(this.inputStreamHandler.getException());
            if(this.inputStreamHandler.getCloseException() != null)
                errors.add(this.inputStreamHandler.getCloseException());
            if(this.errorStreamHandler.getException() != null)
                errors.add(this.errorStreamHandler.getException());
            if(this.errorStreamHandler.getCloseException() != null)
                errors.add(this.errorStreamHandler.getCloseException());
        } catch (Exception ex) {
            try {
                if (this.inputStreamHandler != null) {
                    if (this.inputStreamHandler.getException() != null)
                        errors.add(this.inputStreamHandler.getException());
                    if (this.inputStreamHandler.getCloseException() != null)
                        errors.add(this.inputStreamHandler.getCloseException());
                }
                if(this.errorStreamHandler != null) {
                    if(this.errorStreamHandler.getException() != null)
                        errors.add(this.errorStreamHandler.getException());
                    if(this.errorStreamHandler.getCloseException() != null)
                        errors.add(this.errorStreamHandler.getCloseException());
                }
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
            errors.add(ex);
            System.out.println(ex.getMessage());
        }
        this.executionErrors = errors.size() > 0 ? (Exception[])errors.toArray() : null;
    }
void executeCommand ( ) { List < Exception > errors = new ArrayList < > ( ) ; try { ProcessBuilder pb = new ProcessBuilder ( this . commandInformation ) ; pb . environment ( ) . clear ( ) ; pb . environment ( ) . putAll ( this . environmentMap ) ; Process process = pb . start ( ) ; InputStream inputStream = process . getInputStream ( ) ; InputStream errorStream = process . getErrorStream ( ) ; this . inputStreamHandler = new StreamHandler ( inputStream ) ; this . errorStreamHandler = new StreamHandler ( errorStream ) ; this . inputStreamHandler . start ( ) ; this . errorStreamHandler . start ( ) ; process . waitFor ( ) ; this . inputStreamHandler . join ( ) ; this . errorStreamHandler . join ( ) ; if ( this . inputStreamHandler . getException ( ) != null ) errors . add ( this . inputStreamHandler . getException ( ) ) ; if ( this . inputStreamHandler . getCloseException ( ) != null ) errors . add ( this . inputStreamHandler . getCloseException ( ) ) ; if ( this . errorStreamHandler . getException ( ) != null ) errors . add ( this . errorStreamHandler . getException ( ) ) ; if ( this . errorStreamHandler . getCloseException ( ) != null ) errors . add ( this . errorStreamHandler . getCloseException ( ) ) ; } catch ( Exception ex ) { try { if ( this . inputStreamHandler != null ) { if ( this . inputStreamHandler . getException ( ) != null ) errors . add ( this . inputStreamHandler . getException ( ) ) ; if ( this . inputStreamHandler . getCloseException ( ) != null ) errors . add ( this . inputStreamHandler . getCloseException ( ) ) ; } if ( this . errorStreamHandler != null ) { if ( this . errorStreamHandler . getException ( ) != null ) errors . add ( this . errorStreamHandler . getException ( ) ) ; if ( this . errorStreamHandler . getCloseException ( ) != null ) errors . add ( this . errorStreamHandler . getCloseException ( ) ) ; } } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } errors . add ( ex ) ; System . out . println ( ex . getMessage ( ) ) ; } this . executionErrors = errors . size ( ) > 0 ? ( Exception [ ] ) errors . toArray ( ) : null ; }
Use this method to execute the command.
Use this method to execute the command .
// Reading from the process outputs in an asynchronous manner. // Note that the outputs of the process are inputs to this application thus they are input streams. // Make sure that we have read all the data from the streams. // Record any exceptions that where thrown. // Ignore