make sure local snapshot is used in mboot

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280362 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-12 16:21:52 +00:00
parent c6dc853abb
commit 997774aa7b
1 changed files with 48 additions and 53 deletions

View File

@ -155,8 +155,10 @@ public class ArtifactDownloader
catch ( IOException e ) catch ( IOException e )
{ {
log( "WARNING: remote metadata version not found, using local: " + e.getMessage() ); log( "WARNING: remote metadata version not found, using local: " + e.getMessage() );
remoteFile.delete();
} }
boolean legacy = false;
File file = localFile; File file = localFile;
if ( remoteFile.exists() ) if ( remoteFile.exists() )
{ {
@ -165,18 +167,62 @@ public class ArtifactDownloader
file = remoteFile; file = remoteFile;
} }
} }
else
{
log( "WARNING: attempting to use legacy metadata" );
boolean found = false; filename = getSnapshotMetadataFile( destinationFile.getName(), "SNAPSHOT.version.txt" );
if ( file.exists() ) File f = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), filename );
metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), filename );
metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
log( "Downloading " + metaUrl );
try
{
HttpUtils.getFile( metaUrl, f, ignoreErrors, true, proxyHost, proxyPort, proxyUserName,
proxyPassword, false );
}
catch ( IOException e )
{
log( "WARNING: remote SNAPSHOT version not found, using local: " + e.getMessage() );
f.delete();
}
if ( f.exists() )
{
if ( !localFile.exists() || localFile.lastModified() < f.lastModified() )
{
version = FileUtils.fileRead( f );
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;
}
legacy = true;
}
}
else
{
log( "WARNING: local SNAPSHOT version not found, using default" );
}
}
if ( !legacy && file.exists() )
{ {
log( "Using metadata: " + file ); log( "Using metadata: " + file );
RepositoryMetadata metadata; RepositoryMetadata metadata = RepositoryMetadata.read( file );
metadata = RepositoryMetadata.read( file );
if ( version.equals( metadata.getVersion() ) )
{
found = true;
version = metadata.constructVersion( version ); version = metadata.constructVersion( version );
log( "Resolved version: " + version ); log( "Resolved version: " + version );
dep.setResolvedVersion( version ); dep.setResolvedVersion( version );
@ -193,57 +239,6 @@ public class ArtifactDownloader
return true; return true;
} }
} }
else
{
log( "WARNING: versions did not match, not using metadata (" + version + " vs " +
metadata.getVersion() + ")" );
}
}
if ( !found )
{
log( "WARNING: attempting to use legacy metadata" );
filename = getSnapshotMetadataFile( destinationFile.getName(), "SNAPSHOT.version.txt" );
file = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(),
dep.getType(), filename );
metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), filename );
metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
log( "Downloading " + metaUrl );
try
{
HttpUtils.getFile( metaUrl, file, ignoreErrors, true, proxyHost, proxyPort, proxyUserName,
proxyPassword, false );
}
catch ( IOException e )
{
log( "WARNING: remote SNAPSHOT version not found, using local: " + e.getMessage() );
}
if ( file.exists() )
{
version = FileUtils.fileRead( file );
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;
}
}
else
{
log( "WARNING: local SNAPSHOT version not found, using default" );
}
}
} }
if ( !"pom".equals( dep.getType() ) ) if ( !"pom".equals( dep.getType() ) )
{ {