Skip to content

Commit

Permalink
MRELEASE-901: Goal stage should take parameter localCheckout as well.
Browse files Browse the repository at this point in the history
This commit moves most of the logic from StageReleaseMojo to PerformReleaseMojo.


git-svn-id: https://svn.apache.org/repos/asf/maven/release/trunk@1672738 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mfriedenhagen committed Apr 10, 2015
1 parent e52dd2c commit 6f8b530
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 114 deletions.
Expand Up @@ -21,7 +21,7 @@
File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()

def projectRoot = new XmlSlurper().parse( new File( basedir, pom.xml" ) )
def projectRoot = new XmlSlurper().parse( new File( basedir, "pom.xml" ) )

assert projectRoot.version.text() == "1.1-SNAPSHOT"

Expand Down
Expand Up @@ -50,7 +50,7 @@ public class PerformReleaseMojo
* <code>deploy site-deploy</code>, if the project has a &lt;distributionManagement&gt;/&lt;site&gt; element.
*/
@Parameter( property = "goals" )
private String goals;
protected String goals;

/**
* Comma separated profiles to enable on deployment, in addition to active profiles for project execution.
Expand Down Expand Up @@ -80,7 +80,7 @@ public class PerformReleaseMojo
*
* TODO: we should think about having the defaults for the various SCM providers provided via modello!
*
* @since 2.0
* @since 2.0 for release:perform and 2.5.2 for release:stage
*/
@Parameter( defaultValue = "false", property = "localCheckout" )
private boolean localCheckout;
Expand Down Expand Up @@ -135,6 +135,7 @@ public void execute()

try
{
setDeploymentRepository();
// Note that the working directory here is not the same as in the release configuration, so don't reuse that
ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
if ( connectionUrl != null )
Expand All @@ -157,16 +158,7 @@ public void execute()
releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
releaseDescriptor.setUseReleaseProfile( useReleaseProfile );

if ( goals == null )
{
// set default
goals = "deploy";
if ( project.getDistributionManagement() != null
&& project.getDistributionManagement().getSite() != null )
{
goals += " site-deploy";
}
}
createGoals();
releaseDescriptor.setPerformGoals( goals );

ReleasePerformRequest performRequest = new ReleasePerformRequest();
Expand All @@ -186,4 +178,24 @@ public void execute()
throw new MojoFailureException( e.getMessage(), e );
}
}

/** Just here so it may be overridden by StageReleaseMojo */
protected void setDeploymentRepository()
{
}

/** Just here so it may be overridden by StageReleaseMojo */
protected void createGoals()
{
if ( goals == null )
{
// set default
goals = "deploy";
if ( project.getDistributionManagement() != null
&& project.getDistributionManagement().getSite() != null )
{
goals += " site-deploy";
}
}
}
}
Expand Up @@ -32,57 +32,21 @@

/**
* Perform a release from SCM to a staging repository.
*
* If no goals are given, these default to <code>deploy</code> or <code>deploy site:stage-deploy</code>,
* if the project has a &lt;distributionManagement&gt;/&lt;site&gt; element.
*
* If the goals contain <code>site-deploy</code> or <code>site:deploy</code>, these
* are overridden with <code>site:stage-deploy</code>.
*
* @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
* @version $Id$
* @since 2.0-beta-8
*/
@Mojo( name = "stage", aggregator = true, requiresProject = false )
public class StageReleaseMojo
extends AbstractScmReleaseMojo
extends PerformReleaseMojo
{
/**
* A comma or space separated list of goals to execute on deployment. Default value is either <code>deploy</code> or
* <code>deploy site-deploy</code>, if the project has a &lt;distributionManagement&gt;/&lt;site&gt; element.
*
* @since 2.0-beta-8
*/
@Parameter( property = "goals" )
private String goals;

/**
* Comma separated profiles to enable on deployment, in addition to active profiles for project execution.
*
* @since 2.0-beta-8
*/
@Parameter( property = "releaseProfiles" )
private String releaseProfiles;

/**
* The checkout directory.
*
* @since 2.0-beta-8
*/
@Parameter( defaultValue = "${project.build.directory}/checkout", property = "workingDirectory", required = true )
private File workingDirectory;

/**
* The SCM URL to checkout from. If omitted, the one from the <code>release.properties</code> file is used, followed
* by the URL from the current POM.
*
* @since 2.0-beta-8
*/
@Parameter( property = "connectionUrl" )
private String connectionUrl;

/**
* Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate.
*
* @since 2.0-beta-8
*/
@Parameter( defaultValue = "true", property = "useReleaseProfile" )
private boolean useReleaseProfile;

/**
* URL of the staging repository to use.
*
Expand All @@ -91,68 +55,27 @@ public class StageReleaseMojo
@Parameter( property = "stagingRepository", required = true )
private String stagingRepository;

/**
* {@inheritDoc}
*/
protected String getAdditionalProfiles()
@Override
protected void createGoals()
{
return releaseProfiles;
}

/**
* {@inheritDoc}
*/
public void execute()
throws MojoExecutionException, MojoFailureException
{
super.execute();

// goals may be splitted into multiple line in configuration.
// Let's build a single line command
if ( goals != null )
{
goals = StringUtils.join( StringUtils.split( goals ), " " );
}

try
if ( goals == null )
{
addArgument( "-DaltDeploymentRepository=\"" + stagingRepository + "\"" );

// Note that the working directory here is not the same as in the release configuration, so don't reuse that
ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
if ( connectionUrl != null )
// set default
goals = "deploy";
if ( project.getDistributionManagement() != null
&& project.getDistributionManagement().getSite() != null )
{
releaseDescriptor.setScmSourceUrl( connectionUrl );
goals += " site:stage-deploy";
}
}

releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() );
releaseDescriptor.setUseReleaseProfile( useReleaseProfile );

if ( goals == null )
{
// set default
goals = "deploy";
if ( project.getDistributionManagement() != null
&& project.getDistributionManagement().getSite() != null )
{
goals += " site:stage-deploy";
}
}

goals = StringUtils.replace( goals, "site-deploy", "site:stage-deploy" );
goals = StringUtils.replace( goals, "site:deploy", "site:stage-deploy" );

releaseDescriptor.setPerformGoals( goals );
goals = StringUtils.replace( goals, "site-deploy", "site:stage-deploy" );
goals = StringUtils.replace( goals, "site:deploy", "site:stage-deploy" );
}

releaseManager.perform( releaseDescriptor, getReleaseEnvironment(), getReactorProjects(), false );
}
catch ( ReleaseExecutionException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
catch ( ReleaseFailureException e )
{
throw new MojoFailureException( e.getMessage(), e );
}
@Override
protected void setDeploymentRepository()
{
addArgument( "-DaltDeploymentRepository=\"" + stagingRepository + "\"" );
}
}
Expand Up @@ -34,8 +34,10 @@
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.release.ReleaseManager;
import org.apache.maven.shared.release.ReleasePerformRequest;
import org.apache.maven.shared.release.config.ReleaseDescriptor;
import org.apache.maven.shared.release.env.ReleaseEnvironment;
import org.mockito.ArgumentCaptor;

/**
* Test release:perform.
Expand All @@ -60,12 +62,24 @@ public void testStage()
releaseDescriptor.setPerformGoals( "deploy site:stage-deploy" );
releaseDescriptor.setAdditionalArguments( "-DaltDeploymentRepository=\"staging\"" );

ReleasePerformRequest performRequest = new ReleasePerformRequest();
performRequest.setReleaseDescriptor( releaseDescriptor );
performRequest.setReleaseEnvironment( mojo.getReleaseEnvironment() );
performRequest.setReactorProjects( mojo.getReactorProjects() );
performRequest.setDryRun( false );

ReleaseManager mock = mock( ReleaseManager.class );
mojo.setReleaseManager( mock );

mojo.execute();

verify( mock ).perform( eq( releaseDescriptor ), isA( ReleaseEnvironment.class ), isNull( List.class ), eq( false ) );
// verify
ArgumentCaptor<ReleasePerformRequest> argument = ArgumentCaptor.forClass(ReleasePerformRequest.class);
verify( mock ).perform( argument.capture() );
assertEquals( releaseDescriptor, argument.getValue().getReleaseDescriptor() );
assertNotNull( argument.getValue().getReleaseEnvironment() );
assertNull( argument.getValue().getReactorProjects() );
assertEquals( Boolean.FALSE, argument.getValue().getDryRun() );
verifyNoMoreInteractions( mock );
}

Expand Down

0 comments on commit 6f8b530

Please sign in to comment.