Skip to content

Commit caf91d5

Browse files
author
Henning Schmiedehausen
committed
Add 'skip' configuration option.
Includes integration tests
1 parent 0f3aeef commit caf91d5

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ It's really simple to setup this plugin; below is a sample pom that you may base
177177
-->
178178
<forceLongFormat>false</forceLongFormat>
179179
</gitDescribe>
180+
181+
<!-- @since 2.1.8 -->
182+
<!--
183+
skip the plugin execution completely. This is useful for e.g. profile activated plugin invocations or
184+
to use properties to enable / disable pom features. Default value is 'false'.
185+
-->
186+
<skip>false</skip>
180187
</configuration>
181188

182189
</plugin>
@@ -482,6 +489,7 @@ Optional parameters:
482489
* **generateGitPropertiesFilename** - `(default: src/main/resources/git.properties)` - The path for the to be generated properties file, it's relative to ${project.basedir}
483490
* **skipPoms** - `(default: true)` - Force the plugin to run even if you're inside of an pom packaged project.
484491
* **failOnNoGitDirectory** - `(default: true)` *(available since v2.0.4)* - Specify whether the plugin should fail when a .git directory can not be found. When set to false and no .git directory is found the plugin will skip execution.
492+
* **skip** - `(default: false)` *(available since v2.1.8)* - Skip the plugin execution completely.
485493

486494
**gitDescribe**:
487495
Worth pointing out is, that git-commit-id tries to be 1-to-1 compatible with git's plain output, even though the describe functionality has been reimplemented manually using JGit (you don't have to have a git executable to use the plugin). So if you're familiar with [git-describe](https://github.com/ktoso/maven-git-commit-id-plugin#git-describe---short-intro-to-an-awesome-command), you probably can skip this section, as it just explains the same options that git provides.

src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ public class GitCommitIdMojo extends AbstractMojo {
239239
@SuppressWarnings("UnusedDeclaration")
240240
private boolean failOnUnableToExtractRepoInfo;
241241

242+
/**
243+
* Skip the plugin execution.
244+
*
245+
* @parameter default-value="false"
246+
* @since 2.1.8
247+
*/
248+
@SuppressWarnings("UnusedDeclaration")
249+
private boolean skip = false;
250+
242251
/**
243252
* The properties we store our data in and then expose them
244253
*/
@@ -253,6 +262,11 @@ public void execute() throws MojoExecutionException {
253262
// Set the verbose setting now it should be correctly loaded from maven.
254263
loggerBridge.setVerbose(verbose);
255264

265+
if (skip) {
266+
log("skip is true, return");
267+
return;
268+
}
269+
256270
if (isPomProject(project) && skipPoms) {
257271
log("isPomProject is true and skipPoms is true, return");
258272
return;

src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ public void shouldResolvePropertiesOnDefaultSettingsForNonPomProject() throws Ex
5252
assertGitPropertiesPresentInProject(targetProject.getProperties());
5353
}
5454

55+
@Test
56+
public void shouldNotRunWhenSkipIsSet() throws Exception {
57+
// given
58+
mavenSandbox.withParentProject("my-skip-project", "jar").withNoChildProject().withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT).create(CleanUp.CLEANUP_FIRST);
59+
MavenProject targetProject = mavenSandbox.getParentProject();
60+
setProjectToExecuteMojoIn(targetProject);
61+
alterMojoSettings("skip", Boolean.TRUE);
62+
63+
// when
64+
mojo.execute();
65+
66+
// then
67+
assertThat(targetProject.getProperties()).isEmpty();
68+
}
69+
5570
@Test
5671
public void shouldNotRunWhenPackagingPomAndDefaultSettingsApply() throws Exception {
5772
// given
@@ -111,6 +126,7 @@ public void shouldUseChildProjectRepoIfInvokedFromChild() throws Exception {
111126
assertGitPropertiesPresentInProject(targetProject.getProperties());
112127
}
113128

129+
@Test
114130
public void shouldFailWithExceptionWhenNoGitRepoFound() throws Exception {
115131
// given
116132
mavenSandbox.withParentProject("my-pom-project", "pom")
@@ -196,6 +212,44 @@ public void shouldGenerateCustomPropertiesFileJson() throws Exception {
196212
}
197213
}
198214

215+
@Test
216+
public void shouldSkipWithoutFailOnNoGitDirectoryWhenNoGitRepoFound() throws Exception {
217+
// given
218+
mavenSandbox.withParentProject("my-jar-project", "jar")
219+
.withNoChildProject()
220+
.withNoGitRepoAvailable()
221+
.create(CleanUp.CLEANUP_FIRST);
222+
223+
MavenProject targetProject = mavenSandbox.getParentProject();
224+
setProjectToExecuteMojoIn(targetProject);
225+
alterMojoSettings("failOnNoGitDirectory", false);
226+
227+
// when
228+
mojo.execute();
229+
230+
// then
231+
assertThat(targetProject.getProperties()).isEmpty();
232+
}
233+
234+
@Test
235+
public void shouldNotSkipWithoutFailOnNoGitDirectoryWhenNoGitRepoIsPresent() throws Exception {
236+
// given
237+
mavenSandbox.withParentProject("my-jar-project", "jar")
238+
.withNoChildProject()
239+
.withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT)
240+
.create(CleanUp.CLEANUP_FIRST);
241+
242+
MavenProject targetProject = mavenSandbox.getParentProject();
243+
setProjectToExecuteMojoIn(targetProject);
244+
alterMojoSettings("failOnNoGitDirectory", false);
245+
246+
// when
247+
mojo.execute();
248+
249+
// then
250+
assertGitPropertiesPresentInProject(targetProject.getProperties());
251+
}
252+
199253
private void alterMojoSettings(String parameterName, Object parameterValue) {
200254
setInternalState(mojo, parameterName, parameterValue);
201255
}

0 commit comments

Comments
 (0)