From 6b7e9ca6e2706ce4b6e58053030ca690cdc24740 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Sun, 18 Aug 2019 16:27:28 +0200 Subject: [PATCH 1/2] Allow to override useNativeGit from command line Right now, because JGit doesn't support Git worktrees, I need to override `useNativeGit` in the `pom.xml` of different projects, and it's easy to make a mistake and commit the changes. The proposed PR should allow to override this property from command-line via `maven.gitcommitid.nativegit`, without modification of the `pom.xml`. --- docs/using-the-plugin.md | 2 ++ src/main/java/pl/project13/maven/git/GitCommitIdMojo.java | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/using-the-plugin.md b/docs/using-the-plugin.md index cdad2088..62c8dfe0 100644 --- a/docs/using-the-plugin.md +++ b/docs/using-the-plugin.md @@ -372,6 +372,8 @@ It's really simple to setup this plugin; below is a sample pom that you may base Although this should usually give your build some performance boost, it may randomly break if you upgrade your git version and it decides to print information in a different format suddenly. As rule of thumb, keep using the default `jgit` implementation (keep this `false`) until you notice performance problems within your build (usually when you have *hundreds* of maven modules). + + With version *3.0.2* you can also control it using the commandline option `-Dmaven.gitcommitid.nativegit=true` --> false diff --git a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java index 0e813d07..665c0ad4 100644 --- a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java +++ b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java @@ -198,9 +198,14 @@ public class GitCommitIdMojo extends AbstractMojo { * Set this to {@code 'true'} to use native Git executable to fetch information about the repository. * It is in most cases faster but requires a git executable to be installed in system. * By default the plugin will use jGit implementation as a source of information about the repository. + * + * NOTE / WARNING: + * Do *NOT* set this property inside the configuration of your plugin, so it would be + * possible to override it from command line. + * * @since 2.1.9 */ - @Parameter(defaultValue = "false") + @Parameter(property = "maven.gitcommitid.nativegit", defaultValue = "false") boolean useNativeGit; /** From 1b56f0dc0a83b03de1bbb285b3b06fc67f936b46 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Sat, 24 Aug 2019 13:09:04 +0200 Subject: [PATCH 2/2] Re-implement as per suggestion --- .../project13/maven/git/GitCommitIdMojo.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java index 665c0ad4..f612f7fe 100644 --- a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java +++ b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java @@ -199,15 +199,25 @@ public class GitCommitIdMojo extends AbstractMojo { * It is in most cases faster but requires a git executable to be installed in system. * By default the plugin will use jGit implementation as a source of information about the repository. * - * NOTE / WARNING: - * Do *NOT* set this property inside the configuration of your plugin, so it would be - * possible to override it from command line. - * * @since 2.1.9 */ - @Parameter(property = "maven.gitcommitid.nativegit", defaultValue = "false") + @Parameter(defaultValue = "false") boolean useNativeGit; + /** + * Option to be used in command-line to override the value of {@code 'useNativeGit'} specified in + * the pom.xml, or its default value if it's not set explicitly. + * + * NOTE / WARNING: + * Do *NOT* set this property inside the configuration of your plugin. + * Please read https://github.com/git-commit-id/maven-git-commit-id-plugin/issues/315 + * to find out why. + * + * @since 3.0.2 + */ + @Parameter(property = "maven.gitcommitid.nativegit", defaultValue = "false") + boolean useNativeGitViaCommandLine; + /** * Set this to {@code 'true'} to skip plugin execution. * @since 2.1.8 @@ -562,8 +572,15 @@ private void logProperties() { } } + private boolean isUseNativeGit() { + if (System.getProperty("maven.gitcommitid.nativegit") != null) { + return useNativeGitViaCommandLine; + } + return useNativeGit; + } + private void loadGitData(@Nonnull Properties properties) throws GitCommitIdExecutionException { - if (useNativeGit) { + if (isUseNativeGit()) { loadGitDataWithNativeGit(properties); } else { loadGitDataWithJGit(properties);