diff --git a/README.md b/README.md index 72f39e5c..63135089 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,13 @@ It's really simple to setup this plugin; below is a sample pom that you may base --> false + + + + false @@ -482,6 +489,7 @@ Optional parameters: * **generateGitPropertiesFilename** - `(default: src/main/resources/git.properties)` - The path for the to be generated properties file, it's relative to ${project.basedir} * **skipPoms** - `(default: true)` - Force the plugin to run even if you're inside of an pom packaged project. * **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. +* **skip** - `(default: false)` *(available since v2.1.8)* - Skip the plugin execution completely. **gitDescribe**: 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. diff --git a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java index 051cd116..b821df5d 100644 --- a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java +++ b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java @@ -239,6 +239,15 @@ public class GitCommitIdMojo extends AbstractMojo { @SuppressWarnings("UnusedDeclaration") private boolean failOnUnableToExtractRepoInfo; + /** + * Skip the plugin execution. + * + * @parameter default-value="false" + * @since 2.1.8 + */ + @SuppressWarnings("UnusedDeclaration") + private boolean skip = false; + /** * The properties we store our data in and then expose them */ @@ -253,6 +262,11 @@ public void execute() throws MojoExecutionException { // Set the verbose setting now it should be correctly loaded from maven. loggerBridge.setVerbose(verbose); + if (skip) { + log("skip is true, return"); + return; + } + if (isPomProject(project) && skipPoms) { log("isPomProject is true and skipPoms is true, return"); return; diff --git a/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java b/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java index a86e8f17..897aac4d 100644 --- a/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java +++ b/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java @@ -52,6 +52,21 @@ public void shouldResolvePropertiesOnDefaultSettingsForNonPomProject() throws Ex assertGitPropertiesPresentInProject(targetProject.getProperties()); } + @Test + public void shouldNotRunWhenSkipIsSet() throws Exception { + // given + mavenSandbox.withParentProject("my-skip-project", "jar").withNoChildProject().withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT).create(CleanUp.CLEANUP_FIRST); + MavenProject targetProject = mavenSandbox.getParentProject(); + setProjectToExecuteMojoIn(targetProject); + alterMojoSettings("skip", Boolean.TRUE); + + // when + mojo.execute(); + + // then + assertThat(targetProject.getProperties()).isEmpty(); + } + @Test public void shouldNotRunWhenPackagingPomAndDefaultSettingsApply() throws Exception { // given @@ -111,6 +126,7 @@ public void shouldUseChildProjectRepoIfInvokedFromChild() throws Exception { assertGitPropertiesPresentInProject(targetProject.getProperties()); } + @Test public void shouldFailWithExceptionWhenNoGitRepoFound() throws Exception { // given mavenSandbox.withParentProject("my-pom-project", "pom") @@ -196,6 +212,44 @@ public void shouldGenerateCustomPropertiesFileJson() throws Exception { } } + @Test + public void shouldSkipWithoutFailOnNoGitDirectoryWhenNoGitRepoFound() throws Exception { + // given + mavenSandbox.withParentProject("my-jar-project", "jar") + .withNoChildProject() + .withNoGitRepoAvailable() + .create(CleanUp.CLEANUP_FIRST); + + MavenProject targetProject = mavenSandbox.getParentProject(); + setProjectToExecuteMojoIn(targetProject); + alterMojoSettings("failOnNoGitDirectory", false); + + // when + mojo.execute(); + + // then + assertThat(targetProject.getProperties()).isEmpty(); + } + + @Test + public void shouldNotSkipWithoutFailOnNoGitDirectoryWhenNoGitRepoIsPresent() throws Exception { + // given + mavenSandbox.withParentProject("my-jar-project", "jar") + .withNoChildProject() + .withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT) + .create(CleanUp.CLEANUP_FIRST); + + MavenProject targetProject = mavenSandbox.getParentProject(); + setProjectToExecuteMojoIn(targetProject); + alterMojoSettings("failOnNoGitDirectory", false); + + // when + mojo.execute(); + + // then + assertGitPropertiesPresentInProject(targetProject.getProperties()); + } + private void alterMojoSettings(String parameterName, Object parameterValue) { setInternalState(mojo, parameterName, parameterValue); }