Skip to content

Commit a2e5494

Browse files
author
S L
committed
As suggested in #212: Don't mark the flat property usage as depecated, the intention of this PR is to keep it around; change generateCommitIdOldFashioned to a string where you can specify full/flat depending on what you want and need
1 parent ab1b265 commit a2e5494

File tree

5 files changed

+62
-35
lines changed

5 files changed

+62
-35
lines changed

README.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ You can check the available versions by visiting [search.maven.org](http://searc
4444

4545
Migration Issues you may come across when using the latest 2.2.X
4646
-----------------------------
47-
If you are already using the git-commit-id-plugin and would like to move to the latest major release (2.2.X) there are some design choices we made to fix some of your issues.
48-
1. We dropped the support of Java 1.6 (if you still rely on this version, the version 2.1.15 still has support for this and you may want to check the fixed issues since then before reporting a new one)
49-
2. Due to some naming issues when exporting the properties as an json-object (https://github.com/ktoso/maven-git-commit-id-plugin/issues/122) we needed to change the export of the property from 'git.commit.id' to 'git.commit.id.full'.
50-
However, due to the fact that this is one of the major properties the plugin is exporting we just don't want to change the exporting mechanism and somehow throw the backwards compatibility away.
51-
To overcome this issue we introduced a switch called 'generateCommitIdOldFashioned'.
52-
By default it is set to 'true' and will generate the formerly known property 'git.commit.id' as it was in the previous versions of the plugin. With keeping the switch set to 'true' the plugin will print a warning that using this switch set to 'true' is deprecated and may be removed in a future release. However keeping it to 'true' by default preserve backwards compatibility and allows to migrate to the new properties when it's convenient.
53-
If you set this switch to 'false' the plugin will export the formerly known property 'git.commit.id' as 'git.commit.id.full'.
54-
55-
*Note*: Depending on your plugin configuration you obviously can choose the 'prefix' of your properties by setting it accordingly in the plugin's configuration. As a result this is therefore only an illustration what the switch means when the 'prefix' is set to it's default value.
56-
47+
If you are already using the git-commit-id-plugin and would like to move to the latest major release (2.2.X) there are some design choices that resulted in the fact that we needed to dropped the support of Java 1.6 (if you still rely on this version, the version 2.1.15 still has support for this and you may want to check the fixed issues since then before reporting a new one)
5748

5849
Getting SNAPSHOT versions of the plugin
5950
---------------------------------------
@@ -261,6 +252,23 @@ It's really simple to setup this plugin; below is a sample pom that you may base
261252
-->
262253
<abbrevLength>7</abbrevLength>
263254

255+
256+
<!-- @since v2.2.0 -->
257+
<!--
258+
The option can be used to tell the plugin how it should generate the 'git.commit.id' property. Due to some naming issues when exporting the properties as an json-object (https://github.com/ktoso/maven-git-commit-id-plugin/issues/122) we needed to make it possible to export all properties as a valid json-object.
259+
Due to the fact that this is one of the major properties the plugin is exporting we just don't want to change the exporting mechanism and somehow throw the backwards compatibility away.
260+
We rather provide a convient switch where you can choose if you would like the properties as they always had been, or if you rather need to support full json-object compatibility.
261+
In the case you need to fully support json-object we unfortunately need to change the 'git.commit.id' property from 'git.commit.id' to 'git.commit.id.full' in the exporting mechanism to allow the generation of a fully valid json object.
262+
263+
Currently the switch allows two different options:
264+
1. By default this property is set to 'flat' and will generate the formerly known property 'git.commit.id' as it was in the previous versions of the plugin. Keeping it to 'flat' by default preserve backwards compatibility and does not require further adjustments by the end user.
265+
2. If you set this switch to 'full' the plugin will export the formerly known property 'git.commit.id' as 'git.commit.id.full' and therefore will generate a fully valid json object in the exporting mechanism.
266+
267+
*Note*: Depending on your plugin configuration you obviously can choose the 'prefix' of your properties by setting it accordingly in the plugin's configuration. As a result this is therefore only an illustration what the switch means when the 'prefix' is set to it's default value.
268+
*Note*: If you set the value to something that's not equal to 'flat' or 'full' (ignoring the case) the plugin will output a warning and will fallback to the default 'flat' mode.
269+
-->
270+
<commitIdGenerationMode>flat</commitIdGenerationMode>
271+
264272
<!-- @since 2.1.0 -->
265273
<!--
266274
read up about git-describe on the in man, or it's homepage - it's a really powerful versioning helper
@@ -318,8 +326,9 @@ git.tags=${git.tags}
318326
git.branch=${git.branch}
319327
git.dirty=${git.dirty}
320328
git.remote.origin.url=${git.remote.origin.url}
321-
322-
git.commit.id.full=${git.commit.id.full}
329+
git.commit.id=${git.commit.id}
330+
OR (depends on commitIdGenerationMode)
331+
git.commit.id.full=${git.commit.id.full}
323332
git.commit.id.abbrev=${git.commit.id.abbrev}
324333
git.commit.id.describe=${git.commit.id.describe}
325334
git.commit.id.describe-short=${git.commit.id.describe-short}
@@ -358,6 +367,7 @@ Start out with with adding the above steps to your project, next paste this **gi
358367
<property name="remoteOriginUrl" value="${git.remote.origin.url}"/>
359368

360369
<property name="commitId" value="${git.commit.id.full}"/>
370+
<!-- OR value="${git.commit.id}" depending on your configuration of commitIdGenerationMode -->
361371
<property name="commitIdAbbrev" value="${git.commit.id.abbrev}"/>
362372
<property name="describe" value="${git.commit.id.describe}"/>
363373
<property name="describeShort" value="${git.commit.id.describe-short}"/>
@@ -397,7 +407,7 @@ public class GitRepositoryState {
397407
String dirty; // =${git.dirty}
398408
String remoteOriginUrl; // =${git.remote.origin.url}
399409

400-
String commitId; // =${git.commit.id.full}
410+
String commitId; // =${git.commit.id.full} OR ${git.commit.id}
401411
String commitIdAbbrev; // =${git.commit.id.abbrev}
402412
String describe; // =${git.commit.id.describe}
403413
String describeShort; // =${git.commit.id.describe-short}
@@ -528,7 +538,7 @@ public GitRepositoryState(Properties properties)
528538
this.dirty = properties.get("git.dirty").toString();
529539
this.remoteOriginUrl = properties.get("git.remote.origin.url").toString();
530540

531-
this.commitId = properties.get("git.commit.id.full").toString();
541+
this.commitId = properties.get("git.commit.id.full").toString(); // OR properties.get("git.commit.id") depending on your configuration
532542
this.commitIdAbbrev = properties.get("git.commit.id.abbrev").toString();
533543
this.describe = properties.get("git.commit.id.describe").toString();
534544
this.describeShort = properties.get("git.commit.id.describe-short").toString();
@@ -660,7 +670,12 @@ Optional parameters:
660670
* **includeOnlyProperties** - `(default: empty)` *(available since v2.1.14)* - Allows to include only properties that you want to expose. This feature was implemented to avoid big exclude properties tag when we only want very few specific properties.
661671
* **useNativeGit** - `(default: false)` *(available since v2.1.10)* - Uses the native `git` binary instead of the custom `jgit` implementation shipped with this plugin to obtain all information. Although this should usualy 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 option set to `false`) until you notice performance problems within your build (usualy when you have *hundreds* of maven modules).
662672
* **abbrevLength** - `(default: 7)` *(available since v2.0.4)* - Configure the "git.commit.id.abbrev" property to be at least of length N (see gitDescribe abbrev for special case abbrev = 0).
673+
* **commitIdGenerationMode** - `(default: flat)` *(available since v2.2.0)* is an option that can be used to tell the plugin how it should generate the 'git.commit.id' property. Due to some naming issues when exporting the properties as an json-object (https://github.com/ktoso/maven-git-commit-id-plugin/issues/122) we needed to make it possible to export all properties as a valid json-object. Currently the switch allows two different options:
674+
1. By default this property is set to 'flat' and will generate the formerly known property 'git.commit.id' as it was in the previous versions of the plugin. Keeping it to 'flat' by default preserve backwards compatibility and does not require further adjustments by the end user.
675+
2. If you set this switch to 'full' the plugin will export the formerly known property 'git.commit.id' as 'git.commit.id.full' and therefore will generate a fully valid json object in the exporting mechanism.
663676

677+
*Note*: Depending on your plugin configuration you obviously can choose the 'prefix' of your properties by setting it accordingly in the plugin's configuration. As a result this is therefore only an illustration what the switch means when the 'prefix' is set to it's default value.
678+
*Note*: If you set the value to something that's not equal to 'flat' or 'full' (ignoring the case) the plugin will output a warning and will fallback to the default 'flat' mode.
664679

665680
**gitDescribe**:
666681
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.

src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ public class GitCommitIdMojo extends AbstractMojo {
6666
// these properties will be exposed to maven
6767
public static final String BRANCH = "branch";
6868
public static final String DIRTY = "dirty";
69-
@Deprecated
70-
public static final String COMMIT_ID_OLD = "commit.id";
71-
public static final String COMMIT_ID_NEW = "commit.id.full";
72-
public static String COMMIT_ID = COMMIT_ID_NEW;
69+
public static final String COMMIT_ID_FLAT = "commit.id";
70+
public static final String COMMIT_ID_FULL = "commit.id.full";
71+
public static String COMMIT_ID = COMMIT_ID_FLAT;
7372

7473
public static final String COMMIT_ID_ABBREV = "commit.id.abbrev";
7574
public static final String COMMIT_DESCRIBE = "commit.id.describe";
@@ -332,19 +331,22 @@ public class GitCommitIdMojo extends AbstractMojo {
332331
private List<String> includeOnlyProperties = Collections.emptyList();
333332

334333
/**
335-
* The option can be used to tell the plugin how it should generate the formerly known property 'git.commit.id'. Due to some naming issues when exporting the properties as an json-object (https://github.com/ktoso/maven-git-commit-id-plugin/issues/122) we needed to change the export of the property from 'git.commit.id' to 'git.commit.id.full'.
336-
* However, due to the fact that this is one of the major properties the plugin is exporting we just don't want to change the exporting mechanism and somehow throw the backwards compatibility away.
337-
* That's the point where this switch comes into place!
338-
* By default it is set to 'true' and will generate the formerly known property 'git.commit.id' as it was in the previous versions of the plugin. With keeping the switch set to 'true' the plugin will print a warning that using this switch set to 'true' is deprecated and may be removed in a future release. However keeping it to 'true' by default preserve backwards compatibility and allows to migrate to the new properties when it's convenient.
339-
* If you set this switch to 'false' the plugin will export the formerly known property 'git.commit.id' as 'git.commit.id.full'.
334+
* The option can be used to tell the plugin how it should generate the 'git.commit.id' property. Due to some naming issues when exporting the properties as an json-object (https://github.com/ktoso/maven-git-commit-id-plugin/issues/122) we needed to make it possible to export all properties as a valid json-object.
335+
* Due to the fact that this is one of the major properties the plugin is exporting we just don't want to change the exporting mechanism and somehow throw the backwards compatibility away.
336+
* We rather provide a convient switch where you can choose if you would like the properties as they always had been, or if you rather need to support full json-object compatibility.
337+
* In the case you need to fully support json-object we unfortunately need to change the 'git.commit.id' property from 'git.commit.id' to 'git.commit.id.full' in the exporting mechanism to allow the generation of a fully valid json object.
338+
*
339+
* Currently the switch allows two different options:
340+
* 1. By default this property is set to 'flat' and will generate the formerly known property 'git.commit.id' as it was in the previous versions of the plugin. Keeping it to 'flat' by default preserve backwards compatibility and does not require further adjustments by the end user.
341+
* 2. If you set this switch to 'full' the plugin will export the formerly known property 'git.commit.id' as 'git.commit.id.full' and therefore will generate a fully valid json object in the exporting mechanism.
340342
*
341343
* *Note*: Depending on your plugin configuration you obviously can choose the 'prefix' of your properties by setting it accordingly in the plugin's configuration. As a result this is therefore only an illustration what the switch means when the 'prefix' is set to it's default value.
344+
* *Note*: If you set the value to something that's not equal to 'flat' or 'full' (ignoring the case) the plugin will output a warning and will fallback to the default 'flat' mode.
342345
*
343-
* @parameter default-value="true"
346+
* @parameter default-value="flat"
344347
* @since 2.2.0
345348
*/
346-
@Deprecated
347-
private boolean generateCommitIdOldFashioned;
349+
private String commitIdGenerationMode;
348350

349351
/**
350352
* The Maven Session Object
@@ -402,13 +404,18 @@ public void execute() throws MojoExecutionException {
402404
}
403405

404406
try {
405-
if(generateCommitIdOldFashioned){
406-
loggerBridge.warn("Using the property 'generateCommitIdOldFashioned' set to 'true' is deprecated and may be removed in a future release! Please refer to the readme on this issue.");
407-
COMMIT_ID = COMMIT_ID_OLD;
408-
}else{
409-
// need to have this for the tests due the fact that they are switching back and forth
410-
// for the end-user setting this shouldn't perform any changes (it's set to COMMIT_ID_NEW by default)
411-
COMMIT_ID = COMMIT_ID_NEW;
407+
if(commitIdGenerationMode == null){
408+
commitIdGenerationMode = "flat";
409+
}
410+
switch(commitIdGenerationMode.toLowerCase()){
411+
default:
412+
loggerBridge.warn("Detected wrong setting for 'commitIdGenerationMode' will fallback to default 'flat'-Mode!");
413+
case "flat":
414+
COMMIT_ID = COMMIT_ID_FLAT;
415+
break;
416+
case "full":
417+
COMMIT_ID = COMMIT_ID_FULL;
418+
break;
412419
}
413420

414421
properties = initProperties();
@@ -856,6 +863,10 @@ public void useNativeGit(boolean useNativeGit) {
856863
this.useNativeGit = useNativeGit;
857864
}
858865

866+
public void setCommitIdGenerationMode(String commitIdGenerationMode){
867+
this.commitIdGenerationMode = commitIdGenerationMode;
868+
}
869+
859870
public LoggerBridge getLoggerBridge() {
860871
return loggerBridge;
861872
}

src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ public void shouldGenerateCommitIdOldFashioned(boolean useNativeGit) throws Exce
805805
setProjectToExecuteMojoIn(targetProject);
806806

807807
alterMojoSettings("useNativeGit", useNativeGit);
808-
alterMojoSettings("generateCommitIdOldFashioned", true);
808+
alterMojoSettings("commitIdGenerationMode", "flat");
809809

810810
// when
811811
mojo.execute();

src/test/java/pl/project13/maven/git/GitCommitIdMojoTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void setUp() throws Exception {
6161
mojo.setVerbose(true);
6262
mojo.useNativeGit(false);
6363
mojo.setGitDescribe(gitDescribeConfig);
64+
mojo.setCommitIdGenerationMode("full");
6465

6566

6667
mojo.runningTests = true;

src/test/java/pl/project13/maven/git/GitIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static void initializeMojoWithDefaults(GitCommitIdMojo mojo) {
7676
mojoDefaults.put("dateFormat", "dd.MM.yyyy '@' HH:mm:ss z");
7777
mojoDefaults.put("failOnNoGitDirectory", true);
7878
mojoDefaults.put("useNativeGit", false);
79-
mojoDefaults.put("generateCommitIdOldFashioned", false);
79+
mojoDefaults.put("commitIdGenerationMode", "full");
8080
for (Map.Entry<String, Object> entry : mojoDefaults.entrySet()) {
8181
setInternalState(mojo, entry.getKey(), entry.getValue());
8282
}

0 commit comments

Comments
 (0)