repositories.addAll( ( (Model) i.next() ).getRepositories() );
}
for ( Iterator i = repositories.iterator(); i.hasNext(); )
{
Repository remoteRepo = (Repository) i.next();
boolean snapshot = isSnapshot( dep );
if ( snapshot && !remoteRepo.isSnapshots() )
{
continue;
}
if ( !snapshot && !remoteRepo.isReleases() )
{
continue;
}
// The username and password parameters are not being used here.
String url = remoteRepo.getBasedir() + "/" + remoteRepo.getArtifactPath( dep );
// Attempt to retrieve the artifact and set the checksum if retrieval
// of the checksum file was successful.
try
{
String version = dep.getVersion();
if ( snapshot )
{
String filename = "maven-metadata-" + remoteRepo.getId() + ".xml";
File localFile = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(),
"maven-metadata-local.xml" );
File remoteFile = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), filename );
String metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(),
"maven-metadata.xml" );
String metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
log( "Downloading " + metaUrl );
try
{
HttpUtils.getFile( metaUrl, remoteFile, ignoreErrors, true, proxyHost, proxyPort, proxyUserName,
proxyPassword, false );
}
catch ( IOException e )
{
log( "WARNING: remote metadata version not found, using local: " + e.getMessage() );
remoteFile.delete();
}
File file = localFile;
if ( remoteFile.exists() )
{
if ( !localFile.exists() )
{
file = remoteFile;
}
else
{
RepositoryMetadata localMetadata = RepositoryMetadata.read( localFile );
RepositoryMetadata remoteMetadata = RepositoryMetadata.read( remoteFile );
if ( remoteMetadata.getLastUpdatedUtc() > localMetadata.getLastUpdatedUtc() )
{
file = remoteFile;
}
else
{
file = localFile;
}
}
}
if ( file.exists() )
{
log( "Using metadata: " + file );
RepositoryMetadata metadata = RepositoryMetadata.read( file );
if ( !file.equals( localFile ) )
{
version = metadata.constructVersion( version );
}
log( "Resolved version: " + version );
dep.setResolvedVersion( version );
if ( !version.endsWith( "SNAPSHOT" ) )
{
String ver =
version.substring( version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 );
String extension = url.substring( url.length() - 4 );
url = getSnapshotMetadataFile( url, ver + extension );
}
else if ( destinationFile.exists() )
{
// It's already there
return true;
}
}
}
if ( !"pom".equals( dep.getType() ) )
{
String name = dep.getArtifactId() + "-" + dep.getResolvedVersion() + ".pom";
File file = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), name );
file.getParentFile().mkdirs();
if ( !file.exists() || version.indexOf( "SNAPSHOT" ) >= 0 )
{
String filename = dep.getArtifactId() + "-" + version + ".pom";
String metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), filename );
String metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
log( "Downloading " + metaUrl );
try
{
HttpUtils.getFile( metaUrl, file, ignoreErrors, false, proxyHost, proxyPort, proxyUserName,