int trigger = getTrigger( context );
List updatedDependencies = getUpdatedDependencies( context );
ContinuumBuildExecutor buildExecutor = buildExecutorManager.getBuildExecutor( project.getExecutorId() );
// ----------------------------------------------------------------------
// Make the buildResult
// ----------------------------------------------------------------------
BuildResult buildResult = new BuildResult();
buildResult.setStartTime( new Date().getTime() );
buildResult.setState( ContinuumProjectState.BUILDING );
buildResult.setTrigger( trigger );
buildResult.setModifiedDependencies( updatedDependencies );
buildResult.setBuildDefinition( getBuildDefinition( context ) );
buildResultDao.addBuildResult( project, buildResult );
context.put( KEY_BUILD_ID, Integer.toString( buildResult.getId() ) );
context.put( KEY_CANCELLED, new Boolean( false ) );
buildResult = buildResultDao.getBuildResult( buildResult.getId() );
try
{
notifier.runningGoals( project, buildDefinition, buildResult );
File buildOutputFile = configurationService.getBuildOutputFile( buildResult.getId(), project.getId() );
ContinuumBuildExecutionResult result = buildExecutor.build( project, buildDefinition, buildOutputFile );
buildResult.setState( result.getExitCode() == 0 ? ContinuumProjectState.OK : ContinuumProjectState.FAILED );
buildResult.setExitCode( result.getExitCode() );
}
catch ( ContinuumBuildCancelledException e )
{
getLogger().info( "Cancelled build" );
buildResult.setState( ContinuumProjectState.CANCELLED );
context.put( KEY_CANCELLED, new Boolean( true ) );
}
catch ( Throwable e )
{
getLogger().error( "Error running buildResult", e );
buildResult.setState( ContinuumProjectState.ERROR );
buildResult.setError( ContinuumUtils.throwableToString( e ) );
}
finally
{
project = projectDao.getProject( project.getId() );
if ( buildResult.getState() == ContinuumProjectState.CANCELLED )
{
project.setState( project.getOldState() );
project.setOldState( 0 );
int buildResultId = getOldBuildId( context );
project.setLatestBuildId( buildResultId );
buildResultDao.removeBuildResult( buildResult );
}
else
{
buildResult.setEndTime( new Date().getTime() );
if ( buildResult.getState() == ContinuumProjectState.OK )
{
project.setBuildNumber( project.getBuildNumber() + 1 );
}
project.setLatestBuildId( buildResult.getId() );
buildResult.setBuildNumber( project.getBuildNumber() );
if ( buildResult.getState() != ContinuumProjectState.OK &&
buildResult.getState() != ContinuumProjectState.FAILED &&
buildResult.getState() != ContinuumProjectState.ERROR )
{
buildResult.setState( ContinuumProjectState.ERROR );
}
project.setState( buildResult.getState() );
// ----------------------------------------------------------------------
// Copy over the buildResult result
// ----------------------------------------------------------------------
buildResultDao.updateBuildResult( buildResult );
buildResult = buildResultDao.getBuildResult( buildResult.getId() );
notifier.goalsCompleted( project, buildDefinition, buildResult );
}
context.put( KEY_PROJECT, project );
projectDao.updateProject( project );
// ----------------------------------------------------------------------
// Backup test result files
// ----------------------------------------------------------------------
//TODO: Move as a plugin
buildExecutor.backupTestFiles( project, buildResult.getId() );
}
}