Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRELEASE-1082] configuration option for using a shallow clone #121

Merged
merged 1 commit into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ public interface ReleaseDescriptor
*/
String getScmCommentPrefix();

/**
* Get whether to use a shallow clone with no history or a full clone containing the full history during the
* release.
*
* @return boolean
* @since 3.0.0-M6
*/
boolean isScmShallowClone();

/**
* Get the SCM commit comment when setting pom.xml to release.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,19 @@ public ReleaseDescriptorBuilder setScmCommentPrefix( String scmCommentPrefix )
return this;
}

/**
* <p>setScmShallowClone.</p>
*
* @param scmShallowClone a boolean
* @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object
* @since 3.0.0-M6
*/
public ReleaseDescriptorBuilder setScmShallowClone( boolean scmShallowClone )
{
releaseDescriptor.setScmShallowClone( scmShallowClone );
return this;
}

/**
* <p>setScmReleaseCommitComment.</p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ private ReleaseResult performCheckout( ReleaseDescriptor releaseDescriptor, Rele
checkoutDirectory.mkdirs();

CommandParameters commandParameters = new CommandParameters();
commandParameters.setString( CommandParameter.SHALLOW, Boolean.TRUE.toString() );
commandParameters.setString( CommandParameter.SHALLOW,
Boolean.valueOf( releaseDescriptor.isScmShallowClone() ).toString() );

CheckOutScmResult scmResult = provider.checkOut( repository, new ScmFileSet( checkoutDirectory ),
new ScmTag( releaseDescriptor.getScmReleaseLabel() ), commandParameters );
Expand Down
10 changes: 10 additions & 0 deletions maven-release-manager/src/main/mdo/release-descriptor.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
The prefix of SCM modification messages
</description>
</field>
<field>
<name>scmShallowClone</name>
<version>3.0.0+</version>
<type>boolean</type>
<defaultValue>true</defaultValue>
<description>
Get whether to use a shallow clone with no history or a full clone containing the full history during the
release
</description>
</field>
<field>
<name>scmReleaseCommitComment</name>
<version>3.0.0+</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
Expand All @@ -34,7 +33,7 @@
import java.util.List;

import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.CommandParameter;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmTag;
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
Expand Down Expand Up @@ -86,8 +85,8 @@ public void testExecuteStandard()
when( scmProviderMock.checkOut( eq( repository ),
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
any( CommandParameters.class)))
.thenReturn( new CheckOutScmResult( "",null ) );
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ) )
.thenReturn( new CheckOutScmResult( "", null ) );

ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
stub.setScmProvider( scmProviderMock );
Expand All @@ -106,7 +105,7 @@ public void testExecuteStandard()
verify( scmProviderMock ).checkOut( eq( repository ),
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
any( CommandParameters.class ));
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) );
verifyNoMoreInteractions( scmProviderMock );
}

Expand All @@ -129,7 +128,7 @@ public void testExecuteMultiModuleWithDeepSubprojects()
when( scmProviderMock.checkOut( eq( repository ),
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
any(CommandParameters.class)))
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ) )
.thenReturn( new CheckOutScmResult( "", null ) );

ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
Expand All @@ -149,7 +148,7 @@ public void testExecuteMultiModuleWithDeepSubprojects()
verify( scmProviderMock ).checkOut( eq( repository ),
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
any( CommandParameters.class ));
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) );
verifyNoMoreInteractions( scmProviderMock );
}

Expand All @@ -172,8 +171,8 @@ public void testExecuteFlatMultiModule()
when( scmProviderMock.checkOut( eq( repository ),
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
any( CommandParameters.class )) )
.thenReturn( new CheckOutScmResult( "",null ) );
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ) )
.thenReturn( new CheckOutScmResult( "", null ) );

ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
stub.setScmProvider( scmProviderMock );
Expand All @@ -193,7 +192,7 @@ public void testExecuteFlatMultiModule()
verify( scmProviderMock ).checkOut( eq( repository ),
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
any( CommandParameters.class ));
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) );
verifyNoMoreInteractions( scmProviderMock );
}

Expand Down Expand Up @@ -257,4 +256,4 @@ public void testScmRepositoryExceptionThrown()
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.apache.maven.shared.release.phase;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.scm.CommandParameter;
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.mockito.ArgumentMatcher;

/**
* Mockito constraint to check if a command parameter has a specific value.
*
* @author <a href="mailto:[email protected]">Michael Cramer</a>
*/
public class HasCommandParameter implements ArgumentMatcher<CommandParameters>
{
private final CommandParameter commandParameter;

private final Object expected;

public HasCommandParameter( CommandParameter commandParameter, Object expected )
{
this.commandParameter = commandParameter;
this.expected = expected;
}

@Override
public boolean matches( CommandParameters argument )
{
CommandParameters commandParameters = (CommandParameters) argument;

try
{
return commandParameters.getString( this.commandParameter ).equals( String.valueOf( expected ) );
}
catch ( ScmException e )
{
return false;
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ public abstract class AbstractScmReleaseMojo
@Parameter( defaultValue = "[maven-release-plugin] ", property = "scmCommentPrefix" )
private String scmCommentPrefix;

/**
* When cloning a repository if it should be a shallow clone or a full clone.
*/
@Parameter( defaultValue = "true", property = "scmShallowClone" )
private boolean scmShallowClone = true;

/**
* Implemented with git will or not push changes to the upstream repository.
* <code>true</code> by default to preserve backward compatibility.
Expand Down Expand Up @@ -149,6 +155,7 @@ protected ReleaseDescriptorBuilder createReleaseDescriptor()
descriptor.setScmTagBase( tagBase );
descriptor.setScmUsername( username );
descriptor.setScmCommentPrefix( scmCommentPrefix );
descriptor.setScmShallowClone( scmShallowClone );

descriptor.setPushChanges( pushChanges );
descriptor.setWorkItem( workItem );
Expand Down