}
if ( firstProjectId != 0 )
{
BuildDefinition buildDef = projectsBuildDefinitionsMap.get( firstProjectId );
OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectsInGroupAreQueued( projectGroupId );
if ( overallBuildQueue == null )
{
overallBuildQueue = getOverallBuildQueue( BUILD_QUEUE, buildDef.getSchedule().getBuildQueues() );
}
if ( overallBuildQueue != null )
{
for ( Project project : projects )
{
try
{
if ( isInQueue( project.getId(), BUILD_QUEUE,
projectsBuildDefinitionsMap.get( project.getId() ).getId() ) )
{
log.warn( "Project '" + project.getId() + "' - '" + project.getName() +
"' is already in build queue." );
continue;
}
else if ( isProjectInAnyCurrentBuild( project.getId() ) )
{
log.warn( "Project '" + project.getId() + "' - '" + project.getName() +
"' is already building." );
continue;
}
}
catch ( TaskQueueException e )
{
log.warn( "Error occurred while verifying if project is already queued." );
continue;
}
BuildDefinition buildDefinition = projectsBuildDefinitionsMap.get( project.getId() );
String buildDefinitionLabel = buildDefinition.getDescription();
if ( StringUtils.isEmpty( buildDefinitionLabel ) )
{
buildDefinitionLabel = buildDefinition.getGoals();
}
ScmResult scmResult = scmResultMap.get( project.getId() );
BuildProjectTask buildTask =
new BuildProjectTask( project.getId(), buildDefinition.getId(), buildTrigger, project.getName(),
buildDefinitionLabel, scmResult, projectGroupId );
buildTask.setMaxExecutionTime( buildDefinition.getSchedule().getMaxJobExecutionTime() * 1000 );
try
{
log.info( "Project '" + project.getId() + "' - '" + project.getName() +
"' added to overall build queue '" + overallBuildQueue.getName() + "'." );
overallBuildQueue.addToBuildQueue( buildTask );
}
catch ( TaskQueueException e )
{
throw new BuildManagerException(
"Error occurred while adding project to build queue: " + e.getMessage() );