buildProjectExecutor.setBuildContextManager( buildContextManager );
buildProjectExecutor.setBuildAgentManager( buildAgentManager );
final BuildContext buildContext = createBuildContext();
final List<LocalRepository> localRepos = new ArrayList<LocalRepository>();
LocalRepository localRepo = createLocalRepository( "temp", "/tmp/.m2/repository", "default" );
localRepos.add( localRepo );
localRepo = createLocalRepository( "default", "/home/user/.m2/repository", "default" );
localRepos.add( localRepo );
final Map<String, String> masterBuildEnvironments = new HashMap<String, String>();
masterBuildEnvironments.put( "M2_HOME", "/tmp/apache-maven-2.2.1" );
final List<Installation> slaveBuildEnvironments = new ArrayList<Installation>();
Installation slaveBuildEnvironment = createInstallation( "M2_HOME", "/home/user/apache-maven-2.2.1" );
slaveBuildEnvironments.add( slaveBuildEnvironment );
slaveBuildEnvironment = createInstallation( "EXTRA_VAR", "/home/user/extra" );
slaveBuildEnvironments.add( slaveBuildEnvironment );
final ContinuumAgentBuildExecutor executor = context.mock( ContinuumAgentBuildExecutor.class );
final File workingDir = new File( "/tmp/data/working-directory/project-test" );
final MavenProject project = new MavenProject();
final File outputFile = new File( "/tmp/data/build-output-directory/output.txt" );
context.checking( new Expectations()
{
{
one( buildContextManager ).getBuildContext( 1 );
will( returnValue( buildContext ) );
one( buildAgentManager ).getEnvironments( 1, "maven2" );
will( returnValue( masterBuildEnvironments ) );
one( buildAgentConfigurationService ).getAvailableInstallations();
will( returnValue( slaveBuildEnvironments ) );
one( buildAgentConfigurationService ).getLocalRepositories();
will( returnValue( localRepos ) );
one( buildAgentManager ).shouldBuild( with( any( Map.class ) ) );
will( returnValue( true ) );
one( buildAgentBuildExecutorManager ).getBuildExecutor(
ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
will( returnValue( executor ) );
one( buildAgentConfigurationService ).getWorkingDirectory( 1 );
will( returnValue( workingDir ) );
one( executor ).getMavenProject( with( any( File.class ) ), with( any( BuildDefinition.class ) ) );
will( returnValue( project ) );
one( buildAgentManager ).startProjectBuild( 1 );
one( buildAgentConfigurationService ).getBuildOutputFile( 1 );
will( returnValue( outputFile ) );
one( buildAgentManager ).returnBuildResult( with( any( Map.class ) ) );
one( buildContextManager ).removeBuildContext( 1 );
}
} );
try
{
buildProjectExecutor.executeTask( createBuildProjectTask() );
Map<String, String> environments = (Map<String, String>) buildContext.getActionContext().get(
ContinuumBuildAgentUtil.KEY_ENVIRONMENTS );
assertEquals( 2, environments.size() );
assertTrue( environments.containsKey( "M2_HOME" ) );
assertTrue( environments.containsKey( "EXTRA_VAR" ) );
// shows that build agent's environment variables overwrites Continuum Master's environment variables