mirror of https://github.com/apache/maven.git
PR: MNG-230
create a local copy of the snapshot git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@292401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
04de595b24
commit
5404045229
|
@ -34,9 +34,11 @@ import java.io.FileReader;
|
|||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultRepositoryMetadataManager
|
||||
|
@ -100,6 +102,8 @@ public class DefaultRepositoryMetadataManager
|
|||
// TODO: this needs to be repeated here so the merging doesn't interfere with the written metadata
|
||||
// - we'd be much better having a pristine input, and an ongoing metadata for merging instead
|
||||
|
||||
Map previousMetadata = new HashMap();
|
||||
ArtifactRepository selected = null;
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
ArtifactRepository repository = (ArtifactRepository) i.next();
|
||||
|
@ -109,16 +113,68 @@ public class DefaultRepositoryMetadataManager
|
|||
|
||||
if ( policy.isEnabled() )
|
||||
{
|
||||
loadMetadata( metadata, repository, localRepository, true );
|
||||
if ( loadMetadata( metadata, repository, localRepository, previousMetadata ) )
|
||||
{
|
||||
metadata.setRepository( repository );
|
||||
selected = repository;
|
||||
}
|
||||
}
|
||||
}
|
||||
loadMetadata( metadata, localRepository, localRepository, false );
|
||||
if ( loadMetadata( metadata, localRepository, localRepository, previousMetadata ) )
|
||||
{
|
||||
selected = localRepository;
|
||||
}
|
||||
|
||||
// TODO: this could be a lot nicer... should really be in the snapshot transformation?
|
||||
if ( metadata.isSnapshot() )
|
||||
{
|
||||
Metadata prevMetadata = metadata.getMetadata();
|
||||
|
||||
for ( Iterator i = previousMetadata.keySet().iterator(); i.hasNext(); )
|
||||
{
|
||||
ArtifactRepository repository = (ArtifactRepository) i.next();
|
||||
Metadata m = (Metadata) previousMetadata.get( repository );
|
||||
if ( repository.equals( selected ) )
|
||||
{
|
||||
if ( m.getVersioning() == null )
|
||||
{
|
||||
m.setVersioning( new Versioning() );
|
||||
}
|
||||
|
||||
if ( m.getVersioning().getSnapshot() == null )
|
||||
{
|
||||
m.getVersioning().setSnapshot( new Snapshot() );
|
||||
}
|
||||
|
||||
if ( !m.getVersioning().getSnapshot().isLocalCopy() )
|
||||
{
|
||||
m.getVersioning().getSnapshot().setLocalCopy( true );
|
||||
metadata.setMetadata( m );
|
||||
metadata.storeInLocalRepository( localRepository, repository );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m.getVersioning() != null && m.getVersioning().getSnapshot() != null &&
|
||||
m.getVersioning().getSnapshot().isLocalCopy() )
|
||||
{
|
||||
m.getVersioning().getSnapshot().setLocalCopy( false );
|
||||
metadata.setMetadata( m );
|
||||
metadata.storeInLocalRepository( localRepository, repository );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
metadata.setMetadata( prevMetadata );
|
||||
}
|
||||
}
|
||||
|
||||
private void loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository,
|
||||
ArtifactRepository localRepository, boolean setRepository )
|
||||
private boolean loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository,
|
||||
ArtifactRepository localRepository, Map previousMetadata )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
boolean setRepository = false;
|
||||
|
||||
File metadataFile = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
|
||||
|
||||
|
@ -126,25 +182,22 @@ public class DefaultRepositoryMetadataManager
|
|||
{
|
||||
Metadata metadata = readMetadata( metadataFile );
|
||||
|
||||
if ( repoMetadata.isSnapshot() && previousMetadata != null )
|
||||
{
|
||||
previousMetadata.put( remoteRepository, metadata );
|
||||
}
|
||||
|
||||
if ( repoMetadata.getMetadata() != null )
|
||||
{
|
||||
if ( repoMetadata.getMetadata().merge( metadata ) )
|
||||
{
|
||||
if ( setRepository )
|
||||
{
|
||||
repoMetadata.setRepository( remoteRepository );
|
||||
}
|
||||
}
|
||||
setRepository = repoMetadata.getMetadata().merge( metadata );
|
||||
}
|
||||
else
|
||||
{
|
||||
repoMetadata.setMetadata( metadata );
|
||||
if ( setRepository )
|
||||
{
|
||||
repoMetadata.setRepository( remoteRepository );
|
||||
}
|
||||
setRepository = true;
|
||||
}
|
||||
}
|
||||
return setRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,8 +27,10 @@ import org.apache.maven.artifact.transform.ArtifactTransformationManager;
|
|||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||
import org.apache.maven.wagon.TransferFailedException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
@ -116,10 +118,10 @@ public class DefaultArtifactResolver
|
|||
if ( !wagonManager.isOnline() )
|
||||
{
|
||||
getLogger().debug( "System is offline. Cannot resolve artifact: " + artifact.getId() + "." );
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if ( artifact.getRepository() != null )
|
||||
|
@ -147,6 +149,23 @@ public class DefaultArtifactResolver
|
|||
{
|
||||
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
||||
}
|
||||
|
||||
if ( artifact.isSnapshot() && !artifact.getBaseVersion().equals( artifact.getVersion() ) )
|
||||
{
|
||||
String version = artifact.getVersion();
|
||||
artifact.selectVersion( artifact.getBaseVersion() );
|
||||
File copy = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
|
||||
try
|
||||
{
|
||||
FileUtils.copyFile( destination, copy );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ArtifactResolutionException( "Unable to copy resolved artifact for local use",
|
||||
artifact, remoteRepositories, e );
|
||||
}
|
||||
artifact.selectVersion( version );
|
||||
}
|
||||
}
|
||||
else if ( destination.exists() )
|
||||
{
|
||||
|
|
|
@ -107,15 +107,15 @@ public class SnapshotTransformation
|
|||
Snapshot snapshot = versioning.getSnapshot();
|
||||
if ( snapshot != null )
|
||||
{
|
||||
if ( snapshot.isLocalCopy() )
|
||||
{
|
||||
version = baseVersion;
|
||||
}
|
||||
else if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
|
||||
if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
|
||||
{
|
||||
String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
|
||||
version = StringUtils.replace( baseVersion, "SNAPSHOT", newVersion );
|
||||
}
|
||||
else
|
||||
{
|
||||
version = baseVersion;
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
|
|
@ -79,9 +79,9 @@
|
|||
mappedPlugin.setArtifactId( plugin.getArtifactId() );
|
||||
|
||||
mappedPlugin.setPrefix( plugin.getPrefix() );
|
||||
|
||||
|
||||
mappedPlugin.setName( plugin.getName() );
|
||||
|
||||
|
||||
addPlugin( mappedPlugin );
|
||||
|
||||
changed = true;
|
||||
|
@ -142,30 +142,22 @@
|
|||
changed = true;
|
||||
}
|
||||
|
||||
if ( snapshot.isLocalCopy() )
|
||||
// overwrite
|
||||
if ( s.getTimestamp() == null ? snapshot.getTimestamp() != null
|
||||
: !s.getTimestamp().equals( snapshot.getTimestamp() ) )
|
||||
{
|
||||
s.setLocalCopy( true );
|
||||
s.setTimestamp( null );
|
||||
s.setBuildNumber( 0 );
|
||||
s.setTimestamp( snapshot.getTimestamp() );
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
if ( s.getBuildNumber() != snapshot.getBuildNumber() )
|
||||
{
|
||||
if ( snapshot.getTimestamp() != null && !snapshot.getTimestamp().equals( s.getTimestamp() ) )
|
||||
{
|
||||
s.setTimestamp( snapshot.getTimestamp() );
|
||||
changed = true;
|
||||
}
|
||||
if ( snapshot.getBuildNumber() > 0 && s.getBuildNumber() != snapshot.getBuildNumber() )
|
||||
{
|
||||
s.setBuildNumber( snapshot.getBuildNumber() );
|
||||
changed = true;
|
||||
}
|
||||
if ( s.isLocalCopy() )
|
||||
{
|
||||
s.setLocalCopy( false );
|
||||
changed = true;
|
||||
}
|
||||
s.setBuildNumber( snapshot.getBuildNumber() );
|
||||
changed = true;
|
||||
}
|
||||
if ( s.isLocalCopy() != snapshot.isLocalCopy() )
|
||||
{
|
||||
s.setLocalCopy( snapshot.isLocalCopy() );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue