ScmResult scmResult = getScmResult( context );
List<ProjectDependency> 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( buildTrigger.getTrigger() );
buildResult.setUsername( buildTrigger.getUsername() );
buildResult.setScmResult( scmResult );
buildResult.setModifiedDependencies( updatedDependencies );
buildResult.setBuildDefinition( getBuildDefinition( context ) );
buildResultDao.addBuildResult( project, buildResult );
AbstractContinuumAction.setBuildId( context, Integer.toString( buildResult.getId() ) );
setCancelled( context, 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 );
setCancelled( context, 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 );
}
AbstractContinuumAction.setProject( context, project );
projectDao.updateProject( project );
// ----------------------------------------------------------------------
// Backup test result files
// ----------------------------------------------------------------------
//TODO: Move as a plugin
buildExecutor.backupTestFiles( project, buildResult.getId() );
}
}