{
if ( checkProtocol )
{
if ( !urlValidator.validate( metadataUrl ) )
{
ContinuumProjectBuildingResult res = new ContinuumProjectBuildingResult();
res.addError( ContinuumProjectBuildingResult.ERROR_PROTOCOL_NOT_ALLOWED );
return res;
}
}
Map context = new HashMap();
context.put( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDER_ID, projectBuilderId );
context.put( CreateProjectsFromMetadataAction.KEY_URL, metadataUrl );
context.put( CreateProjectsFromMetadataAction.KEY_LOAD_RECURSIVE_PROJECTS, Boolean
.valueOf( loadRecursiveProjects ) );
context.put( CreateProjectsFromMetadataAction.KEY_SCM_USE_CREDENTIALS_CACHE, Boolean
.valueOf( useCredentialsCache ) );
context.put( AbstractContinuumAction.KEY_WORKING_DIRECTORY, getWorkingDirectory() );
// CreateProjectsFromMetadataAction will check null and use default
if ( buildDefintionTemplateId > 0 )
{
try
{
context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION_TEMPLATE, buildDefinitionService
.getBuildDefinitionTemplate( buildDefintionTemplateId ) );
}
catch ( BuildDefinitionServiceException e )
{
throw new ContinuumException( e.getMessage(), e );
}
}
// ----------------------------------------------------------------------
// Create the projects from the URL
// ----------------------------------------------------------------------
executeAction( "create-projects-from-metadata", context );
ContinuumProjectBuildingResult result = (ContinuumProjectBuildingResult) context
.get( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDING_RESULT );
if ( log.isInfoEnabled() )
{
if ( result.getProjects() != null )
{
log.info( "Created " + result.getProjects().size() + " projects." );
}
if ( result.getProjectGroups() != null )
{
log.info( "Created " + result.getProjectGroups().size() + " project groups." );
}
log.info( result.getErrors().size() + " errors." );
// ----------------------------------------------------------------------
// Look for any errors.
// ----------------------------------------------------------------------
if ( result.hasErrors() )
{
log.info( result.getErrors().size() + " errors during project add: " );
log.info( result.getErrorsAsString() );
return result;
}
}
// ----------------------------------------------------------------------
// Save any new project groups that we've found. Currently all projects
// will go into the first project group in the list.
// ----------------------------------------------------------------------
if ( result.getProjectGroups().size() != 1 )
{
throw new ContinuumException( "The project building result has to contain exactly one project group." );
}
ProjectGroup projectGroup = (ProjectGroup) result.getProjectGroups().iterator().next();
ProjectScmRoot projectScmRoot;
boolean projectGroupCreation = false;
try
{
if ( projectGroupId == -1 )
{
try
{
projectGroup = projectGroupDao.getProjectGroupByGroupId( projectGroup.getGroupId() );
projectGroupId = projectGroup.getId();
log.info(
"Using existing project group with the group id: '" + projectGroup.getGroupId() + "'." );
}
catch ( ContinuumObjectNotFoundException e )
{
log.info(
"Creating project group with the group id: '" + projectGroup.getGroupId() + "'." );
Map pgContext = new HashMap();
pgContext.put( AbstractContinuumAction.KEY_WORKING_DIRECTORY, getWorkingDirectory() );
pgContext.put( AbstractContinuumAction.KEY_UNVALIDATED_PROJECT_GROUP, projectGroup );
executeAction( "validate-project-group", pgContext );
executeAction( "store-project-group", pgContext );
projectGroupId = AbstractContinuumAction.getProjectGroupId( pgContext );
projectGroupCreation = true;
}
}
projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId( projectGroupId );
String url = (String) context.get( CreateProjectsFromMetadataAction.KEY_URL );
projectScmRoot = getProjectScmRootByProjectGroupAndScmRootAddress( projectGroup.getId(), url );
if ( projectScmRoot == null )
{
projectScmRoot = createProjectScmRoot( projectGroup, url );
}
/* add the project group loaded from database, which has more info, like id */
result.getProjectGroups().remove( 0 );
result.getProjectGroups().add( projectGroup );
}
catch ( ContinuumStoreException e )
{
throw new ContinuumException( "Error while querying for project group.", e );
}
// ----------------------------------------------------------------------
// Save all the projects if recursive mode asked
// TODO: Validate all the projects before saving them
// ----------------------------------------------------------------------
List<Project> projects = result.getProjects();
String scmUserName = null;
String scmPassword = null;
for ( Project project : projects )