You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-1Lines changed: 84 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,50 @@ And not imagine that you need to deploy a drastic API change - so the new versio
26
26
Using this plugin, you can easily expose the information needed - based on git tags for example.
27
27
One might say that this is usually accomplished by using `${project.version}` and I generally would agree, but maybe tags would fit your use case better than a plain version. :-)
28
28
29
+
Validate if properties are set as expected
30
+
---------------------------------------------
31
+
Since version **2.2.2** the maven-git-commit-id-plugin comes equipped with an additional validation utility which can be used to verify if your project properties are set as you would like to have them set.
32
+
The validation can be used for *any* property that is visible inside the pom.xml and therefore can be used for a various amount of different use cases.
33
+
In order to understand the ideology and intention here are some pretty usefull ideas you could achive by using the validation:
34
+
* validate if the version of your project does not end with SNAPSHOT
35
+
* validate if you are currently on a tag
36
+
* ensure that your repository is not dirty
37
+
* may other's :-)
38
+
39
+
With the current version of the validation the user can decide if the build should fail if *at least one* of the defined criterias do not match with the desired values.
40
+
41
+
For flexibility and due to the fact that this validation has a different scope than the maven-git-commit-id-plugin this validation needs to be configured as additional execution inside the configuration of the pom.xml.
42
+
Once configured, the validation is executed during the verification-phase. However since the validation is done in a seperate execution the phase can easily be changed by adding the desired phase to the execution configuration.
43
+
44
+
Usage Example:
45
+
46
+
```xml
47
+
<validationProperties>
48
+
<!-- verify that the project version does not end with `-SNAPSHOT` -->
<!-- for future reference on this particular regex, please refer to lookahead and lookbehind expressions -->
54
+
<!-- we could also use: <shouldMatchTo>^[0-9\.]*$</shouldMatchTo> -->
55
+
</validationProperty>
56
+
<!-- verify that the current repository is not dirty -->
57
+
<validationProperty>
58
+
<name>validating git dirty</name>
59
+
<value>${git.dirty}</value>
60
+
<shouldMatchTo>false</shouldMatchTo>
61
+
</validationProperty>
62
+
<!-- verify that the current commit has a tag -->
63
+
<validationProperty>
64
+
<name>validating current commit has a tag</name>
65
+
<value>${git.closest.tag.commit.count}</value>
66
+
<shouldMatchTo>0</shouldMatchTo>
67
+
</validationProperty>
68
+
</validationProperties>
69
+
```
70
+
71
+
*Note* : In order to be able to validate the generated git-properties inside the pom itself you may need to set the configutation `<injectAllReactorProjects>true</injectAllReactorProjects>`.
72
+
29
73
Other
30
74
-----
31
75
If you have a nice use case to share, please do fork this file and file a pull request with your story :-)
@@ -108,9 +152,18 @@ It's really simple to setup this plugin; below is a sample pom that you may base
108
152
<version>2.2.1</version>
109
153
<executions>
110
154
<execution>
155
+
<id>get-the-git-infos</id>
111
156
<goals>
112
157
<goal>revision</goal>
113
-
</goals>
158
+
</goals>
159
+
</execution>
160
+
<execution>
161
+
<id>validate-the-git-infos</id>
162
+
<goals>
163
+
<goal>validateRevision</goal>
164
+
</goals>
165
+
<!-- *NOTE*: The default phase of validateRevision is verify, but in case you want to change it, you can do so by adding the phase here -->
166
+
<phase>package</phase>
114
167
</execution>
115
168
</executions>
116
169
@@ -317,6 +370,36 @@ It's really simple to setup this plugin; below is a sample pom that you may base
317
370
-->
318
371
<forceLongFormat>false</forceLongFormat>
319
372
</gitDescribe>
373
+
<!-- @since 2.2.2 -->
374
+
<!--
375
+
Since version **2.2.2** the maven-git-commit-id-plugin comes equipped with an additional validation utility which can be used to verify if your project properties are set as you would like to have them set.
376
+
*Note*: This configuration will only be taken into account when the additional goal `validateRevision` is configured inside an execution.
377
+
-->
378
+
<validationProperties>
379
+
<validationProperty>
380
+
<!--
381
+
A descriptive name that will be used to be able to identify the validation that does not match up (will be displayed in the error message).
382
+
-->
383
+
<name>validating project version</name>
384
+
<!--
385
+
the value that needs the validation
386
+
*Note* : In order to be able to validate the generated git-properties inside the pom itself you may need to set the configutation `<injectAllReactorProjects>true</injectAllReactorProjects>`.
<!-- the next validationProperty you would like to validate -->
395
+
</validationProperties>
396
+
<!-- @since 2.2.2 -->
397
+
<!--
398
+
true by default, controls whether the validation will fail if *at least one* of the validationProperties does not match with it's expected values.
399
+
If you don't care about this, you may want to set this value to false (this makes the configuration of validationProperties useless).
400
+
*Note*: This configuration will only be taken into account when the additional goal `validateRevision` is configured inside an execution and at least one validationProperty is defined.
StringcommonLogMessage = "Expected '" + value + "' to match with '" + shouldMatchTo + "'!";
71
+
if (name != null) {
72
+
thrownewMojoExecutionException("Validation '" + name + "' failed! " +commonLogMessage);
73
+
} else {
74
+
thrownewMojoExecutionException("Validation of an unidentified validation (please set the name property-tag to be able to identify the validation) failed! " +commonLogMessage);
0 commit comments