various release plugin fixes

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@279256 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-07 06:01:23 +00:00
parent 22f9a34107
commit 457a613ee9
7 changed files with 109 additions and 152 deletions

View File

@ -23,7 +23,6 @@ import org.apache.maven.plugins.release.helpers.ScmHelper;
import org.apache.maven.scm.manager.ScmManager;
/**
*
* @author <a href="mailto:jdcasey@apache.org">John Casey</a>
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id$
@ -41,7 +40,7 @@ public abstract class AbstractReleaseMojo
protected abstract ReleaseProgressTracker getReleaseProgress()
throws MojoExecutionException;
protected ScmHelper getScm()
protected ScmHelper getScm( String directory )
throws MojoExecutionException
{
if ( scmHelper == null )
@ -63,6 +62,8 @@ public abstract class AbstractReleaseMojo
scmHelper.setPassword( releaseProgress.getPassword() );
}
scmHelper.setWorkingDirectory( directory );
return scmHelper;
}

View File

@ -30,11 +30,10 @@ import java.io.IOException;
/**
* Perform a release from SCM
*
* @aggregator
* @goal perform
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id: DoxiaMojo.java 169372 2005-05-09 22:47:34Z evenisse $
* @aggregator
* @goal perform
*/
public class PerformReleaseMojo
extends AbstractReleaseMojo
@ -74,9 +73,7 @@ public class PerformReleaseMojo
try
{
ScmHelper scm = getScm();
scm.setWorkingDirectory( workingDirectory );
ScmHelper scm = getScm( workingDirectory );
scm.checkout();
}
@ -128,8 +125,8 @@ public class PerformReleaseMojo
}
catch ( IOException e )
{
throw new MojoExecutionException( "Failed to load release information from file: "
+ ReleaseProgressTracker.getReleaseProgressFilename(), e );
throw new MojoExecutionException( "Failed to load release information from file: " +
ReleaseProgressTracker.getReleaseProgressFilename(), e );
}
}

View File

@ -123,9 +123,9 @@ public class PrepareReleaseMojo
private String urlScm;
/**
* @parameter expression="${maven.username}"
* @parameter expression="${username}"
*/
private String username = System.getProperty( "user.name" );
private String username;
/**
* @parameter expression="${password}"
@ -208,17 +208,17 @@ public class PrepareReleaseMojo
tagRelease();
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
getVersionResolver().incrementVersion( project );
getScmRewriter().restoreScmInfo( project );
}
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSORMED_FOR_DEVELOPMENT ) )
{
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
getVersionResolver().incrementVersion( project );
getScmRewriter().restoreScmInfo( project );
}
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
@ -358,24 +358,22 @@ public class PrepareReleaseMojo
}
}
}
}
Writer writer = null;
Writer writer = null;
try
{
writer = new FileWriter( project.getFile() );
try
{
writer = new FileWriter( project.getFile() );
project.writeOriginalModel( writer );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot write development version of pom to: " + project.getFile(),
e );
}
finally
{
IOUtil.close( writer );
}
project.writeOriginalModel( writer );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot write development version of pom to: " + project.getFile(), e );
}
finally
{
IOUtil.close( writer );
}
}
@ -403,6 +401,10 @@ public class PrepareReleaseMojo
if ( releaseProgress.getUsername() == null )
{
if ( username == null )
{
username = System.getProperty( "user.name" );
}
releaseProgress.setUsername( username );
}
@ -446,10 +448,11 @@ public class PrepareReleaseMojo
}
protected ProjectScmRewriter getScmRewriter()
throws MojoExecutionException
{
if ( scmRewriter == null )
{
scmRewriter = new ProjectScmRewriter();
scmRewriter = new ProjectScmRewriter( getReleaseProgress() );
}
return scmRewriter;
@ -471,9 +474,7 @@ public class PrepareReleaseMojo
try
{
ScmHelper scm = getScm();
scm.setWorkingDirectory( basedir );
ScmHelper scm = getScm( basedir );
changedFiles = scm.getStatus();
}
@ -934,9 +935,7 @@ public class PrepareReleaseMojo
releasePomPath = releasePomPath.substring( canonicalBasedir.length() + 1 );
ScmHelper scm = getScm();
scm.setWorkingDirectory( basedir );
ScmHelper scm = getScm( basedir );
scm.add( releasePomPath );
}
@ -999,7 +998,7 @@ public class PrepareReleaseMojo
{
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_CHECKED_IN_RELEASE_VERSION ) )
{
checkIn( "**/pom.xml,**/release-pom.xml", "[maven-release-plugin] prepare release " + getTagLabel() );
checkIn( "[maven-release-plugin] prepare release " + getTagLabel() );
try
{
@ -1029,11 +1028,13 @@ public class PrepareReleaseMojo
currentReleasePomFile = new File( project.getFile().getParentFile(), RELEASE_POM );
String releasePom = trimPathForScmCalculation( currentReleasePomFile );
String releasePomPath = trimPathForScmCalculation( currentReleasePomFile );
releasePom = releasePom.substring( canonicalBasedir.length() );
releasePomPath = releasePomPath.substring( canonicalBasedir.length() + 1 );
getScm().remove( "Removing for next development iteration.", releasePom );
ScmHelper scm = getScm( basedir );
scm.remove( "Removing for next development iteration.", releasePomPath );
currentReleasePomFile.delete();
}
@ -1080,7 +1081,7 @@ public class PrepareReleaseMojo
{
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_CHECKED_IN_DEVELOPMENT_VERSION ) )
{
checkIn( "**/pom.xml", "[maven-release-plugin] prepare for next development iteration" );
checkIn( "[maven-release-plugin] prepare for next development iteration" );
try
{
@ -1093,21 +1094,19 @@ public class PrepareReleaseMojo
}
}
private void checkIn( String includePattern, String message )
private void checkIn( String message )
throws MojoExecutionException
{
try
{
ScmHelper scm = getScm();
scm.setWorkingDirectory( basedir );
ScmHelper scm = getScm( basedir );
String tag = scm.getTag();
// No tag here - we suppose user works on correct branch
scm.setTag( null );
scm.checkin( message, includePattern, null );
scm.checkin( message );
scm.setTag( tag );
}
@ -1179,9 +1178,7 @@ public class PrepareReleaseMojo
try
{
ScmHelper scm = getScm();
scm.setWorkingDirectory( basedir );
ScmHelper scm = getScm( basedir );
scm.setTag( tag );

View File

@ -23,25 +23,20 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
public class ProjectScmRewriter
{
private ReleaseProgressTracker releaseProgress;
private Map originalScmInformation = new HashMap();
public ProjectScmRewriter( ReleaseProgressTracker releaseProgress )
{
this.releaseProgress = releaseProgress;
}
public void rewriteScmInfo( MavenProject project, String tagLabel )
throws MojoExecutionException
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
if ( originalScmInformation.containsKey( projectId ) )
{
throw new IllegalArgumentException( "Project: " + projectId +
" already has it's original SCM info cached. Each project should only be resolved once." );
}
if ( project.getScm() == null )
{
throw new MojoExecutionException(
@ -54,17 +49,7 @@ public class ProjectScmRewriter
// If SCM is null in original model, it is inherited, no mods needed
if ( scm != null )
{
String tag = scm.getTag();
String connection = scm.getConnection();
String developerConnection = scm.getDeveloperConnection();
String url = scm.getUrl();
ScmInfo info = new ScmInfo( tag, connection, developerConnection, url );
originalScmInformation.put( projectId, info );
releaseProgress.addOriginalScmInfo( projectId, scm );
rewriteScmConnection( scm, tagLabel );
}
@ -72,17 +57,13 @@ public class ProjectScmRewriter
public void restoreScmInfo( MavenProject project )
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
ScmInfo original = (ScmInfo) originalScmInformation.get( projectId );
if ( original == null )
Scm scm = project.getOriginalModel().getScm();
if ( scm != null )
{
throw new IllegalArgumentException(
"Project \'" + projectId + "\' has not had its SCM info cached. Cannot restore uncached SCM info." );
}
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
original.modify( project );
releaseProgress.restoreScmInfo( projectId, scm );
}
}
// TODO: Add other SCM types for rewriting, and allow other layouts
@ -121,41 +102,4 @@ public class ProjectScmRewriter
}
return scmConnection;
}
private static class ScmInfo
{
private String tag;
private String connection;
private String developerConnection;
private String url;
ScmInfo( String tag, String connection, String developerConnection, String url )
{
this.tag = tag;
this.connection = connection;
this.developerConnection = developerConnection;
this.url = url;
}
void modify( MavenProject project )
{
Model model = project.getOriginalModel();
Scm scm = model.getScm();
if ( scm != null )
{
scm.setTag( tag );
scm.setConnection( connection );
scm.setDeveloperConnection( developerConnection );
scm.setUrl( url );
}
}
}
}

View File

@ -84,15 +84,7 @@ public class ProjectVersionResolver
public void incrementVersion( MavenProject project )
throws MojoExecutionException
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
String projectVersion = (String) resolvedVersions.get( projectId );
if ( projectVersion == null )
{
throw new IllegalArgumentException(
"Project \'" + projectId + "\' has not been resolved. Cannot increment an unresolved version." );
}
String projectVersion = project.getOriginalModel().getVersion();
// TODO: we will need to incorporate versioning strategies here because it is unlikely
// that everyone will be able to agree on a standard. This is extremely limited right
@ -115,6 +107,7 @@ public class ProjectVersionResolver
projectVersion = "";
}
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
if ( interactive )
{
try
@ -127,10 +120,6 @@ public class ProjectVersionResolver
{
projectVersion = inputVersion;
}
project.getOriginalModel().setVersion( projectVersion );
resolvedVersions.put( projectId, projectVersion );
}
catch ( IOException e )
{
@ -141,6 +130,10 @@ public class ProjectVersionResolver
{
throw new MojoExecutionException( "Cannot determine incremented development version for: " + projectId );
}
project.getOriginalModel().setVersion( projectVersion );
resolvedVersions.put( projectId, projectVersion );
}
}

View File

@ -1,5 +1,6 @@
package org.apache.maven.plugins.release.helpers;
import org.apache.maven.model.Scm;
import org.codehaus.plexus.util.IOUtil;
import java.io.File;
@ -27,6 +28,8 @@ public class ReleaseProgressTracker
private static final String CHECKPOINT_PREFIX = "checkpoint.";
private static final String SCM_INFO_PREFIX = "scm-info.";
public static final String CP_INITIALIZED = "initialized";
public static final String CP_LOCAL_MODIFICATIONS_CHECKED = "local-modifications-checked";
@ -193,4 +196,27 @@ public class ReleaseProgressTracker
this.resumeAtCheckpoint = resumeAtCheckpoint;
}
public void addOriginalScmInfo( String projectId, Scm scm )
{
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".connection", scm.getConnection() );
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".developerConnection",
scm.getDeveloperConnection() );
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".url", scm.getUrl() );
releaseProperties.setProperty( SCM_INFO_PREFIX + projectId + ".tag", scm.getTag() );
}
public void restoreScmInfo( String projectId, Scm scm )
{
String connection = releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".connection" );
if ( connection == null )
{
throw new IllegalArgumentException(
"Project \'" + projectId + "\' has not had its SCM info cached. Cannot restore uncached SCM info." );
}
scm.setConnection( connection );
scm.setDeveloperConnection(
releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".developerConnection" ) );
scm.setUrl( releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".url" ) );
scm.setTag( releaseProperties.getProperty( SCM_INFO_PREFIX + projectId + ".tag" ) );
}
}

View File

@ -1,20 +1,19 @@
package org.apache.maven.plugins.release.helpers;
/* =====================================================================
* Copyright 2001-2005 The Apache Software Foundation.
/*
* 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
* 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
* 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.
* ====================================================================
* 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.scm.ScmException;
@ -197,7 +196,7 @@ public class ScmHelper
{
ScmRepository repository = getScmRepository();
ScmFileSet fs = new ScmFileSet( new File( workingDirectory ), file, null );
ScmFileSet fs = new ScmFileSet( new File( workingDirectory ), new File( file ) );
RemoveScmResult result = getScmManager().getProviderByRepository( repository ).remove( repository, fs,
message );
@ -205,13 +204,13 @@ public class ScmHelper
checkResult( result );
}
public void checkin( String message, String includes, String excludes )
public void checkin( String message )
throws Exception
{
ScmRepository repository = getScmRepository();
CheckInScmResult result = getScmManager().getProviderByRepository( repository )
.checkIn( repository, new ScmFileSet( new File( workingDirectory ), includes, excludes ), tag, message );
.checkIn( repository, new ScmFileSet( new File( workingDirectory ) ), tag, message );
checkResult( result );
}