mirror of https://github.com/apache/maven.git
o still a work in progress but i can release using the plugin, have released
several components now and have worked out most of the kinks. there some debugging info but by the time i go through the continuum release i'll know what's what. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@171270 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
41717d1744
commit
aed93fb8b4
|
@ -18,17 +18,17 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.maven.scm</groupId>
|
||||
<artifactId>maven-scm-api</artifactId>
|
||||
<version>1.0-alpha-1-SNAPSHOT</version>
|
||||
<version>1.0-alpha-1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.scm</groupId>
|
||||
<artifactId>maven-scm-provider-cvs</artifactId>
|
||||
<version>1.0-alpha-1-SNAPSHOT</version>
|
||||
<version>1.0-alpha-1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.scm</groupId>
|
||||
<artifactId>maven-scm-provider-svn</artifactId>
|
||||
<version>1.0-alpha-1-SNAPSHOT</version>
|
||||
<version>1.0-alpha-1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dom4j</groupId>
|
||||
|
|
|
@ -27,6 +27,11 @@ import org.codehaus.plexus.context.Context;
|
|||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
|
||||
* @version $Id: DoxiaMojo.java 169372 2005-05-09 22:47:34Z evenisse $
|
||||
|
@ -35,69 +40,58 @@ public abstract class AbstractReleaseMojo
|
|||
extends AbstractMojo
|
||||
implements Contextualizable
|
||||
{
|
||||
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
|
||||
*/
|
||||
private String workingDirectory;
|
||||
protected String workingDirectory;
|
||||
|
||||
/**
|
||||
* @parameter expression="${project.scm.developerConnection}"
|
||||
* @required
|
||||
*/
|
||||
private String urlScm;
|
||||
protected String urlScm;
|
||||
|
||||
/**
|
||||
* @parameter expression="${maven.username}"
|
||||
* @required
|
||||
*/
|
||||
private String username;
|
||||
protected String username;
|
||||
|
||||
/**
|
||||
* @parameter expression="${password}"
|
||||
*/
|
||||
private String password;
|
||||
protected String password;
|
||||
|
||||
/**
|
||||
* @parameter expression="${tagBase}"
|
||||
*/
|
||||
private String tagBase = "../tags";
|
||||
protected String tagBase = "../tags";
|
||||
|
||||
/**
|
||||
* @parameter expression="${tag}"
|
||||
*/
|
||||
private String tag;
|
||||
protected String tag;
|
||||
|
||||
/**
|
||||
* @parameter expression="${project}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private MavenProject project;
|
||||
protected MavenProject project;
|
||||
|
||||
private PlexusContainer container;
|
||||
|
||||
private ScmManager scmManager;
|
||||
protected ScmManager scmManager;
|
||||
|
||||
public MavenProject getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
public String getWorkingDirectory()
|
||||
{
|
||||
return workingDirectory;
|
||||
}
|
||||
|
||||
protected ScmManager getScmManager()
|
||||
{
|
||||
return scmManager;
|
||||
}
|
||||
|
||||
public String getTag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
private Properties releaseProperties;
|
||||
|
||||
protected ScmBean getScm()
|
||||
{
|
||||
|
@ -105,12 +99,31 @@ public abstract class AbstractReleaseMojo
|
|||
|
||||
scm.setScmManager( scmManager );
|
||||
|
||||
if ( releaseProperties != null )
|
||||
{
|
||||
urlScm = releaseProperties.getProperty( SCM_URL );
|
||||
}
|
||||
|
||||
scm.setUrl( urlScm );
|
||||
|
||||
System.out.println( "urlScm = " + urlScm );
|
||||
|
||||
if ( releaseProperties != null )
|
||||
{
|
||||
tag = releaseProperties.getProperty( TAG );
|
||||
}
|
||||
|
||||
scm.setTag( tag );
|
||||
|
||||
scm.setTagBase( tagBase );
|
||||
|
||||
if ( releaseProperties != null )
|
||||
{
|
||||
username = releaseProperties.getProperty( USERNAME );
|
||||
}
|
||||
|
||||
System.out.println( "username = " + username );
|
||||
|
||||
scm.setUsername( username );
|
||||
|
||||
scm.setPassword( password );
|
||||
|
@ -131,6 +144,23 @@ public abstract class AbstractReleaseMojo
|
|||
try
|
||||
{
|
||||
initScmManager();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// 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 )
|
||||
{
|
||||
|
|
|
@ -72,7 +72,7 @@ public class PerformReleaseMojo
|
|||
|
||||
cl.setExecutable( "m2" );
|
||||
|
||||
cl.setWorkingDirectory( getWorkingDirectory() );
|
||||
cl.setWorkingDirectory( workingDirectory );
|
||||
|
||||
cl.createArgument().setLine( goals );
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.apache.maven.artifact.Artifact;
|
|||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.scm.ScmBean;
|
||||
import org.apache.maven.plugin.transformer.PomTransformer;
|
||||
|
@ -31,10 +30,14 @@ import org.apache.maven.scm.ScmFile;
|
|||
import org.codehaus.plexus.components.inputhandler.InputHandler;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Prepare for a release in SCM
|
||||
|
@ -56,29 +59,30 @@ public class PrepareReleaseMojo
|
|||
*/
|
||||
private String basedir;
|
||||
|
||||
/**
|
||||
* @parameter expression="${project}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private MavenProject project;
|
||||
|
||||
private static final String SNAPSHOT = "-SNAPSHOT";
|
||||
|
||||
private String projectVersion;
|
||||
|
||||
private Model model;
|
||||
|
||||
protected void executeTask()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
model = project.getModel();
|
||||
|
||||
checkForLocalModifications();
|
||||
|
||||
checkForPresenceOfSnapshots();
|
||||
|
||||
transformPom();
|
||||
transformPomToReleaseVersionPom();
|
||||
|
||||
checkInReleaseVersionPom();
|
||||
|
||||
tagRelease();
|
||||
|
||||
transformPomToSnapshotVersionPom();
|
||||
|
||||
checkInSnapshotVersionPom();
|
||||
}
|
||||
|
||||
private boolean isSnapshot( String version )
|
||||
|
@ -207,11 +211,9 @@ public class PrepareReleaseMojo
|
|||
}
|
||||
}
|
||||
|
||||
private void transformPom()
|
||||
private void transformPomToReleaseVersionPom()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
Model model = project.getModel();
|
||||
|
||||
if ( !isSnapshot( model.getVersion() ) )
|
||||
{
|
||||
throw new MojoExecutionException( "This project isn't a snapshot (" + model.getVersion() + ")." );
|
||||
|
@ -240,6 +242,29 @@ public class PrepareReleaseMojo
|
|||
|
||||
model.setVersion( projectVersion );
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
//Rewrite parent version
|
||||
if ( project.hasParent() )
|
||||
{
|
||||
|
@ -304,10 +329,70 @@ public class PrepareReleaseMojo
|
|||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new MojoExecutionException( "Can't update pom.", e );
|
||||
throw new MojoExecutionException( "Can't transform pom to its release version form.", e );
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
// releaseVersion = 1.0-beta-4
|
||||
// snapshotVersion = 1.0-beta-5-SNAPSHOT
|
||||
|
||||
String nextVersionString = projectVersion.substring( projectVersion.lastIndexOf( "-" ) + 1 );
|
||||
|
||||
try
|
||||
{
|
||||
System.out.println( "nextVersionString = " + nextVersionString );
|
||||
|
||||
nextVersionString = Integer.toString( Integer.parseInt( nextVersionString ) + 1 );
|
||||
|
||||
System.out.println( "nextVersionString = " + nextVersionString );
|
||||
|
||||
projectVersion = projectVersion.substring( 0, projectVersion.lastIndexOf( "-" ) + 1 ) + nextVersionString + SNAPSHOT;
|
||||
}
|
||||
catch ( NumberFormatException e )
|
||||
{
|
||||
projectVersion = "";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
getLog().info( "What is the new version? [" + projectVersion + "]" );
|
||||
|
||||
InputHandler handler = (InputHandler) getContainer().lookup( InputHandler.ROLE );
|
||||
|
||||
String inputVersion = handler.readLine();
|
||||
|
||||
if ( !StringUtils.isEmpty( inputVersion ) )
|
||||
{
|
||||
projectVersion = inputVersion;
|
||||
}
|
||||
|
||||
model.setVersion( projectVersion );
|
||||
|
||||
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.
|
||||
|
@ -316,6 +401,18 @@ public class PrepareReleaseMojo
|
|||
*/
|
||||
private void checkInReleaseVersionPom()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
checkInPom( "[maven-release-plugin] prepare release " + projectVersion );
|
||||
}
|
||||
|
||||
private void checkInSnapshotVersionPom()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
checkInPom( "[maven-release-plugin] prepare release " + projectVersion );
|
||||
}
|
||||
|
||||
private void checkInPom( String message )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -323,7 +420,7 @@ public class PrepareReleaseMojo
|
|||
|
||||
scm.setWorkingDirectory( basedir );
|
||||
|
||||
scm.checkin( "[maven-release-plugin] prepare release " + projectVersion, "pom.xml", null );
|
||||
scm.checkin( message, "pom.xml", null );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
@ -331,6 +428,17 @@ public class PrepareReleaseMojo
|
|||
}
|
||||
}
|
||||
|
||||
private String getTagLabel()
|
||||
{
|
||||
String tag = project.getArtifactId().toUpperCase() + "_" + projectVersion.toUpperCase();
|
||||
|
||||
tag = tag.replace( '-', '_' );
|
||||
|
||||
tag = tag.replace( '.', '_' );
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag the release in preparation for performing the release.
|
||||
*
|
||||
|
@ -345,12 +453,7 @@ public class PrepareReleaseMojo
|
|||
private void tagRelease()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
|
||||
String tag = project.getArtifactId().toUpperCase() + "_" + projectVersion.toUpperCase();
|
||||
|
||||
tag = tag.replace( '-', '_' );
|
||||
|
||||
tag = tag.replace( '.', '_' );
|
||||
String tag = getTagLabel();
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.apache.maven.plugin.scm;
|
||||
|
||||
/* ====================================================================
|
||||
/* =========7===========================================================
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -113,9 +113,13 @@ public class ScmBean
|
|||
{
|
||||
// TODO: improve error handling
|
||||
System.err.println( "Provider message:" );
|
||||
|
||||
System.err.println( result.getProviderMessage() );
|
||||
|
||||
System.err.println( "Command output:" );
|
||||
|
||||
System.err.println( result.getCommandOutput() );
|
||||
|
||||
throw new ScmException( "Error!" );
|
||||
}
|
||||
}
|
||||
|
@ -126,12 +130,19 @@ public class ScmBean
|
|||
ScmRepository repository = getScmRepository();
|
||||
|
||||
checkoutDirectory = new File( workingDirectory );
|
||||
if ( checkoutDirectory.exists() )
|
||||
{
|
||||
|
||||
System.out.println( "workingDirectory = " + workingDirectory );
|
||||
|
||||
System.out.println( "tag = " + tag );
|
||||
|
||||
// TODO: sanity check that it is not . or .. or lower
|
||||
FileUtils.deleteDirectory( checkoutDirectory );
|
||||
|
||||
if ( FileUtils.fileExists( workingDirectory ) )
|
||||
{
|
||||
FileUtils.deleteDirectory( workingDirectory );
|
||||
|
||||
FileUtils.mkdir( workingDirectory );
|
||||
}
|
||||
checkoutDirectory.mkdirs();
|
||||
|
||||
CheckOutScmResult result = getScmManager().checkOut( repository, new ScmFileSet( checkoutDirectory ), tag );
|
||||
|
||||
|
|
Loading…
Reference in New Issue