PR: MNG-639

Separate local metadata by repository to ensure it remains consistent

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@267466 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-03 14:38:13 +00:00
parent 66869b1f65
commit 6a5e89785e
20 changed files with 204 additions and 84 deletions

View File

@ -72,9 +72,10 @@ public class DefaultArtifactDeployer
{
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
// TODO: method should be on repository?
metadata.storeInLocalRepository( localRepository );
metadata.storeInLocalRepository( localRepository, deploymentRepository );
// TODO: shouldn't need to calculate this
File f = new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( metadata ) );
File f = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
wagonManager.putArtifactMetadata( f, metadata, deploymentRepository );
}
}

View File

@ -72,7 +72,7 @@ public class DefaultArtifactInstaller
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
// TODO: method should be on repository?
metadata.storeInLocalRepository( localRepository );
metadata.storeInLocalRepository( localRepository, localRepository );
}
}
catch ( IOException e )

View File

@ -95,7 +95,7 @@ public class DefaultWagonManager
throws TransferFailedException
{
getLogger().info( "Uploading " + artifactMetadata );
putRemoteFile( repository, source, repository.pathOfArtifactMetadata( artifactMetadata ), null );
putRemoteFile( repository, source, repository.pathOfRemoteRepositoryMetadata( artifactMetadata ), null );
}
private void putRemoteFile( ArtifactRepository repository, File source, String remotePath,
@ -248,7 +248,7 @@ public class DefaultWagonManager
String checksumPolicy )
throws TransferFailedException, ResourceDoesNotExistException
{
String remotePath = repository.pathOfArtifactMetadata( metadata );
String remotePath = repository.pathOfRemoteRepositoryMetadata( metadata );
getLogger().info( "Retrieving " + metadata );
getRemoteFile( repository, destination, remotePath, null, checksumPolicy );

View File

@ -41,14 +41,15 @@ public abstract class AbstractVersionArtifactMetadata
protected long lastModified;
public AbstractVersionArtifactMetadata( Artifact artifact, String filename )
public AbstractVersionArtifactMetadata( Artifact artifact )
{
super( artifact, filename );
super( artifact );
}
protected File getLocalRepositoryLocation( ArtifactRepository localRepository )
protected File getLocalRepositoryLocation( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
{
return new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( this ) );
return new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
}
private void readFromFile( File file )
@ -70,10 +71,10 @@ public abstract class AbstractVersionArtifactMetadata
return new Date( lastModified );
}
public void readFromLocalRepository( ArtifactRepository localRepository )
public void readFromLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws IOException
{
File f = getLocalRepositoryLocation( localRepository );
File f = getLocalRepositoryLocation( localRepository, remoteRepository );
if ( f.exists() )
{
readFromFile( f );
@ -104,7 +105,7 @@ public abstract class AbstractVersionArtifactMetadata
}
}
public void storeInLocalRepository( ArtifactRepository localRepository )
public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
String version = constructVersion();
@ -112,7 +113,7 @@ public abstract class AbstractVersionArtifactMetadata
{
try
{
String path = getLocalRepositoryLocation( localRepository ).getPath();
String path = getLocalRepositoryLocation( localRepository, remoteRepository ).getPath();
File file = new File( path );
// TODO: this should be centralised before the resolution of the artifact
file.getParentFile().mkdirs();

View File

@ -17,6 +17,7 @@ package org.apache.maven.artifact.metadata;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.File;
@ -27,7 +28,22 @@ public class LatestArtifactMetadata
public LatestArtifactMetadata( Artifact artifact )
{
super( artifact, artifact.getArtifactId() + "-" + Artifact.LATEST_VERSION + "." + SNAPSHOT_VERSION_FILE );
super( artifact );
}
public String getRemoteFilename()
{
return getFilename();
}
public String getLocalFilename( ArtifactRepository repository )
{
return getFilename();
}
private String getFilename()
{
return artifact.getArtifactId() + "-" + Artifact.LATEST_VERSION + "." + SNAPSHOT_VERSION_FILE;
}
public String constructVersion()

View File

@ -17,6 +17,7 @@ package org.apache.maven.artifact.metadata;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.transform.ReleaseArtifactTransformation;
import java.io.File;
@ -35,7 +36,22 @@ public class ReleaseArtifactMetadata
public ReleaseArtifactMetadata( Artifact artifact )
{
super( artifact, artifact.getArtifactId() + "-RELEASE." + SNAPSHOT_VERSION_FILE );
super( artifact );
}
public String getRemoteFilename()
{
return getFilename();
}
public String getLocalFilename( ArtifactRepository repository )
{
return getFilename();
}
private String getFilename()
{
return artifact.getArtifactId() + "-RELEASE." + SNAPSHOT_VERSION_FILE;
}
public String constructVersion()

View File

@ -17,6 +17,7 @@ package org.apache.maven.artifact.metadata;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
@ -45,7 +46,22 @@ public class SnapshotArtifactMetadata
public SnapshotArtifactMetadata( Artifact artifact )
{
super( artifact, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + SNAPSHOT_VERSION_FILE );
super( artifact );
}
public String getRemoteFilename()
{
return getFilename();
}
public String getLocalFilename( ArtifactRepository repository )
{
return getFilename();
}
private String getFilename()
{
return artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + SNAPSHOT_VERSION_FILE;
}
public String constructVersion()

View File

@ -76,9 +76,14 @@ public class DefaultArtifactRepository
return layout.pathOf( artifact );
}
public String pathOfArtifactMetadata( ArtifactMetadata artifactMetadata )
public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
{
return layout.pathOfArtifactMetadata( artifactMetadata );
return layout.pathOfRemoteRepositoryMetadata( artifactMetadata );
}
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
return layout.pathOfLocalRepositoryMetadata( metadata, repository );
}
public ArtifactRepositoryLayout getLayout()
@ -95,4 +100,9 @@ public class DefaultArtifactRepository
{
return releases;
}
public String getKey()
{
return getId();
}
}

View File

@ -50,9 +50,6 @@ public class DefaultRepositoryMetadataManager
boolean alreadyResolved = alreadyResolved( metadata );
if ( !alreadyResolved )
{
File file = new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( metadata ) );
boolean checkedUpdates = false;
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) i.next();
@ -66,25 +63,35 @@ public class DefaultRepositoryMetadataManager
}
else
{
File file = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( metadata, repository ) );
// TODO: should be able to calculate this less often
boolean checkForUpdates = policy.checkOutOfDate( new Date( file.lastModified() ) );
if ( checkForUpdates )
{
checkedUpdates = true;
getLogger().info( metadata.getKey() + ": checking for updates from " + repository.getId() );
try
{
wagonManager.getArtifactMetadata( metadata, repository, file, policy.getChecksumPolicy() );
// TODO: ???
// metadata.setRepository( repository );
// touch file so that this is not checked again until interval has passed
if ( file.exists() )
{
file.setLastModified( System.currentTimeMillis() );
}
}
catch ( ResourceDoesNotExistException e )
{
getLogger().info( "Repository metadata " + metadata +
" could not be found on repository: " + repository.getId(), e );
" could not be found on repository: " + repository.getId() );
getLogger().debug( "Cause", e );
}
catch ( TransferFailedException e )
{
@ -94,16 +101,6 @@ public class DefaultRepositoryMetadataManager
}
}
// touch the file if it was checked for updates, but don't create it if it doesn't exist to avoid
// storing SNAPSHOT as the actual version which doesn't exist remotely.
if ( checkedUpdates )
{
if ( file.exists() )
{
file.setLastModified( System.currentTimeMillis() );
}
}
cachedMetadata.add( metadata.getKey() );
}
}

View File

@ -44,11 +44,6 @@ import java.util.Map;
public class GroupRepositoryMetadata
implements ArtifactMetadata
{
/**
* TODO: reuse.
*/
protected static final String METADATA_FILE = "maven-metadata.xml";
private final String groupId;
private Map pluginMappings = new HashMap();
@ -63,14 +58,14 @@ public class GroupRepositoryMetadata
return "repository metadata for group: \'" + groupId + "\'";
}
public void storeInLocalRepository( ArtifactRepository localRepository )
public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
if ( !pluginMappings.isEmpty() )
{
try
{
updateRepositoryMetadata( localRepository );
updateRepositoryMetadata( localRepository, remoteRepository );
}
catch ( IOException e )
{
@ -79,9 +74,14 @@ public class GroupRepositoryMetadata
}
}
public String getFilename()
public String getRemoteFilename()
{
return METADATA_FILE;
return "maven-metadata.xml";
}
public String getLocalFilename( ArtifactRepository repository )
{
return "maven-metadata-" + repository.getKey() + ".xml";
}
public boolean storedInGroupDirectory()
@ -114,14 +114,15 @@ public class GroupRepositoryMetadata
pluginMappings.put( goalPrefix, artifactId );
}
private void updateRepositoryMetadata( ArtifactRepository localRepository )
private void updateRepositoryMetadata( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws IOException
{
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
Metadata pluginMap = null;
File metadataFile = new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( this ) );
File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
if ( metadataFile.exists() )
{

View File

@ -19,7 +19,6 @@ package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -133,12 +132,14 @@ public class DefaultArtifactResolver
artifact, remoteRepositories );
}
/* TODO: pretty sure this can be removed. No metadata on resolved artifacts
// must be after the artifact is downloaded
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
metadata.storeInLocalRepository( localRepository );
}
*/
}
catch ( ResourceDoesNotExistException e )
{
@ -148,10 +149,6 @@ public class DefaultArtifactResolver
{
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
}
}
else if ( destination.exists() )
{

View File

@ -167,7 +167,8 @@ public abstract class AbstractVersionTransformation
// storing SNAPSHOT as the actual version which doesn't exist remotely.
if ( checkedUpdates && localMetadata.getLastModified().getTime() > 0 )
{
localMetadata.storeInLocalRepository( localRepository );
localMetadata.storeInLocalRepository( localRepository,
null ); // TODO: fix artifact repository - but this will be removed anyway
}
resolvedArtifactCache.add( getCacheKey( artifact ) );
@ -206,7 +207,8 @@ public abstract class AbstractVersionTransformation
{
// TODO: we could cache the results of this, perhaps inside the artifact repository?
AbstractVersionArtifactMetadata metadata = createMetadata( artifact );
metadata.readFromLocalRepository( localRepository );
metadata.readFromLocalRepository( localRepository,
null ); // TODO: fix artifact repository - but this will be removed anyway
return metadata;
}

View File

@ -17,6 +17,7 @@ package org.apache.maven.artifact.metadata;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* Common elements of artifact metadata.
@ -27,19 +28,13 @@ import org.apache.maven.artifact.Artifact;
public abstract class AbstractArtifactMetadata
implements ArtifactMetadata
{
protected final String filename;
protected Artifact artifact;
protected AbstractArtifactMetadata( Artifact artifact, String filename )
protected ArtifactRepository repository;
protected AbstractArtifactMetadata( Artifact artifact )
{
this.artifact = artifact;
this.filename = filename;
}
public String getFilename()
{
return filename;
}
public boolean storedInGroupDirectory()
@ -66,4 +61,9 @@ public abstract class AbstractArtifactMetadata
{
return artifact.getGroupId() + ":" + artifact.getArtifactId();
}
public void setRepository( ArtifactRepository repository )
{
this.repository = repository;
}
}

View File

@ -33,17 +33,11 @@ public interface ArtifactMetadata
* Store the metadata in the local repository.
*
* @param localRepository the local repository
* @param remoteRepository the remote repository it came from
*/
void storeInLocalRepository( ArtifactRepository localRepository )
void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException;
/**
* Get the filename of this metadata.
*
* @return the filename
*/
String getFilename();
/**
* Whether this metadata should be stored alongside the artifact.
*/
@ -63,7 +57,22 @@ public interface ArtifactMetadata
Object getKey();
/**
* @Todo delete?
* @todo delete?
*/
boolean isSnapshot();
/**
* Get the filename of this metadata on the local repository.
*
* @param repository the remote repository it came from
* @return the filename
*/
String getLocalFilename( ArtifactRepository repository );
/**
* Get the filename of this metadata on the remote repository.
*
* @return the filename
*/
String getRemoteFilename();
}

View File

@ -30,7 +30,9 @@ public interface ArtifactRepository
{
String pathOf( Artifact artifact );
String pathOfArtifactMetadata( ArtifactMetadata artifactMetadata );
String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata );
String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository );
String getUrl();
@ -45,4 +47,6 @@ public interface ArtifactRepository
ArtifactRepositoryPolicy getReleases();
ArtifactRepositoryLayout getLayout();
String getKey();
}

View File

@ -18,17 +18,18 @@ package org.apache.maven.artifact.repository.layout;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* @author jdcasey
*/
public interface ArtifactRepositoryLayout
{
String ROLE = ArtifactRepositoryLayout.class.getName();
String pathOf( Artifact artifact );
String pathOfArtifactMetadata( ArtifactMetadata metadata );
String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository );
String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata );
}

View File

@ -19,6 +19,7 @@ package org.apache.maven.artifact.repository.layout;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* @author jdcasey
@ -56,7 +57,12 @@ public class DefaultRepositoryLayout
return path.toString();
}
public String pathOfArtifactMetadata( ArtifactMetadata metadata )
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) );
}
private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename )
{
StringBuffer path = new StringBuffer();
@ -71,11 +77,16 @@ public class DefaultRepositoryLayout
}
}
path.append( metadata.getFilename() );
path.append( filename );
return path.toString();
}
public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata )
{
return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() );
}
private String formatAsDirectory( String directory )
{
return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );

View File

@ -19,6 +19,7 @@ package org.apache.maven.artifact.repository.layout;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* @author jdcasey
@ -26,6 +27,8 @@ import org.apache.maven.artifact.metadata.ArtifactMetadata;
public class LegacyRepositoryLayout
implements ArtifactRepositoryLayout
{
private static final String PATH_SEPARATOR = "/";
public String pathOf( Artifact artifact )
{
ArtifactHandler artifactHandler = artifact.getArtifactHandler();
@ -49,14 +52,25 @@ public class LegacyRepositoryLayout
return path.toString();
}
public String pathOfArtifactMetadata( ArtifactMetadata metadata )
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) );
}
private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename )
{
StringBuffer path = new StringBuffer();
path.append( metadata.getGroupId() ).append( "/poms/" );
path.append( metadata.getFilename() );
path.append( metadata.getGroupId() ).append( PATH_SEPARATOR ).append( "poms" ).append( PATH_SEPARATOR );
path.append( filename );
return path.toString();
}
public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata )
{
return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() );
}
}

View File

@ -98,11 +98,24 @@ public class DefaultPluginMappingManager
{
GroupRepositoryMetadata metadata = new GroupRepositoryMetadata( groupId );
// TODO: aggregate the results of this instead
repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository );
// TODO: can this go directly into the manager?
for ( Iterator i = pluginRepositories.iterator(); i.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) i.next();
loadRepositoryPluginMappings( metadata, repository, localRepository );
}
loadRepositoryPluginMappings( metadata, localRepository, localRepository );
}
private void loadRepositoryPluginMappings( GroupRepositoryMetadata metadata, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfArtifactMetadata( metadata ) );
localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) );
if ( metadataFile.exists() )
{
@ -120,7 +133,7 @@ public class DefaultPluginMappingManager
org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin();
plugin.setGroupId( groupId );
plugin.setGroupId( metadata.getGroupId() );
plugin.setArtifactId( artifactId );

View File

@ -48,19 +48,30 @@ public class ProjectArtifactMetadata
public ProjectArtifactMetadata( Artifact artifact, File file )
{
super( artifact, null );
super( artifact );
this.file = file;
}
public String getFilename()
public String getRemoteFilename()
{
return getFilename();
}
public String getLocalFilename( ArtifactRepository repository )
{
return getFilename();
}
private String getFilename()
{
return getArtifactId() + "-" + artifact.getVersion() + ".pom";
}
public void storeInLocalRepository( ArtifactRepository localRepository )
public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
File destination = new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( this ) );
File destination = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
destination.getParentFile().mkdirs();