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,78 +167,48 @@ public class ArtifactDownloader
file = remoteFile; file = remoteFile;
} }
} }
else
boolean found = false;
if ( file.exists() )
{
log( "Using metadata: " + file );
RepositoryMetadata metadata;
metadata = RepositoryMetadata.read( file );
if ( version.equals( metadata.getVersion() ) )
{
found = true;
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;
}
}
else
{
log( "WARNING: versions did not match, not using metadata (" + version + " vs " +
metadata.getVersion() + ")" );
}
}
if ( !found )
{ {
log( "WARNING: attempting to use legacy metadata" ); log( "WARNING: attempting to use legacy metadata" );
filename = getSnapshotMetadataFile( destinationFile.getName(), "SNAPSHOT.version.txt" ); filename = getSnapshotMetadataFile( destinationFile.getName(), "SNAPSHOT.version.txt" );
file = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), File f = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
dep.getType(), filename ); dep.getVersion(), dep.getType(), filename );
metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(), metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), filename ); dep.getVersion(), dep.getType(), filename );
metaUrl = remoteRepo.getBasedir() + "/" + metadataPath; metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
log( "Downloading " + metaUrl ); log( "Downloading " + metaUrl );
try try
{ {
HttpUtils.getFile( metaUrl, file, ignoreErrors, true, proxyHost, proxyPort, proxyUserName, HttpUtils.getFile( metaUrl, f, ignoreErrors, true, proxyHost, proxyPort, proxyUserName,
proxyPassword, false ); proxyPassword, false );
} }
catch ( IOException e ) catch ( IOException e )
{ {
log( "WARNING: remote SNAPSHOT version not found, using local: " + e.getMessage() ); log( "WARNING: remote SNAPSHOT version not found, using local: " + e.getMessage() );
f.delete();
} }
if ( file.exists() ) if ( f.exists() )
{ {
version = FileUtils.fileRead( file ); if ( !localFile.exists() || localFile.lastModified() < f.lastModified() )
log( "Resolved version: " + version );
dep.setResolvedVersion( version );
if ( !version.endsWith( "SNAPSHOT" ) )
{ {
String ver = version.substring( version = FileUtils.fileRead( f );
version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 ); log( "Resolved version: " + version );
String extension = url.substring( url.length() - 4 ); dep.setResolvedVersion( version );
url = getSnapshotMetadataFile( url, ver + extension ); if ( !version.endsWith( "SNAPSHOT" ) )
} {
else if ( destinationFile.exists() ) String ver = version.substring(
{ version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 );
// It's already there String extension = url.substring( url.length() - 4 );
return true; url = getSnapshotMetadataFile( url, ver + extension );
}
else if ( destinationFile.exists() )
{
// It's already there
return true;
}
legacy = true;
} }
} }
else else
@ -244,6 +216,29 @@ public class ArtifactDownloader
log( "WARNING: local SNAPSHOT version not found, using default" ); log( "WARNING: local SNAPSHOT version not found, using default" );
} }
} }
if ( !legacy && file.exists() )
{
log( "Using metadata: " + file );
RepositoryMetadata metadata = RepositoryMetadata.read( file );
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() ) ) if ( !"pom".equals( dep.getType() ) )
{ {