brett 2005/03/29 21:24:50
Modified:
maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout
AbstractArtifactRepositoryLayout.java
maven-artifact/src/main/java/org/apache/maven/artifact/resolver
DefaultArtifactResolver.java
maven-artifact/src/main/java/org/apache/maven/artifact/transform
SnapshotTransformation.java
Log:
honour an installed SNAPSHOT in favour of the remote version, until a newer
remote version is deployed
Revision Changes Path
1.8 +1 -0
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java
Index: AbstractArtifactRepositoryLayout.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AbstractArtifactRepositoryLayout.java 29 Mar 2005 15:44:28 -0000
1.7
+++ AbstractArtifactRepositoryLayout.java 30 Mar 2005 05:24:50 -0000
1.8
@@ -82,6 +82,7 @@
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 )
1.34 +14 -14
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
Index: DefaultArtifactResolver.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- DefaultArtifactResolver.java 29 Mar 2005 16:41:13 -0000 1.33
+++ DefaultArtifactResolver.java 30 Mar 2005 05:24:50 -0000 1.34
@@ -77,6 +77,19 @@
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 @@
}
}
- 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
1.15 +27 -7
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java
Index: SnapshotTransformation.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- SnapshotTransformation.java 30 Mar 2005 04:52:01 -0000 1.14
+++ SnapshotTransformation.java 30 Mar 2005 05:24:50 -0000 1.15
@@ -24,6 +24,7 @@
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 @@
{
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 @@
}
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 @@
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 @@
}
}
- 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 );
}
}