@@ -295,6 +295,35 @@ public class GitCommitIdMojo extends AbstractMojo {
295295 @ SuppressWarnings ("UnusedDeclaration" )
296296 private List <String > excludeProperties = Collections .emptyList ();
297297
298+ /**
299+ * Can be used to exclude certain properties from being emited into the resulting file.
300+ * May be useful when you want to hide {@code git.remote.origin.url} (maybe because it contains your repo password?),
301+ * or the email of the committer etc.
302+ *
303+ * Each value may be globbing, that is, you can write {@code git.commit.user.*} to include both, the {@code name},
304+ * as well as {@code email} properties into the resulting files.
305+ *
306+ * Please note that the strings here are Java regexes ({@code .*} is globbing, not plain {@code *}).
307+ *
308+ * @parameter
309+ * @since 2.1.14
310+ */
311+ @ SuppressWarnings ("UnusedDeclaration" )
312+ private List <String > includeProperties = Collections .emptyList ();
313+
314+ /**
315+ * Can be used to add some properties in order to gather everything in the same file.
316+ *
317+ * For instance, you can set the maven project version or any dependency information.
318+ *
319+ * The key is the property name, the value is the value.
320+ *
321+ * @parameter
322+ * @since 2.1.14
323+ */
324+ @ SuppressWarnings ("UnusedDeclaration" )
325+ private Map <String , String > additionalProperties = Collections .emptyMap ();
326+
298327 /**
299328 * The Maven Session Object
300329 *
@@ -360,7 +389,9 @@ public void execute() throws MojoExecutionException {
360389 loadBuildTimeData (properties );
361390 loadBuildHostData (properties );
362391 loadShortDescribe (properties );
392+ filter (properties , includeProperties );
363393 filterNot (properties , excludeProperties );
394+ addAdditionalProperties (properties , additionalProperties );
364395 logProperties (properties );
365396
366397 if (generateGitPropertiesFile ) {
@@ -378,7 +409,7 @@ public void execute() throws MojoExecutionException {
378409 }
379410
380411 private void filterNot (Properties properties , @ Nullable List <String > exclusions ) {
381- if (exclusions == null ) {
412+ if (exclusions == null || exclusions . isEmpty () ) {
382413 return ;
383414 }
384415
@@ -402,6 +433,37 @@ public Predicate<CharSequence> apply(String exclude) {
402433 }
403434 }
404435
436+ private void filter (Properties properties , @ Nullable List <String > inclusions ) {
437+ if (inclusions == null || inclusions .isEmpty ()) {
438+ return ;
439+ }
440+
441+ List <Predicate <CharSequence >> includePredicates = Lists .transform (inclusions , new Function <String , Predicate <CharSequence >>() {
442+ @ Override
443+ public Predicate <CharSequence > apply (String exclude ) {
444+ return Predicates .containsPattern (exclude );
445+ }
446+ });
447+
448+ Predicate <CharSequence > shouldInclude = Predicates .alwaysFalse ();
449+ for (Predicate <CharSequence > predicate : includePredicates ) {
450+ shouldInclude = Predicates .or (shouldInclude , predicate );
451+ }
452+
453+ for (String key : properties .stringPropertyNames ()) {
454+ if (!shouldInclude .apply (key )) {
455+ loggerBridge .debug ("!shouldInclude.apply(" + key + ") = " + shouldInclude .apply (key ));
456+ properties .remove (key );
457+ }
458+ }
459+ }
460+
461+ private void addAdditionalProperties (Properties properties , Map <String , String > additionalProperties ) {
462+ for (Map .Entry <String , String > additionalProperty : additionalProperties .entrySet ()) {
463+ properties .put (additionalProperty .getKey (), additionalProperty .getValue ());
464+ }
465+ }
466+
405467 /**
406468 * Reacts to an exception based on the {@code failOnUnableToExtractRepoInfo} setting.
407469 * If it's true, an MojoExecutionException will be throw, otherwise we just log an error message.
@@ -756,6 +818,14 @@ public void setExcludeProperties(List<String> excludeProperties) {
756818 this .excludeProperties = excludeProperties ;
757819 }
758820
821+ public void setIncludeProperties (List <String > includeProperties ) {
822+ this .includeProperties = includeProperties ;
823+ }
824+
825+ public void setAdditionalProperties (Map <String , String > additionalProperties ) {
826+ this .additionalProperties = additionalProperties ;
827+ }
828+
759829 public void useNativeGit (boolean useNativeGit ) {
760830 this .useNativeGit = useNativeGit ;
761831 }
0 commit comments