don't include lifecycle introduced plugins (also resolves issue with release plugin snapshot)

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@290352 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-20 04:35:46 +00:00
parent 26fcb2bae8
commit 385fef3bda
1 changed files with 56 additions and 42 deletions

View File

@ -97,12 +97,12 @@ public class PrepareReleaseMojo
* @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource" * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
*/ */
private ArtifactMetadataSource artifactMetadataSource; private ArtifactMetadataSource artifactMetadataSource;
/** /**
* @component role="org.apache.maven.plugin.version.PluginVersionManager" * @component role="org.apache.maven.plugin.version.PluginVersionManager"
*/ */
private PluginVersionManager pluginVersionManager; private PluginVersionManager pluginVersionManager;
/** /**
* @parameter expression="${component.org.codehaus.plexus.components.inputhandler.InputHandler}" * @parameter expression="${component.org.codehaus.plexus.components.inputhandler.InputHandler}"
* @required * @required
@ -116,7 +116,7 @@ public class PrepareReleaseMojo
* @readonly * @readonly
*/ */
private ArtifactRepository localRepository; private ArtifactRepository localRepository;
/** /**
* @parameter expression="${settings}" * @parameter expression="${settings}"
* @required * @required
@ -835,39 +835,43 @@ public class PrepareReleaseMojo
MavenProject releaseProject = new MavenProject( project ); MavenProject releaseProject = new MavenProject( project );
Model releaseModel = releaseProject.getModel(); Model releaseModel = releaseProject.getModel();
fixNullValueInModel( releaseModel, project.getModel() ); fixNullValueInModel( releaseModel, project.getModel() );
// the release POM should reflect bits of these which were injected at build time... // the release POM should reflect bits of these which were injected at build time...
// we don't need these polluting the POM. // we don't need these polluting the POM.
releaseModel.setProfiles( Collections.EMPTY_LIST ); releaseModel.setProfiles( Collections.EMPTY_LIST );
releaseModel.setDependencyManagement( null ); releaseModel.setDependencyManagement( null );
releaseModel.getBuild().setPluginManagement( null ); releaseModel.getBuild().setPluginManagement( null );
String projectVersion = releaseModel.getVersion(); String projectVersion = releaseModel.getVersion();
if ( ArtifactUtils.isSnapshot( projectVersion ) ) if ( ArtifactUtils.isSnapshot( projectVersion ) )
{ {
String snapshotVersion = projectVersion; String snapshotVersion = projectVersion;
projectVersion = getVersionResolver().getResolvedVersion( releaseModel.getGroupId(), releaseModel.getArtifactId() ); projectVersion = getVersionResolver().getResolvedVersion( releaseModel.getGroupId(),
releaseModel.getArtifactId() );
if ( ArtifactUtils.isSnapshot( projectVersion ) ) if ( ArtifactUtils.isSnapshot( projectVersion ) )
{ {
throw new MojoExecutionException( "MAJOR PROBLEM!!! Cannot find resolved version to be used in releasing project: " + releaseProject.getId() ); throw new MojoExecutionException(
"MAJOR PROBLEM!!! Cannot find resolved version to be used in releasing project: " +
releaseProject.getId() );
} }
releaseModel.setVersion( projectVersion ); releaseModel.setVersion( projectVersion );
String finalName = releaseModel.getBuild().getFinalName(); String finalName = releaseModel.getBuild().getFinalName();
if ( finalName.equals( releaseModel.getArtifactId() + "-" + snapshotVersion ) ) if ( finalName.equals( releaseModel.getArtifactId() + "-" + snapshotVersion ) )
{ {
releaseModel.getBuild().setFinalName( null ); releaseModel.getBuild().setFinalName( null );
} }
else if ( finalName.indexOf( "SNAPSHOT" ) > -1 ) else if ( finalName.indexOf( "SNAPSHOT" ) > -1 )
{ {
throw new MojoExecutionException( "Cannot reliably adjust the finalName of project: " + releaseProject.getId() ); throw new MojoExecutionException(
"Cannot reliably adjust the finalName of project: " + releaseProject.getId() );
} }
} }
releaseModel.setParent( null ); releaseModel.setParent( null );
Set artifacts = releaseProject.getArtifacts(); Set artifacts = releaseProject.getArtifacts();
@ -880,23 +884,25 @@ public class PrepareReleaseMojo
for ( Iterator i = releaseProject.getArtifacts().iterator(); i.hasNext(); ) for ( Iterator i = releaseProject.getArtifacts().iterator(); i.hasNext(); )
{ {
Artifact artifact = (Artifact) i.next(); Artifact artifact = (Artifact) i.next();
Dependency newdep = new Dependency(); Dependency newdep = new Dependency();
newdep.setArtifactId( artifact.getArtifactId() ); newdep.setArtifactId( artifact.getArtifactId() );
newdep.setGroupId( artifact.getGroupId() ); newdep.setGroupId( artifact.getGroupId() );
String version = artifact.getVersion(); String version = artifact.getVersion();
if ( artifact.isSnapshot() ) if ( artifact.isSnapshot() )
{ {
version = getVersionResolver().getResolvedVersion(artifact.getGroupId(), artifact.getArtifactId() ); version = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
artifact.getArtifactId() );
if ( ArtifactUtils.isSnapshot( version ) ) if ( ArtifactUtils.isSnapshot( version ) )
{ {
throw new MojoExecutionException( "Unresolved SNAPSHOT version of: " + artifact.getId() + ". Cannot proceed with release." ); throw new MojoExecutionException( "Unresolved SNAPSHOT version of: " +
artifact.getId() + ". Cannot proceed with release." );
} }
} }
newdep.setVersion( version ); newdep.setVersion( version );
newdep.setType( artifact.getType() ); newdep.setType( artifact.getType() );
newdep.setScope( artifact.getScope() ); newdep.setScope( artifact.getScope() );
@ -909,9 +915,8 @@ public class PrepareReleaseMojo
} }
// Use original - don't want the lifecycle introduced ones // Use original - don't want the lifecycle introduced ones
// TODO: but is it the right settings? Build build = releaseProject.getOriginalModel().getBuild();
Build model = releaseProject.getModel().getBuild(); List plugins = build != null ? build.getPlugins() : null;
List plugins = model != null ? model.getPlugins() : null;
if ( plugins != null ) if ( plugins != null )
{ {
@ -923,16 +928,21 @@ public class PrepareReleaseMojo
String version; String version;
try try
{ {
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, settings, localRepository ); version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
plugin.getArtifactId(), project,
settings, localRepository );
} }
catch ( PluginVersionResolutionException e ) catch ( PluginVersionResolutionException e )
{ {
throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin ); throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin );
} }
if ( ArtifactUtils.isSnapshot(version)) if ( ArtifactUtils.isSnapshot( version ) )
{ {
throw new MojoExecutionException( "Resolved version of plugin is a snapshot. Please release this plugin before releasing this project.\n\nGroupId: " + plugin.getGroupId() + "\nArtifactId: " + plugin.getArtifactId() + "\nResolved Version: " + version + "\n\n" ); throw new MojoExecutionException(
"Resolved version of plugin is a snapshot. Please release this plugin before releasing this project.\n\nGroupId: " +
plugin.getGroupId() + "\nArtifactId: " + plugin.getArtifactId() +
"\nResolved Version: " + version + "\n\n" );
} }
plugin.setVersion( version ); plugin.setVersion( version );
@ -958,10 +968,13 @@ public class PrepareReleaseMojo
{ {
throw new MojoExecutionException( "Cannot resolve version for report plugin: " + plugin ); throw new MojoExecutionException( "Cannot resolve version for report plugin: " + plugin );
} }
if ( ArtifactUtils.isSnapshot(version)) if ( ArtifactUtils.isSnapshot( version ) )
{ {
throw new MojoExecutionException( "Resolved version of plugin is a snapshot. Please release this report plugin before releasing this project.\n\nGroupId: " + plugin.getGroupId() + "\nArtifactId: " + plugin.getArtifactId() + "\nResolved Version: " + version + "\n\n" ); throw new MojoExecutionException(
"Resolved version of plugin is a snapshot. Please release this report plugin before releasing this project.\n\nGroupId: " +
plugin.getGroupId() + "\nArtifactId: " + plugin.getArtifactId() +
"\nResolved Version: " + version + "\n\n" );
} }
plugin.setVersion( version ); plugin.setVersion( version );
@ -988,10 +1001,11 @@ public class PrepareReleaseMojo
ext.setVersion( version ); ext.setVersion( version );
} }
} }
try try
{ {
relativizeBuildPaths( model, project.getFile().getParentFile().getCanonicalPath() ); relativizeBuildPaths( releaseProject.getModel().getBuild(),
project.getFile().getParentFile().getCanonicalPath() );
} }
catch ( IOException e ) catch ( IOException e )
{ {
@ -1051,50 +1065,50 @@ public class PrepareReleaseMojo
private void relativizeBuildPaths( Build build, String canonicalBasedir ) private void relativizeBuildPaths( Build build, String canonicalBasedir )
{ {
int basePathLength = canonicalBasedir.length() + 1; int basePathLength = canonicalBasedir.length() + 1;
String directory = build.getDirectory(); String directory = build.getDirectory();
if ( directory.startsWith( canonicalBasedir ) ) if ( directory.startsWith( canonicalBasedir ) )
{ {
build.setDirectory( directory.substring( basePathLength ) ); build.setDirectory( directory.substring( basePathLength ) );
} }
String outDir = build.getOutputDirectory(); String outDir = build.getOutputDirectory();
if ( outDir.startsWith( canonicalBasedir ) ) if ( outDir.startsWith( canonicalBasedir ) )
{ {
build.setOutputDirectory( outDir.substring( basePathLength ) ); build.setOutputDirectory( outDir.substring( basePathLength ) );
} }
String testOutDir = build.getTestOutputDirectory(); String testOutDir = build.getTestOutputDirectory();
if ( testOutDir.startsWith( canonicalBasedir ) ) if ( testOutDir.startsWith( canonicalBasedir ) )
{ {
build.setTestOutputDirectory( testOutDir.substring( basePathLength ) ); build.setTestOutputDirectory( testOutDir.substring( basePathLength ) );
} }
String srcDir = build.getSourceDirectory(); String srcDir = build.getSourceDirectory();
if ( srcDir.startsWith( canonicalBasedir ) ) if ( srcDir.startsWith( canonicalBasedir ) )
{ {
build.setSourceDirectory( srcDir.substring( basePathLength ) ); build.setSourceDirectory( srcDir.substring( basePathLength ) );
} }
String scriptSrcDir = build.getScriptSourceDirectory(); String scriptSrcDir = build.getScriptSourceDirectory();
if ( scriptSrcDir.startsWith( canonicalBasedir ) ) if ( scriptSrcDir.startsWith( canonicalBasedir ) )
{ {
build.setScriptSourceDirectory( scriptSrcDir.substring( basePathLength ) ); build.setScriptSourceDirectory( scriptSrcDir.substring( basePathLength ) );
} }
String testSrcDir = build.getTestSourceDirectory(); String testSrcDir = build.getTestSourceDirectory();
if ( testSrcDir.startsWith( canonicalBasedir ) ) if ( testSrcDir.startsWith( canonicalBasedir ) )
{ {
build.setTestSourceDirectory( testSrcDir.substring( basePathLength ) ); build.setTestSourceDirectory( testSrcDir.substring( basePathLength ) );
} }
List resources = build.getResources(); List resources = build.getResources();
if ( resources != null ) if ( resources != null )
{ {
for ( Iterator it = resources.iterator(); it.hasNext(); ) for ( Iterator it = resources.iterator(); it.hasNext(); )
{ {
Resource resource = (Resource) it.next(); Resource resource = (Resource) it.next();
String dir = resource.getDirectory(); String dir = resource.getDirectory();
if ( dir.startsWith( canonicalBasedir ) ) if ( dir.startsWith( canonicalBasedir ) )
{ {
@ -1102,14 +1116,14 @@ public class PrepareReleaseMojo
} }
} }
} }
List testResources = build.getTestResources(); List testResources = build.getTestResources();
if ( testResources != null ) if ( testResources != null )
{ {
for ( Iterator it = testResources.iterator(); it.hasNext(); ) for ( Iterator it = testResources.iterator(); it.hasNext(); )
{ {
Resource resource = (Resource) it.next(); Resource resource = (Resource) it.next();
String dir = resource.getDirectory(); String dir = resource.getDirectory();
if ( dir.startsWith( canonicalBasedir ) ) if ( dir.startsWith( canonicalBasedir ) )
{ {