Skip to content

Commit

Permalink
[MRELEASE-1015] Add signTag option to release:prepare goal
Browse files Browse the repository at this point in the history
Signed-off-by: rfscholte <[email protected]>
  • Loading branch information
bdemers authored and rfscholte committed Apr 2, 2021
1 parent dc25df8 commit 8142302
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ public interface ReleaseDescriptor
*/
boolean isRemoteTagging();


/**
* Get if the scm provider should sign the tag. NOTE: currently only implemented with git-exe.
* @return boolean true if SCM tag should be signed
*/
boolean isScmSignTags();

/**
* Get if the scm provider should use local checkouts via file://${basedir} instead of doing a clean checkout over
* the network. This is very helpful for releasing large projects!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ public ReleaseDescriptorBuilder setScmTagNameFormat( String scmTagNameFormat )
return this;
}

public ReleaseDescriptorBuilder setScmSignTags( boolean signTags )
{
releaseDescriptor.setScmSignTags( signTags );
return this;
}

public ReleaseDescriptorBuilder setScmUseEditMode( boolean scmUseEditMode )
{
releaseDescriptor.setScmUseEditMode( scmUseEditMode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnviro
ScmTagParameters scmTagParameters =
new ScmTagParameters( releaseDescriptor.getScmCommentPrefix() + "copy for tag " + tagName );
scmTagParameters.setRemoteTagging( releaseDescriptor.isRemoteTagging() );
scmTagParameters.setSign( releaseDescriptor.isScmSignTags() );
scmTagParameters.setScmRevision( releaseDescriptor.getScmReleasedPomRevision() );
scmTagParameters.setPinExternals( releaseDescriptor.isPinExternals() );
if ( getLogger().isDebugEnabled() )
Expand Down
9 changes: 9 additions & 0 deletions maven-release-manager/src/main/mdo/release-descriptor.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,15 @@
</description>
</field>

<field>
<name>scmSignTags</name>
<version>3.0.0+</version>
<type>boolean</type>
<description>
If the scm provider should use sign tags, for example for git-exe the '--sign' argument would be used.
</description>
</field>

<!-- Announcement Information
Announcement related info, this can be a second part of the process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public boolean matches( ScmTagParameters argument )
ScmTagParameters stp = (ScmTagParameters) argument;
return stp.getMessage().equals( this.scmTagParameters.getMessage() )
&& stp.isRemoteTagging() == this.scmTagParameters.isRemoteTagging()
&& stp.isPinExternals() == this.scmTagParameters.isPinExternals();
&& stp.isPinExternals() == this.scmTagParameters.isPinExternals()
&& stp.isSign() == this.scmTagParameters.isSign();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ public void testTag()
builder.setPomFileName( rootProject.getFile().getName() );
builder.setScmReleaseLabel( "release-label" );
builder.setScmCommentPrefix( "[my prefix] " );
builder.setScmSignTags(true);

ScmTagParameters expectedTagParameters = new ScmTagParameters( "[my prefix] copy for tag release-label" );
expectedTagParameters.setSign(true);

ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() );

ScmProvider scmProviderMock = mock( ScmProvider.class );
when( scmProviderMock.tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ),
eq( "release-label" ),
argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...",
argThat( new IsScmTagParametersEquals( expectedTagParameters ) ) ) ).thenReturn( new TagScmResult( "...",
Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ),
ScmFileStatus.TAGGED ) ) ) );
ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
Expand All @@ -124,7 +128,7 @@ public void testTag()
// verify
verify( scmProviderMock ).tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ),
eq( "release-label" ),
argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) );
argThat( new IsScmTagParametersEquals( expectedTagParameters ) ) );
verifyNoMoreInteractions( scmProviderMock );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ public class PrepareReleaseMojo
@Parameter( defaultValue = "true", property = "remoteTagging" )
private boolean remoteTagging;

/**
* Signs SCM tag when possible, for example when using the git-exe the '--sign' argument is used.
*
* @since 3.0.0
*/
@Parameter( property = "signTag" )
private boolean signTag = false;

/**
* Whether to bump the working copy versions to <code>developmentVersion</code>.
*
Expand Down Expand Up @@ -344,6 +352,7 @@ protected void prepareRelease( boolean generateReleasePoms )
config.setDefaultReleaseVersion( releaseVersion );
config.setDefaultDevelopmentVersion( developmentVersion );
config.setRemoteTagging( remoteTagging );
config.setScmSignTags( signTag );
config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions );
config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTag );
config.setWaitBeforeTagging( waitBeforeTagging );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import java.io.File;
import java.util.Collections;
Expand All @@ -47,6 +49,8 @@
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
import org.apache.maven.shared.release.env.ReleaseEnvironment;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

/**
* Test release:prepare.
Expand All @@ -66,7 +70,7 @@ public void testPrepare()
throws Exception
{
File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" );
final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo( "prepare", testFile );
final PrepareReleaseMojo mojo = spy((PrepareReleaseMojo) lookupMojo( "prepare", testFile ));
setDefaults( mojo );
mojo.setBasedir( testFile.getParentFile() );
mojo.setPomFileName( "pom.xml" );
Expand All @@ -91,6 +95,14 @@ public List<MavenProject> getProjects()
ReleaseManager mock = mock( ReleaseManager.class );
mojo.setReleaseManager( mock );

when(mojo.createReleaseDescriptor()).thenAnswer(new Answer<ReleaseDescriptorBuilder>() {
@Override
public ReleaseDescriptorBuilder answer(InvocationOnMock invocationOnMock) throws Throwable {
ReleaseDescriptorBuilder original = (ReleaseDescriptorBuilder) invocationOnMock.callRealMethod();
return spy(original);
}
});

// execute
mojo.execute();

Expand All @@ -105,6 +117,8 @@ public List<MavenProject> getProjects()
assertThat( prepareRequest.getValue().getReactorProjects(), is( notNullValue() ) );
assertThat( prepareRequest.getValue().getResume(), is( true ) );
assertThat( prepareRequest.getValue().getDryRun(), is( false ) );

verify(prepareRequest.getValue().getReleaseDescriptorBuilder()).setScmSignTags(false);
}

public void testPrepareWithExecutionException()
Expand Down

0 comments on commit 8142302

Please sign in to comment.