honour an installed SNAPSHOT in favour of the remote version, until a newer remote version is deployed

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163713 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-30 05:24:50 +00:00
parent 8fc9b6db13
commit e622d5e323
3 changed files with 42 additions and 21 deletions

View File

@ -82,6 +82,7 @@ public abstract class AbstractArtifactRepositoryLayout
ArtifactHandler artifactHandler = null; ArtifactHandler artifactHandler = null;
try try
{ {
// TODO: this is a poor excuse to have this method throwing an exception. Validate the artifact first, perhaps associate the handler with it
artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() );
} }
catch ( ArtifactHandlerNotFoundException e ) catch ( ArtifactHandlerNotFoundException e )

View File

@ -77,6 +77,19 @@ public class DefaultArtifactResolver
logger.debug( "Resolving: " + artifact.getId() + " from:\n" + "{localRepository: " + localRepository + "}\n" + logger.debug( "Resolving: " + artifact.getId() + " from:\n" + "{localRepository: " + localRepository + "}\n" +
"{remoteRepositories: " + remoteRepositories + "}" ); "{remoteRepositories: " + remoteRepositories + "}" );
String localPath;
try
{
localPath = localRepository.pathOf( artifact );
}
catch ( ArtifactPathFormatException e )
{
throw new ArtifactResolutionException( "Error resolving artifact: ", e );
}
artifact.setFile( new File( localRepository.getBasedir(), localPath ) );
// TODO: better to have a transform manager, or reuse the handler manager again so we don't have these requirements duplicated all over? // TODO: better to have a transform manager, or reuse the handler manager again so we don't have these requirements duplicated all over?
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); ) for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
{ {
@ -91,20 +104,7 @@ public class DefaultArtifactResolver
} }
} }
String localPath; File destination = artifact.getFile();
try
{
localPath = localRepository.pathOf( artifact );
}
catch ( ArtifactPathFormatException e )
{
throw new ArtifactResolutionException( "Error resolving artifact: ", e );
}
File destination = new File( localRepository.getBasedir(), localPath );
artifact.setFile( destination );
if ( !destination.exists() ) if ( !destination.exists() )
{ {
try try

View File

@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@ -54,9 +55,6 @@ public class SnapshotTransformation
{ {
if ( isSnapshot( artifact ) ) if ( isSnapshot( artifact ) )
{ {
// TODO: this mostly works, however...
// - we definitely need the manual/daily check as this is quite slow given the large number of snapshots inside m2 presently
SnapshotArtifactMetadata localMetadata; SnapshotArtifactMetadata localMetadata;
try try
{ {
@ -72,7 +70,8 @@ public class SnapshotTransformation
} }
String version = localMetadata.constructVersion(); String version = localMetadata.constructVersion();
if ( !alreadyResolved( artifact ) ) boolean alreadyResolved = alreadyResolved( artifact );
if ( !alreadyResolved )
{ {
boolean checkedUpdates = false; boolean checkedUpdates = false;
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
@ -131,9 +130,23 @@ public class SnapshotTransformation
localMetadata.storeInLocalRepository( localRepository ); localMetadata.storeInLocalRepository( localRepository );
} }
resolvedArtifactCache.add( getCacheKey( artifact ) );
}
// TODO: if the POM and JAR are inconsistent, this might mean that different version of each are used
if ( artifact.getFile().exists() && artifact.getFile().lastModified() > localMetadata.getLastModified() )
{
if ( !alreadyResolved )
{
// Locally installed file is newer, don't use the resolved version
getLogger().info( artifact.getArtifactId() + ": using locally installed snapshot" );
}
}
else
{
if ( getLogger().isInfoEnabled() ) if ( getLogger().isInfoEnabled() )
{ {
if ( !version.equals( artifact.getBaseVersion() ) ) if ( !version.equals( artifact.getBaseVersion() ) && !alreadyResolved )
{ {
String message = artifact.getArtifactId() + ": resolved to version " + version; String message = artifact.getArtifactId() + ": resolved to version " + version;
if ( artifact.getRepository() != null ) if ( artifact.getRepository() != null )
@ -148,9 +161,16 @@ public class SnapshotTransformation
} }
} }
resolvedArtifactCache.add( getCacheKey( artifact ) ); artifact.setVersion( version );
try
{
artifact.setFile( new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ) );
}
catch ( ArtifactPathFormatException e )
{
throw new ArtifactMetadataRetrievalException( "Error reading local metadata", e );
}
} }
artifact.setVersion( version );
} }
} }