{
int buildDefinitionId = ContinuumBuildConstant.getBuildDefinitionId( context );
int trigger = ContinuumBuildConstant.getTrigger( context );
Project project = projectDao.getProjectWithAllDetails( projectId );
BuildDefinition buildDefinition = buildDefinitionDao.getBuildDefinition( buildDefinitionId );
BuildResult oldBuildResult =
buildResultDao.getLatestBuildResultForBuildDefinition( projectId, buildDefinitionId );
List<ProjectDependency> modifiedDependencies = distributedBuildUtil.getModifiedDependencies( oldBuildResult, context );
List<ChangeSet> changes = distributedBuildUtil.getScmChanges( context );
if ( buildDefinition.isBuildFresh() )
{
log.info( "FreshBuild configured, building (projectId=" + projectId + ")" );
return true;
}
if ( buildDefinition.isAlwaysBuild() )
{
log.info( "AlwaysBuild configured, building (projectId=" + projectId + ")" );
return true;
}
if ( oldBuildResult == null )
{
log.info( "The project '" + projectId + "' was never built with the current build definition, building" );
return true;
}
//CONTINUUM-1428
if ( project.getOldState() == ContinuumProjectState.ERROR ||
oldBuildResult.getState() == ContinuumProjectState.ERROR )
{
log.info( "Latest state was 'ERROR', building (projectId=" + projectId + ")" );
return true;
}
if ( trigger == ContinuumProjectState.TRIGGER_FORCED )
{
log.info( "The project '" + projectId + "' build is forced, building" );
return true;
}
Date date = ContinuumBuildConstant.getLatestUpdateDate( context );
if ( date != null && oldBuildResult.getLastChangedDate() >= date.getTime() )
{
log.info( "No changes found, not building (projectId=" + projectId + ")" );
return false;
}
else if ( date != null && changes.isEmpty() )
{
// fresh checkout from build agent that's why changes is empty
log.info( "Changes found in the current project, building (projectId=" + projectId + ")" );
return true;
}
boolean shouldBuild = false;
boolean allChangesUnknown = true;
if ( project.getOldState() != ContinuumProjectState.NEW &&
project.getOldState() != ContinuumProjectState.CHECKEDOUT &&
project.getState() != ContinuumProjectState.NEW &&
project.getState() != ContinuumProjectState.CHECKEDOUT )
{
// Check SCM changes
allChangesUnknown = checkAllChangesUnknown( changes );
if ( allChangesUnknown )
{
if ( !changes.isEmpty() )
{
log.info( "The project '" + projectId +
"' was not built because all changes are unknown (maybe local modifications or ignored files not defined in your SCM tool." );
}
else
{
log.info( "The project '" + projectId +
"' was not built because no changes were detected in sources since the last build." );
}
}
// Check dependencies changes
if ( modifiedDependencies != null && !modifiedDependencies.isEmpty() )
{
log.info( "Found dependencies changes, building (projectId=" + projectId + ")" );
shouldBuild = true;
}
}
// Check changes
if ( !shouldBuild && ( ( !allChangesUnknown && !changes.isEmpty() ) ||
project.getExecutorId().equals( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR ) ) )
{
shouldBuild = shouldBuild( changes, buildDefinition, project, getMavenProjectVersion( context ),
getMavenProjectModules( context ) );
}