public void executeGoals( List<String> goals, Map<String, String> envVars )
throws VerificationException
{
if ( goals.size() == 0 )
{
throw new VerificationException( "No goals specified" );
}
List<String> allGoals = new ArrayList<String>();
if ( autoclean )
{
/*
* NOTE: Neither test lifecycle binding nor prefix resolution here but call the goal directly.
*/
allGoals.add( "org.apache.maven.plugins:maven-clean-plugin:clean" );
}
allGoals.addAll( goals );
Commandline cli = null;
int ret;
File logFile = new File( getBasedir(), getLogFileName() );
try
{
cli = createCommandLine();
for ( Iterator<String> i = envVars.keySet().iterator(); i.hasNext(); )
{
String key = i.next();
cli.addEnvironment( key, envVars.get( key ) );
/*
* What was the point of this? It doesn't work on windows. try { FileUtils.fileWrite( "/tmp/foo.txt",
* "setting envar[ " + key + " = " + envVars.get( key ) ); } catch ( IOException e ) {
* e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. }
*/
// System.out.println();
}
if ( envVars.get( "JAVA_HOME" ) == null )
{
cli.addEnvironment( "JAVA_HOME", System.getProperty( "java.home" ) );
}
cli.addEnvironment( "MAVEN_TERMINATE_CMD", "on" );
cli.setWorkingDirectory( getBasedir() );
for ( Iterator<String> it = cliOptions.iterator(); it.hasNext(); )
{
String key = String.valueOf( it.next() );
String resolvedArg = resolveCommandLineArg( key );
cli.createArgument().setLine( resolvedArg );
}
cli.createArgument().setValue( "-e" );
cli.createArgument().setValue( "--batch-mode" );
if ( this.mavenDebug )
{
cli.createArgument().setValue( "--debug" );
}
for ( Iterator<String> i = systemProperties.stringPropertyNames().iterator(); i.hasNext(); )
{
String key = (String) i.next();
String value = systemProperties.getProperty( key );
cli.createArgument().setValue( "-D" + key + "=" + value );
}
/*
* NOTE: Unless explicitly requested by the caller, the forked builds should use the current local
* repository. Otherwise, the forked builds would in principle leave the sandbox environment which has been
* setup for the current build. In particular, using "maven.repo.local" will make sure the forked builds use
* the same local repo as the parent build even if a custom user settings is provided.
*/
boolean useMavenRepoLocal =
Boolean.valueOf( verifierProperties.getProperty( "use.mavenRepoLocal", "true" ) ).booleanValue();
if ( useMavenRepoLocal )
{
cli.createArgument().setValue( "-Dmaven.repo.local=" + localRepo );
}
for ( Iterator<String> i = allGoals.iterator(); i.hasNext(); )
{
cli.createArgument().setValue( i.next() );
}
// System.out.println( "Command: " + Commandline.toString( cli.getCommandline() ) );
ret = runCommandLine( cli, logFile );
}
catch ( CommandLineException e )
{
throw new VerificationException( "Failed to execute Maven: " + cli, e );
}
catch ( IOException e )
{
throw new VerificationException( e );
}
if ( ret > 0 )
{
System.err.println( "Exit code: " + ret );
throw new VerificationException( "Exit code was non-zero: " + ret + "; command line and log = \n" + cli
+ "\n" + getLogContents( logFile, 75 ) );
}
}