[MNG-1908] force an update check if there are legacy snapshots within the updatePolicy window

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@375485 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2006-02-07 04:52:06 +00:00
parent ac4a6e321f
commit 83c9eadb09
2 changed files with 129 additions and 80 deletions

View File

@ -349,6 +349,8 @@ public class DefaultWagonManager
File temp = new File( destination + ".tmp" ); File temp = new File( destination + ".tmp" );
temp.deleteOnExit(); temp.deleteOnExit();
boolean downloaded = false;
try try
{ {
wagon.connect( new Repository( repository.getId(), repository.getUrl() ), wagon.connect( new Repository( repository.getId(), repository.getUrl() ),
@ -366,8 +368,18 @@ public class DefaultWagonManager
retry = false; retry = false;
// This should take care of creating destination directory now on // This should take care of creating destination directory now on
if ( destination.exists() )
{
downloaded = wagon.getIfNewer( remotePath, temp, destination.lastModified() );
}
else
{
wagon.get( remotePath, temp ); wagon.get( remotePath, temp );
downloaded = true;
}
if ( downloaded )
{
// keep the checksum files from showing up on the download monitor... // keep the checksum files from showing up on the download monitor...
if ( downloadMonitor != null ) if ( downloadMonitor != null )
{ {
@ -431,6 +443,7 @@ public class DefaultWagonManager
{ {
wagon.addTransferListener( downloadMonitor ); wagon.addTransferListener( downloadMonitor );
} }
}
// unset the firstRun flag, so we don't get caught in an infinite loop... // unset the firstRun flag, so we don't get caught in an infinite loop...
firstRun = false; firstRun = false;
@ -455,6 +468,8 @@ public class DefaultWagonManager
releaseWagon( wagon ); releaseWagon( wagon );
} }
if ( downloaded )
{
if ( !temp.exists() ) if ( !temp.exists() )
{ {
throw new ResourceDoesNotExistException( "Downloaded file does not exist: " + temp ); throw new ResourceDoesNotExistException( "Downloaded file does not exist: " + temp );
@ -481,6 +496,7 @@ public class DefaultWagonManager
} }
} }
} }
}
private void failIfNotOnline() private void failIfNotOnline()
throws TransferFailedException throws TransferFailedException
@ -506,8 +522,8 @@ public class DefaultWagonManager
// otherwise it is ignore // otherwise it is ignore
} }
private void verifyChecksum( ChecksumObserver checksumObserver, File destination, File tempDestination, String remotePath, private void verifyChecksum( ChecksumObserver checksumObserver, File destination, File tempDestination,
String checksumFileExtension, Wagon wagon ) String remotePath, String checksumFileExtension, Wagon wagon )
throws ResourceDoesNotExistException, TransferFailedException, AuthorizationException throws ResourceDoesNotExistException, TransferFailedException, AuthorizationException
{ {
try try
@ -543,7 +559,10 @@ public class DefaultWagonManager
if ( expectedChecksum.equals( actualChecksum ) ) if ( expectedChecksum.equals( actualChecksum ) )
{ {
File checksumFile = new File( destination + checksumFileExtension ); File checksumFile = new File( destination + checksumFileExtension );
if ( checksumFile.exists() ) checksumFile.delete(); if ( checksumFile.exists() )
{
checksumFile.delete();
}
FileUtils.copyFile( tempChecksumFile, checksumFile ); FileUtils.copyFile( tempChecksumFile, checksumFile );
} }
else else
@ -724,7 +743,9 @@ public class DefaultWagonManager
} }
catch ( final ComponentLookupException e ) catch ( final ComponentLookupException e )
{ {
throw new WagonConfigurationException( repositoryId, "Unable to lookup wagon configurator. Wagon configuration cannot be applied.", e ); throw new WagonConfigurationException( repositoryId,
"Unable to lookup wagon configurator. Wagon configuration cannot be applied.",
e );
} }
catch ( ComponentConfigurationException e ) catch ( ComponentConfigurationException e )
{ {

View File

@ -21,6 +21,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.transform.ArtifactTransformationManager; import org.apache.maven.artifact.transform.ArtifactTransformationManager;
import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.ResourceDoesNotExistException;
@ -32,6 +33,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -104,6 +106,32 @@ public class DefaultArtifactResolver
transformationManager.transformForResolve( artifact, remoteRepositories, localRepository ); transformationManager.transformForResolve( artifact, remoteRepositories, localRepository );
File destination = artifact.getFile(); File destination = artifact.getFile();
List repositories = remoteRepositories;
// TODO: would prefer the snapshot transformation took care of this. Maybe we need a "shouldresolve" flag.
if ( artifact.isSnapshot() && artifact.getBaseVersion().equals( artifact.getVersion() ) &&
destination.exists() )
{
Date comparisonDate = new Date( destination.lastModified() );
// cull to list of repositories that would like an update
repositories = new ArrayList( remoteRepositories );
for ( Iterator i = repositories.iterator(); i.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) i.next();
ArtifactRepositoryPolicy policy = repository.getSnapshots();
if ( !policy.isEnabled() || !policy.checkOutOfDate( comparisonDate ) )
{
i.remove();
}
}
if ( !repositories.isEmpty() )
{
// someone wants to check for updates
force = true;
}
}
boolean resolved = false; boolean resolved = false;
if ( !destination.exists() || force ) if ( !destination.exists() || force )
{ {
@ -121,7 +149,7 @@ public class DefaultArtifactResolver
} }
else else
{ {
wagonManager.getArtifact( artifact, remoteRepositories ); wagonManager.getArtifact( artifact, repositories );
} }
if ( !artifact.isResolved() ) if ( !artifact.isResolved() )
@ -242,7 +270,7 @@ public class DefaultArtifactResolver
if ( missingArtifacts.size() > 0 ) if ( missingArtifacts.size() > 0 )
{ {
String message = "required artifacts missing:\n"; String message = "required artifacts missing:\n";
for( Iterator i=missingArtifacts.iterator(); i.hasNext(); ) for ( Iterator i = missingArtifacts.iterator(); i.hasNext(); )
{ {
Artifact missingArtifact = (Artifact) i.next(); Artifact missingArtifact = (Artifact) i.next();
message += " " + missingArtifact.getId() + "\n"; message += " " + missingArtifact.getId() + "\n";