Skip to content
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ It's really simple to setup this plugin; below is a sample pom that you may base
-->
<forceLongFormat>false</forceLongFormat>
</gitDescribe>

<!-- @since 2.1.8 -->
<!--
skip the plugin execution completely. This is useful for e.g. profile activated plugin invocations or
to use properties to enable / disable pom features. Default value is 'false'.
-->
<skip>false</skip>
</configuration>

</plugin>
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
}
Expand Down