private CommandResult executeCommand ( final Commandline cmd , final boolean failOnError , final String argStr , final String ... args ) throws CommandLineException , MojoFailureException { // initialize executables initExecutables ( ) ; if ( getLog ( ) . isDebugEnabled ( ) ) { getLog ( ) . debug ( cmd . getExecutable ( ) + " " + StringUtils . join ( args , " " ) + ( argStr == null ? "" : " " + argStr ) ) ; } cmd . clearArgs ( ) ; cmd . addArguments ( args ) ; if ( StringUtils . isNotBlank ( argStr ) ) { cmd . createArg ( ) . setLine ( argStr ) ; } final StringBufferStreamConsumer out = new StringBufferStreamConsumer ( verbose ) ; final CommandLineUtils . StringStreamConsumer err = new CommandLineUtils . StringStreamConsumer ( ) ; // execute final int exitCode = CommandLineUtils . executeCommandLine ( cmd , out , err ) ; String errorStr = err . getOutput ( ) ; String outStr = out . getOutput ( ) ; if ( failOnError && exitCode != SUCCESS_EXIT_CODE ) { // not all commands print errors to error stream if ( StringUtils . isBlank ( errorStr ) && StringUtils . isNotBlank ( outStr ) ) { errorStr = outStr ; } throw new MojoFailureException ( errorStr ) ; } return new CommandResult ( exitCode , outStr , errorStr ) ; }
Executes command line .