Resolving:

MNG-511
MNG-513

Working on:

MNG-449

o Added code to stop the version manager from prompting the user for unregistered plugins; it will simply register them with the resolved version.

o Added failover fourth plugin-version resolution option, which is a plugin-specific artifact metadata called LATEST.version.txt, and will be published with each install/deployment

o Added MavenProject.get/setArtifact(..) to handle a single artifact instance for a project (allows injection of artifact metadata without having to handle it all within the install/deploy mojos).

o Changed plugin-version resolution to only use MavenMetadataSource rather than resolving the whole plugin artifact.

o Changed the install and deploy mojos to only use ${project.artifact} rather than constructing their own, so they can take advantage of metadata added elsewhere in the build.

o Factored the "RELEASE".equals(..) check in the DefaultRepositoryLayout to use new metadata method storedInArtifactDirectory() instead, since RELEASE and LATEST both share this characteristic.


NOTE: I'm not going to resolve MNG-449 yet, because I'm not sure what else Brett had in mind related to the plugin-development-without-release use case...



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@215919 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-07-12 04:13:40 +00:00
parent 4b53aba3bb
commit cb257db78e
17 changed files with 326 additions and 98 deletions

View File

@ -75,6 +75,7 @@ public void install( File source, Artifact artifact, ArtifactRepository localRep
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
metadata.storeInLocalRepository( localRepository );
}
}

View File

@ -0,0 +1,85 @@
package org.apache.maven.artifact.metadata;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.transform.LatestArtifactTransformation;
import java.io.File;
public class LatestArtifactMetadata
extends AbstractVersionArtifactMetadata
{
private String version;
public LatestArtifactMetadata( Artifact artifact )
{
super( artifact, artifact.getArtifactId() + "-" + LatestArtifactTransformation.LATEST_VERSION + "." + SNAPSHOT_VERSION_FILE );
}
public String constructVersion()
{
return version;
}
public int compareTo( Object o )
{
LatestArtifactMetadata metadata = (LatestArtifactMetadata) o;
// TODO: we need some more complicated version comparison
if ( version == null )
{
if ( metadata.version == null )
{
return 0;
}
else
{
return -1;
}
}
else
{
if ( metadata.version == null )
{
return 1;
}
else
{
return version.compareTo( metadata.version );
}
}
}
public boolean newerThanFile( File file )
{
long fileTime = file.lastModified();
return ( lastModified > fileTime );
}
public String toString()
{
return "latest-version information for " + artifact.getArtifactId();
}
protected void setContent( String content )
{
this.version = content.trim();
}
public void setVersion( String version )
{
this.version = version;
}
public String getBaseVersion()
{
return LatestArtifactTransformation.LATEST_VERSION;
}
public boolean storedInArtifactDirectory()
{
return false;
}
}

View File

@ -98,4 +98,10 @@ public String getBaseVersion()
{
return ReleaseArtifactTransformation.RELEASE_VERSION;
}
public boolean storedInArtifactDirectory()
{
return false;
}
}

View File

@ -0,0 +1,73 @@
package org.apache.maven.artifact.transform;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.LatestArtifactMetadata;
import org.apache.maven.artifact.metadata.VersionArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import java.io.IOException;
import java.util.List;
public class LatestArtifactTransformation
extends AbstractVersionTransformation
{
public static final String LATEST_VERSION = "LATEST";
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
if ( LATEST_VERSION.equals( artifact.getVersion() ) )
{
String version = resolveVersion( artifact, localRepository, remoteRepositories );
if ( !version.equals( artifact.getVersion() ) )
{
artifact.setBaseVersion( version );
artifact.updateVersion( version, localRepository );
}
}
}
public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
// metadata is added at install time
}
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
// metadata is added at deploy time
}
protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact,
ArtifactRepository remoteRepository,
VersionArtifactMetadata localMetadata )
throws ArtifactMetadataRetrievalException
{
AbstractVersionArtifactMetadata metadata = new LatestArtifactMetadata( artifact );
try
{
metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager );
}
catch ( ResourceDoesNotExistException e )
{
if ( localMetadata.constructVersion() == null )
{
throw new ArtifactMetadataRetrievalException( "Unable to find latest version for plugin artifact " + artifact, e );
}
// otherwise, ignore - use the local one
}
return metadata;
}
protected VersionArtifactMetadata readFromLocalRepository( Artifact artifact, ArtifactRepository localRepository )
throws IOException
{
AbstractVersionArtifactMetadata metadata = new LatestArtifactMetadata( artifact );
metadata.readFromLocalRepository( localRepository );
return metadata;
}
}

View File

@ -38,15 +38,10 @@ public class ReleaseArtifactTransformation
{
public static final String RELEASE_VERSION = "RELEASE";
private static boolean isRelease( Artifact artifact )
{
return artifact.getVersion().equals( RELEASE_VERSION );
}
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
if ( isRelease( artifact ) )
if ( RELEASE_VERSION.equals( artifact.getVersion() ) )
{
String version = resolveVersion( artifact, localRepository, remoteRepositories );
if ( !version.equals( artifact.getVersion() ) )

View File

@ -36,6 +36,17 @@
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
<role-hint>latest</role-hint>
<implementation>org.apache.maven.artifact.transform.LatestArtifactTransformation</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
</requirements>
</component>
<!--
|
| Resolver

View File

@ -46,6 +46,11 @@ public String getFilename()
{
return filename;
}
public boolean storedInArtifactDirectory()
{
return true;
}
public String getGroupId()
{

View File

@ -58,6 +58,11 @@ void storeInLocalRepository( ArtifactRepository localRepository )
* @return true or false
*/
boolean exists();
/**
* Whether this metadata should be stored alongside the artifact.
*/
boolean storedInArtifactDirectory();
String getGroupId();

View File

@ -57,7 +57,7 @@ public String pathOfMetadata( ArtifactMetadata metadata )
path.append( formatAsDirectory( metadata.getGroupId() ) ).append( '/' );
path.append( metadata.getArtifactId() ).append( '/' );
if ( !metadata.getBaseVersion().equals( "RELEASE" ) )
if ( metadata.storedInArtifactDirectory() )
{
path.append( metadata.getBaseVersion() ).append( '/' );
}

View File

@ -2,9 +2,11 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.transform.LatestArtifactTransformation;
import org.apache.maven.artifact.transform.ReleaseArtifactTransformation;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.registry.MavenPluginRegistryBuilder;
@ -13,6 +15,8 @@
import org.apache.maven.plugin.registry.TrackableBase;
import org.apache.maven.plugin.registry.io.xpp3.PluginRegistryXpp3Writer;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.components.inputhandler.InputHandler;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@ -58,6 +62,8 @@ public class DefaultPluginVersionManager
private ArtifactFactory artifactFactory;
private MavenProjectBuilder projectBuilder;
private InputHandler inputHandler;
// calculated.
@ -96,8 +102,8 @@ public String resolvePluginVersion( String groupId, String artifactId, MavenProj
if ( Boolean.TRUE.equals( pluginUpdateOverride )
|| ( !Boolean.FALSE.equals( pluginUpdateOverride ) && shouldCheckForUpdates( groupId, artifactId ) ) )
{
updatedVersion = resolveReleaseVersion( groupId, artifactId, project
.getPluginArtifactRepositories(), localRepository );
updatedVersion = resolveMetaVersion( groupId, artifactId, project
.getPluginArtifactRepositories(), localRepository, ReleaseArtifactTransformation.RELEASE_VERSION );
if ( StringUtils.isNotEmpty( updatedVersion ) && !updatedVersion.equals( version ) )
{
@ -115,26 +121,45 @@ public String resolvePluginVersion( String groupId, String artifactId, MavenProj
else
{
getLogger()
.info( "Plugin {" + constructPluginKey( groupId, artifactId ) + "} has updates." );
.info( "Plugin \'" + constructPluginKey( groupId, artifactId ) + "\' has updates." );
}
}
}
}
}
boolean forcePersist = false;
// final pass...retrieve the version for RELEASE and also set that resolved version as the <useVersion/>
// third pass...retrieve the version for RELEASE and also set that resolved version as the <useVersion/>
// in settings.xml.
if ( StringUtils.isEmpty( version ) )
{
// 1. resolve the version to be used THIS TIME
version = resolveReleaseVersion( groupId, artifactId, project.getPluginArtifactRepositories(),
localRepository );
// 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project.getPluginArtifactRepositories(),
localRepository, ReleaseArtifactTransformation.RELEASE_VERSION );
// 2. Set the updatedVersion so the user will be prompted whether to make this version permanent.
updatedVersion = version;
// 3. Tell the system to determine whether this update can/should be persisted.
promptToPersist = true;
// 3. Persist this version without prompting.
forcePersist = true;
promptToPersist = false;
}
// final pass...retrieve the version for LATEST and also set that resolved version as the <useVersion/>
// in settings.xml.
if ( StringUtils.isEmpty( version ) )
{
// 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project.getPluginArtifactRepositories(),
localRepository, LatestArtifactTransformation.LATEST_VERSION );
// 2. Set the updatedVersion so the user will be prompted whether to make this version permanent.
updatedVersion = version;
// 3. Persist this version without prompting.
forcePersist = true;
promptToPersist = false;
}
// if we still haven't found a version, then fail early before we get into the update goop.
@ -160,6 +185,11 @@ public String resolvePluginVersion( String groupId, String artifactId, MavenProj
}
// We should persist by default if:
//
// 0. RELEASE or LATEST was used to resolve the plugin version (it's not in the registry)
//
// -OR-
//
// 1. we detected a change in the plugin version from what was in the registry, or
// a. the plugin is not registered
// 2. the pluginUpdateOverride flag has NOT been set to Boolean.FALSE (suppression mode)
@ -167,13 +197,15 @@ public String resolvePluginVersion( String groupId, String artifactId, MavenProj
// a. the registry is declared to be in autoUpdate mode
//
// NOTE: This is only the default value; it may be changed as the result of prompting the user.
boolean persistUpdate = promptToPersist && !Boolean.FALSE.equals( pluginUpdateOverride )
&& ( inInteractiveMode || autoUpdate );
boolean persistUpdate = forcePersist || ( promptToPersist && !Boolean.FALSE.equals( pluginUpdateOverride )
&& ( inInteractiveMode || autoUpdate ) );
// retrieve the apply-to-all flag, if it's been set previously.
Boolean applyToAll = settings.getRuntimeInfo().getApplyToAllPluginUpdates();
// Incorporate interactive-mode CLI overrides, and previous decisions on apply-to-all, if appropriate.
//
// don't prompt if RELEASE or LATEST was used to resolve the plugin version
// don't prompt if not in interactive mode.
// don't prompt if the CLI pluginUpdateOverride is set (either suppression or force mode will stop prompting)
// don't prompt if the user has selected ALL/NONE previously in this session
@ -554,24 +586,28 @@ private PluginRegistry getPluginRegistry( String groupId, String artifactId )
return pluginRegistry;
}
private String resolveReleaseVersion( String groupId, String artifactId, List remoteRepositories,
ArtifactRepository localRepository )
private String resolveMetaVersion( String groupId, String artifactId, List remoteRepositories,
ArtifactRepository localRepository, String metaVersionId )
throws PluginVersionResolutionException
{
Artifact releaseArtifact = artifactFactory.createArtifact( groupId, artifactId, "RELEASE",
Artifact.SCOPE_RUNTIME, "maven-plugin" );
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, metaVersionId,
Artifact.SCOPE_RUNTIME, "pom" );
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, projectBuilder, artifactFactory );
String version = null;
try
{
artifactResolver.resolve( releaseArtifact, remoteRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{
throw new PluginVersionResolutionException( groupId, artifactId,
"Cannot resolve RELEASE version of this plugin.", e );
}
metadataSource.retrieve( artifact, localRepository, remoteRepositories );
return releaseArtifact.getBaseVersion();
version = artifact.getBaseVersion();
}
catch ( ArtifactMetadataRetrievalException e )
{
getLogger().debug( "Failed to resolve " + metaVersionId + " version", e );
}
return version;
}
}

View File

@ -193,7 +193,7 @@
<process-test-resources>resources:testResources</process-test-resources>
<test-compile>compiler:testCompile</test-compile>
<test>surefire:test</test>
<package>jar:jar,plugin:generateUpdatedMapping</package>
<package>jar:jar,plugin:generateUpdatedMapping,plugin:addPluginArtifactMetadata</package>
<install>install:install,plugin:installMapping</install>
<deploy>deploy:deploy,plugin:deployMapping</deploy>
</phases>
@ -285,6 +285,9 @@
<implementation>org.apache.maven.plugin.version.DefaultPluginVersionManager</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<requirements>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.registry.MavenPluginRegistryBuilder</role>
</requirement>

View File

@ -17,8 +17,6 @@
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
@ -45,25 +43,11 @@ public class DeployMojo
{
/**
* @parameter expression="${project.groupId}"
* @parameter expression="${project.artifact}"
* @required
* @readonly
*/
private String groupId;
/**
* @parameter expression="${project.artifactId}"
* @required
* @readonly
*/
private String artifactId;
/**
* @parameter expression="${project.version}"
* @required
* @readonly
*/
private String version;
private Artifact artifact;
/**
* @parameter expression="${project.packaging}"
@ -120,13 +104,6 @@ public class DeployMojo
*/
private List attachedArtifacts;
/**
* @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
* @required
* @readonly
*/
private ArtifactFactory artifactFactory;
/**
* @parameter expression="${updateReleaseInfo}"
*/
@ -143,9 +120,6 @@ public void execute()
}
// Deploy the POM
// TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, packaging );
boolean isPomArtifact = "pom".equals( packaging );
File pom = new File( parentDir, "pom.xml" );
if ( !isPomArtifact )

View File

@ -17,8 +17,6 @@
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ReleaseArtifactMetadata;
@ -39,27 +37,6 @@
public class InstallMojo
extends AbstractInstallMojo
{
/**
* @parameter expression="${project.groupId}"
* @required
* @readonly
*/
protected String groupId;
/**
* @parameter expression="${project.artifactId}"
* @required
* @readonly
*/
protected String artifactId;
/**
* @parameter expression="${project.version}"
* @required
* @readonly
*/
protected String version;
/**
* @parameter expression="${project.packaging}"
* @required
@ -91,6 +68,13 @@ public class InstallMojo
* @parameter expression="${updateReleaseInfo}"
*/
private boolean updateReleaseInfo = false;
/**
* @parameter expression="${project.artifact}"
* @required
* @readonly
*/
private Artifact artifact;
/**
* @parameter expression="${project.attachedArtifacts}
@ -99,20 +83,11 @@ public class InstallMojo
*/
private List attachedArtifacts;
/**
* @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
* @required
* @readonly
*/
private ArtifactFactory artifactFactory;
public void execute()
throws MojoExecutionException
{
// TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, packaging );
boolean isPomArtifact = "pom".equals( packaging );
File pom = new File( basedir, "pom.xml" );
if ( !isPomArtifact )
{
@ -126,7 +101,7 @@ public void execute()
metadata.setVersion( artifact.getVersion() );
artifact.addMetadata( metadata );
}
try
{
if ( isPomArtifact )

View File

@ -34,6 +34,11 @@
<version>2.0-beta-1-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>

View File

@ -0,0 +1,37 @@
package org.apache.maven.plugin.plugin.metadata;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.LatestArtifactMetadata;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/** 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)
* for shipping alongside the plugin's artifact.
*
* @phase package
* @goal addPluginArtifactMetadata
*/
public class AddPluginArtifactMetadataMojo
extends AbstractMojo
{
/** The project artifact, which should have the LATEST metadata added to it.
*
* @parameter expression="${project.artifact}"
* @required
* @readonly
*/
private Artifact projectArtifact;
public void execute()
throws MojoExecutionException
{
LatestArtifactMetadata metadata = new LatestArtifactMetadata( projectArtifact );
metadata.setVersion( projectArtifact.getVersion() );
projectArtifact.addMetadata( metadata );
}
}

View File

@ -143,9 +143,8 @@ public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepos
// ----------------------------------------------------------------------
// TODO: such a call in MavenMetadataSource too - packaging not really the intention of type
Artifact projectArtifact = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), null, project.getPackaging() );
Artifact projectArtifact = project.getArtifact();
Map managedVersions = createManagedVersionMap( project.getDependencyManagement() );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
projectArtifact, managedVersions,
@ -406,6 +405,12 @@ private MavenProject processProjectLogic( String pomLocation, MavenProject proje
project.addProfileProperties( profileProperties );
project.setActiveProfiles( activeProfiles );
// TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
Artifact projectArtifact = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), null, project.getPackaging() );
project.setArtifact( projectArtifact );
project.setPluginArtifactRepositories(
ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), artifactRepositoryFactory,

View File

@ -102,6 +102,8 @@ public class MavenProject
private List activeProfiles = new ArrayList();
private Set dependencyArtifacts;
private Artifact artifact;
public MavenProject( Model model )
{
@ -143,6 +145,16 @@ public MavenProject( MavenProject project )
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
public Artifact getArtifact()
{
return artifact;
}
public void setArtifact( Artifact artifact )
{
this.artifact = artifact;
}
//@todo I would like to get rid of this. jvz.
public Model getModel()