Skip to content

Commit 8cc2f45

Browse files
BigMichi1michael-o
authored andcommitted
[MRELEASE-1082] Add configuration option for shallow checkout/clone
This closes #121
1 parent 26cd6f6 commit 8cc2f45

File tree

7 files changed

+111
-12
lines changed

7 files changed

+111
-12
lines changed

maven-release-api/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ public interface ReleaseDescriptor
284284
*/
285285
String getScmCommentPrefix();
286286

287+
/**
288+
* Get whether to use a shallow clone with no history or a full clone containing the full history during the
289+
* release.
290+
*
291+
* @return boolean
292+
* @since 3.0.0-M6
293+
*/
294+
boolean isScmShallowClone();
295+
287296
/**
288297
* Get the SCM commit comment when setting pom.xml to release.
289298
*

maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,19 @@ public ReleaseDescriptorBuilder setScmCommentPrefix( String scmCommentPrefix )
473473
return this;
474474
}
475475

476+
/**
477+
* <p>setScmShallowClone.</p>
478+
*
479+
* @param scmShallowClone a boolean
480+
* @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object
481+
* @since 3.0.0-M6
482+
*/
483+
public ReleaseDescriptorBuilder setScmShallowClone( boolean scmShallowClone )
484+
{
485+
releaseDescriptor.setScmShallowClone( scmShallowClone );
486+
return this;
487+
}
488+
476489
/**
477490
* <p>setScmReleaseCommitComment.</p>
478491
*

maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ private ReleaseResult performCheckout( ReleaseDescriptor releaseDescriptor, Rele
218218
checkoutDirectory.mkdirs();
219219

220220
CommandParameters commandParameters = new CommandParameters();
221-
commandParameters.setString( CommandParameter.SHALLOW, Boolean.TRUE.toString() );
221+
commandParameters.setString( CommandParameter.SHALLOW,
222+
Boolean.valueOf( releaseDescriptor.isScmShallowClone() ).toString() );
222223

223224
CheckOutScmResult scmResult = provider.checkOut( repository, new ScmFileSet( checkoutDirectory ),
224225
new ScmTag( releaseDescriptor.getScmReleaseLabel() ), commandParameters );

maven-release-manager/src/main/mdo/release-descriptor.mdo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@
6868
The prefix of SCM modification messages
6969
</description>
7070
</field>
71+
<field>
72+
<name>scmShallowClone</name>
73+
<version>3.0.0+</version>
74+
<type>boolean</type>
75+
<defaultValue>true</defaultValue>
76+
<description>
77+
Get whether to use a shallow clone with no history or a full clone containing the full history during the
78+
release
79+
</description>
80+
</field>
7181
<field>
7282
<name>scmReleaseCommitComment</name>
7383
<version>3.0.0+</version>

maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertNull;
2424
import static org.junit.Assert.fail;
25-
import static org.mockito.ArgumentMatchers.any;
2625
import static org.mockito.ArgumentMatchers.argThat;
2726
import static org.mockito.ArgumentMatchers.eq;
2827
import static org.mockito.Mockito.mock;
@@ -34,7 +33,7 @@
3433
import java.util.List;
3534

3635
import org.apache.maven.project.MavenProject;
37-
import org.apache.maven.scm.CommandParameters;
36+
import org.apache.maven.scm.CommandParameter;
3837
import org.apache.maven.scm.ScmFileSet;
3938
import org.apache.maven.scm.ScmTag;
4039
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
@@ -86,8 +85,8 @@ public void testExecuteStandard()
8685
when( scmProviderMock.checkOut( eq( repository ),
8786
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
8887
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
89-
any( CommandParameters.class)))
90-
.thenReturn( new CheckOutScmResult( "",null ) );
88+
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ) )
89+
.thenReturn( new CheckOutScmResult( "", null ) );
9190

9291
ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
9392
stub.setScmProvider( scmProviderMock );
@@ -106,7 +105,7 @@ public void testExecuteStandard()
106105
verify( scmProviderMock ).checkOut( eq( repository ),
107106
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
108107
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
109-
any( CommandParameters.class ));
108+
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) );
110109
verifyNoMoreInteractions( scmProviderMock );
111110
}
112111

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

135134
ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
@@ -149,7 +148,7 @@ public void testExecuteMultiModuleWithDeepSubprojects()
149148
verify( scmProviderMock ).checkOut( eq( repository ),
150149
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
151150
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
152-
any( CommandParameters.class ));
151+
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) );
153152
verifyNoMoreInteractions( scmProviderMock );
154153
}
155154

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

178177
ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
179178
stub.setScmProvider( scmProviderMock );
@@ -193,7 +192,7 @@ public void testExecuteFlatMultiModule()
193192
verify( scmProviderMock ).checkOut( eq( repository ),
194193
argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ),
195194
argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ),
196-
any( CommandParameters.class ));
195+
argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) );
197196
verifyNoMoreInteractions( scmProviderMock );
198197
}
199198

@@ -257,4 +256,4 @@ public void testScmRepositoryExceptionThrown()
257256
}
258257
}
259258

260-
}
259+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.apache.maven.shared.release.phase;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.apache.maven.scm.CommandParameter;
23+
import org.apache.maven.scm.CommandParameters;
24+
import org.apache.maven.scm.ScmException;
25+
import org.mockito.ArgumentMatcher;
26+
27+
/**
28+
* Mockito constraint to check if a command parameter has a specific value.
29+
*
30+
* @author <a href="mailto:michael@bigmichi1.de">Michael Cramer</a>
31+
*/
32+
public class HasCommandParameter implements ArgumentMatcher<CommandParameters>
33+
{
34+
private final CommandParameter commandParameter;
35+
36+
private final Object expected;
37+
38+
public HasCommandParameter( CommandParameter commandParameter, Object expected )
39+
{
40+
this.commandParameter = commandParameter;
41+
this.expected = expected;
42+
}
43+
44+
@Override
45+
public boolean matches( CommandParameters argument )
46+
{
47+
CommandParameters commandParameters = (CommandParameters) argument;
48+
49+
try
50+
{
51+
return commandParameters.getString( this.commandParameter ).equals( String.valueOf( expected ) );
52+
}
53+
catch ( ScmException e )
54+
{
55+
return false;
56+
}
57+
}
58+
59+
60+
}

maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractScmReleaseMojo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ public abstract class AbstractScmReleaseMojo
8989
@Parameter( defaultValue = "[maven-release-plugin] ", property = "scmCommentPrefix" )
9090
private String scmCommentPrefix;
9191

92+
/**
93+
* When cloning a repository if it should be a shallow clone or a full clone.
94+
*/
95+
@Parameter( defaultValue = "true", property = "scmShallowClone" )
96+
private boolean scmShallowClone = true;
97+
9298
/**
9399
* Implemented with git will or not push changes to the upstream repository.
94100
* <code>true</code> by default to preserve backward compatibility.
@@ -149,6 +155,7 @@ protected ReleaseDescriptorBuilder createReleaseDescriptor()
149155
descriptor.setScmTagBase( tagBase );
150156
descriptor.setScmUsername( username );
151157
descriptor.setScmCommentPrefix( scmCommentPrefix );
158+
descriptor.setScmShallowClone( scmShallowClone );
152159

153160
descriptor.setPushChanges( pushChanges );
154161
descriptor.setWorkItem( workItem );

0 commit comments

Comments
 (0)