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,22 +171,35 @@ public class PrepareReleaseMojo
{ {
checkForLocalModifications(); checkForLocalModifications();
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE ) )
{ {
MavenProject project = (MavenProject) it.next(); for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
getVersionResolver().resolveVersion( project ); getVersionResolver().resolveVersion( project );
getScmRewriter().rewriteScmInfo( project, getTagLabel() ); getScmRewriter().rewriteScmInfo( project, getTagLabel() );
} }
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{ {
MavenProject project = (MavenProject) it.next(); MavenProject project = (MavenProject) it.next();
checkForPresenceOfSnapshots( project ); checkForPresenceOfSnapshots( project );
transformPomToReleaseVersionPom( project );
}
try
{
getReleaseProgress().checkpoint( basedir, ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE );
}
catch ( IOException e )
{
getLog().warn( "Error writing checkpoint.", e );
}
transformPomToReleaseVersionPom( project );
} }
generateReleasePoms(); generateReleasePoms();
@ -204,11 +217,24 @@ public class PrepareReleaseMojo
getScmRewriter().restoreScmInfo( project ); getScmRewriter().restoreScmInfo( project );
} }
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_POM_TRANSORMED_FOR_DEVELOPMENT ) )
{ {
MavenProject project = (MavenProject) it.next(); for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
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();
@ -229,109 +255,106 @@ 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() ) ) throw new MojoExecutionException( "This project is a snapshot (" + project.getVersion() +
"). It appears that the release version has not been committed." );
}
Model model = project.getOriginalModel();
ProjectVersionResolver versionResolver = getVersionResolver();
Parent parent = model.getParent();
//Rewrite parent version
if ( parent != null )
{
String incrementedVersion = versionResolver.getResolvedVersion( parent.getGroupId(), parent
.getArtifactId() );
if ( incrementedVersion != null )
{ {
throw new MojoExecutionException( "This project is a snapshot (" + project.getVersion() + parent.setVersion( incrementedVersion );
"). It appears that the release version has not been committed." );
} }
}
Model model = project.getOriginalModel(); //Rewrite dependencies section
List dependencies = model.getDependencies();
ProjectVersionResolver versionResolver = getVersionResolver(); if ( dependencies != null )
{
Parent parent = model.getParent(); for ( Iterator i = dependencies.iterator(); i.hasNext(); )
//Rewrite parent version
if ( parent != null )
{ {
String incrementedVersion = versionResolver.getResolvedVersion( parent.getGroupId(), parent Dependency dep = (Dependency) i.next();
.getArtifactId() );
if ( incrementedVersion != null ) String version = versionResolver.getResolvedVersion( dep.getGroupId(), dep.getArtifactId() );
if ( version != null )
{ {
parent.setVersion( incrementedVersion ); dep.setVersion( version );
} }
} }
}
//Rewrite dependencies section //Rewrite plugins section
List dependencies = model.getDependencies(); Build build = model.getBuild();
if ( dependencies != null ) if ( build != null )
{
List plugins = build.getPlugins();
if ( plugins != null )
{ {
for ( Iterator i = dependencies.iterator(); i.hasNext(); ) for ( Iterator i = plugins.iterator(); i.hasNext(); )
{ {
Dependency dep = (Dependency) i.next(); Plugin plugin = (Plugin) i.next();
String version = versionResolver.getResolvedVersion( dep.getGroupId(), dep.getArtifactId() ); String version = versionResolver.getResolvedVersion( plugin.getGroupId(), plugin
.getArtifactId() );
if ( version != null ) if ( version != null )
{ {
dep.setVersion( version ); plugin.setVersion( version );
} }
} }
} }
//Rewrite plugins section //Rewrite extensions section
Build build = model.getBuild(); List extensions = build.getExtensions();
if ( build != null ) for ( Iterator i = extensions.iterator(); i.hasNext(); )
{ {
List plugins = build.getPlugins(); Extension ext = (Extension) i.next();
if ( plugins != null ) String version = versionResolver.getResolvedVersion( ext.getGroupId(), ext.getArtifactId() );
if ( version != null )
{ {
for ( Iterator i = plugins.iterator(); i.hasNext(); ) ext.setVersion( version );
{
Plugin plugin = (Plugin) i.next();
String version = versionResolver.getResolvedVersion( plugin.getGroupId(), plugin
.getArtifactId() );
if ( version != null )
{
plugin.setVersion( version );
}
}
} }
}
}
//Rewrite extensions section Reporting reporting = model.getReporting();
List extensions = build.getExtensions();
for ( Iterator i = extensions.iterator(); i.hasNext(); ) if ( reporting != null )
{
//Rewrite reports section
List reports = reporting.getPlugins();
if ( reports != null )
{
for ( Iterator i = reports.iterator(); i.hasNext(); )
{ {
Extension ext = (Extension) i.next(); ReportPlugin plugin = (ReportPlugin) i.next();
String version = versionResolver.getResolvedVersion( ext.getGroupId(), ext.getArtifactId() ); String version = versionResolver.getResolvedVersion( plugin.getGroupId(), plugin
.getArtifactId() );
if ( version != null ) if ( version != null )
{ {
ext.setVersion( version ); plugin.setVersion( version );
}
}
}
Reporting reporting = model.getReporting();
if ( reporting != null )
{
//Rewrite reports section
List reports = reporting.getPlugins();
if ( reports != null )
{
for ( Iterator i = reports.iterator(); i.hasNext(); )
{
ReportPlugin plugin = (ReportPlugin) i.next();
String version = versionResolver.getResolvedVersion( plugin.getGroupId(), plugin
.getArtifactId() );
if ( version != null )
{
plugin.setVersion( version );
}
} }
} }
} }
@ -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 );
}
} }
} }
@ -370,49 +384,54 @@ public class PrepareReleaseMojo
{ {
if ( releaseProgress == null ) if ( releaseProgress == null )
{ {
try
{
releaseProgress = ReleaseProgressTracker.loadOrCreate( basedir );
}
catch ( IOException e )
{
getLog().warn( "Cannot read existing release progress file from directory: " + basedir + "." );
getLog().debug( "Cause", e );
releaseProgress = ReleaseProgressTracker.create();
}
if ( resume ) if ( resume )
{ {
try releaseProgress.setResumeAtCheckpoint( true );
{
releaseProgress = ReleaseProgressTracker.load( basedir );
releaseProgress.verifyResumeCapable();
}
catch ( IOException e )
{
throw new MojoExecutionException(
"Cannot read existing release progress file from directory: " + basedir + ". Cannot resume." );
}
} }
else
if ( releaseProgress.getUsername() == null )
{ {
try
{
releaseProgress = ReleaseProgressTracker.loadOrCreate( basedir );
}
catch ( IOException e )
{
getLog().warn( "Cannot read existing release progress file from directory: " + basedir +
". Creating new instance." );
}
releaseProgress.setResumeAtCheckpoint( resume );
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;
} }
@ -514,287 +533,263 @@ 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 ..." );
MavenProject currentProject = project;
while ( currentProject.hasParent() )
{ {
getLog().info( "Checking lineage for snapshots ..." ); MavenProject parentProject = currentProject.getParent();
MavenProject currentProject = project; String parentVersion = getVersionResolver().getResolvedVersion( parentProject.getGroupId(),
parentProject.getArtifactId() );
while ( currentProject.hasParent() ) if ( isSnapshot( parentVersion ) )
{ {
MavenProject parentProject = currentProject.getParent(); throw new MojoExecutionException( "Can't release project due to non released parent." );
String parentVersion = getVersionResolver().getResolvedVersion( parentProject.getGroupId(),
parentProject.getArtifactId() );
if ( isSnapshot( parentVersion ) )
{
throw new MojoExecutionException( "Can't release project due to non released parent." );
}
currentProject = parentProject;
} }
getLog().info( "Checking dependencies for snapshots ..." ); currentProject = parentProject;
}
Set snapshotDependencies = new HashSet(); getLog().info( "Checking dependencies for snapshots ..." );
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); ) Set snapshotDependencies = new HashSet();
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
String artifactVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
artifact.getArtifactId() );
if ( artifactVersion == null )
{
artifactVersion = artifact.getVersion();
}
if ( isSnapshot( artifactVersion ) )
{
snapshotDependencies.add( artifact );
}
}
getLog().info( "Checking plugins for snapshots ..." );
for ( Iterator i = project.getPluginArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
String artifactVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
artifact.getArtifactId() );
if ( artifactVersion == null )
{
artifactVersion = artifact.getVersion();
}
if ( isSnapshot( artifactVersion ) )
{
snapshotDependencies.add( artifact );
}
}
if ( !snapshotDependencies.isEmpty() )
{
List snapshotsList = new ArrayList( snapshotDependencies );
Collections.sort( snapshotsList );
StringBuffer message = new StringBuffer();
for ( Iterator i = snapshotsList.iterator(); i.hasNext(); )
{ {
Artifact artifact = (Artifact) i.next(); Artifact artifact = (Artifact) i.next();
String artifactVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(), message.append( " " );
artifact.getArtifactId() );
if ( artifactVersion == null ) message.append( artifact.getId() );
{
artifactVersion = artifact.getVersion();
}
if ( isSnapshot( artifactVersion ) ) message.append( "\n" );
{
snapshotDependencies.add( artifact );
}
} }
getLog().info( "Checking plugins for snapshots ..." ); throw new MojoExecutionException(
"Can't release project due to non released dependencies :\n" + message.toString() );
for ( Iterator i = project.getPluginArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
String artifactVersion = getVersionResolver().getResolvedVersion( artifact.getGroupId(),
artifact.getArtifactId() );
if ( artifactVersion == null )
{
artifactVersion = artifact.getVersion();
}
if ( isSnapshot( artifactVersion ) )
{
snapshotDependencies.add( artifact );
}
}
if ( !snapshotDependencies.isEmpty() )
{
List snapshotsList = new ArrayList( snapshotDependencies );
Collections.sort( snapshotsList );
StringBuffer message = new StringBuffer();
for ( Iterator i = snapshotsList.iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
message.append( " " );
message.append( artifact.getId() );
message.append( "\n" );
}
throw new MojoExecutionException(
"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() + ":" + project.getArtifactId() +
" isn't a snapshot (" + project.getVersion() + ")." );
}
Model model = project.getOriginalModel();
//Rewrite parent version
if ( model.getParent() != null )
{
Artifact parentArtifact = project.getParentArtifact();
if ( isSnapshot( parentArtifact.getBaseVersion() ) )
{ {
throw new MojoExecutionException( "The project " + project.getGroupId() + ":" + String version = resolveVersion( parentArtifact, "parent", project );
project.getArtifactId() + " isn't a snapshot (" + project.getVersion() + ")." );
model.getParent().setVersion( version );
} }
}
Model model = project.getOriginalModel(); //Rewrite dependencies section
List dependencies = model.getDependencies();
//Rewrite parent version if ( dependencies != null )
if ( model.getParent() != null ) {
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{ {
Artifact parentArtifact = project.getParentArtifact(); Dependency dep = (Dependency) i.next();
if ( isSnapshot( parentArtifact.getBaseVersion() ) ) // Avoid in dep mgmt
if ( dep.getVersion() != null )
{ {
String version = resolveVersion( parentArtifact, "parent", project ); String resolvedVersion = getVersionResolver().getResolvedVersion( dep.getGroupId(),
dep.getArtifactId() );
model.getParent().setVersion( version );
}
}
//Rewrite dependencies section
List dependencies = model.getDependencies();
if ( dependencies != null )
{
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{
Dependency dep = (Dependency) i.next();
// Avoid in dep mgmt
if ( dep.getVersion() != null )
{
String resolvedVersion = getVersionResolver().getResolvedVersion( dep.getGroupId(),
dep.getArtifactId() );
if ( resolvedVersion != null )
{
dep.setVersion( resolvedVersion );
}
}
}
}
DependencyManagement dependencyManagement = model.getDependencyManagement();
dependencies = dependencyManagement != null ? dependencyManagement.getDependencies() : null;
if ( dependencies != null )
{
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{
Dependency dep = (Dependency) i.next();
if ( dep.getVersion() != null )
{
String resolvedVersion = getVersionResolver().getResolvedVersion( dep.getGroupId(),
dep.getArtifactId() );
if ( resolvedVersion != null )
{
dep.setVersion( resolvedVersion );
}
}
}
}
Build build = model.getBuild();
if ( build != null )
{
//Rewrite plugins section
List plugins = build.getPlugins();
if ( plugins != null )
{
for ( Iterator i = plugins.iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
// Avoid in plugin mgmt
if ( plugin.getVersion() != null )
{
String resolvedVersion = getVersionResolver().getResolvedVersion( plugin.getGroupId(),
plugin.getArtifactId() );
if ( resolvedVersion != null )
{
plugin.setVersion( resolvedVersion );
}
}
}
}
PluginManagement pluginManagement = build.getPluginManagement();
plugins = pluginManagement != null ? pluginManagement.getPlugins() : null;
if ( plugins != null )
{
for ( Iterator i = plugins.iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
if ( plugin.getVersion() != null )
{
String resolvedVersion = getVersionResolver().getResolvedVersion( plugin.getGroupId(),
plugin.getArtifactId() );
if ( resolvedVersion != null )
{
plugin.setVersion( resolvedVersion );
}
}
}
}
//Rewrite extensions section
List extensions = build.getExtensions();
for ( Iterator i = extensions.iterator(); i.hasNext(); )
{
Extension ext = (Extension) i.next();
String resolvedVersion = getVersionResolver().getResolvedVersion( ext.getGroupId(),
ext.getArtifactId() );
if ( resolvedVersion != null ) if ( resolvedVersion != null )
{ {
ext.setVersion( resolvedVersion ); dep.setVersion( resolvedVersion );
} }
} }
} }
}
Reporting reporting = model.getReporting(); DependencyManagement dependencyManagement = model.getDependencyManagement();
dependencies = dependencyManagement != null ? dependencyManagement.getDependencies() : null;
if ( reporting != null ) if ( dependencies != null )
{
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{ {
//Rewrite reports section Dependency dep = (Dependency) i.next();
List reports = reporting.getPlugins();
for ( Iterator i = reports.iterator(); i.hasNext(); ) if ( dep.getVersion() != null )
{ {
ReportPlugin plugin = (ReportPlugin) i.next(); String resolvedVersion = getVersionResolver().getResolvedVersion( dep.getGroupId(),
dep.getArtifactId() );
String resolvedVersion = getVersionResolver().getResolvedVersion( plugin.getGroupId(),
plugin.getArtifactId() );
if ( resolvedVersion != null ) if ( resolvedVersion != null )
{ {
plugin.setVersion( resolvedVersion ); dep.setVersion( resolvedVersion );
}
}
}
}
Build build = model.getBuild();
if ( build != null )
{
//Rewrite plugins section
List plugins = build.getPlugins();
if ( plugins != null )
{
for ( Iterator i = plugins.iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
// Avoid in plugin mgmt
if ( plugin.getVersion() != null )
{
String resolvedVersion = getVersionResolver().getResolvedVersion( plugin.getGroupId(),
plugin.getArtifactId() );
if ( resolvedVersion != null )
{
plugin.setVersion( resolvedVersion );
}
} }
} }
} }
Writer writer = null; PluginManagement pluginManagement = build.getPluginManagement();
plugins = pluginManagement != null ? pluginManagement.getPlugins() : null;
try if ( plugins != null )
{ {
writer = new FileWriter( project.getFile() ); for ( Iterator i = plugins.iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
project.writeOriginalModel( writer ); if ( plugin.getVersion() != null )
} {
catch ( IOException e ) String resolvedVersion = getVersionResolver().getResolvedVersion( plugin.getGroupId(),
{ plugin.getArtifactId() );
throw new MojoExecutionException( "Cannot write released version of pom to: " + project.getFile(), e );
} if ( resolvedVersion != null )
finally {
{ plugin.setVersion( resolvedVersion );
IOUtil.close( writer ); }
}
}
} }
try //Rewrite extensions section
List extensions = build.getExtensions();
for ( Iterator i = extensions.iterator(); i.hasNext(); )
{ {
getReleaseProgress().checkpoint( basedir, ReleaseProgressTracker.CP_POM_TRANSFORMED_FOR_RELEASE ); Extension ext = (Extension) i.next();
String resolvedVersion = getVersionResolver().getResolvedVersion( ext.getGroupId(),
ext.getArtifactId() );
if ( resolvedVersion != null )
{
ext.setVersion( resolvedVersion );
}
} }
catch ( IOException e ) }
Reporting reporting = model.getReporting();
if ( reporting != null )
{
//Rewrite reports section
List reports = reporting.getPlugins();
for ( Iterator i = reports.iterator(); i.hasNext(); )
{ {
getLog().warn( "Error writing checkpoint.", e ); ReportPlugin plugin = (ReportPlugin) i.next();
String resolvedVersion = getVersionResolver().getResolvedVersion( plugin.getGroupId(),
plugin.getArtifactId() );
if ( resolvedVersion != null )
{
plugin.setVersion( resolvedVersion );
}
} }
} }
Writer writer = null;
try
{
writer = new FileWriter( project.getFile() );
project.writeOriginalModel( writer );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot write released version of pom to: " + project.getFile(), e );
}
finally
{
IOUtil.close( writer );
}
} }
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();
originalScmInformation.put( projectId, info ); String url = scm.getUrl();
scm.setTag( tagLabel ); ScmInfo info = new ScmInfo( tag, connection, developerConnection, url );
scm.setConnection( rewriteScmConnection( connection, tagLabel ) ); originalScmInformation.put( projectId, info );
scm.setDeveloperConnection( rewriteScmConnection( developerConnection, tagLabel ) ); rewriteScmConnection( scm, 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 ) );
} }