Class CommandlineExecutor

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class CommandlineExecutor
    extends java.lang.Object
    implements java.io.Closeable
    Programming model with this class:
     
     try ( CommandlineExecutor exec = new CommandlineExecutor( cli, endOfStreamsCountdown );
           CommandlineStreams streams = exec.execute() )
     {
         // register exec in the shutdown hook to destroy pending process
    
         // register streams in the shutdown hook to close all three streams
    
         ReadableByteChannel stdOut = streams.getStdOutChannel();
         ReadableByteChannel stdErr = streams.getStdErrChannel();
         WritableByteChannel stdIn = streams.getStdInChannel();
         // lineConsumerThread = new LineConsumerThread( ..., stdErr, ..., endOfStreamsCountdown );
         // lineConsumerThread.start();
    
         // stdIn.write( ... );
    
         int exitCode = exec.awaitExit();
         // process exitCode
     }
     catch ( InterruptedException e )
     {
         lineConsumerThread.disable();
     }
     catch ( CommandLineException e )
     {
         // handle the exceptions
     }
      
    • Constructor Detail

      • CommandlineExecutor

        public CommandlineExecutor​(org.apache.maven.shared.utils.cli.Commandline cli,
                                   CountdownCloseable endOfStreamsCountdown)
    • Method Detail

      • execute

        public CommandlineStreams execute()
                                   throws org.apache.maven.shared.utils.cli.CommandLineException
        Throws:
        org.apache.maven.shared.utils.cli.CommandLineException
      • awaitExit

        public int awaitExit()
                      throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable