maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r1054651 - in /maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal: DefaultVersionResolver.java LocalSnapshotMetadata.java LocalSnapshotMetadataGenerator.java
Date Mon, 03 Jan 2011 15:30:57 GMT
Author: bentmann
Date: Mon Jan  3 15:30:55 2011
New Revision: 1054651

URL: http://svn.apache.org/viewvc?rev=1054651&view=rev
Log:
[MNG-4955] [regression] Outdated remote snapshots are preferred over locally installed snapshots

Modified:
    maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
    maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java
    maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java

Modified: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java?rev=1054651&r1=1054650&r2=1054651&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
(original)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
Mon Jan  3 15:30:55 2011
@@ -240,8 +240,9 @@ public class DefaultVersionResolver
             }
             else
             {
-                if ( !resolve( result, infos, SNAPSHOT + getKey( artifact.getClassifier(),
artifact.getExtension() ) )
-                    && !resolve( result, infos, SNAPSHOT ) )
+                String key = SNAPSHOT + getKey( artifact.getClassifier(), artifact.getExtension()
);
+                merge( infos, SNAPSHOT, key );
+                if ( !resolve( result, infos, key ) )
                 {
                     result.setVersion( version );
                 }
@@ -363,7 +364,7 @@ public class DefaultVersionResolver
         }
 
         Snapshot snapshot = versioning.getSnapshot();
-        if ( snapshot != null )
+        if ( snapshot != null && versioning.getSnapshotVersions().isEmpty() )
         {
             String version = artifact.getVersion();
             if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() >
0 )
@@ -391,6 +392,18 @@ public class DefaultVersionResolver
         }
     }
 
+    private void merge( Map<String, VersionInfo> infos, String srcKey, String dstKey
)
+    {
+        VersionInfo srcInfo = infos.get( srcKey );
+        VersionInfo dstInfo = infos.get( dstKey );
+
+        if ( dstInfo == null
+            || ( srcInfo != null && dstInfo.isOutdated( srcInfo.timestamp ) &&
srcInfo.repository != dstInfo.repository ) )
+        {
+            infos.put( dstKey, srcInfo );
+        }
+    }
+
     private String getKey( String classifier, String extension )
     {
         return StringUtils.clean( classifier ) + ':' + StringUtils.clean( extension );

Modified: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java?rev=1054651&r1=1054650&r2=1054651&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java
(original)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java
Mon Jan  3 15:30:55 2011
@@ -20,9 +20,14 @@ package org.apache.maven.repository.inte
  */
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 import org.apache.maven.artifact.repository.metadata.Metadata;
 import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.apache.maven.artifact.repository.metadata.SnapshotVersion;
 import org.apache.maven.artifact.repository.metadata.Versioning;
 import org.sonatype.aether.artifact.Artifact;
 
@@ -33,21 +38,23 @@ final class LocalSnapshotMetadata
     extends MavenMetadata
 {
 
-    private final Artifact artifact;
+    private final Collection<Artifact> artifacts = new ArrayList<Artifact>();
 
-    public LocalSnapshotMetadata( Artifact artifact )
+    private final boolean legacyFormat;
+
+    public LocalSnapshotMetadata( Artifact artifact, boolean legacyFormat )
     {
-        super( createMetadata( artifact ), null );
-        this.artifact = artifact;
+        super( createMetadata( artifact, legacyFormat ), null );
+        this.legacyFormat = legacyFormat;
     }
 
-    public LocalSnapshotMetadata( Artifact artifact, File file )
+    public LocalSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat )
     {
-        super( createMetadata( artifact ), file );
-        this.artifact = artifact;
+        super( metadata, file );
+        this.legacyFormat = legacyFormat;
     }
 
-    private static Metadata createMetadata( Artifact artifact )
+    private static Metadata createMetadata( Artifact artifact, boolean legacyFormat )
     {
         Snapshot snapshot = new Snapshot();
         snapshot.setLocalCopy( true );
@@ -60,12 +67,22 @@ final class LocalSnapshotMetadata
         metadata.setArtifactId( artifact.getArtifactId() );
         metadata.setVersion( artifact.getBaseVersion() );
 
+        if ( !legacyFormat )
+        {
+            metadata.setModelVersion( "1.1.0" );
+        }
+
         return metadata;
     }
 
+    public void bind( Artifact artifact )
+    {
+        artifacts.add( artifact );
+    }
+
     public MavenMetadata setFile( File file )
     {
-        return new LocalSnapshotMetadata( artifact, file );
+        return new LocalSnapshotMetadata( metadata, file, legacyFormat );
     }
 
     public Object getKey()
@@ -82,21 +99,60 @@ final class LocalSnapshotMetadata
     protected void merge( Metadata recessive )
     {
         metadata.getVersioning().updateTimestamp();
+
+        if ( !legacyFormat )
+        {
+            String lastUpdated = metadata.getVersioning().getLastUpdated();
+
+            Map<String, SnapshotVersion> versions = new LinkedHashMap<String, SnapshotVersion>();
+
+            for ( Artifact artifact : artifacts )
+            {
+                SnapshotVersion sv = new SnapshotVersion();
+                sv.setClassifier( artifact.getClassifier() );
+                sv.setExtension( artifact.getExtension() );
+                sv.setVersion( getVersion() );
+                sv.setUpdated( lastUpdated );
+                versions.put( getKey( sv.getClassifier(), sv.getExtension() ), sv );
+            }
+
+            Versioning versioning = recessive.getVersioning();
+            if ( versioning != null )
+            {
+                for ( SnapshotVersion sv : versioning.getSnapshotVersions() )
+                {
+                    String key = getKey( sv.getClassifier(), sv.getExtension() );
+                    if ( !versions.containsKey( key ) )
+                    {
+                        versions.put( key, sv );
+                    }
+                }
+            }
+
+            metadata.getVersioning().setSnapshotVersions( new ArrayList<SnapshotVersion>(
versions.values() ) );
+        }
+
+        artifacts.clear();
+    }
+
+    private String getKey( String classifier, String extension )
+    {
+        return classifier + ':' + extension;
     }
 
     public String getGroupId()
     {
-        return artifact.getGroupId();
+        return metadata.getGroupId();
     }
 
     public String getArtifactId()
     {
-        return artifact.getArtifactId();
+        return metadata.getArtifactId();
     }
 
     public String getVersion()
     {
-        return artifact.getBaseVersion();
+        return metadata.getVersion();
     }
 
     public Nature getNature()

Modified: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java?rev=1054651&r1=1054650&r2=1054651&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java
(original)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java
Mon Jan  3 15:30:55 2011
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+import org.sonatype.aether.ConfigurationProperties;
 import org.sonatype.aether.RepositorySystemSession;
 import org.sonatype.aether.artifact.Artifact;
 import org.sonatype.aether.impl.MetadataGenerator;
@@ -39,8 +40,12 @@ class LocalSnapshotMetadataGenerator
 
     private Map<Object, LocalSnapshotMetadata> snapshots;
 
+    private final boolean legacyFormat;
+
     public LocalSnapshotMetadataGenerator( RepositorySystemSession session, InstallRequest
request )
     {
+        legacyFormat = ConfigurationProperties.get( session.getConfigProperties(), "maven.metadata.legacy",
false );
+
         snapshots = new LinkedHashMap<Object, LocalSnapshotMetadata>();
     }
 
@@ -54,9 +59,10 @@ class LocalSnapshotMetadataGenerator
                 LocalSnapshotMetadata snapshotMetadata = snapshots.get( key );
                 if ( snapshotMetadata == null )
                 {
-                    snapshotMetadata = new LocalSnapshotMetadata( artifact );
+                    snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat
);
                     snapshots.put( key, snapshotMetadata );
                 }
+                snapshotMetadata.bind( artifact );
             }
         }
 



Mime
View raw message