PR: MNG-1060, 1061

corrections to the model used for the release plugin

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@293076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-02 06:12:03 +00:00
parent ad0d7ac805
commit 9382b9c8d9
9 changed files with 133 additions and 120 deletions

View File

@ -30,11 +30,11 @@ public final class ArtifactUtils
public static boolean isSnapshot( String version )
{
return version != null
&& ( version.toUpperCase().endsWith( "SNAPSHOT" ) || Artifact.VERSION_FILE_PATTERN.matcher( version )
return version != null &&
( version.toUpperCase().endsWith( "SNAPSHOT" ) || Artifact.VERSION_FILE_PATTERN.matcher( version )
.matches() );
}
public static String versionlessKey( Artifact artifact )
{
return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
@ -42,6 +42,14 @@ public final class ArtifactUtils
public static String versionlessKey( String groupId, String artifactId )
{
if ( groupId == null )
{
throw new NullPointerException( "groupId was null" );
}
if ( artifactId == null )
{
throw new NullPointerException( "artifactId was null" );
}
return groupId + ":" + artifactId;
}
@ -60,7 +68,7 @@ public final class ArtifactUtils
public static Map artifactMapByVersionlessId( Collection artifacts )
{
Map artifactMap = new HashMap();
if ( artifacts != null )
{
for ( Iterator it = artifacts.iterator(); it.hasNext(); )

View File

@ -13,7 +13,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0-beta-1</version>
<version>2.0-beta-2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>

View File

@ -32,6 +32,7 @@ import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.version.PluginVersionManager;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
@ -189,22 +190,28 @@ public class PrepareReleaseMojo
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE ) )
{
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
getVersionResolver().resolveVersion( project );
getScmRewriter().rewriteScmInfo( project, getTagLabel() );
}
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
checkForPresenceOfSnapshots( project );
transformPomToReleaseVersionPom( project );
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
if ( !ArtifactUtils.isSnapshot( project.getVersion() ) )
{
throw new MojoExecutionException( "The project " + project.getGroupId() + ":" +
project.getArtifactId() + " isn't a snapshot (" + project.getVersion() + ")." );
}
getVersionResolver().resolveVersion( project.getOriginalModel(), projectId );
MavenProject clonedProject = new MavenProject( project );
Model model = clonedProject.getOriginalModel();
transformPomToReleaseVersionPom( model, projectId, project.getFile(), project.getParentArtifact(),
project.getPluginArtifactRepositories() );
}
try
@ -230,16 +237,17 @@ public class PrepareReleaseMojo
{
MavenProject project = (MavenProject) it.next();
getVersionResolver().incrementVersion( project );
// TODO: use clone model instead... (requires beta-3)
project = new MavenProject( project );
getScmRewriter().restoreScmInfo( project );
}
Model model = project.getOriginalModel();
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
getVersionResolver().incrementVersion( model, projectId );
transformPomToSnapshotVersionPom( project );
getScmRewriter().restoreScmInfo( model );
transformPomToSnapshotVersionPom( model, project.getFile() );
}
try
@ -268,11 +276,9 @@ public class PrepareReleaseMojo
}
}
private void transformPomToSnapshotVersionPom( MavenProject project )
private void transformPomToSnapshotVersionPom( Model model, File file )
throws MojoExecutionException
{
Model model = project.getOriginalModel();
ProjectVersionResolver versionResolver = getVersionResolver();
Parent parent = model.getParent();
@ -369,19 +375,21 @@ public class PrepareReleaseMojo
}
}
}
Writer writer = null;
File file = new File( project.getFile().getParentFile(), POM );
File pomFile = new File( file.getParentFile(), POM );
Writer writer = null;
try
{
writer = new FileWriter( file );
writer = new FileWriter( pomFile );
project.writeOriginalModel( writer );
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
pomWriter.write( writer, model );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot write development version of pom to: " + file, e );
throw new MojoExecutionException( "Cannot write development version of pom to: " + pomFile, e );
}
finally
{
@ -515,7 +523,7 @@ public class PrepareReleaseMojo
}
throw new MojoExecutionException(
"Cannot prepare the release because you have local modifications : \n" + message.toString() );
"Cannot prepare the release because you have local modifications : \n" + message );
}
try
@ -549,7 +557,7 @@ public class PrepareReleaseMojo
{
MavenProject parentProject = currentProject.getParent();
String parentVersion = null;
String parentVersion;
if ( ArtifactUtils.isSnapshot( parentProject.getVersion() ) )
{
@ -632,30 +640,22 @@ public class PrepareReleaseMojo
message.append( "\n" );
}
throw new MojoExecutionException(
"Can't release project due to non released dependencies :\n" + message.toString() );
throw new MojoExecutionException( "Can't release project due to non released dependencies :\n" + message );
}
}
private void transformPomToReleaseVersionPom( MavenProject project )
private void transformPomToReleaseVersionPom( Model model, String projectId, File file, Artifact parentArtifact,
List pluginArtifactRepositories )
throws MojoExecutionException
{
if ( !ArtifactUtils.isSnapshot( project.getVersion() ) )
{
throw new MojoExecutionException( "The project " + project.getGroupId() + ":" + project.getArtifactId() +
" isn't a snapshot (" + project.getVersion() + ")." );
}
Model model = project.getOriginalModel();
getScmRewriter().rewriteScmInfo( model, projectId, getTagLabel() );
//Rewrite parent version
if ( model.getParent() != null )
{
Artifact parentArtifact = project.getParentArtifact();
if ( ArtifactUtils.isSnapshot( parentArtifact.getBaseVersion() ) )
{
String version = resolveVersion( parentArtifact, "parent", project );
String version = resolveVersion( parentArtifact, "parent", pluginArtifactRepositories );
model.getParent().setVersion( version );
}
@ -795,16 +795,18 @@ public class PrepareReleaseMojo
Writer writer = null;
File file = new File( project.getFile().getParentFile(), POM );
File pomFile = new File( file.getParentFile(), POM );
try
{
writer = new FileWriter( file );
writer = new FileWriter( pomFile );
project.writeOriginalModel( writer );
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
pomWriter.write( writer, model );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot write released version of pom to: " + file, e );
throw new MojoExecutionException( "Cannot write released version of pom to: " + pomFile, e );
}
finally
{
@ -840,15 +842,15 @@ public class PrepareReleaseMojo
// we don't need these polluting the POM.
releaseModel.setProfiles( Collections.EMPTY_LIST );
releaseModel.setDependencyManagement( null );
releaseModel.getBuild().setPluginManagement( null );
releaseProject.getBuild().setPluginManagement( null );
String projectVersion = releaseModel.getVersion();
if ( ArtifactUtils.isSnapshot( projectVersion ) )
{
String snapshotVersion = projectVersion;
projectVersion = getVersionResolver().getResolvedVersion( releaseModel.getGroupId(),
releaseModel.getArtifactId() );
projectVersion = getVersionResolver().getResolvedVersion( project.getGroupId(),
project.getArtifactId() );
if ( ArtifactUtils.isSnapshot( projectVersion ) )
{
@ -929,12 +931,12 @@ public class PrepareReleaseMojo
try
{
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
plugin.getArtifactId(), project,
plugin.getArtifactId(), releaseProject,
settings, localRepository );
}
catch ( PluginVersionResolutionException e )
{
throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin );
throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin, e );
}
if ( ArtifactUtils.isSnapshot( version ) )
@ -949,7 +951,8 @@ public class PrepareReleaseMojo
}
}
List reports = releaseProject.getReportPlugins();
Reporting reporting = releaseModel.getReporting();
List reports = reporting != null ? reporting.getPlugins() : null;
if ( reports != null )
{
@ -961,12 +964,15 @@ public class PrepareReleaseMojo
String version;
try
{
version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin
.getArtifactId(), project, settings, localRepository, true );
version = pluginVersionManager.resolveReportPluginVersion( plugin.getGroupId(),
plugin.getArtifactId(),
releaseProject, settings,
localRepository );
}
catch ( PluginVersionResolutionException e )
{
throw new MojoExecutionException( "Cannot resolve version for report plugin: " + plugin );
throw new MojoExecutionException( "Cannot resolve version for report plugin: " + plugin,
e );
}
if ( ArtifactUtils.isSnapshot( version ) )
@ -981,7 +987,7 @@ public class PrepareReleaseMojo
}
}
List extensions = releaseProject.getBuildExtensions();
List extensions = build != null ? build.getExtensions() : null;
if ( extensions != null )
{
@ -996,7 +1002,8 @@ public class PrepareReleaseMojo
Artifact artifact = (Artifact) extensionArtifacts.get( extensionId );
String version = resolveVersion( artifact, "extension", releaseProject );
String version = resolveVersion( artifact, "extension",
releaseProject.getPluginArtifactRepositories() );
ext.setVersion( version );
}
@ -1210,7 +1217,7 @@ public class PrepareReleaseMojo
return newParent;
}
private String resolveVersion( Artifact artifact, String artifactUsage, MavenProject project )
private String resolveVersion( Artifact artifact, String artifactUsage, List pluginArtifactRepositories )
throws MojoExecutionException
{
String resolvedVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
@ -1222,8 +1229,7 @@ public class PrepareReleaseMojo
{
try
{
artifactMetadataSource.retrieve( artifact, localRepository,
project.getPluginArtifactRepositories() );
artifactMetadataSource.retrieve( artifact, localRepository, pluginArtifactRepositories );
}
catch ( ArtifactMetadataRetrievalException e )
{
@ -1347,23 +1353,23 @@ public class PrepareReleaseMojo
private void checkIn( String message )
throws MojoExecutionException
{
ScmHelper scm = getScm( basedir );
String tag = scm.getTag();
// No tag here - we suppose user works on correct branch
scm.setTag( null );
try
{
ScmHelper scm = getScm( basedir );
String tag = scm.getTag();
// No tag here - we suppose user works on correct branch
scm.setTag( null );
scm.checkin( message );
scm.setTag( tag );
}
catch ( Exception e )
catch ( ScmException e )
{
throw new MojoExecutionException( "An error is occurred in the checkin process.", e );
}
scm.setTag( tag );
}
private String getTagLabel()
@ -1389,7 +1395,7 @@ public class PrepareReleaseMojo
userTag = tag;
}
}
catch ( Exception e )
catch ( IOException e )
{
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
}
@ -1436,7 +1442,7 @@ public class PrepareReleaseMojo
scm.tag();
}
catch ( Exception e )
catch ( ScmException e )
{
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
}

View File

@ -20,11 +20,6 @@ import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.Scm;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ProjectScmRewriter
{
@ -35,13 +30,9 @@ public class ProjectScmRewriter
this.releaseProgress = releaseProgress;
}
public void rewriteScmInfo( MavenProject project, String tagLabel )
public void rewriteScmInfo( Model model, String projectId, String tagLabel )
throws MojoExecutionException
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
Model model = project.getOriginalModel();
Scm scm = model.getScm();
// If SCM is null in original model, it is inherited, no mods needed
if ( scm != null )
@ -52,12 +43,12 @@ public class ProjectScmRewriter
}
}
public void restoreScmInfo( MavenProject project )
public void restoreScmInfo( Model model )
{
Scm scm = project.getOriginalModel().getScm();
Scm scm = model.getScm();
if ( scm != null )
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
String projectId = ArtifactUtils.versionlessKey( model.getGroupId(), model.getArtifactId() );
releaseProgress.restoreScmInfo( projectId, scm );
}
@ -72,13 +63,13 @@ public class ProjectScmRewriter
if ( scmConnection != null && scmConnection.startsWith( "scm:svn" ) )
{
scm.setConnection( convertSvnConnectionString( scmConnection, tag ) );
String devConnection = scm.getDeveloperConnection();
if ( devConnection != null )
{
scm.setDeveloperConnection( convertSvnConnectionString( devConnection, tag ) );
}
String url = scm.getUrl();
if ( url != null )
{
@ -91,21 +82,21 @@ public class ProjectScmRewriter
private String convertSvnConnectionString( String scmConnection, String tag )
{
int trunkBegin = scmConnection.indexOf( "/trunk" );
if ( trunkBegin >= 0 )
{
String tail = "";
if ( scmConnection.length() > trunkBegin + "/trunk".length() )
{
tail = scmConnection.substring( trunkBegin + "/trunk".length() );
if ( !tail.startsWith( "/" ) )
{
tail += "/";
}
}
scmConnection = scmConnection.substring( 0, trunkBegin ) + "/tags/" + tag + tail;
}
else

View File

@ -1,10 +1,25 @@
package org.apache.maven.plugins.release.helpers;
/*
* 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.ArtifactUtils;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.components.inputhandler.InputHandler;
import org.codehaus.plexus.util.StringUtils;
@ -14,7 +29,6 @@ import java.util.Map;
public class ProjectVersionResolver
{
private static final String SNAPSHOT_CLASSIFIER = "-SNAPSHOT";
private Map resolvedVersions = new HashMap();
@ -32,11 +46,9 @@ public class ProjectVersionResolver
this.interactive = interactive;
}
public void resolveVersion( MavenProject project )
public void resolveVersion( Model model, String projectId )
throws MojoExecutionException
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
if ( resolvedVersions.containsKey( projectId ) )
{
throw new IllegalArgumentException(
@ -44,7 +56,7 @@ public class ProjectVersionResolver
}
//Rewrite project version
String projectVersion = project.getVersion();
String projectVersion = model.getVersion();
projectVersion = projectVersion.substring( 0, projectVersion.length() - SNAPSHOT_CLASSIFIER.length() );
@ -67,8 +79,6 @@ public class ProjectVersionResolver
}
}
Model model = project.getOriginalModel();
model.setVersion( projectVersion );
resolvedVersions.put( projectId, projectVersion );
@ -81,14 +91,13 @@ public class ProjectVersionResolver
return (String) resolvedVersions.get( projectId );
}
public void incrementVersion( MavenProject project )
public void incrementVersion( Model model, String projectId )
throws MojoExecutionException
{
String projectVersion = project.getOriginalModel().getVersion();
String projectVersion = model.getVersion();
if ( ArtifactUtils.isSnapshot( projectVersion ) )
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
throw new MojoExecutionException( "The project " + projectId + " is a snapshot (" + projectVersion +
"). It appears that the release version has not been committed." );
}
@ -105,10 +114,10 @@ public class ProjectVersionResolver
String staticVersionPart = null;
String nextVersionString = null;
int dashIdx = projectVersion.lastIndexOf( "-" );
int dotIdx = projectVersion.lastIndexOf( "." );
if ( dashIdx > 0 )
{
staticVersionPart = projectVersion.substring( 0, dashIdx + 1 );
@ -136,7 +145,6 @@ public class ProjectVersionResolver
projectVersion = "";
}
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
if ( interactive )
{
try
@ -160,7 +168,7 @@ public class ProjectVersionResolver
throw new MojoExecutionException( "Cannot determine incremented development version for: " + projectId );
}
project.getOriginalModel().setVersion( projectVersion );
model.setVersion( projectVersion );
resolvedVersions.put( projectId, projectVersion );
}

View File

@ -205,7 +205,7 @@ public class ScmHelper
}
public void checkin( String message )
throws Exception
throws ScmException
{
ScmRepository repository = getScmRepository();

View File

@ -160,6 +160,7 @@ public class MavenProject
this.pluginArtifacts = Collections.unmodifiableSet( project.pluginArtifacts );
this.reportArtifacts = Collections.unmodifiableSet( project.reportArtifacts );
this.extensionArtifacts = Collections.unmodifiableSet( project.extensionArtifacts );
this.parentArtifact = project.parentArtifact;
this.remoteArtifactRepositories = Collections.unmodifiableList( project.remoteArtifactRepositories );
this.pluginArtifactRepositories = Collections.unmodifiableList( project.pluginArtifactRepositories );

View File

@ -55,7 +55,7 @@ import java.util.TreeMap;
public final class ModelUtils
{
public static void mergePluginLists( PluginContainer childContainer, PluginContainer parentContainer,
boolean handleAsInheritance )
boolean handleAsInheritance )
{
if ( childContainer == null || parentContainer == null )
{
@ -77,8 +77,8 @@ public final class ModelUtils
String parentInherited = parentPlugin.getInherited();
if ( !handleAsInheritance || parentInherited == null
|| Boolean.valueOf( parentInherited ).booleanValue() )
if ( !handleAsInheritance || parentInherited == null ||
Boolean.valueOf( parentInherited ).booleanValue() )
{
Plugin assembledPlugin = parentPlugin;
@ -139,8 +139,8 @@ public final class ModelUtils
String parentInherited = parentPlugin.getInherited();
if ( !handleAsInheritance || parentInherited == null
|| Boolean.valueOf( parentInherited ).booleanValue() )
if ( !handleAsInheritance || parentInherited == null ||
Boolean.valueOf( parentInherited ).booleanValue() )
{
ReportPlugin assembledPlugin = parentPlugin;
@ -258,7 +258,7 @@ public final class ModelUtils
}
public static void mergeReportPluginDefinitions( ReportPlugin child, ReportPlugin parent,
boolean handleAsInheritance )
boolean handleAsInheritance )
{
if ( child == null || parent == null )
{
@ -471,7 +471,7 @@ public final class ModelUtils
child.setConfiguration( childConfiguration );
}
static Model cloneModel( Model model )
public static Model cloneModel( Model model )
{
// TODO: would be nice for the modello:java code to generate this as a copy constructor
Model newModel = new Model();
@ -545,7 +545,7 @@ public final class ModelUtils
{
Properties newProps = new Properties();
newProps.putAll( props );
newProfile.setProperties( newProps );
}

View File

@ -96,7 +96,7 @@ public class ProjectSorter
}
}
/* TODO: can this be removed?
// TODO: this MUST be fixed before beta-3, but it is required for a sane release plugin.
MavenProject parent = project.getParent();
if ( parent != null )
{
@ -106,7 +106,6 @@ public class ProjectSorter
dag.addEdge( id, parentId );
}
}
*/
List buildPlugins = project.getBuildPlugins();
if ( buildPlugins != null )