Working on: MNG-662

o Moved release.properties management to a helper class
o Created a helper class for caching/prompting for project-versions
o Created a helper class for managing SCM info updates during the release:prepare process
o Moved as many of the shared fields out of AbstractReleaseMojo as possible, given the refactor to reactorized processing
o Refactored the PrepareReleaseMojo to process a list of projects, and resolve inter-dependencies during transforms, etc.
o Refactored the PerformReleaseMojo to adjust to the new helper classes.
o Removed the old transformers, since MavenProject.writeOriginalModel() can be used instead, using the modello writer
o Bumped the maven-scm versions up to 1.0-alpha-2-SNAPSHOT, and added maven-scm-manager-plexus.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@227148 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-08-03 02:36:14 +00:00
parent 094a5a4312
commit 8f4b0deaaf
14 changed files with 1832 additions and 1633 deletions

View File

@ -11,6 +11,16 @@
<packaging>maven-plugin</packaging>
<name>Maven Release plugin</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
@ -19,27 +29,22 @@
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-api</artifactId>
<version>1.0-alpha-1</version>
<version>1.0-alpha-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-manager-plexus</artifactId>
<version>1.0-alpha-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-cvs</artifactId>
<version>1.0-alpha-1</version>
<version>1.0-alpha-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-svn</artifactId>
<version>1.0-alpha-1</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.4-dev-8</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.0-FCS</version>
<version>1.0-alpha-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>plexus</groupId>

View File

@ -1,168 +0,0 @@
package org.apache.maven.plugin.release;
/*
* 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.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.scm.ScmBean;
import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.manager.ScmManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
/**
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id: DoxiaMojo.java 169372 2005-05-09 22:47:34Z evenisse $
*/
public abstract class AbstractReleaseMojo
extends AbstractMojo
{
public static final String RELEASE_PROPS = "release.properties";
public static final String USERNAME = "maven.username";
public static final String TAG = "tag";
public static final String SCM_URL = "scm.url";
/**
* @parameter expression="${project.build.directory}/checkout"
* @required
*/
protected String workingDirectory;
/**
* @parameter expression="${project.scm.developerConnection}"
* @required
*/
protected String urlScm;
/**
* @parameter expression="${maven.username}"
*/
protected String username;
/**
* @parameter expression="${password}"
*/
protected String password;
/**
* @parameter expression="${tagBase}"
*/
protected String tagBase = "../tags";
/**
* @parameter expression="${tag}"
*/
protected String tag;
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
protected MavenProject project;
/**
* @parameter expression="${org.apache.maven.scm.manager.ScmManager}"
* @required
* @readonly
*/
protected ScmManager scmManager;
private Properties releaseProperties;
protected ScmBean getScm()
{
ScmBean scm = new ScmBean();
scm.setScmManager( scmManager );
if ( releaseProperties != null )
{
urlScm = releaseProperties.getProperty( SCM_URL );
}
scm.setUrl( urlScm );
if ( releaseProperties != null )
{
tag = releaseProperties.getProperty( TAG );
}
scm.setTag( tag );
scm.setTagBase( tagBase );
if ( releaseProperties != null )
{
username = releaseProperties.getProperty( USERNAME );
}
scm.setUsername( username );
scm.setPassword( password );
scm.setWorkingDirectory( workingDirectory );
return scm;
}
public void execute()
throws MojoExecutionException
{
try
{
if ( username == null )
{
username = System.getProperty( "user.name" );
}
// ----------------------------------------------------------------------
// The release properties file has been created by the prepare phase and
// wants to be shared with the perform.
// ----------------------------------------------------------------------
File releasePropertiesFile = new File( project.getFile().getParentFile(), RELEASE_PROPS );
if ( releasePropertiesFile.exists() )
{
releaseProperties = new Properties();
InputStream is = new FileInputStream( releasePropertiesFile );
releaseProperties.load( is );
}
}
catch ( Exception e )
{
throw new MojoExecutionException( "Can't initialize ReleaseMojo.", e );
}
executeTask();
}
protected abstract void executeTask()
throws MojoExecutionException;
}

View File

@ -1,755 +0,0 @@
package org.apache.maven.plugin.release;
/*
* 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.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.scm.ScmBean;
import org.apache.maven.plugin.transformer.PomTransformer;
import org.apache.maven.plugin.transformer.VersionTransformer;
import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFile;
import org.apache.maven.scm.ScmFileStatus;
import org.codehaus.plexus.components.inputhandler.InputHandler;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* Prepare for a release in SCM
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id: DoxiaMojo.java 169372 2005-05-09 22:47:34Z evenisse $
* @goal prepare
* @requiresDependencyResolution test
* @todo check how this works with version ranges
*/
public class PrepareReleaseMojo
extends AbstractReleaseMojo
{
/**
* @parameter expression="${basedir}"
* @required
* @readonly
*/
private String basedir;
/**
* @parameter expression="${settings.interactiveMode}"
* @readonly
*/
private boolean interactive = true;
/**
* @parameter expression="${component.org.apache.maven.artifact.metadata.ArtifactMetadataSource}"
* @required
* @readonly
*/
private ArtifactMetadataSource artifactMetadataSource;
/**
* @parameter expression="${component.org.codehaus.plexus.components.inputhandler.InputHandler}"
* @required
* @readonly
*/
private InputHandler inputHandler;
/**
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
private ArtifactRepository localRepository;
private static final String SNAPSHOT = "-SNAPSHOT";
private static final String RELEASE_POM = "release-pom.xml";
private String projectVersion;
private Model model;
private String userTag;
private String currentTag;
private String currentScmConnection;
private String currentScmDeveloperConnection;
protected void executeTask()
throws MojoExecutionException
{
model = project.getModel();
checkForLocalModifications();
checkForPresenceOfSnapshots();
transformPomToReleaseVersionPom();
generateReleasePropertiesFile();
generateReleasePom();
checkInReleaseVersionPom();
tagRelease();
transformPomToSnapshotVersionPom();
new File( basedir, RELEASE_POM ).delete();
checkInSnapshotVersionPom();
}
private void generateReleasePropertiesFile()
throws MojoExecutionException
{
try
{
Properties releaseProperties = new Properties();
releaseProperties.setProperty( "version", projectVersion );
releaseProperties.setProperty( USERNAME, username );
releaseProperties.setProperty( TAG, getTagLabel() );
releaseProperties.setProperty( SCM_URL, urlScm );
FileOutputStream os = new FileOutputStream( new File( project.getFile().getParentFile(), RELEASE_PROPS ) );
releaseProperties.store( os, "maven release plugin info" );
os.close();
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannote write release-version file.", e );
}
}
private boolean isSnapshot( String version )
{
return version.endsWith( SNAPSHOT );
}
private void checkForLocalModifications()
throws MojoExecutionException
{
getLog().info( "Verifying there are no local modifications ..." );
List changedFiles;
try
{
ScmBean scm = getScm();
scm.setWorkingDirectory( basedir );
changedFiles = scm.getStatus();
}
catch ( ScmException e )
{
throw new MojoExecutionException( "An error is occurred in the status process.", e );
}
for ( Iterator i = changedFiles.iterator(); i.hasNext(); )
{
ScmFile f = (ScmFile) i.next();
if ( f.getPath().equals( "pom.xml.backup" ) || f.getPath().equals( RELEASE_PROPS ) )
{
i.remove();
}
}
if ( !changedFiles.isEmpty() )
{
StringBuffer message = new StringBuffer();
for ( Iterator i = changedFiles.iterator(); i.hasNext(); )
{
ScmFile file = (ScmFile) i.next();
message.append( file.toString() );
message.append( "\n" );
}
throw new MojoExecutionException(
"Cannot prepare the release because you have local modifications : \n" + message.toString() );
}
}
/**
* Check the POM in an attempt to remove all instances of SNAPSHOTs in preparation for a release. The goal
* is to make the build reproducable so the removal of SNAPSHOTs is a necessary one.
*
* A check is made to ensure any parents in the lineage are released, that all the dependencies are
* released and that any plugins utilized by this project are released.
*
* @throws MojoExecutionException
*/
private void checkForPresenceOfSnapshots()
throws MojoExecutionException
{
MavenProject currentProject = project;
getLog().info( "Checking lineage for snapshots ..." );
while ( currentProject.hasParent() )
{
Artifact parentArtifact = currentProject.getParentArtifact();
if ( isSnapshot( parentArtifact.getVersion() ) )
{
throw new MojoExecutionException( "Can't release project due to non released parent." );
}
currentProject = currentProject.getParent();
}
getLog().info( "Checking dependencies for snapshots ..." );
List snapshotDependencies = new ArrayList();
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
if ( isSnapshot( artifact.getVersion() ) )
{
snapshotDependencies.add( artifact );
}
}
getLog().info( "Checking plugins for snapshots ..." );
for ( Iterator i = project.getPluginArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
if ( isSnapshot( artifact.getVersion() ) )
{
snapshotDependencies.add( artifact );
}
}
if ( !snapshotDependencies.isEmpty() )
{
Collections.sort( snapshotDependencies );
StringBuffer message = new StringBuffer();
for ( Iterator i = snapshotDependencies.iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
message.append( " " );
message.append( artifact.getGroupId() );
message.append( ":" );
message.append( artifact.getArtifactId() );
message.append( ":" );
message.append( artifact.getVersion() );
message.append( "\n" );
}
throw new MojoExecutionException(
"Can't release project due to non released dependencies :\n" + message.toString() );
}
}
private void transformPomToReleaseVersionPom()
throws MojoExecutionException
{
if ( !isSnapshot( model.getVersion() ) )
{
throw new MojoExecutionException( "This project isn't a snapshot (" + model.getVersion() + ")." );
}
//Rewrite project version
projectVersion = model.getVersion().substring( 0, model.getVersion().length() - SNAPSHOT.length() );
try
{
getLog().info( "What is the new version? [" + projectVersion + "]" );
String inputVersion = inputHandler.readLine();
if ( !StringUtils.isEmpty( inputVersion ) )
{
projectVersion = inputVersion;
}
}
catch ( Exception e )
{
throw new MojoExecutionException( "Can't read user input.", e );
}
model.setVersion( projectVersion );
currentTag = model.getScm().getTag();
currentScmConnection = model.getScm().getConnection();
currentScmDeveloperConnection = model.getScm().getDeveloperConnection();
if ( model.getScm() != null )
{
model.getScm().setTag( getTagLabel() );
model.getScm().setConnection( rewriteScmConnection( model.getScm().getConnection(), getTagLabel() ) );
model.getScm().setDeveloperConnection(
rewriteScmConnection( model.getScm().getDeveloperConnection(), getTagLabel() ) );
}
//Rewrite parent version
if ( project.hasParent() )
{
Artifact parentArtifact = project.getParentArtifact();
if ( isSnapshot( parentArtifact.getBaseVersion() ) )
{
String version = resolveVersion( parentArtifact, "parent" );
model.getParent().setVersion( version );
}
}
//Rewrite dependencies section
Map artifactMap = ArtifactUtils.artifactMapByArtifactId( project.getArtifacts() );
for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); )
{
Dependency dep = (Dependency) i.next();
String conflictId = ArtifactUtils.artifactId( dep.getGroupId(), dep.getArtifactId(), dep.getType(),
dep.getClassifier(), dep.getVersion() );
Artifact artifact = (Artifact) artifactMap.get( conflictId );
dep.setVersion( artifact.getVersion() );
}
try
{
PomTransformer transformer = new VersionTransformer();
transformer.setOutputFile( project.getFile() );
transformer.setProject( project.getFile() );
transformer.setUpdatedModel( model );
transformer.transformNodes();
transformer.write();
}
catch ( Exception e )
{
throw new MojoExecutionException( "Can't transform pom to its release version form.", e );
}
}
private void generateReleasePom()
throws MojoExecutionException
{
MavenProject releaseProject = new MavenProject( project );
Model releaseModel = releaseProject.getModel();
//Rewrite parent version
if ( project.hasParent() )
{
Artifact parentArtifact = project.getParentArtifact();
if ( isSnapshot( parentArtifact.getBaseVersion() ) )
{
String version = resolveVersion( parentArtifact, "parent" );
model.getParent().setVersion( version );
}
}
//Rewrite dependencies section
List newdeps = new ArrayList();
for ( Iterator i = releaseProject.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
Dependency newdep = new Dependency();
newdep.setArtifactId( artifact.getArtifactId() );
newdep.setGroupId( artifact.getGroupId() );
newdep.setVersion( artifact.getVersion() );
newdep.setType( artifact.getType() );
newdep.setScope( artifact.getScope() );
newdep.setClassifier( artifact.getClassifier() );
newdeps.add( newdep );
}
releaseModel.setDependencies( newdeps );
//Rewrite plugins version
for ( Iterator i = releaseProject.getPluginArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
if ( isSnapshot( artifact.getBaseVersion() ) )
{
for ( Iterator j = releaseModel.getBuild().getPlugins().iterator(); j.hasNext(); )
{
Plugin plugin = (Plugin) j.next();
if ( ArtifactUtils.versionlessKey( artifact ).equals( plugin.getKey() ) )
{
String version = resolveVersion( artifact, "plugin" );
plugin.setGroupId( artifact.getGroupId() );
plugin.setVersion( version );
}
}
}
}
//Rewrite report version
for ( Iterator i = releaseProject.getReportArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
if ( isSnapshot( artifact.getBaseVersion() ) )
{
List reportPlugins = releaseProject.getReportPlugins();
if ( reportPlugins != null )
{
for ( Iterator j = reportPlugins.iterator(); j.hasNext(); )
{
ReportPlugin plugin = (ReportPlugin) j.next();
if ( ArtifactUtils.versionlessKey( artifact ).equals( plugin.getKey() ) )
{
String version = resolveVersion( artifact, "report" );
plugin.setGroupId( artifact.getGroupId() );
plugin.setVersion( version );
}
}
}
}
}
File releasePomFile = new File( basedir, RELEASE_POM );
Writer writer = null;
try
{
writer = new FileWriter( releasePomFile );
releaseProject.writeModel( writer );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot write release-pom to: " + releasePomFile, e );
}
finally
{
IOUtil.close( writer );
}
try
{
ScmBean scm = getScm();
scm.setWorkingDirectory( basedir );
List scmChanges = scm.getStatus();
for ( Iterator i = scmChanges.iterator(); i.hasNext(); )
{
ScmFile f = (ScmFile) i.next();
if ( f.getPath().equals( "release-pom.xml" ) && f.getStatus() != ScmFileStatus.MODIFIED )
{
getScm().add( RELEASE_POM );
}
}
}
catch ( ScmException e )
{
throw new MojoExecutionException( "Error updating the release-pom.xml.", e );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error updating the release-pom.xml.", e );
}
}
private String resolveVersion( Artifact artifact, String artifactUsage )
throws MojoExecutionException
{
if ( artifact.getFile() == null )
{
try
{
artifactMetadataSource.retrieve( artifact, localRepository, project.getPluginArtifactRepositories() );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new MojoExecutionException( "Cannot resolve " + artifactUsage + ": " + artifact.getId(), e );
}
}
return artifact.getVersion();
}
private void transformPomToSnapshotVersionPom()
throws MojoExecutionException
{
// 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
// now and really only works for the way maven is versioned.
// releaseVersion = 1.0-beta-4
// snapshotVersion = 1.0-beta-5-SNAPSHOT
String nextVersionString = projectVersion.substring( projectVersion.lastIndexOf( "-" ) + 1 );
try
{
nextVersionString = Integer.toString( Integer.parseInt( nextVersionString ) + 1 );
projectVersion = projectVersion.substring( 0, projectVersion.lastIndexOf( "-" ) + 1 ) + nextVersionString +
SNAPSHOT;
}
catch ( NumberFormatException e )
{
projectVersion = "";
}
try
{
getLog().info( "What is the new version? [" + projectVersion + "]" );
String inputVersion = inputHandler.readLine();
if ( !StringUtils.isEmpty( inputVersion ) )
{
projectVersion = inputVersion;
}
model.setVersion( projectVersion );
if ( model.getScm() != null )
{
model.getScm().setTag( currentTag );
model.getScm().setConnection( currentScmConnection );
model.getScm().setDeveloperConnection( currentScmDeveloperConnection );
}
PomTransformer transformer = new VersionTransformer();
transformer.setOutputFile( project.getFile() );
transformer.setProject( project.getFile() );
transformer.setUpdatedModel( model );
transformer.transformNodes();
transformer.write();
}
catch ( Exception e )
{
throw new MojoExecutionException( "Can't transform pom to its snapshot version form.", e );
}
}
/**
* Check in the POM to SCM after it has been transformed where the version has been
* set to the release version.
*
* @throws MojoExecutionException
*/
private void checkInReleaseVersionPom()
throws MojoExecutionException
{
checkIn( "pom.xml,release-pom.xml", "[maven-release-plugin] prepare release " + projectVersion );
}
private void checkInSnapshotVersionPom()
throws MojoExecutionException
{
checkIn( "pom.xml", "[maven-release-plugin] prepare for development " + projectVersion );
}
private void checkIn( String includePattern, String message )
throws MojoExecutionException
{
try
{
ScmBean scm = getScm();
scm.setWorkingDirectory( basedir );
String tag = scm.getTag();
// No tag here - we suppose user works on correct branch
scm.setTag( null );
scm.checkin( message, includePattern, null );
scm.setTag( tag );
}
catch ( Exception e )
{
throw new MojoExecutionException( "An error is occurred in the checkin process.", e );
}
}
private String getDefaultTagLabel()
{
String tag = project.getArtifactId().toUpperCase() + "_" + projectVersion.toUpperCase();
tag = tag.replace( '-', '_' );
tag = tag.replace( '.', '_' );
return tag;
}
private String getTagLabel()
throws MojoExecutionException
{
if ( userTag == null )
{
userTag = getDefaultTagLabel();
try
{
ScmBean scm = getScm();
if ( scm.getTag() == null && interactive )
{
getLog().info( "What tag name should be used? [ " + tag + " ]" );
String inputTag = inputHandler.readLine();
if ( !StringUtils.isEmpty( inputTag ) )
{
userTag = inputTag;
}
}
else
{
userTag = scm.getTag();
}
}
catch ( Exception e )
{
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
}
}
return userTag;
}
/**
* Tag the release in preparation for performing the release.
*
* We will provide the user with a default tag name based on the artifact id
* and the version of the project being released.
*
* where artifactId is <code>plexus-action</code> and the version is <code>1.0-beta-4</code>, the
* the suggested tag will be <code>PLEXUS_ACTION_1_0_BETA_4</code>.
*
* @throws MojoExecutionException
*/
private void tagRelease()
throws MojoExecutionException
{
String tag = getTagLabel();
try
{
ScmBean scm = getScm();
scm.setWorkingDirectory( basedir );
scm.setTag( tag );
getLog().info( "Tagging release with the label " + tag + "." );
scm.tag();
}
catch ( Exception e )
{
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
}
}
private String rewriteScmConnection( String scmConnection, String tag )
{
if ( scmConnection != null )
{
if ( scmConnection.startsWith( "svn" ) )
{
if ( scmConnection.endsWith( "trunk/" ) )
{
scmConnection = scmConnection.substring( 0, scmConnection.length() - "trunk/".length() );
}
if ( scmConnection.endsWith( "branches/" ) )
{
scmConnection = scmConnection.substring( 0, scmConnection.length() - "branches/".length() );
}
scmConnection += "tags/" + tag;
}
}
return scmConnection;
}
}

View File

@ -1,299 +0,0 @@
package org.apache.maven.plugin.transformer;
/* ====================================================================
* 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.model.Model;
import org.codehaus.plexus.util.FileUtils;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.jaxen.XPath;
import org.jaxen.dom4j.Dom4jXPath;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* This is the base class for any tool that attempts to transform fields
* in the POM. Currently we are using the XML form of the POM and using Jaxen
* but eventually we will be able to perform the same transformations on
* POM beans. Jaxen needs to be modified and some serious cleanup needs to
* go on in Maven internally, but this will serve as a start. An attempt is
* made to make this tool GUI friendly.
*
* @author <a href="mailto:jason --at-- maven.org">Jason van Zyl</a>
*
* @version $Id: AbstractPomTransformer.java 115932 2004-08-06 22:43:03Z carlos $
*/
public abstract class AbstractPomTransformer
implements PomTransformer
{
/** POM document */
private File project;
/** Dom4j document. */
private Document document;
/** Output file. */
private File outputFile;
/** Properties used in transformNode */
private Map variables;
/** Nodes selected for transformation using xpath. */
private List selectedNodes;
/** Updated model obtain from MavenProject. */
private Model updatedModel;
private List transformations;
// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
public Model getUpdatedModel()
{
return updatedModel;
}
public void setUpdatedModel( Model updatedModel )
{
this.updatedModel = updatedModel;
}
public Map getVariables()
{
return variables;
}
public void setVariables( Map variables )
{
this.variables = variables;
}
public void setProject( File project )
{
this.project = project;
}
public File getProject()
{
return project;
}
public Document getDocument()
{
return document;
}
public void setDocument( Document document )
{
this.document = document;
}
public File getOutputFile()
{
return outputFile;
}
public void setOutputFile( File outputFile )
{
this.outputFile = outputFile;
}
public List getSelectedNodes()
{
if ( selectedNodes == null )
{
try
{
selectNodes();
}
catch ( Exception e )
{
// do nothing.
}
}
return selectedNodes;
}
public void setSelectedNodes( List selectedNodes )
{
this.selectedNodes = selectedNodes;
}
public int getSelectedNodeCount()
{
return getSelectedNodes().size();
}
public List getTransformations()
{
if ( transformations == null )
{
createTransformations();
}
return transformations;
}
public void createTransformations()
{
transformations = new ArrayList();
for ( Iterator i = getSelectedNodes().iterator(); i.hasNext(); )
{
Object o = i.next();
if ( o instanceof Node )
{
Transformation transformation = new Transformation( this );
transformation.setNode( (Node) o );
transformations.add( transformation );
}
}
}
/**
* This is the automated way of transforming the nodes if there is
* no user interaction involved.
*
* @throws Exception If an error occurs while transforming the nodes.
*/
public void transformNodes()
throws Exception
{
if ( getSelectedNodes().isEmpty() )
{
throw new Exception( "Your pom doesn't respect the standard format." );
}
for ( Iterator i = getSelectedNodes().iterator(); i.hasNext(); )
{
Object o = i.next();
if ( o instanceof Node )
{
transformNode( (Node) o );
}
}
}
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
public abstract String selectProjectNodeXPathExpression();
public abstract String selectDependenciesNodesXPathExpression();
public abstract String selectPluginsNodesXPathExpression();
public abstract String selectScmTagNodesXPathExpression();
public abstract void transformNode( Node node );
/**
* Update the snapshot version identifiers with actual timestamp versions
* and write out the POM in its updated form.
*
* @throws Exception
*/
public void selectNodes()
throws Exception
{
SAXReader reader = new SAXReader();
setDocument( reader.read( getProject() ) );
// The selecting nodes with the xpath expression will give us a list
// of dependencies elements where the version element is equal to 'SNAPSHOT'.
// So we can get any information we need, and alter anything we need to before writing
// the dom4j document back out.
XPath pomXpath = new Dom4jXPath( selectProjectNodeXPathExpression() );
XPath dependenciesXpath = new Dom4jXPath( selectDependenciesNodesXPathExpression() );
XPath pluginsXpath = new Dom4jXPath( selectPluginsNodesXPathExpression() );
XPath scmXpath = new Dom4jXPath( selectScmTagNodesXPathExpression() );
List nodes = new ArrayList();
nodes.addAll( pomXpath.selectNodes( getDocument() ) );
nodes.addAll( dependenciesXpath.selectNodes( getDocument() ) );
nodes.addAll( pluginsXpath.selectNodes( getDocument() ) );
nodes.addAll( scmXpath.selectNodes( getDocument() ) );
setSelectedNodes( nodes );
}
/**
*
* @throws Exception
*/
public void write()
throws Exception
{
OutputStream os = null;
if ( getOutputFile() != null )
{
// Backup the original first.
FileUtils.copyFile( getOutputFile(), new File( getOutputFile() + ".backup" ) );
// Now hand of the os.
os = new FileOutputStream( getOutputFile() );
}
else
{
os = new PrintStream( System.out );
}
OutputFormat format = new OutputFormat();
format.setIndentSize( 2 );
format.setNewlines( true );
format.setTrimText( true );
XMLWriter writer = new XMLWriter( format );
writer.setOutputStream( os );
writer.write( getDocument() );
writer.flush();
writer.close();
}
}

View File

@ -1,53 +0,0 @@
package org.apache.maven.plugin.transformer;
/* ====================================================================
* 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.model.Model;
import org.dom4j.Node;
import java.io.File;
/**
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
* @version $Id: PomTransformer.java 114783 2004-03-02 15:37:56Z evenisse $
*/
public interface PomTransformer
{
File getProject();
void setProject( File project );
void transformNodes()
throws Exception;
void transformNode( Node node );
Node getTransformedNode( Node node )
throws Exception;
void write()
throws Exception;
Model getUpdatedModel();
void setUpdatedModel( Model updatedModel );
File getOutputFile();
void setOutputFile( File outputFile );
}

View File

@ -1,95 +0,0 @@
package org.apache.maven.plugin.transformer;
/* ====================================================================
* 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.dom4j.Node;
/**
*
*
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
*
* @version $Id: Transformation.java 114783 2004-03-02 15:37:56Z evenisse $
*/
public class Transformation
{
/** Pom Transformer associated with this transformation. */
private PomTransformer pomTransformer;
/** Node to transform. */
private Node node;
public Transformation( PomTransformer pomTransformer )
{
this.pomTransformer = pomTransformer;
}
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
/**
*
* @return
*/
public Node getNode()
{
return node;
}
/**
*
* @param node
*/
public void setNode( Node node )
{
this.node = node;
}
/**
*
* @throws Exception
*/
public void transform()
throws Exception
{
pomTransformer.transformNode( node );
}
/**
*
* @return
* @throws Exception
*/
public String getBeforeTransformation()
throws Exception
{
return getNode().asXML();
}
/**
*
* @return
* @throws Exception
*/
public String getAfterTransformation()
throws Exception
{
return pomTransformer.getTransformedNode( getNode() ).asXML();
}
}

View File

@ -1,227 +0,0 @@
package org.apache.maven.plugin.transformer;
/*
* 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.model.Dependency;
import org.apache.maven.model.Plugin;
import org.dom4j.Element;
import org.dom4j.Node;
import java.util.Iterator;
/**
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id: VersionTransformer.java 115421 2004-06-01 02:20:18Z dion $
*/
public class VersionTransformer
extends AbstractPomTransformer
{
// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
public String selectProjectNodeXPathExpression()
{
return "/project";
}
public String selectDependenciesNodesXPathExpression()
{
return "/project/dependencies/dependency";
}
public String selectPluginsNodesXPathExpression()
{
return "/project/build/plugins/plugin";
}
public String selectScmTagNodesXPathExpression()
{
return "/project/scm/tag";
}
public void transformNode( Node node )
{
if ( selectProjectNodeXPathExpression().equals( node.getPath() ) )
{
// Modify project version
Element project = (Element) node;
Node version = node.selectSingleNode( "version" );
if ( version != null )
{
version.setText( getUpdatedModel().getVersion() );
}
else
{
project.addElement( "version" ).addText( getUpdatedModel().getVersion() );
}
}
else if ( selectDependenciesNodesXPathExpression().equals( node.getPath() ) )
{
// Modify dependency version
Element dependency = (Element) node;
Node groupId = node.selectSingleNode( "groupId" );
Node artifactId = node.selectSingleNode( "artifactId" );
Node type = node.selectSingleNode( "type" );
Node classifier = node.selectSingleNode( "classifier" );
String typeText = "jar";
if ( type != null )
{
typeText = type.getText();
}
Node version = node.selectSingleNode( "version" );
String versionText = getDependency( groupId.getText(), artifactId.getText(), typeText,
classifier.getText() ).getVersion();
if ( version != null )
{
version.setText( versionText );
}
else
{
dependency.addElement( "version" ).addText( versionText );
}
}
else if ( selectPluginsNodesXPathExpression().equals( node.getPath() ) )
{
// Modify plugin version
Element plugin = (Element) node;
Node groupId = node.selectSingleNode( "groupId" );
String groupIdText = "org.apache.maven.plugins";
if ( groupId != null )
{
groupIdText = groupId.getText();
}
Node artifactId = node.selectSingleNode( "artifactId" );
Node version = node.selectSingleNode( "version" );
Plugin p = getPlugin( groupIdText, artifactId.getText() );
if ( groupId != null )
{
groupId.setText( p.getGroupId() );
}
else
{
plugin.addElement( "groupId" ).addText( p.getGroupId() );
}
if ( version != null )
{
version.setText( p.getVersion() );
}
else
{
plugin.addElement( "version" ).addText( p.getVersion() );
}
}
else
{
if ( getUpdatedModel().getScm() != null )
{
// Modify scm tag
Element scm = (Element) node;
Node tag = node.selectSingleNode( "tag" );
if ( tag == null )
{
if ( !"HEAD".equals( getUpdatedModel().getScm().getTag() ) )
{
scm.addElement( "tag" ).addText( getUpdatedModel().getScm().getTag() );
}
}
else
{
tag.setText( getUpdatedModel().getScm().getTag() );
}
// Modify scmConnections
Node connection = node.selectSingleNode( "connection" );
if ( connection != null )
{
if ( !connection.getText().equals( getUpdatedModel().getScm().getConnection() ) )
{
connection.setText( getUpdatedModel().getScm().getConnection() );
}
}
Node developerConnection = node.selectSingleNode( "developerConnection" );
if ( developerConnection != null )
{
if ( !developerConnection.getText().equals( getUpdatedModel().getScm().getDeveloperConnection() ) )
{
developerConnection.setText( getUpdatedModel().getScm().getDeveloperConnection() );
}
}
}
}
}
private Dependency getDependency( String groupId, String artifactId, String type, String classifier )
{
// TODO: equals() in Dependency would be better
for ( Iterator i = getUpdatedModel().getDependencies().iterator(); i.hasNext(); )
{
Dependency dependency = (Dependency) i.next();
if ( dependency.getGroupId().equals( groupId ) && dependency.getArtifactId().equals( artifactId ) &&
dependency.getType().equals( type ) && dependency.getClassifier() != null
? dependency.getClassifier().equals( classifier ) : classifier == null )
{
return dependency;
}
}
return null;
}
private Plugin getPlugin( String groupId, String artifactId )
{
for ( Iterator i = getUpdatedModel().getBuild().getPlugins().iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals( artifactId ) )
{
return plugin;
}
}
return null;
}
public Node getTransformedNode( Node node )
throws Exception
{
throw new UnsupportedOperationException( "getTransformedNode not implemented" );
}
}

View File

@ -0,0 +1,80 @@
package org.apache.maven.plugins.release;
/*
* 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.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.release.helpers.ReleaseProgressTracker;
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$
*/
public abstract class AbstractReleaseMojo
extends AbstractMojo
{
/**
* @parameter expression="${org.apache.maven.scm.manager.ScmManager}"
* @required
* @readonly
*/
private ScmManager scmManager;
private ScmHelper scmHelper;
protected abstract ReleaseProgressTracker getReleaseProgress()
throws MojoExecutionException;
protected ScmHelper getScm()
throws MojoExecutionException
{
if ( scmHelper == null )
{
scmHelper = new ScmHelper();
scmHelper.setScmManager( scmManager );
ReleaseProgressTracker releaseProgress = getReleaseProgress();
scmHelper.setUrl( releaseProgress.getScmUrl() );
scmHelper.setTag( releaseProgress.getScmTag() );
scmHelper.setTagBase( releaseProgress.getScmTagBase() );
scmHelper.setUsername( releaseProgress.getUsername() );
scmHelper.setPassword( releaseProgress.getPassword() );
}
return scmHelper;
}
public void execute()
throws MojoExecutionException
{
executeTask();
}
protected abstract void executeTask()
throws MojoExecutionException;
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.plugin.release;
package org.apache.maven.plugins.release;
/*
* Copyright 2001-2005 The Apache Software Foundation.
@ -17,15 +17,20 @@
*/
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.release.helpers.ReleaseProgressTracker;
import org.apache.maven.plugins.release.helpers.ScmHelper;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.DefaultConsumer;
import org.codehaus.plexus.util.cli.StreamConsumer;
import java.io.IOException;
/**
* Perform a release from SCM
*
* @aggregator
* @goal perform
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@ -34,11 +39,26 @@
public class PerformReleaseMojo
extends AbstractReleaseMojo
{
/**
* @parameter expression="${basedir}"
* @required
* @readonly
*/
private String basedir;
/**
* @parameter expression="${goals}"
*/
private String goals = "deploy";
/**
* @parameter expression="${project.build.directory}/checkout"
* @required
*/
protected String workingDirectory;
private ReleaseProgressTracker releaseProgress;
protected void executeTask()
throws MojoExecutionException
{
@ -50,11 +70,15 @@ protected void executeTask()
private void checkout()
throws MojoExecutionException
{
System.out.println( "Checking out the project to perform the release ..." );
getLog().info( "Checking out the project to perform the release ..." );
try
{
getScm().checkout();
ScmHelper scm = getScm();
scm.setWorkingDirectory( workingDirectory );
scm.checkout();
}
catch ( Exception e )
{
@ -92,4 +116,23 @@ private void runGoals()
throw new MojoExecutionException( "Can't run goal " + goals, e );
}
}
protected ReleaseProgressTracker getReleaseProgress()
throws MojoExecutionException
{
if ( releaseProgress == null )
{
try
{
releaseProgress = ReleaseProgressTracker.load( basedir );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Failed to load release information from file: "
+ ReleaseProgressTracker.getReleaseProgressFilename(), e );
}
}
return releaseProgress;
}
}

View File

@ -0,0 +1,122 @@
package org.apache.maven.plugins.release.helpers;
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 java.util.HashMap;
import java.util.Map;
public class ProjectScmRewriter
{
private Map originalScmInformation = new HashMap();
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." );
}
Model model = project.getModel();
Scm scm = model.getScm();
if ( scm == null )
{
throw new MojoExecutionException( "Project: " + projectId
+ " does not have a SCM section! Cannot proceed with release." );
}
String tag = model.getScm().getTag();
String connection = model.getScm().getConnection();
String developerConnection = model.getScm().getDeveloperConnection();
ScmInfo info = new ScmInfo( tag, connection, developerConnection );
originalScmInformation.put( projectId, info );
scm.setTag( tagLabel );
scm.setConnection( rewriteScmConnection( connection, tagLabel ) );
scm.setDeveloperConnection( rewriteScmConnection( developerConnection, tagLabel ) );
}
public void restoreScmInfo( MavenProject project )
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
ScmInfo original = (ScmInfo) originalScmInformation.get( projectId );
if ( original == null )
{
throw new IllegalArgumentException( "Project \'" + projectId
+ "\' has not had its SCM info cached. Cannot restore uncached SCM info." );
}
original.modify( project );
}
// TODO: Add other SCM types for rewriting...
private String rewriteScmConnection( String scmConnection, String tag )
{
if ( scmConnection != null )
{
if ( scmConnection.startsWith( "svn" ) )
{
if ( scmConnection.endsWith( "trunk/" ) )
{
scmConnection = scmConnection.substring( 0, scmConnection.length() - "trunk/".length() );
}
if ( scmConnection.endsWith( "branches/" ) )
{
scmConnection = scmConnection.substring( 0, scmConnection.length() - "branches/".length() );
}
scmConnection += "tags/" + tag;
}
}
return scmConnection;
}
private static class ScmInfo
{
private String tag;
private String connection;
private String developerConnection;
ScmInfo( String tag, String connection, String developerConnection )
{
this.tag = tag;
this.connection = connection;
this.developerConnection = developerConnection;
}
void modify( MavenProject project )
{
Model model = project.getModel();
if ( model.getScm() != null )
{
model.getScm().setTag( tag );
model.getScm().setConnection( connection );
model.getScm().setDeveloperConnection( developerConnection );
}
}
}
}

View File

@ -0,0 +1,143 @@
package org.apache.maven.plugins.release.helpers;
import org.apache.maven.artifact.ArtifactUtils;
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;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class ProjectVersionResolver
{
private static final String SNAPSHOT_CLASSIFIER = "-SNAPSHOT";
private Map resolvedVersions = new HashMap();
private final Log log;
private final InputHandler inputHandler;
private final boolean interactive;
public ProjectVersionResolver( Log log, InputHandler inputHandler, boolean interactive )
{
this.log = log;
this.inputHandler = inputHandler;
this.interactive = interactive;
}
public void resolveVersion( MavenProject project )
throws MojoExecutionException
{
String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
if ( resolvedVersions.containsKey( projectId ) )
{
throw new IllegalArgumentException( "Project: " + projectId
+ " is already resolved. Each project should only be resolved once." );
}
//Rewrite project version
String projectVersion = project.getVersion();
projectVersion = projectVersion.substring( 0, projectVersion.length() - SNAPSHOT_CLASSIFIER.length() );
if ( interactive )
{
try
{
log.info( "What is the release version for \'" + projectId + "\'? [" + projectVersion + "]" );
String inputVersion = inputHandler.readLine();
if ( !StringUtils.isEmpty( inputVersion ) )
{
projectVersion = inputVersion;
}
}
catch ( Exception e )
{
throw new MojoExecutionException( "Can't read release version from user input.", e );
}
}
project.setVersion( projectVersion );
resolvedVersions.put( projectId, projectVersion );
}
public String getResolvedVersion( String groupId, String artifactId )
{
String projectId = ArtifactUtils.versionlessKey( groupId, artifactId );
return (String) resolvedVersions.get( projectId );
}
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." );
}
// 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
// now and really only works for the way maven is versioned.
// releaseVersion = 1.0-beta-4
// snapshotVersion = 1.0-beta-5-SNAPSHOT
String nextVersionString = projectVersion.substring( projectVersion.lastIndexOf( "-" ) + 1 );
try
{
nextVersionString = Integer.toString( Integer.parseInt( nextVersionString ) + 1 );
projectVersion = projectVersion.substring( 0, projectVersion.lastIndexOf( "-" ) + 1 ) + nextVersionString
+ SNAPSHOT_CLASSIFIER;
}
catch ( NumberFormatException e )
{
projectVersion = "";
}
if ( interactive )
{
try
{
log.info( "What is the new development version for \'" + projectId + "\'? [" + projectVersion + "]" );
String inputVersion = inputHandler.readLine();
if ( !StringUtils.isEmpty( inputVersion ) )
{
projectVersion = inputVersion;
}
project.setVersion( projectVersion );
resolvedVersions.put( projectId, projectVersion );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Can't read next development version from user input.", e );
}
}
else if ( "".equals( projectVersion ) )
{
throw new MojoExecutionException( "Cannot determine incremented development version for: " + projectId );
}
}
}

View File

@ -0,0 +1,240 @@
package org.apache.maven.plugins.release.helpers;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.IOUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Properties;
public class ReleaseProgressTracker
{
private static final String RELEASE_PROPERTIES = "release.properties";
private static final String USERNAME = "maven.username";
private static final String SCM_TAG = "scm.tag";
private static final String SCM_URL = "scm.url";
private static final String SCM_TAG_BASE = "scm.tag-base";
private static final String SCM_PASSWORD = "scm.password";
private static final String CHECKPOINT_PREFIX = "checkpoint.";
public static final String CP_INITIALIZED = "initialized";
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_GENERATED_RELEASE_POM = "generated-release-pom";
public static final String CP_CHECKED_IN_RELEASE_VERSION = "checked-in-release-version";
public static final String CP_TAGGED_RELEASE = "tagged-release";
public static final String CP_POM_TRANSORMED_FOR_DEVELOPMENT = "transform-pom-for-development";
public static final String CP_REMOVED_RELEASE_POM = "removed-release-pom";
public static final String CP_CHECKED_IN_DEVELOPMENT_VERSION = "check-in-development-version";
public static final String CP_PREPARED_RELEASE = "prepared-release";
private Properties releaseProperties;
private ReleaseProgressTracker()
{
}
public static ReleaseProgressTracker loadOrCreate( String basedir )
throws IOException
{
ReleaseProgressTracker tracker = null;
if ( new File( basedir, RELEASE_PROPERTIES ).exists() )
{
tracker = load( basedir );
}
else
{
tracker = new ReleaseProgressTracker();
}
return tracker;
}
public static ReleaseProgressTracker load( String basedir )
throws IOException
{
File releasePropertiesFile = new File( basedir, RELEASE_PROPERTIES );
ReleaseProgressTracker tracker = new ReleaseProgressTracker();
InputStream inStream = null;
try
{
inStream = new FileInputStream( releasePropertiesFile );
Properties rp = new Properties();
rp.load( inStream );
tracker.releaseProperties = rp;
}
finally
{
IOUtil.close( inStream );
}
return tracker;
}
public static String getReleaseProgressFilename()
{
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 )
{
checkInitialized();
releaseProperties.setProperty( USERNAME, username );
}
public String getUsername()
{
checkLoaded();
return releaseProperties.getProperty( USERNAME );
}
public void setScmTag( String scmTag )
{
checkInitialized();
releaseProperties.setProperty( SCM_TAG, scmTag );
}
public String getScmTag()
{
checkLoaded();
return releaseProperties.getProperty( SCM_TAG );
}
public void setScmUrl( String scmUrl )
{
checkInitialized();
releaseProperties.setProperty( SCM_URL, scmUrl );
}
public String getScmUrl()
{
checkLoaded();
return releaseProperties.getProperty( SCM_URL );
}
public void setScmTagBase( String tagBase )
{
checkInitialized();
releaseProperties.setProperty( SCM_TAG_BASE, tagBase );
}
public String getScmTagBase()
{
checkLoaded();
return releaseProperties.getProperty( SCM_TAG_BASE );
}
public void setPassword( String password )
{
checkInitialized();
releaseProperties.setProperty( SCM_PASSWORD, password );
}
public String getPassword()
{
checkInitialized();
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 )
throws IOException
{
setCheckpoint( pointName );
File releasePropertiesFile = new File( basedir, RELEASE_PROPERTIES );
FileOutputStream outStream = null;
try
{
outStream = new FileOutputStream( releasePropertiesFile );
releaseProperties.store( outStream, "Generated by Release Plugin on: " + new Date() );
}
finally
{
IOUtil.close( outStream );
}
}
private void setCheckpoint( String pointName )
{
checkInitialized();
releaseProperties.setProperty( CHECKPOINT_PREFIX + pointName, "OK" );
}
public boolean reachedCheckpoint( String pointName )
{
checkLoaded();
return "OK".equals( releaseProperties.getProperty( CHECKPOINT_PREFIX + pointName ) );
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.plugin.scm;
package org.apache.maven.plugins.release.helpers;
/* =====================================================================
* Copyright 2001-2005 The Apache Software Foundation.
@ -20,14 +20,15 @@
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
import org.apache.maven.scm.command.add.AddScmResult;
import org.apache.maven.scm.command.checkin.CheckInScmResult;
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
import org.apache.maven.scm.command.remove.RemoveScmResult;
import org.apache.maven.scm.command.status.StatusScmResult;
import org.apache.maven.scm.command.tag.TagScmResult;
import org.apache.maven.scm.command.update.UpdateScmResult;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.scm.repository.ScmRepository;
import org.codehaus.plexus.util.FileUtils;
@ -40,9 +41,9 @@
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id: DoxiaMojo.java 169372 2005-05-09 22:47:34Z evenisse $
* @version $Id$
*/
public class ScmBean
public class ScmHelper
{
private String username;
@ -99,7 +100,7 @@ private ScmRepository getScmRepository()
}
}
}
catch( Exception e )
catch ( Exception e )
{
throw new ScmException( "Can't load the scm provider.", e );
}
@ -141,7 +142,8 @@ public void checkout()
FileUtils.mkdir( workingDirectory );
}
CheckOutScmResult result = getScmManager().checkOut( repository, new ScmFileSet( checkoutDirectory ), tag );
CheckOutScmResult result = getScmManager().getProviderByRepository( repository )
.checkOut( repository, new ScmFileSet( checkoutDirectory ), tag );
checkResult( result );
}
@ -154,7 +156,8 @@ public void update()
checkoutDirectory = new File( workingDirectory );
// TODO: want includes/excludes?
UpdateScmResult result = getScmManager().update( repository, new ScmFileSet( new File( workingDirectory ) ), tag );
UpdateScmResult result = getScmManager().getProviderByRepository( repository )
.update( repository, new ScmFileSet( new File( workingDirectory ) ), tag );
checkResult( result );
}
@ -167,7 +170,8 @@ public List getStatus()
ScmRepository repository = getScmRepository();
// TODO: want includes/excludes?
StatusScmResult result = getScmManager().status( repository, new ScmFileSet( new File( workingDirectory ) ) );
StatusScmResult result = getScmManager().getProviderByRepository( repository )
.status( repository, new ScmFileSet( new File( workingDirectory ) ) );
checkResult( result );
@ -176,13 +180,26 @@ public List getStatus()
return changedFiles;
}
public void add( String file ) throws ScmException, IOException
public void add( String file )
throws ScmException, IOException
{
ScmRepository repository = getScmRepository();
ScmFileSet fs = new ScmFileSet( new File( workingDirectory ), file, null );
AddScmResult result = getScmManager().add(repository, fs);
AddScmResult result = getScmManager().getProviderByRepository( repository ).add( repository, fs );
checkResult( result );
}
public void remove( String message, String file )
throws ScmException, IOException
{
ScmRepository repository = getScmRepository();
ScmFileSet fs = new ScmFileSet( new File( workingDirectory ), file, null );
RemoveScmResult result = getScmManager().getProviderByRepository( repository ).remove( repository, fs, message );
checkResult( result );
}
@ -192,10 +209,8 @@ public void checkin( String message, String includes, String excludes )
{
ScmRepository repository = getScmRepository();
CheckInScmResult result = getScmManager().checkIn( repository,
new ScmFileSet( new File( workingDirectory ), includes, excludes ),
tag,
message );
CheckInScmResult result = getScmManager().getProviderByRepository( repository )
.checkIn( repository, new ScmFileSet( new File( workingDirectory ), includes, excludes ), tag, message );
checkResult( result );
}
@ -205,7 +220,8 @@ public void tag()
ScmRepository repository = getScmRepository();
// TODO: want includes/excludes?
TagScmResult result = getScmManager().tag( repository, new ScmFileSet( new File( workingDirectory ) ), tag );
TagScmResult result = getScmManager().getProviderByRepository( repository )
.tag( repository, new ScmFileSet( new File( workingDirectory ) ), tag );
checkResult( result );
}
@ -282,4 +298,3 @@ public void setPassword( String password )
this.password = password;
}
}