4646import java .net .InetAddress ;
4747import java .net .UnknownHostException ;
4848import java .text .SimpleDateFormat ;
49- import java .util .Collections ;
5049import java .util .Date ;
5150import java .util .HashMap ;
5251import java .util .List ;
@@ -65,12 +64,9 @@ public class GitCommitIdMojo extends AbstractMojo {
6564 // these properties will be exposed to maven
6665 public static final String BRANCH = "branch" ;
6766 public static final String DIRTY = "dirty" ;
67+ // only one of the following two will be exposed, depending on the commitIdGenerationMode
6868 public static final String COMMIT_ID_FLAT = "commit.id" ;
6969 public static final String COMMIT_ID_FULL = "commit.id.full" ;
70-
71- // TODO this should be private instance field with getter and setter
72- public static String COMMIT_ID = COMMIT_ID_FLAT ;
73-
7470 public static final String COMMIT_ID_ABBREV = "commit.id.abbrev" ;
7571 public static final String COMMIT_DESCRIBE = "commit.id.describe" ;
7672 public static final String COMMIT_SHORT_DESCRIBE = "commit.id.describe-short" ;
@@ -134,7 +130,7 @@ public class GitCommitIdMojo extends AbstractMojo {
134130 *
135131 * <p>Defaults to {@code true}.</p>
136132 */
137- @ Parameter (defaultValue = "true" , name = "git.skipPoms" )
133+ @ Parameter (defaultValue = "true" )
138134 private boolean skipPoms ;
139135
140136 /**
@@ -351,6 +347,7 @@ public class GitCommitIdMojo extends AbstractMojo {
351347 */
352348 @ Parameter (defaultValue = "flat" )
353349 private String commitIdGenerationMode ;
350+ private CommitIdGenerationMode commitIdGenerationModeEnum ;
354351
355352 /**
356353 * The properties we store our data in and then expose them.
@@ -399,15 +396,11 @@ public void execute() throws MojoExecutionException {
399396 }
400397
401398 try {
402- switch (CommitIdGenerationModeEnum .getValue (commitIdGenerationMode )){
403- default :
399+ try {
400+ commitIdGenerationModeEnum = CommitIdGenerationMode .valueOf (commitIdGenerationMode .toUpperCase ());
401+ } catch (IllegalArgumentException e ) {
404402 log .warn ("Detected wrong setting for 'commitIdGenerationMode'. Falling back to default 'flat' mode!" );
405- case FLAT :
406- COMMIT_ID = COMMIT_ID_FLAT ;
407- break ;
408- case FULL :
409- COMMIT_ID = COMMIT_ID_FULL ;
410- break ;
403+ commitIdGenerationModeEnum = CommitIdGenerationMode .FLAT ;
411404 }
412405
413406 properties = initProperties ();
@@ -603,7 +596,8 @@ void loadGitDataWithNativeGit(@NotNull Properties properties) throws IOException
603596 .setAbbrevLength (abbrevLength )
604597 .setDateFormat (dateFormat )
605598 .setDateFormatTimeZone (dateFormatTimeZone )
606- .setGitDescribe (gitDescribe );
599+ .setGitDescribe (gitDescribe )
600+ .setCommitIdGenerationMode (commitIdGenerationModeEnum );
607601
608602 nativeGitProvider .loadGitData (properties );
609603 }
@@ -615,7 +609,8 @@ void loadGitDataWithJGit(@NotNull Properties properties) throws IOException, Moj
615609 .setAbbrevLength (abbrevLength )
616610 .setDateFormat (dateFormat )
617611 .setDateFormatTimeZone (dateFormatTimeZone )
618- .setGitDescribe (gitDescribe );
612+ .setGitDescribe (gitDescribe )
613+ .setCommitIdGenerationMode (commitIdGenerationModeEnum );
619614
620615 jGitProvider .loadGitData (properties );
621616 }
0 commit comments