URL url;
ContinuumProjectBuilder projectBuilder = projectBuilderManager.getProjectBuilder( projectBuilderId );
ContinuumProjectBuildingResult result;
try
{
BuildDefinitionTemplate buildDefinitionTemplate = getBuildDefinitionTemplate( context );
if ( buildDefinitionTemplate == null )
{
buildDefinitionTemplate = projectBuilder.getDefaultBuildDefinitionTemplate();
}
if ( !curl.startsWith( "http" ) )
{
url = new URL( curl );
result = projectBuilder.buildProjectsFromMetadata( url, null, null, loadRecursiveProjects,
buildDefinitionTemplate );
}
else
{
url = new URL( curl );
String username = null;
String password = null;
try
{
Settings settings = getSettings();
getLogger().info( "checking for settings auth setup" );
if ( settings != null && settings.getServer( url.getHost() ) != null )
{
getLogger().info( "found setting based auth setup, using" );
Server server = settings.getServer( url.getHost() );
username = server.getUsername();
password = server.getPassword();
}
}
catch ( SettingsConfigurationException se )
{
getLogger().warn( "problem with settings file, disabling scm resolution of username and password" );
}
if ( username == null )
{
URLUserInfo urlUserInfo = urlValidator.extractURLUserInfo( curl );
username = urlUserInfo.getUsername();
password = urlUserInfo.getPassword();
}
if ( urlValidator.isValid( curl ) )
{
result = projectBuilder.buildProjectsFromMetadata( url, username, password, loadRecursiveProjects,
buildDefinitionTemplate );
}
else
{
result = new ContinuumProjectBuildingResult();
getLogger().info( "Malformed URL (MungedHttpsURL is not valid): " + hidePasswordInUrl( curl ) );
result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
}
}
if ( result.getProjects() != null )
{
String scmRootUrl = getScmRootUrl( result.getProjects() );
if ( scmRootUrl == null || scmRootUrl.equals( "" ) )
{
if ( curl.indexOf( "pom.xml" ) > 0 )
{
scmRootUrl = curl.substring( 0, curl.indexOf( "pom.xml" ) - 1 );
}
else
{
scmRootUrl = curl;
}
}
context.put( KEY_URL, scmRootUrl );
}
}
catch ( MalformedURLException e )
{
getLogger().info( "Malformed URL: " + hidePasswordInUrl( curl ), e );
result = new ContinuumProjectBuildingResult();
result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
}
catch ( URISyntaxException e )
{
getLogger().info( "Malformed URL: " + hidePasswordInUrl( curl ), e );
result = new ContinuumProjectBuildingResult();
result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
}
context.put( KEY_PROJECT_BUILDING_RESULT, result );
}