org.codehaus.plexus.util.cli.StreamConsumer Java Examples

The following examples show how to use org.codehaus.plexus.util.cli.StreamConsumer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCommunityEnvFactory.java    From maven-native with MIT License 6 votes vote down vote up
protected Map<String, String> executeCommandLine(Commandline command) throws NativeBuildException
{
    EnvStreamConsumer stdout = new EnvStreamConsumer();
    StreamConsumer stderr = new DefaultConsumer();

    try
    {
        CommandLineUtils.executeCommandLine( command, stdout, stderr );
    }
    catch ( CommandLineException e )
    {
        throw new NativeBuildException( "Failed to execute vcvarsall.bat" );
    }

    return stdout.getParsedEnv();
}
 
Example #2
Source File: MavenProcessInvoker.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static Process executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr)
    throws CommandLineException {
    if (cl == null) {
        throw new IllegalArgumentException("the command line cannot be null.");
    } else {
        final Process p = cl.execute();
        final StreamPumper outputPumper = new StreamPumper(p.getInputStream(), systemOut);
        final StreamPumper errorPumper = new StreamPumper(p.getErrorStream(), systemErr);

        outputPumper.start();
        errorPumper.start();

        new Thread(() -> {
            try {
                // Wait for termination
                p.waitFor();
                outputPumper.waitUntilDone();
                errorPumper.waitUntilDone();
            } catch (Exception e) {
                outputPumper.disable();
                errorPumper.disable();
                e.printStackTrace();
            } finally {
                outputPumper.close();
                errorPumper.close();
            }
        }).start();

        return p;
    }
}
 
Example #3
Source File: MavenProcessInvoker.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static Process executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr)
    throws CommandLineException {
    if (cl == null) {
        throw new IllegalArgumentException("the command line cannot be null.");
    } else {
        final Process p = cl.execute();
        final StreamPumper outputPumper = new StreamPumper(p.getInputStream(), systemOut);
        final StreamPumper errorPumper = new StreamPumper(p.getErrorStream(), systemErr);

        outputPumper.start();
        errorPumper.start();

        new Thread(() -> {
            try {
                // Wait for termination
                p.waitFor();
                outputPumper.waitUntilDone();
                errorPumper.waitUntilDone();
            } catch (Exception e) {
                outputPumper.disable();
                errorPumper.disable();
                e.printStackTrace();
            } finally {
                outputPumper.close();
                errorPumper.close();
            }
        }).start();

        return p;
    }
}
 
Example #4
Source File: ScmUtils.java    From gitflow-helper-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static void execGitCmd(ScmLogger logger, StreamConsumer consumer, Commandline cl) throws ScmException {
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

    int exitCode = GitCommandLineUtils.execute(cl, consumer, stderr, logger);

    if (exitCode != 0)
    {
        throw new ScmException("Git command failed: " + stderr.getOutput());
    }
}
 
Example #5
Source File: AbstractMSVCEnvFactory.java    From maven-native with MIT License 4 votes vote down vote up
protected Map<String, String> createEnvs( String commonToolEnvKey, String platform )
    throws NativeBuildException
{

    File tmpEnvExecFile = null;
    try
    {
        File vsCommonToolDir = this.getCommonToolDirectory( commonToolEnvKey );

        File vsInstallDir = this.getVisualStudioInstallDirectory( vsCommonToolDir );

        if ( !vsInstallDir.isDirectory() )
        {
            throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." );
        }

        tmpEnvExecFile = this.createEnvWrapperFile( vsInstallDir, platform );

        Commandline cl = new Commandline();
        cl.setExecutable( tmpEnvExecFile.getAbsolutePath() );

        EnvStreamConsumer stdout = new EnvStreamConsumer();
        StreamConsumer stderr = new DefaultConsumer();

        CommandLineUtils.executeCommandLine( cl, stdout, stderr );

        return stdout.getParsedEnv();
    }
    catch ( Exception e )
    {
        throw new NativeBuildException( "Unable to retrieve env", e );
    }
    finally
    {
        if ( tmpEnvExecFile != null )
        {
            tmpEnvExecFile.delete();
        }
    }

}