Skip to content

Commit 7ee11ec

Browse files
committed
Implemented #133 tags on current commit in jgit and native
It's hacky as in native... oh well, <3 jgit. Resolves #133
1 parent fba077c commit 7ee11ec

14 files changed

+276
-172
lines changed

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ maven git commit id plugin
22
==================================
33
[![Build Status](https://secure.travis-ci.org/ktoso/maven-git-commit-id-plugin.svg?branch=master)](http://travis-ci.org/ktoso/maven-git-commit-id-plugin)
44

5-
git-commit-id-plugin is a plugin quite similar to https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4 fo example but as buildnumber only supports svn (which is very sad) and cvs (which is even more sad, and makes bunnies cry) I had to quickly develop an git version of such a plugin. For those who don't know the previous plugins, let me explain what this plugin does:
5+
git-commit-id-plugin is a plugin quite similar to https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4 fo example but as buildnumber at the time when I started this plugin only supported CVS and SVN, something had to be done.
6+
I had to quickly develop an git version of such a plugin. For those who don't know the previous plugins, let me explain what this plugin does:
67

78
Use cases
89
=========
@@ -35,7 +36,7 @@ A detailed description of using the pluing is available in the <a href="https://
3536

3637
Versions
3738
--------
38-
The current version is **2.1.10**.
39+
The current version is **2.1.11**:
3940

4041
You can check the available versions by visiting [search.maven.org](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22pl.project13.maven%22%20AND%20a%3A%22git-commit-id-plugin%22), though using the newest is obviously the best choice.
4142

@@ -93,7 +94,7 @@ It's really simple to setup this plugin; below is a sample pom that you may base
9394
<plugin>
9495
<groupId>pl.project13.maven</groupId>
9596
<artifactId>git-commit-id-plugin</artifactId>
96-
<version>2.1.10</version>
97+
<version>2.1.11</version>
9798
<executions>
9899
<execution>
99100
<goals>
@@ -239,6 +240,7 @@ Now you just have to include such a properties file in your project under `/src/
239240

240241
```
241242
git.branch=${git.branch}
243+
git.commit.tags=${git.tags}
242244
243245
git.commit.id.describe=${git.commit.id.describe}
244246
@@ -270,6 +272,7 @@ Start out with with adding the above steps to your project, next paste this **gi
270272

271273
<bean name="gitRepositoryInformation" class="pl.project13.maven.example.git.GitRepositoryState">
272274
<property name="branch" value="${git.branch}"/>
275+
<property name="tags" value="${git.tags}"/>
273276
<property name="describe" value="${git.commit.id.describe}"/>
274277
<property name="commitId" value="${git.commit.id}"/>
275278
<property name="commitIdAbbrev" value="${git.commit.id.abbrev}"/>
@@ -300,6 +303,7 @@ import org.codehaus.jackson.annotate.JsonWriteNullProperties;
300303
@JsonWriteNullProperties(true)
301304
public class GitRepositoryState {
302305
String branch; // =${git.branch}
306+
String branch; // =${git.tags} // comma separated tag names
303307
String describe; // =${git.commit.id.describe}
304308
String shortDescribe; // =${git.commit.id.describe-short}
305309
String commitId; // =${git.commit.id}
@@ -352,6 +356,7 @@ In the end *this is what this service would return*:
352356
```json
353357
{
354358
"branch" : "testing-maven-git-plugin",
359+
"tags" : "v2.1.11,testing",
355360
"describe" : "v2.1.0-2-g2346463",
356361
"describeShort" : "v2.1.0-2",
357362
"commitTime" : "06.01.1970 @ 16:16:26 CET",
@@ -416,6 +421,7 @@ You'd have to add such an constructor to your GitRepositoryState bean:
416421
public GitRepositoryState(Properties properties)
417422
{
418423
this.branch = properties.get("git.branch").toString();
424+
this.tags = properties.get("git.tags").toString();
419425
this.describe = properties.get("git.commit.id.describe").toString();
420426
this.describeShort = properties.get("git.commit.id.describe-short").toString();
421427
this.commitId = properties.get("git.commit.id").toString();

pom.xml

+20-26
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<name>Git Commit Id Plugin Maven Mojo</name>
1515
<description>
1616
git-commit-id-plugin is a plugin quite similar to
17-
https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4 for example but as buildnumber
18-
only supports svn (which is very sad) and cvs (which is even more sad).
17+
https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4 for example but as buildnumber at
18+
the time when I started this plugin only supported CVS and SVN, something had to be done.
1919
This plugin makes basic repository information available through maven resources. This can be used to display
2020
"what version is this?" or "who has deployed this and when, from which branch?" information at runtime - making
2121
it easy to find things like "oh, that isn't deployed yet, I'll test it tomorrow" and making both testers and
@@ -46,7 +46,7 @@
4646
<id>ktoso</id>
4747
<name>Konrad Malawski</name>
4848
<email>[email protected]</email>
49-
<organization>Project13.pl</organization>
49+
<organization>project13.pl</organization>
5050
<url>http://blog.project13.pl</url>
5151
</developer>
5252
</developers>
@@ -100,12 +100,6 @@
100100
<version>2.2.3</version>
101101
</dependency>
102102

103-
<dependency>
104-
<groupId>com.google.inject</groupId>
105-
<artifactId>guice</artifactId>
106-
<version>2.0</version>
107-
</dependency>
108-
109103
<!-- Joda Time -->
110104
<dependency>
111105
<groupId>joda-time</groupId>
@@ -165,7 +159,7 @@
165159
</dependency>
166160

167161
<dependency>
168-
<groupId>org.apache.commons</groupId>
162+
<groupId>commons-io</groupId>
169163
<artifactId>commons-io</artifactId>
170164
<version>1.3.2</version>
171165
<type>jar</type>
@@ -247,22 +241,22 @@
247241
</configuration>
248242
</plugin>
249243

250-
<plugin>
251-
<artifactId>maven-plugin-plugin</artifactId>
252-
<version>3.2</version>
253-
<executions>
254-
<execution>
255-
<id>generated-helpmojo</id>
256-
<goals>
257-
<goal>helpmojo</goal>
258-
</goals>
259-
<configuration>
260-
<goalPrefix>git-commit-id</goalPrefix>
261-
<helpPackageName>pl.project13.maven</helpPackageName>
262-
</configuration>
263-
</execution>
264-
</executions>
265-
</plugin>
244+
<!--<plugin>-->
245+
<!--<artifactId>maven-plugin-plugin</artifactId>-->
246+
<!--<version>${maven-plugin-api.version}</version>-->
247+
<!--<executions>-->
248+
<!--<execution>-->
249+
<!--<id>generated-helpmojo</id>-->
250+
<!--<goals>-->
251+
<!--<goal>helpmojo</goal>-->
252+
<!--</goals>-->
253+
<!--<configuration>-->
254+
<!--<goalPrefix>git-commit-id</goalPrefix>-->
255+
<!--<helpPackageName>pl.project13.maven</helpPackageName>-->
256+
<!--</configuration>-->
257+
<!--</execution>-->
258+
<!--</executions>-->
259+
<!--</plugin>-->
266260
</plugins>
267261
</build>
268262

release.properties

-8
This file was deleted.

src/main/java/pl/project13/jgit/DescribeCommand.java

+15-32
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,8 @@
5454

5555
/**
5656
* Implements git's <pre>describe</pre> command.
57-
* <p/>
58-
* <code><pre>
59-
* usage: git describe [options] <committish>*
60-
* or: git describe [options] --dirty
61-
* <p/>
62-
* --contains find the tag that comes after the commit
63-
* --debug debug search strategy on stderr
64-
* --all use any ref in .git/refs
65-
* --tags use any tag in .git/refs/tags
66-
* --long always use long format
67-
* --abbrev[=<n>] use <n> digits to display SHA-1s
68-
* --exact-match only output exact matches
69-
* --candidates <n> consider <n> most recent tags (default: 10)
70-
* --match <pattern> only consider tags matching <pattern>
71-
* --always show abbreviated commit object as fallback
72-
* --dirty[=<mark>] append <mark> on dirty working tree (default: "-dirty")
73-
* </pre></code>
7457
*
75-
* @author <a href="mailto:[email protected]">Konrad 'ktoso' Malawski</a>
58+
* @author Konrad Malawski
7659
*/
7760
public class DescribeCommand extends GitCommand<DescribeResult> {
7861

@@ -153,9 +136,9 @@ public DescribeCommand withLoggerBridge(LoggerBridge bridge) {
153136

154137
/**
155138
* <pre>--always</pre>
156-
* <p/>
139+
*
157140
* Show uniquely abbreviated commit object as fallback.
158-
* <p/>
141+
*
159142
* <pre>true</pre> by default.
160143
*/
161144
@NotNull
@@ -167,13 +150,13 @@ public DescribeCommand always(boolean always) {
167150

168151
/**
169152
* <pre>--long</pre>
170-
* <p/>
153+
*
171154
* Always output the long format (the tag, the number of commits and the abbreviated commit name)
172155
* even when it matches a tag. This is useful when you want to see parts of the commit object name
173156
* in "describe" output, even when the commit in question happens to be a tagged version. Instead
174157
* of just emitting the tag name, it will describe such a commit as v1.2-0-gdeadbee (0th commit
175158
* since tag v1.2 that points at object deadbee....).
176-
* <p/>
159+
*
177160
* <pre>false</pre> by default.
178161
*/
179162
@NotNull
@@ -187,11 +170,11 @@ public DescribeCommand forceLongFormat(@Nullable Boolean forceLongFormat) {
187170

188171
/**
189172
* <pre>--abbrev=N</pre>
190-
* <p/>
173+
*
191174
* Instead of using the default <em>7 hexadecimal digits</em> as the abbreviated object name,
192175
* use <b>N</b> digits, or as many digits as needed to form a unique object name.
193-
* <p/>
194-
* An <n> of 0 will suppress long format, only showing the closest tag.
176+
*
177+
* An `n` of 0 will suppress long format, only showing the closest tag.
195178
*/
196179
@NotNull
197180
public DescribeCommand abbrev(@Nullable Integer n) {
@@ -210,22 +193,22 @@ public DescribeCommand abbrev(@Nullable Integer n) {
210193
* Instead of using only the annotated tags, use any tag found in .git/refs/tags.
211194
* This option enables matching a lightweight (non-annotated) tag.
212195
* </p>
213-
* <p/>
196+
*
214197
* <p>Searching for lightweight tags is <b>false</b> by default.</p>
215-
* <p/>
198+
*
216199
* Example:
217200
* <pre>
218201
* b6a73ed - (HEAD, master)
219202
* d37a598 - (v1.0-fixed-stuff) - a lightweight tag (with no message)
220203
* 9597545 - (v1.0) - an annotated tag
221204
*
222-
* > git describe
205+
* $ git describe
223206
* annotated-tag-2-gb6a73ed # the nearest "annotated" tag is found
224207
*
225-
* > git describe --tags
208+
* $ git describe --tags
226209
* lightweight-tag-1-gb6a73ed # the nearest tag (including lightweights) is found
227210
* </pre>
228-
* <p/>
211+
*
229212
* <p>
230213
* Using only annotated tags to mark builds may be useful if you're using tags to help yourself with annotating
231214
* things like "i'll get back to that" etc - you don't need such tags to be exposed. But if you want lightweight
@@ -249,7 +232,7 @@ public DescribeCommand tags() {
249232
}
250233

251234
/**
252-
* Apply all configuration options passed in with {@param config}.
235+
* Apply all configuration options passed in with `config`.
253236
* If a setting is null, it will not be applied - so for abbrev for example, the default 7 would be used.
254237
*
255238
* @return itself, after applying the settings
@@ -342,7 +325,7 @@ public DescribeResult call() throws GitAPIException {
342325
* Prepares the final result of this command.
343326
* It tries to put as much information as possible into the result,
344327
* and will fallback to a plain commit hash if nothing better is returnable.
345-
* <p/>
328+
*
346329
* The exact logic is following what <pre>git-describe</pre> would do.
347330
*/
348331
private DescribeResult createDescribeResult(ObjectReader objectReader, ObjectId headCommitId, boolean dirty, @Nullable Pair<Integer, String> howFarFromWhichTag) {

src/main/java/pl/project13/jgit/DescribeResult.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
/**
3535
* Represents the result of a <code>git describe</code> command.
36-
* <p/>
36+
*
3737
* See {@link pl.project13.jgit.DescribeResult#toString()} for a detailed information how this result looks like.
3838
*/
3939
public class DescribeResult {
@@ -115,15 +115,15 @@ public DescribeResult withCommitIdAbbrev(int n) {
115115
* | |--------------- the number of commits away from the found tag. So "2414721" is 14 commits ahead of "v1.0.4", in this example.
116116
* |-------------------- the "nearest" tag, to the mentioned commit.
117117
* </pre>
118-
* <p/>
118+
*
119119
* Other outputs may look like:
120120
* <pre>
121121
* v1.0.4 -- if the repository is "on a tag"
122122
* v1.0.4-DEV -- if the repository is "on a tag", but in "dirty" state
123123
* 2414721 -- a plain commit id hash if not tags were defined (of determined "near" this commit).
124124
* It does NOT include the "g" prefix, that is used in the "full" describe output format!
125125
* </pre>
126-
* <p/>
126+
*
127127
* For more details (on when what output will be returned etc), see <code>man git-describe</code>.
128128
* In general, you can assume it's a "best effort" approach, to give you as much info about the repo state as possible.
129129
*
@@ -170,7 +170,7 @@ public String dirtyMarker() {
170170
* This is following git's behaviour - so any git tooling should be happy with this output.
171171
* </p>
172172
* <p>
173-
* Notes about the abbriverated object id:<br/>
173+
* Notes about the abbriverated object id:
174174
* Git will try to use your given abbrev lenght, but when it's to short to guarantee uniqueness -
175175
* a longer one will be used (which WILL guarantee uniqueness).
176176
* If you need the full commit id, it's always available via {@link pl.project13.jgit.DescribeResult#commitObjectId()}.

0 commit comments

Comments
 (0)