mirror of https://github.com/apache/maven.git
[MNG-4955] [regression] Outdated remote snapshots are preferred over locally installed snapshots
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1054651 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
88f67117cf
commit
12649ae4a7
|
@ -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 );
|
||||
|
|
|
@ -20,9 +20,14 @@ package org.apache.maven.repository.internal;
|
|||
*/
|
||||
|
||||
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()
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue