From e622d5e323b93012d5daa8594eb43658fb34144c Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 30 Mar 2005 05:24:50 +0000 Subject: [PATCH] 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 --- .../AbstractArtifactRepositoryLayout.java | 1 + .../resolver/DefaultArtifactResolver.java | 28 +++++++-------- .../transform/SnapshotTransformation.java | 34 +++++++++++++++---- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java index 980fad70c6..2b7d204b56 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java @@ -82,6 +82,7 @@ public abstract class AbstractArtifactRepositoryLayout ArtifactHandler artifactHandler = null; 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() ); } catch ( ArtifactHandlerNotFoundException e ) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 59924d3fef..3e9dc905a2 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -77,6 +77,19 @@ public class DefaultArtifactResolver logger.debug( "Resolving: " + artifact.getId() + " from:\n" + "{localRepository: " + localRepository + "}\n" + "{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? for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); ) { @@ -91,20 +104,7 @@ public class DefaultArtifactResolver } } - String localPath; - - 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 ); - + File destination = artifact.getFile(); if ( !destination.exists() ) { try diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index b54418648e..5e353ed9a5 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; import org.codehaus.plexus.logging.AbstractLogEnabled; +import java.io.File; import java.io.IOException; import java.util.Calendar; import java.util.Date; @@ -54,9 +55,6 @@ public class SnapshotTransformation { 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; try { @@ -72,7 +70,8 @@ public class SnapshotTransformation } String version = localMetadata.constructVersion(); - if ( !alreadyResolved( artifact ) ) + boolean alreadyResolved = alreadyResolved( artifact ); + if ( !alreadyResolved ) { boolean checkedUpdates = false; for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) @@ -131,9 +130,23 @@ public class SnapshotTransformation 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 ( !version.equals( artifact.getBaseVersion() ) ) + if ( !version.equals( artifact.getBaseVersion() ) && !alreadyResolved ) { String message = artifact.getArtifactId() + ": resolved to version " + version; 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 ); } }