PR: MNG-613

make repository metadata behave more like snapshots with daily updates.
next step is to move the version checking to use that instead and fallback to the old files

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@266298 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-02 07:16:16 +00:00
parent a3a73ebaec
commit abd4ae6018
37 changed files with 551 additions and 720 deletions

View File

@ -1,5 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
@ -17,6 +17,11 @@
<artifactId>maven-artifact</artifactId> <artifactId>maven-artifact</artifactId>
<version>2.0-beta-1-SNAPSHOT</version> <version>2.0-beta-1-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>plexus</groupId> <groupId>plexus</groupId>
<artifactId>plexus-container-default</artifactId> <artifactId>plexus-container-default</artifactId>

View File

@ -71,6 +71,7 @@ public class DefaultArtifactDeployer
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); ) for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{ {
ArtifactMetadata metadata = (ArtifactMetadata) i.next(); ArtifactMetadata metadata = (ArtifactMetadata) i.next();
// TODO: method should be on repository?
metadata.storeInLocalRepository( localRepository ); metadata.storeInLocalRepository( localRepository );
// TODO: shouldn't need to calculate this // TODO: shouldn't need to calculate this
File f = new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( metadata ) ); File f = new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( metadata ) );

View File

@ -34,7 +34,9 @@ public class DefaultArtifactInstaller
{ {
private ArtifactTransformationManager transformationManager; private ArtifactTransformationManager transformationManager;
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */ /**
* @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly.
*/
public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository ) public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
throws ArtifactInstallationException throws ArtifactInstallationException
{ {
@ -68,7 +70,8 @@ public class DefaultArtifactInstaller
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); ) for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{ {
ArtifactMetadata metadata = (ArtifactMetadata) i.next(); ArtifactMetadata metadata = (ArtifactMetadata) i.next();
// TODO: method should be on repository?
metadata.storeInLocalRepository( localRepository ); metadata.storeInLocalRepository( localRepository );
} }
} }

View File

@ -21,7 +21,6 @@ import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.TransferFailedException;
@ -99,14 +98,6 @@ public class DefaultWagonManager
putRemoteFile( repository, source, repository.pathOfArtifactMetadata( artifactMetadata ), null ); putRemoteFile( repository, source, repository.pathOfArtifactMetadata( artifactMetadata ), null );
} }
public void putRepositoryMetadata( File source, RepositoryMetadata metadata, ArtifactRepository repository )
throws TransferFailedException
{
getLogger().info( "Uploading " + metadata );
putRemoteFile( repository, source, repository.pathOfRepositoryMetadata( metadata ), null );
}
private void putRemoteFile( ArtifactRepository repository, File source, String remotePath, private void putRemoteFile( ArtifactRepository repository, File source, String remotePath,
TransferListener downloadMonitor ) TransferListener downloadMonitor )
throws TransferFailedException throws TransferFailedException
@ -263,17 +254,6 @@ public class DefaultWagonManager
getRemoteFile( repository, destination, remotePath, null, checksumPolicy ); getRemoteFile( repository, destination, remotePath, null, checksumPolicy );
} }
public void getRepositoryMetadata( RepositoryMetadata metadata, ArtifactRepository remoteRepository,
File destination )
throws TransferFailedException, ResourceDoesNotExistException
{
String remotePath = remoteRepository.pathOfRepositoryMetadata( metadata );
getLogger().info( "Retrieving " + metadata );
getRemoteFile( remoteRepository, destination, remotePath, null, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
}
private void getRemoteFile( ArtifactRepository repository, File destination, String remotePath, private void getRemoteFile( ArtifactRepository repository, File destination, String remotePath,
TransferListener downloadMonitor, String checksumPolicy ) TransferListener downloadMonitor, String checksumPolicy )
throws TransferFailedException, ResourceDoesNotExistException, ChecksumFailedException throws TransferFailedException, ResourceDoesNotExistException, ChecksumFailedException

View File

@ -19,7 +19,6 @@ package org.apache.maven.artifact.manager;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException; import org.apache.maven.wagon.UnsupportedProtocolException;
@ -58,12 +57,6 @@ public interface WagonManager
String checksumPolicy ) String checksumPolicy )
throws TransferFailedException, ResourceDoesNotExistException; throws TransferFailedException, ResourceDoesNotExistException;
void putRepositoryMetadata( File source, RepositoryMetadata metadata, ArtifactRepository repository )
throws TransferFailedException;
void getRepositoryMetadata( RepositoryMetadata metadata, ArtifactRepository remoteRepository, File destination )
throws TransferFailedException, ResourceDoesNotExistException;
void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts ); void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey,

View File

@ -91,9 +91,13 @@ public class LatestArtifactMetadata
return Artifact.LATEST_VERSION; return Artifact.LATEST_VERSION;
} }
public boolean storedInArtifactDirectory() public boolean storedInArtifactVersionDirectory()
{ {
return false; return false;
} }
public boolean isSnapshot()
{
return false;
}
} }

View File

@ -99,9 +99,13 @@ public class ReleaseArtifactMetadata
return ReleaseArtifactTransformation.RELEASE_VERSION; return ReleaseArtifactTransformation.RELEASE_VERSION;
} }
public boolean storedInArtifactDirectory() public boolean storedInArtifactVersionDirectory()
{ {
return false; return false;
} }
public boolean isSnapshot()
{
return false;
}
} }

View File

@ -80,7 +80,7 @@ public class SnapshotArtifactMetadata
buildNumber = 0; buildNumber = 0;
} }
} }
public void setVersion( String timestamp, int buildNumber ) public void setVersion( String timestamp, int buildNumber )
{ {
this.timestamp = timestamp; this.timestamp = timestamp;
@ -91,7 +91,7 @@ public class SnapshotArtifactMetadata
{ {
return timestamp; return timestamp;
} }
public int getBuildNumber() public int getBuildNumber()
{ {
return buildNumber; return buildNumber;
@ -157,4 +157,19 @@ public class SnapshotArtifactMetadata
{ {
return "snapshot information for " + artifact.getArtifactId() + " " + artifact.getBaseVersion(); return "snapshot information for " + artifact.getArtifactId() + " " + artifact.getBaseVersion();
} }
public boolean storedInArtifactVersionDirectory()
{
return true;
}
public boolean isSnapshot()
{
return true;
}
public String getBaseVersion()
{
return artifact.getBaseVersion();
}
} }

View File

@ -19,7 +19,6 @@ package org.apache.maven.artifact.repository;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.wagon.repository.Repository; import org.apache.maven.wagon.repository.Repository;
/** /**
@ -82,11 +81,6 @@ public class DefaultArtifactRepository
return layout.pathOfArtifactMetadata( artifactMetadata ); return layout.pathOfArtifactMetadata( artifactMetadata );
} }
public String pathOfRepositoryMetadata( RepositoryMetadata metadata )
{
return layout.pathOfRepositoryMetadata( metadata );
}
public ArtifactRepositoryLayout getLayout() public ArtifactRepositoryLayout getLayout()
{ {
return layout; return layout;

View File

@ -17,14 +17,16 @@ package org.apache.maven.artifact.repository.metadata;
*/ */
import org.apache.maven.artifact.manager.WagonManager; 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.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.TransferFailedException;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.FileUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -38,106 +40,77 @@ public class DefaultRepositoryMetadataManager
private WagonManager wagonManager; private WagonManager wagonManager;
/** /**
* @todo very primitve. Probably we can cache artifacts themselves in a central location, as well as reset the flag over time in a long running process. * @todo very primitive. Probably we can cache artifacts themselves in a central location, as well as reset the flag over time in a long running process.
*/ */
private Set cachedMetadata = new HashSet(); private Set cachedMetadata = new HashSet();
public void resolve( RepositoryMetadata metadata, List repositories, ArtifactRepository local ) public void resolve( ArtifactMetadata metadata, List remoteRepositories, ArtifactRepository localRepository )
throws RepositoryMetadataManagementException throws ArtifactMetadataRetrievalException
{ {
boolean alreadyResolved = alreadyResolved( metadata ); boolean alreadyResolved = alreadyResolved( metadata );
if ( !alreadyResolved ) if ( !alreadyResolved )
{ {
for ( Iterator i = repositories.iterator(); i.hasNext(); ) File file = new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( metadata ) );
boolean checkedUpdates = false;
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{ {
ArtifactRepository repository = (ArtifactRepository) i.next(); ArtifactRepository repository = (ArtifactRepository) i.next();
// TODO: replace with a more general repository update mechanism like artifact metadata uses ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots()
// (Actually, this should now supersede artifact metadata...) : repository.getReleases();
File metadataFile = new File( local.getBasedir(), local.pathOfRepositoryMetadata( metadata ) );
if ( !metadataFile.exists() ) if ( policy == null || !policy.isEnabled() )
{ {
try getLogger().debug( "Skipping disabled repository " + repository.getId() );
{
try
{
wagonManager.getRepositoryMetadata( metadata, repository, metadataFile );
}
catch ( ResourceDoesNotExistException e )
{
if ( !metadataFile.exists() )
{
throw new RepositoryMetadataManagementException( metadata,
"Remote repository metadata not found.",
e );
}
else
{
String message = "Cannot find " + metadata +
" in remote repository - Using local copy.";
getLogger().info( message );
getLogger().debug( message, e );
}
}
}
catch ( TransferFailedException e )
{
throw new RepositoryMetadataManagementException( metadata,
"Failed to download repository metadata.", e );
}
} }
else else
{ {
getLogger().info( "Using local copy of " + metadata + " from: " + metadataFile ); // 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 );
}
catch ( ResourceDoesNotExistException e )
{
getLogger().info( "Repository metadata " + metadata +
" could not be found on repository: " + repository.getId(), e );
}
catch ( TransferFailedException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata", e );
}
}
} }
cachedMetadata.add( metadata.getRepositoryPath() );
} }
}
}
public void deploy( File source, RepositoryMetadata metadata, ArtifactRepository remote ) // touch the file if it was checked for updates, but don't create it if it doesn't exist to avoid
throws RepositoryMetadataManagementException // storing SNAPSHOT as the actual version which doesn't exist remotely.
{ if ( checkedUpdates )
try
{
wagonManager.putRepositoryMetadata( source, metadata, remote );
}
catch ( TransferFailedException e )
{
throw new RepositoryMetadataManagementException( metadata, "Failed to upload repository metadata.", e );
}
}
public void install( File source, RepositoryMetadata metadata, ArtifactRepository local )
throws RepositoryMetadataManagementException
{
File metadataFile = new File( local.getBasedir(), local.pathOfRepositoryMetadata( metadata ) );
try
{
File dir = metadataFile.getParentFile();
if ( !dir.exists() )
{ {
dir.mkdirs(); if ( file.exists() )
{
file.setLastModified( System.currentTimeMillis() );
}
} }
FileUtils.copyFile( source, metadataFile ); cachedMetadata.add( metadata.getKey() );
} }
catch ( IOException e )
{
throw new RepositoryMetadataManagementException( metadata, "Failed to install repository metadata.", e );
}
} }
private boolean alreadyResolved( RepositoryMetadata metadata ) private boolean alreadyResolved( ArtifactMetadata metadata )
{ {
return cachedMetadata.contains( metadata.getRepositoryPath() ); return cachedMetadata.contains( metadata.getKey() );
} }
} }

View File

@ -0,0 +1,216 @@
package org.apache.maven.artifact.repository.metadata;
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Metadata for the group directory of the repository.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
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();
public GroupRepositoryMetadata( String groupId )
{
this.groupId = groupId;
}
public String toString()
{
return "repository metadata for group: \'" + groupId + "\'";
}
public void storeInLocalRepository( ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
if ( !pluginMappings.isEmpty() )
{
try
{
updateRepositoryMetadata( localRepository );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( "Error updating group repository metadata", e );
}
}
}
public String getFilename()
{
return METADATA_FILE;
}
public boolean storedInGroupDirectory()
{
return true;
}
public boolean storedInArtifactVersionDirectory()
{
return false;
}
public String getGroupId()
{
return groupId;
}
public String getArtifactId()
{
return null;
}
public String getBaseVersion()
{
return null;
}
public void addPluginMapping( String goalPrefix, String artifactId )
{
pluginMappings.put( goalPrefix, artifactId );
}
private void updateRepositoryMetadata( ArtifactRepository localRepository )
throws IOException
{
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
Metadata pluginMap = null;
File metadataFile = new File( localRepository.getBasedir(), localRepository.pathOfArtifactMetadata( this ) );
if ( metadataFile.exists() )
{
Reader reader = null;
try
{
reader = new FileReader( metadataFile );
pluginMap = mappingReader.read( reader );
}
catch ( FileNotFoundException e )
{
// TODO: Log a warning
}
catch ( IOException e )
{
// TODO: Log a warning
}
catch ( XmlPullParserException e )
{
// TODO: Log a warning
}
finally
{
IOUtil.close( reader );
}
}
// If file could not be found or was not valid, start from scratch
if ( pluginMap == null )
{
pluginMap = new Metadata();
pluginMap.setGroupId( groupId );
}
for ( Iterator i = pluginMappings.keySet().iterator(); i.hasNext(); )
{
String prefix = (String) i.next();
boolean found = false;
for ( Iterator it = pluginMap.getPlugins().iterator(); it.hasNext() && !found; )
{
Plugin preExisting = (Plugin) it.next();
if ( preExisting.getPrefix().equals( prefix ) )
{
// TODO: log
// getLog().info( "Plugin-mapping metadata for prefix: " + prefix + " already exists. Skipping." );
found = true;
}
}
if ( !found )
{
Plugin mappedPlugin = new Plugin();
mappedPlugin.setArtifactId( (String) pluginMappings.get( prefix ) );
mappedPlugin.setPrefix( prefix );
pluginMap.addPlugin( mappedPlugin );
}
}
Writer writer = null;
try
{
writer = new FileWriter( metadataFile );
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
mappingWriter.write( writer, pluginMap );
}
finally
{
IOUtil.close( writer );
}
}
public Object getKey()
{
return groupId;
}
public boolean isSnapshot()
{
return false;
}
}

View File

@ -81,8 +81,8 @@ public class DefaultArtifactResolver
if ( !systemFile.exists() ) if ( !systemFile.exists() )
{ {
throw new ArtifactResolutionException( "System artifact: " + artifact.getId() throw new ArtifactResolutionException(
+ " not found in path: " + systemFile, artifact ); "System artifact: " + artifact.getId() + " not found in path: " + systemFile, artifact );
} }
else else
{ {
@ -90,7 +90,7 @@ public class DefaultArtifactResolver
} }
} }
// skip artifacts with a file - they are already resolved // skip artifacts with a file - they are already resolved
else if ( artifact.getFile() == null ) else if ( !artifact.isResolved() )
{ {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Check for the existence of the artifact in the specified local // Check for the existence of the artifact in the specified local
@ -129,8 +129,8 @@ public class DefaultArtifactResolver
if ( !artifact.isResolved() ) if ( !artifact.isResolved() )
{ {
throw new ArtifactResolutionException( throw new ArtifactResolutionException(
"Failed to resolve artifact, possibly due to a repository list that is not appropriately equipped for this artifact's metadata.", "Failed to resolve artifact, possibly due to a repository list that is not appropriately equipped for this artifact's metadata.",
artifact, remoteRepositories ); artifact, remoteRepositories );
} }
// must be after the artifact is downloaded // must be after the artifact is downloaded

View File

@ -19,6 +19,7 @@ package org.apache.maven.artifact.transform;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata; import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.VersionArtifactMetadata; import org.apache.maven.artifact.metadata.VersionArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
@ -51,6 +52,52 @@ public abstract class AbstractVersionTransformation
protected String resolveVersion( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) protected String resolveVersion( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException throws ArtifactMetadataRetrievalException
{
ArtifactMetadata localMetadata = resolveMetadata( artifact, localRepository, remoteRepositories );
String version;
if ( localMetadata == null )
{
version = artifact.getVersion();
}
else
{
VersionArtifactMetadata versionMetadata = (VersionArtifactMetadata) localMetadata;
version = versionMetadata.constructVersion();
}
// TODO: also do this logging for other metadata?
if ( getLogger().isDebugEnabled() )
{
if ( version != null && !version.equals( artifact.getBaseVersion() ) )
{
String message = artifact.getArtifactId() + ": resolved to version " + version;
if ( artifact.getRepository() != null )
{
message += " from repository " + artifact.getRepository().getId();
}
else
{
message += " from local repository";
}
getLogger().debug( message );
}
}
return version;
}
/**
* @param artifact
* @param localRepository
* @param remoteRepositories
* @return
* @throws ArtifactMetadataRetrievalException
* @todo share with DefaultRepositoryMetadataManager
*/
private ArtifactMetadata resolveMetadata( Artifact artifact, ArtifactRepository localRepository,
List remoteRepositories )
throws ArtifactMetadataRetrievalException
{ {
VersionArtifactMetadata localMetadata; VersionArtifactMetadata localMetadata;
try try
@ -116,9 +163,9 @@ public abstract class AbstractVersionTransformation
} }
} }
// touch the file if it was checked for updates, but don't create it if it doesn't exist to avoid // touch the file if it was checked for updates, but don't create it if it doesn't exist remotely to avoid
// storing SNAPSHOT as the actual version which doesn't exist remotely. // storing SNAPSHOT as the actual version which doesn't exist remotely.
if ( checkedUpdates && localMetadata.exists() ) if ( checkedUpdates && localMetadata.getLastModified().getTime() > 0 )
{ {
localMetadata.storeInLocalRepository( localRepository ); localMetadata.storeInLocalRepository( localRepository );
} }
@ -126,44 +173,22 @@ public abstract class AbstractVersionTransformation
resolvedArtifactCache.add( getCacheKey( artifact ) ); resolvedArtifactCache.add( getCacheKey( artifact ) );
} }
String version = localMetadata.constructVersion();
// TODO: if the POM and JAR are inconsistent, this might mean that different version of each are used // TODO: if the POM and JAR are inconsistent, this might mean that different version of each are used
if ( !artifact.getFile().exists() || localMetadata.newerThanFile( artifact.getFile() ) ) if ( artifact.getFile().exists() && !localMetadata.newerThanFile( artifact.getFile() ) )
{ {
if ( getLogger().isInfoEnabled() && !alreadyResolved ) if ( getLogger().isDebugEnabled() && !alreadyResolved )
{
if ( version != null && !version.equals( artifact.getBaseVersion() ) )
{
String message = artifact.getArtifactId() + ": resolved to version " + version;
if ( artifact.getRepository() != null )
{
message += " from repository " + artifact.getRepository().getId();
}
else
{
message += " from local repository";
}
getLogger().info( message );
}
}
return version;
}
else
{
if ( getLogger().isInfoEnabled() && !alreadyResolved )
{ {
// Locally installed file is newer, don't use the resolved version // Locally installed file is newer, don't use the resolved version
getLogger().info( artifact.getArtifactId() + ": using locally installed snapshot" ); getLogger().debug( artifact.getArtifactId() + ": using locally installed snapshot" );
} }
return artifact.getVersion(); localMetadata = null;
} }
return localMetadata;
} }
protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact, protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact,
ArtifactRepository remoteRepository, ArtifactRepository remoteRepository,
VersionArtifactMetadata localMetadata, ArtifactMetadata localMetadata,
String checksumPolicy ) String checksumPolicy )
throws ArtifactMetadataRetrievalException, ResourceDoesNotExistException throws ArtifactMetadataRetrievalException, ResourceDoesNotExistException
{ {

View File

@ -54,7 +54,8 @@ public class SnapshotTransformation
if ( artifact.isSnapshot() ) if ( artifact.isSnapshot() )
{ {
SnapshotArtifactMetadata metadata = new SnapshotArtifactMetadata( artifact ); SnapshotArtifactMetadata metadata = new SnapshotArtifactMetadata( artifact );
metadata.storeInLocalRepository( localRepository );
artifact.addMetadata( metadata );
} }
} }

View File

@ -41,10 +41,10 @@ public abstract class AbstractArtifactMetadata
{ {
return filename; return filename;
} }
public boolean storedInArtifactDirectory() public boolean storedInGroupDirectory()
{ {
return true; return false;
} }
public String getGroupId() public String getGroupId()
@ -62,9 +62,8 @@ public abstract class AbstractArtifactMetadata
return artifact.getVersion(); return artifact.getVersion();
} }
public String getBaseVersion() public Object getKey()
{ {
return artifact.getBaseVersion(); return artifact.getGroupId() + ":" + artifact.getArtifactId();
} }
} }

View File

@ -44,23 +44,26 @@ public interface ArtifactMetadata
*/ */
String getFilename(); String getFilename();
/**
* Whether the artifact metadata exists.
* @return true or false
*/
boolean exists();
/** /**
* Whether this metadata should be stored alongside the artifact. * Whether this metadata should be stored alongside the artifact.
*/ */
boolean storedInArtifactDirectory(); boolean storedInArtifactVersionDirectory();
/**
* Whether this metadata should be stored alongside the group.
*/
boolean storedInGroupDirectory();
String getGroupId(); String getGroupId();
String getArtifactId(); String getArtifactId();
String getVersion();
String getBaseVersion(); String getBaseVersion();
Object getKey();
/**
* @Todo delete?
*/
boolean isSnapshot();
} }

View File

@ -28,7 +28,6 @@ import java.util.Date;
public interface VersionArtifactMetadata public interface VersionArtifactMetadata
extends ArtifactMetadata, Comparable extends ArtifactMetadata, Comparable
{ {
/** /**
* Determine if the metadata is considered newer than a given file. * Determine if the metadata is considered newer than a given file.
* *

View File

@ -19,7 +19,6 @@ package org.apache.maven.artifact.repository;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
/** /**
* Specifies the repository used for artifact handling. * Specifies the repository used for artifact handling.
@ -33,8 +32,6 @@ public interface ArtifactRepository
String pathOfArtifactMetadata( ArtifactMetadata artifactMetadata ); String pathOfArtifactMetadata( ArtifactMetadata artifactMetadata );
String pathOfRepositoryMetadata( RepositoryMetadata metadata );
String getUrl(); String getUrl();
String getBasedir(); String getBasedir();

View File

@ -18,7 +18,6 @@ package org.apache.maven.artifact.repository.layout;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
/** /**
* @author jdcasey * @author jdcasey
@ -32,5 +31,4 @@ public interface ArtifactRepositoryLayout
String pathOfArtifactMetadata( ArtifactMetadata metadata ); String pathOfArtifactMetadata( ArtifactMetadata metadata );
String pathOfRepositoryMetadata( RepositoryMetadata metadata );
} }

View File

@ -19,7 +19,6 @@ package org.apache.maven.artifact.repository.layout;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
/** /**
* @author jdcasey * @author jdcasey
@ -62,10 +61,14 @@ public class DefaultRepositoryLayout
StringBuffer path = new StringBuffer(); StringBuffer path = new StringBuffer();
path.append( formatAsDirectory( metadata.getGroupId() ) ).append( PATH_SEPARATOR ); path.append( formatAsDirectory( metadata.getGroupId() ) ).append( PATH_SEPARATOR );
path.append( metadata.getArtifactId() ).append( PATH_SEPARATOR ); if ( !metadata.storedInGroupDirectory() )
if ( metadata.storedInArtifactDirectory() )
{ {
path.append( metadata.getBaseVersion() ).append( PATH_SEPARATOR ); path.append( metadata.getArtifactId() ).append( PATH_SEPARATOR );
if ( metadata.storedInArtifactVersionDirectory() )
{
path.append( metadata.getBaseVersion() ).append( PATH_SEPARATOR );
}
} }
path.append( metadata.getFilename() ); path.append( metadata.getFilename() );
@ -73,28 +76,6 @@ public class DefaultRepositoryLayout
return path.toString(); return path.toString();
} }
public String pathOfRepositoryMetadata( RepositoryMetadata metadata )
{
String file = metadata.getRepositoryPath();
String result;
int lastSlash = file.lastIndexOf( PATH_SEPARATOR );
if ( lastSlash > -1 )
{
String filePart = file.substring( lastSlash );
String dirPart = file.substring( 0, lastSlash );
result = formatAsDirectory( dirPart ) + filePart;
}
else
{
result = file;
}
return result;
}
private String formatAsDirectory( String directory ) private String formatAsDirectory( String directory )
{ {
return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR ); return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );

View File

@ -19,7 +19,6 @@ package org.apache.maven.artifact.repository.layout;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
/** /**
* @author jdcasey * @author jdcasey
@ -60,9 +59,4 @@ public class LegacyRepositoryLayout
return path.toString(); return path.toString();
} }
public String pathOfRepositoryMetadata( RepositoryMetadata metadata )
{
return metadata.getRepositoryPath();
}
} }

View File

@ -1,44 +0,0 @@
package org.apache.maven.artifact.repository.metadata;
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class GroupRepositoryMetadata
implements RepositoryMetadata
{
/**
* TODO: reuse.
*/
protected static final String METADATA_FILE = "maven-metadata.xml";
private final String groupId;
public GroupRepositoryMetadata( String groupId )
{
this.groupId = groupId;
}
public String getRepositoryPath()
{
return groupId + "/" + METADATA_FILE;
}
public String toString()
{
return "repository metadata for group: \'" + groupId + "\'";
}
}

View File

@ -1,23 +0,0 @@
package org.apache.maven.artifact.repository.metadata;
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public interface RepositoryMetadata
{
String getRepositoryPath();
}

View File

@ -1,54 +0,0 @@
package org.apache.maven.artifact.repository.metadata;/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class RepositoryMetadataManagementException
extends Exception
{
private final RepositoryMetadata metadata;
public RepositoryMetadataManagementException( RepositoryMetadata metadata, String message, Throwable cause )
{
super( "Failed to resolve repository metadata: " + metadata + ".\n\nOriginal message: " + message +
"\n\nError was: " + cause.getMessage(), cause );
this.metadata = metadata;
}
public RepositoryMetadataManagementException( RepositoryMetadata metadata, String message )
{
super( "Failed to resolve repository metadata: " + metadata + ".\n\nOriginal message: " + message );
this.metadata = metadata;
}
public RepositoryMetadataManagementException( String message )
{
super( message );
this.metadata = null;
}
public RepositoryMetadataManagementException( String message, Throwable cause )
{
super( message, cause );
this.metadata = null;
}
public RepositoryMetadata getMetadata()
{
return metadata;
}
}

View File

@ -16,21 +16,14 @@ package org.apache.maven.artifact.repository.metadata;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.File;
import java.util.List; import java.util.List;
public interface RepositoryMetadataManager public interface RepositoryMetadataManager
{ {
void resolve( ArtifactMetadata repositoryMetadata, List repositories, ArtifactRepository localRepository )
void resolve( RepositoryMetadata repositoryMetadata, List repositories, ArtifactRepository local ) throws ArtifactMetadataRetrievalException;
throws RepositoryMetadataManagementException;
void deploy( File source, RepositoryMetadata repositoryMetadata, ArtifactRepository remote )
throws RepositoryMetadataManagementException;
void install( File source, RepositoryMetadata repositoryMetadata, ArtifactRepository local )
throws RepositoryMetadataManagementException;
} }

View File

@ -61,5 +61,5 @@ public interface ArtifactTransformation
*/ */
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository ) void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException; throws ArtifactMetadataRetrievalException;
} }

View File

@ -23,7 +23,6 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -142,16 +141,9 @@ public class DefaultPluginManager
{ {
// TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other // TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other
// use for the mapping manager in here // use for the mapping manager in here
try return pluginMappingManager.getByPrefix( prefix, session.getSettings().getPluginGroups(),
{ project.getPluginArtifactRepositories(),
return pluginMappingManager.getByPrefix( prefix, session.getSettings().getPluginGroups(), session.getLocalRepository() );
project.getPluginArtifactRepositories(),
session.getLocalRepository() );
}
catch ( RepositoryMetadataManagementException e )
{
throw new PluginManagerException( "Error getting plugin prefix", e );
}
} }
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,

View File

@ -16,11 +16,11 @@ package org.apache.maven.plugin;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Plugin; import org.apache.maven.artifact.repository.metadata.Plugin;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
@ -54,7 +54,6 @@ public class DefaultPluginMappingManager
public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories, public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories,
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws RepositoryMetadataManagementException
{ {
// if not found, try from the remote repository // if not found, try from the remote repository
if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) ) if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) )
@ -85,7 +84,7 @@ public class DefaultPluginMappingManager
{ {
loadPluginMappings( groupId, pluginRepositories, localRepository ); loadPluginMappings( groupId, pluginRepositories, localRepository );
} }
catch ( RepositoryMetadataManagementException e ) catch ( ArtifactMetadataRetrievalException e )
{ {
getLogger().warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." ); getLogger().warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." );
@ -95,15 +94,15 @@ public class DefaultPluginMappingManager
} }
private void loadPluginMappings( String groupId, List pluginRepositories, ArtifactRepository localRepository ) private void loadPluginMappings( String groupId, List pluginRepositories, ArtifactRepository localRepository )
throws RepositoryMetadataManagementException throws ArtifactMetadataRetrievalException
{ {
GroupRepositoryMetadata metadata = new GroupRepositoryMetadata( groupId ); GroupRepositoryMetadata metadata = new GroupRepositoryMetadata( groupId );
// TOOD: aggregate the results of this instead // TODO: aggregate the results of this instead
repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository ); repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository );
File metadataFile = new File( localRepository.getBasedir(), File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfRepositoryMetadata( metadata ) ); localRepository.pathOfArtifactMetadata( metadata ) );
if ( metadataFile.exists() ) if ( metadataFile.exists() )
{ {
@ -132,7 +131,7 @@ public class DefaultPluginMappingManager
} }
private static Metadata readMetadata( File mappingFile ) private static Metadata readMetadata( File mappingFile )
throws RepositoryMetadataManagementException throws ArtifactMetadataRetrievalException
{ {
Metadata result; Metadata result;
@ -147,15 +146,15 @@ public class DefaultPluginMappingManager
} }
catch ( FileNotFoundException e ) catch ( FileNotFoundException e )
{ {
throw new RepositoryMetadataManagementException( "Cannot read plugin mappings from: " + mappingFile, e ); throw new ArtifactMetadataRetrievalException( "Cannot read plugin mappings from: " + mappingFile, e );
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new RepositoryMetadataManagementException( "Cannot read plugin mappings from: " + mappingFile, e ); throw new ArtifactMetadataRetrievalException( "Cannot read plugin mappings from: " + mappingFile, e );
} }
catch ( XmlPullParserException e ) catch ( XmlPullParserException e )
{ {
throw new RepositoryMetadataManagementException( "Cannot parse plugin mappings from: " + mappingFile, e ); throw new ArtifactMetadataRetrievalException( "Cannot parse plugin mappings from: " + mappingFile, e );
} }
finally finally
{ {

View File

@ -17,7 +17,6 @@ package org.apache.maven.plugin;
*/ */
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import java.util.List; import java.util.List;
@ -31,6 +30,5 @@ import java.util.List;
public interface PluginMappingManager public interface PluginMappingManager
{ {
Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories, Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories,
ArtifactRepository localRepository ) ArtifactRepository localRepository );
throws RepositoryMetadataManagementException;
} }

View File

@ -244,14 +244,8 @@
org.apache.maven.plugins:maven-jar-plugin:jar, org.apache.maven.plugins:maven-jar-plugin:jar,
org.apache.maven.plugins:maven-plugin-plugin:addPluginArtifactMetadata org.apache.maven.plugins:maven-plugin-plugin:addPluginArtifactMetadata
</package> </package>
<install> <install>org.apache.maven.plugins:maven-install-plugin:install</install>
org.apache.maven.plugins:maven-install-plugin:install, <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
org.apache.maven.plugins:maven-plugin-plugin:installMapping
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:deploy,
org.apache.maven.plugins:maven-plugin-plugin:deployMapping
</deploy>
</phases> </phases>
<!-- END SNIPPET: maven-plugin-lifecycle --> <!-- END SNIPPET: maven-plugin-lifecycle -->
</configuration> </configuration>

View File

@ -1,207 +0,0 @@
package org.apache.maven.plugin.plugin.metadata;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Plugin;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.EOFException;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
public abstract class AbstractPluginMappingMojo
extends AbstractMojo
{
/**
* @parameter
*/
private String goalPrefix;
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter expression="${project.build.outputDirectory}"
* @required
* @readonly
*/
private String classesDirectory;
/**
* @parameter expression="${project.build.directory}/repository-metadata"
* @required
* @readonly
*/
private String metadataOutputDirectory;
/**
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
private ArtifactRepository localRepository;
/**
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
* @required
* @readonly
*/
private RepositoryMetadataManager repositoryMetadataManager;
protected RepositoryMetadataManager getRepositoryMetadataManager()
{
return repositoryMetadataManager;
}
protected ArtifactRepository getLocalRepository()
{
return localRepository;
}
protected MavenProject getProject()
{
return project;
}
protected File updatePluginMap( RepositoryMetadata metadata )
throws MojoExecutionException
{
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
Metadata pluginMap = null;
File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfRepositoryMetadata( metadata ) );
if ( metadataFile.exists() )
{
Reader reader = null;
try
{
reader = new FileReader( metadataFile );
pluginMap = mappingReader.read( reader );
}
catch ( EOFException e )
{
getLog().warn( metadata + " located in: " + metadataFile + " seems to be corrupt - OVERWRITING." );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot read plugin-mapping metadata from file: " + metadataFile, e );
}
catch ( XmlPullParserException e )
{
throw new MojoExecutionException( "Cannot parse plugin-mapping metadata from file: " + metadataFile,
e );
}
finally
{
IOUtil.close( reader );
}
}
if ( pluginMap == null )
{
pluginMap = new Metadata();
pluginMap.setGroupId( project.getGroupId() );
}
for ( Iterator it = pluginMap.getPlugins().iterator(); it.hasNext(); )
{
Plugin preExisting = (Plugin) it.next();
if ( preExisting.getArtifactId().equals( project.getArtifactId() ) )
{
getLog().info(
"Plugin-mapping metadata for prefix: " + project.getArtifactId() + " already exists. Skipping." );
return null;
}
}
Plugin mappedPlugin = new Plugin();
mappedPlugin.setArtifactId( project.getArtifactId() );
mappedPlugin.setPrefix( getGoalPrefix() );
pluginMap.addPlugin( mappedPlugin );
Writer writer = null;
try
{
File generatedMetadataFile = new File( metadataOutputDirectory, metadata.getRepositoryPath() );
File dir = generatedMetadataFile.getParentFile();
if ( !dir.exists() )
{
dir.mkdirs();
}
writer = new FileWriter( generatedMetadataFile );
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
mappingWriter.write( writer, pluginMap );
return generatedMetadataFile;
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error writing repository metadata to build directory.", e );
}
finally
{
IOUtil.close( writer );
}
}
private String getGoalPrefix()
{
if ( goalPrefix == null )
{
goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
}
return goalPrefix;
}
}

View File

@ -2,39 +2,62 @@ package org.apache.maven.plugin.plugin.metadata;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.LatestArtifactMetadata; import org.apache.maven.artifact.metadata.LatestArtifactMetadata;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
/** Inject any plugin-specific artifact metadata to the project's artifact, for subsequent installation /**
* and deployment. The first use-case for this is to add the LATEST metadata (which is plugin-specific) * Inject any plugin-specific artifact metadata to the project's artifact, for subsequent installation
* for shipping alongside the plugin's artifact. * and deployment. The first use-case for this is to add the LATEST metadata (which is plugin-specific)
* * for shipping alongside the plugin's artifact.
*
* @phase package * @phase package
* @goal addPluginArtifactMetadata * @goal addPluginArtifactMetadata
*/ */
public class AddPluginArtifactMetadataMojo public class AddPluginArtifactMetadataMojo
extends AbstractMojo extends AbstractMojo
{ {
/** The project artifact, which should have the LATEST metadata added to it. /**
* * The project artifact, which should have the LATEST metadata added to it.
*
* @parameter expression="${project}" * @parameter expression="${project}"
* @required * @required
* @readonly * @readonly
*/ */
private MavenProject project; private MavenProject project;
/**
* @parameter
*/
private String goalPrefix;
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
{ {
Artifact projectArtifact = project.getArtifact(); Artifact projectArtifact = project.getArtifact();
LatestArtifactMetadata metadata = new LatestArtifactMetadata( projectArtifact ); LatestArtifactMetadata metadata = new LatestArtifactMetadata( projectArtifact );
metadata.setVersion( projectArtifact.getVersion() ); metadata.setVersion( projectArtifact.getVersion() );
projectArtifact.addMetadata( metadata ); projectArtifact.addMetadata( metadata );
GroupRepositoryMetadata groupMetadata = new GroupRepositoryMetadata( project.getGroupId() );
groupMetadata.addPluginMapping( getGoalPrefix(), project.getArtifactId() );
projectArtifact.addMetadata( groupMetadata );
} }
private String getGoalPrefix()
{
if ( goalPrefix == null )
{
goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
}
return goalPrefix;
}
} }

View File

@ -1,67 +0,0 @@
package org.apache.maven.plugin.plugin.metadata;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File;
import java.util.Collections;
/**
* @goal deployMapping
* @phase deploy
*/
public class PluginMappingDeployMojo
extends AbstractPluginMappingMojo
{
public void execute()
throws MojoExecutionException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( getProject().getGroupId() );
ArtifactRepository distributionRepository = getProject().getDistributionManagementArtifactRepository();
if ( distributionRepository == null )
{
throw new MojoExecutionException(
"No distribution repository specified. You must specify a <distributionManagement/> section with a valid <repository/> specified within." );
}
try
{
getRepositoryMetadataManager().resolve( metadata, Collections.singletonList( distributionRepository ),
getLocalRepository() );
File metadataFile = updatePluginMap( metadata );
if ( metadataFile != null )
{
getRepositoryMetadataManager().deploy( metadataFile, metadata, distributionRepository );
}
}
catch ( RepositoryMetadataManagementException e )
{
throw new MojoExecutionException( "Failed to install " + metadata, e );
}
}
}

View File

@ -1,54 +0,0 @@
package org.apache.maven.plugin.plugin.metadata;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File;
/**
* @goal installMapping
* @phase install
*/
public class PluginMappingInstallMojo
extends AbstractPluginMappingMojo
{
public void execute()
throws MojoExecutionException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( getProject().getGroupId() );
try
{
File metadataFile = updatePluginMap( metadata );
if ( metadataFile != null )
{
getRepositoryMetadataManager().install( metadataFile, metadata, getLocalRepository() );
}
}
catch ( RepositoryMetadataManagementException e )
{
throw new MojoExecutionException( "Failed to install " + metadata, e );
}
}
}

View File

@ -354,7 +354,7 @@ public class DefaultMavenProjectBuilder
artifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" ); artifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
try try
{ {
artifact.setFile( null ); artifact.setResolved( false );
artifactResolver.resolveAlways( artifact, remoteArtifactRepositories, localRepository ); artifactResolver.resolveAlways( artifact, remoteArtifactRepositories, localRepository );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
@ -581,7 +581,7 @@ public class DefaultMavenProjectBuilder
// We don't need all the project methods that are added over those in the model, but we do need basedir // We don't need all the project methods that are added over those in the model, but we do need basedir
Map context = new HashMap( System.getProperties() ); Map context = new HashMap( System.getProperties() );
context.put( "basedir", project.getBasedir() ); context.put( "basedir", project.getBasedir() );
model = modelInterpolator.interpolate( model, context ); model = modelInterpolator.interpolate( model, context );
// interpolation is before injection, because interpolation is off-limits in the injected variables // interpolation is before injection, because interpolation is off-limits in the injected variables

View File

@ -33,6 +33,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Date;
/** /**
* Attach a POM to an artifact. * Attach a POM to an artifact.
@ -53,12 +54,7 @@ public class ProjectArtifactMetadata
public String getFilename() public String getFilename()
{ {
return getArtifactId() + "-" + getVersion() + ".pom"; return getArtifactId() + "-" + artifact.getVersion() + ".pom";
}
public boolean exists()
{
return file.exists();
} }
public void storeInLocalRepository( ArtifactRepository localRepository ) public void storeInLocalRepository( ArtifactRepository localRepository )
@ -77,7 +73,7 @@ public class ProjectArtifactMetadata
MavenXpp3Reader modelReader = new MavenXpp3Reader(); MavenXpp3Reader modelReader = new MavenXpp3Reader();
Model model = modelReader.read( reader ); Model model = modelReader.read( reader );
model.setVersion( getVersion() ); model.setVersion( artifact.getVersion() );
DistributionManagement distributionManagement = model.getDistributionManagement(); DistributionManagement distributionManagement = model.getDistributionManagement();
if ( distributionManagement == null ) if ( distributionManagement == null )
@ -113,4 +109,29 @@ public class ProjectArtifactMetadata
{ {
return "project information for " + artifact.getArtifactId() + " " + artifact.getVersion(); return "project information for " + artifact.getArtifactId() + " " + artifact.getVersion();
} }
public boolean storedInArtifactVersionDirectory()
{
return true;
}
public String getBaseVersion()
{
return artifact.getBaseVersion();
}
public boolean newerThanFile( File file )
{
return this.file.lastModified() > file.lastModified();
}
public Date getLastModified()
{
return new Date( file.lastModified() );
}
public boolean isSnapshot()
{
return artifact.isSnapshot();
}
} }

View File

@ -19,6 +19,26 @@
<type>String</type> <type>String</type>
<description>The groupId that is directory represents, if any.</description> <description>The groupId that is directory represents, if any.</description>
</field> </field>
<field>
<name>artifactId</name>
<version>1.0.0</version>
<type>String</type>
<description>The artifactId that is directory represents, if any.</description>
</field>
<field>
<name>version</name>
<version>1.0.0</version>
<type>String</type>
<description>The version that is directory represents, if any.</description>
</field>
<field>
<name>versioning</name>
<version>1.0.0</version>
<association>
<type>Versioning</type>
</association>
<description>Versioning information for the artifact.</description>
</field>
<field> <field>
<name>plugins</name> <name>plugins</name>
<version>1.0.0</version> <version>1.0.0</version>
@ -30,6 +50,61 @@
</field> </field>
</fields> </fields>
</class> </class>
<class>
<name>Versioning</name>
<version>1.0.0</version>
<description>Versioning information for an artifact</description>
<fields>
<field>
<name>latest</name>
<version>1.0.0</version>
<type>String</type>
<description>What the latest version in the directory is, including snapshots</description>
</field>
<field>
<name>release</name>
<version>1.0.0</version>
<type>String</type>
<description>What the latest version in the directory is, of the releases</description>
</field>
<field>
<name>snapshot</name>
<version>1.0.0</version>
<association>
<type>Snapshot</type>
</association>
<description>The current snapshot data in use for this version</description>
</field>
<field>
<name>versions</name>
<version>1.0.0</version>
<description>Versions available for the artifact</description>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
<class>
<name>Snapshot</name>
<version>1.0.0</version>
<description>Snapshot data for the current version</description>
<fields>
<field>
<name>timestamp</name>
<version>1.0.0</version>
<description>The time it was deployed</description>
<type>String</type>
</field>
<field>
<name>buildNumber</name>
<version>1.0.0</version>
<description>The incremental build number</description>
<type>int</type>
</field>
</fields>
</class>
<class> <class>
<name>Plugin</name> <name>Plugin</name>
<version>1.0.0</version> <version>1.0.0</version>
@ -53,4 +128,4 @@
</fields> </fields>
</class> </class>
</classes> </classes>
</model> </model>