various release plugin fixes

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@279240 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-07 04:14:22 +00:00
parent 434ec90fa6
commit 22f9a34107
4 changed files with 418 additions and 439 deletions

View File

@ -171,6 +171,8 @@ public class PrepareReleaseMojo
{ {
checkForLocalModifications(); checkForLocalModifications();
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE ) )
{
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{ {
MavenProject project = (MavenProject) it.next(); MavenProject project = (MavenProject) it.next();
@ -189,6 +191,17 @@ public class PrepareReleaseMojo
transformPomToReleaseVersionPom( project ); transformPomToReleaseVersionPom( project );
} }
try
{
getReleaseProgress().checkpoint( basedir, ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE );
}
catch ( IOException e )
{
getLog().warn( "Error writing checkpoint.", e );
}
}
generateReleasePoms(); generateReleasePoms();
checkInRelease(); checkInRelease();
@ -204,6 +217,8 @@ public class PrepareReleaseMojo
getScmRewriter().restoreScmInfo( project ); getScmRewriter().restoreScmInfo( project );
} }
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSORMED_FOR_DEVELOPMENT ) )
{
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{ {
MavenProject project = (MavenProject) it.next(); MavenProject project = (MavenProject) it.next();
@ -211,6 +226,17 @@ public class PrepareReleaseMojo
transformPomToSnapshotVersionPom( project ); transformPomToSnapshotVersionPom( project );
} }
try
{
getReleaseProgress().checkpoint( basedir,
ReleaseProgressTracker.CP_POM_TRANSORMED_FOR_DEVELOPMENT );
}
catch ( IOException e )
{
getLog().warn( "Error writing checkpoint.", e );
}
}
removeReleasePoms(); removeReleasePoms();
checkInNextSnapshot(); checkInNextSnapshot();
@ -228,8 +254,6 @@ public class PrepareReleaseMojo
private void transformPomToSnapshotVersionPom( MavenProject project ) private void transformPomToSnapshotVersionPom( MavenProject project )
throws MojoExecutionException throws MojoExecutionException
{
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSORMED_FOR_DEVELOPMENT ) )
{ {
if ( isSnapshot( project.getVersion() ) ) if ( isSnapshot( project.getVersion() ) )
{ {
@ -334,7 +358,6 @@ public class PrepareReleaseMojo
} }
} }
} }
}
Writer writer = null; Writer writer = null;
@ -353,15 +376,6 @@ public class PrepareReleaseMojo
{ {
IOUtil.close( writer ); IOUtil.close( writer );
} }
try
{
getReleaseProgress().checkpoint( basedir, ReleaseProgressTracker.CP_POM_TRANSORMED_FOR_DEVELOPMENT );
}
catch ( IOException e )
{
getLog().warn( "Error writing checkpoint.", e );
}
} }
} }
@ -369,22 +383,6 @@ public class PrepareReleaseMojo
throws MojoExecutionException throws MojoExecutionException
{ {
if ( releaseProgress == null ) if ( releaseProgress == null )
{
if ( resume )
{
try
{
releaseProgress = ReleaseProgressTracker.load( basedir );
releaseProgress.verifyResumeCapable();
}
catch ( IOException e )
{
throw new MojoExecutionException(
"Cannot read existing release progress file from directory: " + basedir + ". Cannot resume." );
}
}
else
{ {
try try
{ {
@ -392,27 +390,48 @@ public class PrepareReleaseMojo
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLog().warn( "Cannot read existing release progress file from directory: " + basedir + getLog().warn( "Cannot read existing release progress file from directory: " + basedir + "." );
". Creating new instance." ); getLog().debug( "Cause", e );
releaseProgress = ReleaseProgressTracker.create();
} }
releaseProgress.setResumeAtCheckpoint( resume ); if ( resume )
{
releaseProgress.setResumeAtCheckpoint( true );
}
if ( releaseProgress.getUsername() == null )
{
releaseProgress.setUsername( username ); releaseProgress.setUsername( username );
}
if ( password != null ) if ( releaseProgress.getPassword() == null && password != null )
{ {
releaseProgress.setPassword( password ); releaseProgress.setPassword( password );
} }
if ( releaseProgress.getScmTag() == null )
{
releaseProgress.setScmTag( getTagLabel() ); releaseProgress.setScmTag( getTagLabel() );
}
if ( releaseProgress.getScmTagBase() == null )
{
releaseProgress.setScmTagBase( tagBase ); releaseProgress.setScmTagBase( tagBase );
}
if ( releaseProgress.getScmUrl() == null )
{
releaseProgress.setScmUrl( urlScm ); releaseProgress.setScmUrl( urlScm );
} }
}
if ( releaseProgress.getUsername() == null || releaseProgress.getScmTag() == null ||
releaseProgress.getScmTagBase() == null || releaseProgress.getScmUrl() == null )
{
throw new MojoExecutionException( "Missing release preparation information." );
}
}
return releaseProgress; return releaseProgress;
} }
@ -513,8 +532,6 @@ public class PrepareReleaseMojo
*/ */
private void checkForPresenceOfSnapshots( MavenProject project ) private void checkForPresenceOfSnapshots( MavenProject project )
throws MojoExecutionException throws MojoExecutionException
{
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_SNAPSHOTS_CHECKED ) )
{ {
getLog().info( "Checking lineage for snapshots ..." ); getLog().info( "Checking lineage for snapshots ..." );
@ -599,27 +616,15 @@ public class PrepareReleaseMojo
throw new MojoExecutionException( throw new MojoExecutionException(
"Can't release project due to non released dependencies :\n" + message.toString() ); "Can't release project due to non released dependencies :\n" + message.toString() );
} }
try
{
getReleaseProgress().checkpoint( basedir, ReleaseProgressTracker.CP_SNAPSHOTS_CHECKED );
}
catch ( IOException e )
{
getLog().warn( "Error writing checkpoint.", e );
}
}
} }
private void transformPomToReleaseVersionPom( MavenProject project ) private void transformPomToReleaseVersionPom( MavenProject project )
throws MojoExecutionException throws MojoExecutionException
{
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE ) )
{ {
if ( !isSnapshot( project.getVersion() ) ) if ( !isSnapshot( project.getVersion() ) )
{ {
throw new MojoExecutionException( "The project " + project.getGroupId() + ":" + throw new MojoExecutionException( "The project " + project.getGroupId() + ":" + project.getArtifactId() +
project.getArtifactId() + " isn't a snapshot (" + project.getVersion() + ")." ); " isn't a snapshot (" + project.getVersion() + ")." );
} }
Model model = project.getOriginalModel(); Model model = project.getOriginalModel();
@ -785,16 +790,6 @@ public class PrepareReleaseMojo
{ {
IOUtil.close( writer ); IOUtil.close( writer );
} }
try
{
getReleaseProgress().checkpoint( basedir, ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE );
}
catch ( IOException e )
{
getLog().warn( "Error writing checkpoint.", e );
}
}
} }
private void generateReleasePoms() private void generateReleasePoms()
@ -1004,7 +999,7 @@ public class PrepareReleaseMojo
{ {
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_CHECKED_IN_RELEASE_VERSION ) ) if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_CHECKED_IN_RELEASE_VERSION ) )
{ {
checkIn( "**/pom.xml,**/release-pom.xml", "[maven-release-plugin] prepare release" ); checkIn( "**/pom.xml,**/release-pom.xml", "[maven-release-plugin] prepare release " + getTagLabel() );
try try
{ {
@ -1151,6 +1146,16 @@ public class PrepareReleaseMojo
} }
} }
if ( userTag == null )
{
userTag = releaseProgress.getScmTag();
}
if ( userTag == null )
{
throw new MojoExecutionException( "A tag must be specified" );
}
return userTag; return userTag;
} }

View File

@ -21,6 +21,7 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.Scm; import org.apache.maven.model.Scm;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -41,31 +42,32 @@ public class ProjectScmRewriter
" already has it's original SCM info cached. Each project should only be resolved once." ); " already has it's original SCM info cached. Each project should only be resolved once." );
} }
Model model = project.getModel(); if ( project.getScm() == null )
Scm scm = model.getScm();
if ( scm == null )
{ {
throw new MojoExecutionException( throw new MojoExecutionException(
"Project: " + projectId + " does not have a SCM section! Cannot proceed with release." ); "Project: " + projectId + " does not have a SCM section! Cannot proceed with release." );
} }
String tag = model.getScm().getTag(); Model model = project.getOriginalModel();
String connection = model.getScm().getConnection(); Scm scm = model.getScm();
// If SCM is null in original model, it is inherited, no mods needed
if ( scm != null )
{
String tag = scm.getTag();
String developerConnection = model.getScm().getDeveloperConnection(); String connection = scm.getConnection();
ScmInfo info = new ScmInfo( tag, connection, developerConnection ); String developerConnection = scm.getDeveloperConnection();
String url = scm.getUrl();
ScmInfo info = new ScmInfo( tag, connection, developerConnection, url );
originalScmInformation.put( projectId, info ); originalScmInformation.put( projectId, info );
scm.setTag( tagLabel ); rewriteScmConnection( scm, tagLabel );
}
scm.setConnection( rewriteScmConnection( connection, tagLabel ) );
scm.setDeveloperConnection( rewriteScmConnection( developerConnection, tagLabel ) );
} }
public void restoreScmInfo( MavenProject project ) public void restoreScmInfo( MavenProject project )
@ -83,25 +85,40 @@ public class ProjectScmRewriter
original.modify( project ); original.modify( project );
} }
// TODO: Add other SCM types for rewriting... // TODO: Add other SCM types for rewriting, and allow other layouts
private String rewriteScmConnection( String scmConnection, String tag ) private void rewriteScmConnection( Scm scm, String tag )
{ {
if ( scmConnection != null ) if ( scm != null )
{ {
if ( scmConnection.startsWith( "svn" ) ) String scmConnection = scm.getConnection();
if ( scmConnection != null && scmConnection.startsWith( "scm:svn" ) )
{ {
if ( scmConnection.endsWith( "trunk/" ) ) scm.setConnection( convertSvnConnectionString( scmConnection, tag ) );
{ scm.setDeveloperConnection( convertSvnConnectionString( scm.getDeveloperConnection(), tag ) );
scmConnection = scmConnection.substring( 0, scmConnection.length() - "trunk/".length() ); scm.setUrl( convertSvnConnectionString( scm.getUrl(), tag ) );
} }
if ( scmConnection.endsWith( "branches/" ) )
{
scmConnection = scmConnection.substring( 0, scmConnection.length() - "branches/".length() );
}
scmConnection += "tags/" + tag;
} }
} }
private String convertSvnConnectionString( String scmConnection, String tag )
{
if ( scmConnection.indexOf( "/trunk" ) >= 0 )
{
scmConnection = StringUtils.replace( scmConnection, "/trunk", "/tags/" + tag );
}
else
{
int begin = scmConnection.indexOf( "/branches/" );
if ( begin >= 0 )
{
int end = scmConnection.indexOf( '/', begin + "/branches/".length() );
scmConnection = scmConnection.substring( 0, begin ) + "/tags/" + tag;
if ( end >= 0 && end < scmConnection.length() - 1 )
{
scmConnection += scmConnection.substring( end );
}
}
}
return scmConnection; return scmConnection;
} }
@ -113,24 +130,30 @@ public class ProjectScmRewriter
private String developerConnection; private String developerConnection;
ScmInfo( String tag, String connection, String developerConnection ) private String url;
ScmInfo( String tag, String connection, String developerConnection, String url )
{ {
this.tag = tag; this.tag = tag;
this.connection = connection; this.connection = connection;
this.developerConnection = developerConnection; this.developerConnection = developerConnection;
this.url = url;
} }
void modify( MavenProject project ) void modify( MavenProject project )
{ {
Model model = project.getModel(); Model model = project.getOriginalModel();
if ( model.getScm() != null ) Scm scm = model.getScm();
if ( scm != null )
{ {
model.getScm().setTag( tag ); scm.setTag( tag );
model.getScm().setConnection( connection ); scm.setConnection( connection );
model.getScm().setDeveloperConnection( developerConnection ); scm.setDeveloperConnection( developerConnection );
scm.setUrl( url );
} }
} }
} }

View File

@ -128,7 +128,7 @@ public class ProjectVersionResolver
projectVersion = inputVersion; projectVersion = inputVersion;
} }
project.setVersion( projectVersion ); project.getOriginalModel().setVersion( projectVersion );
resolvedVersions.put( projectId, projectVersion ); resolvedVersions.put( projectId, projectVersion );
} }

View File

@ -1,6 +1,5 @@
package org.apache.maven.plugins.release.helpers; package org.apache.maven.plugins.release.helpers;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.IOUtil;
import java.io.File; import java.io.File;
@ -32,8 +31,6 @@ public class ReleaseProgressTracker
public static final String CP_LOCAL_MODIFICATIONS_CHECKED = "local-modifications-checked"; public static final String CP_LOCAL_MODIFICATIONS_CHECKED = "local-modifications-checked";
public static final String CP_SNAPSHOTS_CHECKED = "snapshots-checked";
public static final String CP_POM_TRANSFORMED_FOR_RELEASE = "transformed-pom-for-release"; public static final String CP_POM_TRANSFORMED_FOR_RELEASE = "transformed-pom-for-release";
public static final String CP_GENERATED_RELEASE_POM = "generated-release-pom"; public static final String CP_GENERATED_RELEASE_POM = "generated-release-pom";
@ -54,14 +51,15 @@ public class ReleaseProgressTracker
private boolean resumeAtCheckpoint = false; private boolean resumeAtCheckpoint = false;
private ReleaseProgressTracker() private ReleaseProgressTracker( Properties properties )
{ {
this.releaseProperties = properties;
} }
public static ReleaseProgressTracker loadOrCreate( String basedir ) public static ReleaseProgressTracker loadOrCreate( String basedir )
throws IOException throws IOException
{ {
ReleaseProgressTracker tracker = null; ReleaseProgressTracker tracker;
if ( new File( basedir, RELEASE_PROPERTIES ).exists() ) if ( new File( basedir, RELEASE_PROPERTIES ).exists() )
{ {
@ -69,37 +67,39 @@ public class ReleaseProgressTracker
} }
else else
{ {
tracker = new ReleaseProgressTracker(); tracker = create();
} }
return tracker; return tracker;
} }
public static ReleaseProgressTracker create()
{
return new ReleaseProgressTracker( new Properties() );
}
public static ReleaseProgressTracker load( String basedir ) public static ReleaseProgressTracker load( String basedir )
throws IOException throws IOException
{ {
File releasePropertiesFile = new File( basedir, RELEASE_PROPERTIES ); File releasePropertiesFile = new File( basedir, RELEASE_PROPERTIES );
ReleaseProgressTracker tracker = new ReleaseProgressTracker();
InputStream inStream = null; InputStream inStream = null;
Properties rp;
try try
{ {
inStream = new FileInputStream( releasePropertiesFile ); inStream = new FileInputStream( releasePropertiesFile );
Properties rp = new Properties(); rp = new Properties();
rp.load( inStream ); rp.load( inStream );
tracker.releaseProperties = rp;
} }
finally finally
{ {
IOUtil.close( inStream ); IOUtil.close( inStream );
} }
return tracker; return new ReleaseProgressTracker( rp );
} }
public static String getReleaseProgressFilename() public static String getReleaseProgressFilename()
@ -107,101 +107,56 @@ public class ReleaseProgressTracker
return RELEASE_PROPERTIES; return RELEASE_PROPERTIES;
} }
private void checkInitialized()
{
if ( releaseProperties == null )
{
releaseProperties = new Properties();
}
}
private void checkLoaded()
{
if ( releaseProperties == null )
{
throw new IllegalStateException( "You must load this instance before reading from it." );
}
}
public void setUsername( String username ) public void setUsername( String username )
{ {
checkInitialized();
releaseProperties.setProperty( USERNAME, username ); releaseProperties.setProperty( USERNAME, username );
} }
public String getUsername() public String getUsername()
{ {
checkLoaded();
return releaseProperties.getProperty( USERNAME ); return releaseProperties.getProperty( USERNAME );
} }
public void setScmTag( String scmTag ) public void setScmTag( String scmTag )
{ {
checkInitialized();
releaseProperties.setProperty( SCM_TAG, scmTag ); releaseProperties.setProperty( SCM_TAG, scmTag );
} }
public String getScmTag() public String getScmTag()
{ {
checkLoaded();
return releaseProperties.getProperty( SCM_TAG ); return releaseProperties.getProperty( SCM_TAG );
} }
public void setScmUrl( String scmUrl ) public void setScmUrl( String scmUrl )
{ {
checkInitialized();
releaseProperties.setProperty( SCM_URL, scmUrl ); releaseProperties.setProperty( SCM_URL, scmUrl );
} }
public String getScmUrl() public String getScmUrl()
{ {
checkLoaded();
return releaseProperties.getProperty( SCM_URL ); return releaseProperties.getProperty( SCM_URL );
} }
public void setScmTagBase( String tagBase ) public void setScmTagBase( String tagBase )
{ {
checkInitialized();
releaseProperties.setProperty( SCM_TAG_BASE, tagBase ); releaseProperties.setProperty( SCM_TAG_BASE, tagBase );
} }
public String getScmTagBase() public String getScmTagBase()
{ {
checkLoaded();
return releaseProperties.getProperty( SCM_TAG_BASE ); return releaseProperties.getProperty( SCM_TAG_BASE );
} }
public void setPassword( String password ) public void setPassword( String password )
{ {
checkInitialized();
releaseProperties.setProperty( SCM_PASSWORD, password ); releaseProperties.setProperty( SCM_PASSWORD, password );
} }
public String getPassword() public String getPassword()
{ {
checkInitialized();
return releaseProperties.getProperty( SCM_PASSWORD ); return releaseProperties.getProperty( SCM_PASSWORD );
} }
public void verifyResumeCapable()
throws MojoExecutionException
{
if ( getUsername() == null || getScmTag() == null || getScmTagBase() == null || getScmUrl() == null )
{
throw new MojoExecutionException( "Missing release preparation information. Failed to resume" );
}
}
public void checkpoint( String basedir, String pointName ) public void checkpoint( String basedir, String pointName )
throws IOException throws IOException
{ {
@ -225,15 +180,11 @@ public class ReleaseProgressTracker
private void setCheckpoint( String pointName ) private void setCheckpoint( String pointName )
{ {
checkInitialized();
releaseProperties.setProperty( CHECKPOINT_PREFIX + pointName, "OK" ); releaseProperties.setProperty( CHECKPOINT_PREFIX + pointName, "OK" );
} }
public boolean verifyCheckpoint( String pointName ) public boolean verifyCheckpoint( String pointName )
{ {
checkLoaded();
return resumeAtCheckpoint && "OK".equals( releaseProperties.getProperty( CHECKPOINT_PREFIX + pointName ) ); return resumeAtCheckpoint && "OK".equals( releaseProperties.getProperty( CHECKPOINT_PREFIX + pointName ) );
} }