}
public int run( String[] cliArgs, Map<String, String> envVars, String workingDirectory, File logFile )
throws IOException, LauncherException
{
Commandline cmd = new Commandline();
cmd.setExecutable( executable );
if ( mavenHome != null )
{
cmd.addEnvironment( "M2_HOME", mavenHome );
}
if ( envVars != null )
{
for ( Map.Entry<String, String> envVar : envVars.entrySet() )
{
cmd.addEnvironment( envVar.getKey(), envVar.getValue() );
}
}
if ( envVars == null || envVars.get( "JAVA_HOME" ) == null )
{
cmd.addEnvironment( "JAVA_HOME", System.getProperty( "java.home" ) );
}
cmd.addEnvironment( "MAVEN_TERMINATE_CMD", "on" );
cmd.setWorkingDirectory( workingDirectory );
for ( String cliArg : cliArgs )
{
cmd.createArg().setValue( cliArg );
}
Writer logWriter = new FileWriter( logFile );
StreamConsumer out = new WriterStreamConsumer( logWriter );