Skip to content

Commit 4274dfc

Browse files
committed
minor refactorings and typos
1 parent e4827eb commit 4274dfc

13 files changed

+63
-120
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ It's really simple to setup this plugin; below is a sample pom that you may base
118118
<!--
119119
If you'd like to tell the plugin where your .git directory is,
120120
use this setting, otherwise we'll perform a search trying to
121-
figure out the right directory. It's better to add it explicite IMHO.
121+
figure out the right directory. It's better to add it explicitly IMHO.
122122
-->
123123
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
124124

@@ -207,7 +207,7 @@ It's really simple to setup this plugin; below is a sample pom that you may base
207207

208208
<!-- @since 2.1.9 -->
209209
<!--
210-
Can be used to exclude certain properties from being emited into the resulting file.
210+
Can be used to exclude certain properties from being emitted into the resulting file.
211211
May be useful when you want to hide {@code git.remote.origin.url} (maybe because it contains your repo password?),
212212
or the email of the committer etc.
213213
@@ -236,8 +236,8 @@ It's really simple to setup this plugin; below is a sample pom that you may base
236236

237237
<!-- @since 2.1.10 -->
238238
<!--
239-
false is default here, if set to true it uses native `git` excutable for extracting all data.
240-
This usually has better performance than the default (jgit) implemenation, but requires you to
239+
false is default here, if set to true it uses native `git` executable for extracting all data.
240+
This usually has better performance than the default (jgit) implementation, but requires you to
241241
have git available as executable for the build as well as *might break unexpectedly* when you
242242
upgrade your system-wide git installation.
243243
@@ -260,7 +260,7 @@ It's really simple to setup this plugin; below is a sample pom that you may base
260260
<!--
261261
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.
262262
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.
263-
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.
263+
We rather provide a convenient 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.
264264
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.
265265
266266
Currently the switch allows two different options:
@@ -386,7 +386,7 @@ Start out with with adding the above steps to your project, next paste this **gi
386386
<property name="buildUserEmail" value="${git.build.user.email}"/>
387387
<property name="buildTime" value="${git.build.time}"/>
388388
<property name="buildHost" value="${git.build.host}"/>
389-
<porperty name="buildVersion" value="${git.build.version}"/>
389+
<property name="buildVersion" value="${git.build.version}"/>
390390
</bean>
391391
</beans>
392392
```
@@ -671,7 +671,7 @@ Optional parameters:
671671
* **runOnlyOnce** - `(default: false)` *(available since v2.1.12)* - Use with caution! In a multi-module build, only run once. This means that the plugins effects will only execute once, for the parent project. This probably won't "do the right thing" if your project has more than one git repository. Important: If you're using `generateGitPropertiesFile`, setting `runOnlyOnce` will make the plugin only generate the file in the directory where you started your build :warning:. The `git.*` maven properties are available in all modules.
672672
* **excludeProperties** - `(default: empty)` *(available since v2.1.9)* - Allows to filter out properties that you *don't* want to expose. This feature was implemented in response to [this issue](https://github.com/ktoso/maven-git-commit-id-plugin/issues/91), so if you're curious about the use-case, check that issue.
673673
* **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.
674-
* **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).
674+
* **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 usually 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 (usually when you have *hundreds* of maven modules).
675675
* **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).
676676
* **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:
677677
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.
@@ -684,8 +684,8 @@ Optional parameters:
684684
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.
685685

686686
* **abbrev** - `(default: 7)` in the describe output, the object id of the hash is always abbreviated to N letters, by default 7. The typical describe output you'll see therefore is: `v2.1.0-1-gf5cd254`, where `-1-` means the number of commits away from the mentioned tag and the `-gf5cd254` part means the first 7 chars of the current commit's id `f5cd254`. **Please note that the `g` prefix is included to notify you that it's a commit id, it is NOT part of the commit's object id** - *this is default git behaviour, so we're doing the same*. You can set this to any value between 0 and 40 (inclusive).
687-
* **abbrev = 0** is a special case. Setting *abbrev* to `0` has the effect of hiding the "distance from tag" and "object id" parts of the output, so you endup with just the "nearest tag" (that is, instead `tag-12-gaaaaaaa` with `abbrev = 0` you'd get `tag`).
688-
* **dirty** - `(default: "-dirty")` when you run describe on a repository that's in "dirty state" (has uncommited changes), the describe output will contain an additional suffix, such as "-devel" in this example: `v3.5-3-g2222222-devel`. You can configure that suffix to be anything you want, "-DEV" being a nice example. The "-" sign should be inclided in the configuration parameter, as it will not be added automatically. If in doubt run `git describe --dirty=-my_thing` to see how the end result will look like.
687+
* **abbrev = 0** is a special case. Setting *abbrev* to `0` has the effect of hiding the "distance from tag" and "object id" parts of the output, so you end up with just the "nearest tag" (that is, instead `tag-12-gaaaaaaa` with `abbrev = 0` you'd get `tag`).
688+
* **dirty** - `(default: "-dirty")` when you run describe on a repository that's in "dirty state" (has uncommitted changes), the describe output will contain an additional suffix, such as "-devel" in this example: `v3.5-3-g2222222-devel`. You can configure that suffix to be anything you want, "-DEV" being a nice example. The "-" sign should be included in the configuration parameter, as it will not be added automatically. If in doubt run `git describe --dirty=-my_thing` to see how the end result will look like.
689689
* **tags** - `(default: false)` if true this option enables matching a lightweight (non-annotated) tag.
690690
* **match** - `(default: *)` only consider tags matching the given pattern (can be used to avoid leaking private tags made from the repository)
691691
* **long** - `(default: false)` git-describe, by default, returns just the tag name, if the current commit is tagged. Use this option to force it to format the output using the typical describe format. An example would be: `tagname-0-gc0ffebabe` - notice that the distance from the tag is 0 here, if you don't use **forceLongFormat** mode, the describe for such commit would look like this: `tagname`.

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,9 @@ private String createMatchPattern() {
384384
return ".*";
385385
}
386386

387-
StringBuffer buf = new StringBuffer();
388-
buf.append("^refs/tags/\\Q");
389-
buf.append(matchOption.get().replace("*", "\\E.*\\Q").replace("?", "\\E.\\Q"));
390-
buf.append("\\E$");
391-
return buf.toString();
387+
return "^refs/tags/\\Q" +
388+
matchOption.get().replace("*", "\\E.*\\Q").replace("?", "\\E.\\Q") +
389+
"\\E$";
392390
}
393391
}
394392

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public String dirtyMarker() {
160160
}
161161

162162
/**
163-
* <p>The (possibly) "g" prefixed <strong>abbriverated</strong> object id of a commit.</p>
163+
* <p>The (possibly) "g" prefixed <strong>abbreviated</strong> object id of a commit.</p>
164164
* <p>
165165
* The "g" prefix is prepended to be compatible with git's describe output, please refer to
166166
* <b>man git-describe</b> to check why it's included.
@@ -170,8 +170,8 @@ 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:
174-
* Git will try to use your given abbrev lenght, but when it's to short to guarantee uniqueness -
173+
* Notes about the abbreviated object id:
174+
* Git will try to use your given abbrev length, but when it's too 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()}.
177177
* </p>
@@ -208,14 +208,14 @@ private String gPrefixedCommitId(String name) {
208208
*
209209
* @return the abbreviated commit id, possibly longer than the requested len (if it wouldn't be unique)
210210
*/
211-
private static Optional<AbbreviatedObjectId> createAbbreviatedCommitId(@NotNull ObjectReader objectReader, ObjectId commitId, int requestedLenght) {
212-
if(requestedLenght < 2) {
211+
private static Optional<AbbreviatedObjectId> createAbbreviatedCommitId(@NotNull ObjectReader objectReader, ObjectId commitId, int requestedLength) {
212+
if (requestedLength < 2) {
213213
// 0 means we don't want to print commit id's at all
214214
return Optional.absent();
215215
}
216216

217217
try {
218-
AbbreviatedObjectId abbreviatedObjectId = objectReader.abbreviate(commitId, requestedLenght);
218+
AbbreviatedObjectId abbreviatedObjectId = objectReader.abbreviate(commitId, requestedLength);
219219
return Optional.of(abbreviatedObjectId);
220220
} catch (IOException e) {
221221
return Optional.absent();

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public Collection<String> getTags(Repository repo, final ObjectId headId) throws
8585
});
8686

8787
return tags;
88-
} catch (GitAPIException e) {
89-
throw e;
9088
} finally {
9189
if (walk != null) {
9290
walk.dispose();
@@ -130,7 +128,7 @@ private Map<ObjectId, List<DatedRevTag>> getClosestTagAsMap(@NotNull Repository
130128
}
131129

132130
private LinkedHashMap<ObjectId, List<DatedRevTag>> sortByDatedRevTag(Map<ObjectId, List<DatedRevTag>> map) {
133-
List<Map.Entry<ObjectId, List<DatedRevTag>>> list = new LinkedList<Map.Entry<ObjectId, List<DatedRevTag>>>(map.entrySet());
131+
List<Map.Entry<ObjectId, List<DatedRevTag>>> list = new LinkedList<>(map.entrySet());
134132

135133
Collections.sort(list, new Comparator<Map.Entry<ObjectId, List<DatedRevTag>>>() {
136134
public int compare(Map.Entry<ObjectId, List<DatedRevTag>> m1, Map.Entry<ObjectId, List<DatedRevTag>> m2) {
@@ -144,7 +142,7 @@ public int compare(Map.Entry<ObjectId, List<DatedRevTag>> m1, Map.Entry<ObjectId
144142
}
145143
});
146144

147-
LinkedHashMap<ObjectId, List<DatedRevTag>> result = new LinkedHashMap<ObjectId, List<DatedRevTag>>();
145+
LinkedHashMap<ObjectId, List<DatedRevTag>> result = new LinkedHashMap<>();
148146
for (Map.Entry<ObjectId, List<DatedRevTag>> entry : list) {
149147
result.put(entry.getKey(), entry.getValue());
150148
}
@@ -154,8 +152,7 @@ public int compare(Map.Entry<ObjectId, List<DatedRevTag>> m1, Map.Entry<ObjectId
154152
protected Map<ObjectId, List<DatedRevTag>> getCommitIdsToTags(@NotNull Repository repo, boolean includeLightweightTags, String matchPattern, @NotNull Mojo mojo){
155153
Map<ObjectId, List<DatedRevTag>> commitIdsToTags = newHashMap();
156154

157-
RevWalk walk = new RevWalk(repo);
158-
try {
155+
try (RevWalk walk = new RevWalk(repo)) {
159156
walk.markStart(walk.parseCommit(repo.resolve("HEAD")));
160157

161158
List<Ref> tagRefs = Git.wrap(repo).tagList().call();
@@ -210,11 +207,9 @@ protected Map<ObjectId, List<DatedRevTag>> getCommitIdsToTags(@NotNull Repositor
210207
for (Map.Entry<ObjectId, List<DatedRevTag>> entry : commitIdsToTags.entrySet()) {
211208
mojo.getLog().info("key [" + entry.getKey() + "], tags => [" + entry.getValue() + "] ");
212209
}
213-
return commitIdsToTags;
210+
return commitIdsToTags;
214211
} catch (Exception e) {
215212
mojo.getLog().info("Unable to locate tags", e);
216-
} finally {
217-
walk.close();
218213
}
219214
return Collections.emptyMap();
220215
}
@@ -264,8 +259,7 @@ protected String trimFullTagName(@NotNull String tagName) {
264259
}
265260

266261
public List<RevCommit> findCommitsUntilSomeTag(Repository repo, RevCommit head, @NotNull Map<ObjectId, List<String>> tagObjectIdToName) {
267-
RevWalk revWalk = new RevWalk(repo);
268-
try {
262+
try (RevWalk revWalk = new RevWalk(repo)) {
269263
revWalk.markStart(head);
270264

271265
for (RevCommit commit : revWalk) {
@@ -291,9 +285,7 @@ public List<RevCommit> findCommitsUntilSomeTag(Repository repo, RevCommit head,
291285
* @see <a href="https://github.com/mdonoughe/jgit-describe/blob/master/src/org/mdonoughe/JGitDescribeTask.java">mdonoughe/jgit-describe/blob/master/src/org/mdonoughe/JGitDescribeTask.java</a>
292286
*/
293287
protected int distanceBetween(@NotNull Repository repo, @NotNull RevCommit child, @NotNull RevCommit parent) {
294-
RevWalk revWalk = new RevWalk(repo);
295-
296-
try {
288+
try (RevWalk revWalk = new RevWalk(repo)) {
297289
revWalk.markStart(child);
298290

299291
Set<ObjectId> seena = newHashSet();
@@ -336,8 +328,6 @@ protected int distanceBetween(@NotNull Repository repo, @NotNull RevCommit child
336328
return distance;
337329
} catch (Exception e) {
338330
throw new RuntimeException(String.format("Unable to calculate distance between [%s] and [%s]", child, parent), e);
339-
} finally {
340-
revWalk.dispose();
341331
}
342332
}
343333

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum CommitIdGenerationModeEnum{
2424
public static CommitIdGenerationModeEnum getValue(String o){
2525
if(o != null){
2626
for(CommitIdGenerationModeEnum v : values()){
27-
if(v.name().toString().equalsIgnoreCase(o)){
27+
if(v.name().equalsIgnoreCase(o)){
2828
return v;
2929
}
3030
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public class GitCommitIdMojo extends AbstractMojo {
262262
* Setting this value to `false`, causes the plugin to gracefully tell you "I did my best" and abort it's execution
263263
* if unable to obtain git meta data - yet the build will continue to run (without failing).
264264
*
265-
* See https://github.com/ktoso/maven-git-commit-id-plugin/issues/63 for a rationale behing this flag.
265+
* See https://github.com/ktoso/maven-git-commit-id-plugin/issues/63 for a rationale behind this flag.
266266
*
267267
* @parameter default-value="true"
268268
*/
@@ -303,7 +303,7 @@ public class GitCommitIdMojo extends AbstractMojo {
303303
private boolean runOnlyOnce = false;
304304

305305
/**
306-
* Can be used to exclude certain properties from being emited into the resulting file.
306+
* Can be used to exclude certain properties from being emitted into the resulting file.
307307
* May be useful when you want to hide {@code git.remote.origin.url} (maybe because it contains your repo password?),
308308
* or the email of the committer etc.
309309
*
@@ -336,7 +336,7 @@ public class GitCommitIdMojo extends AbstractMojo {
336336
/**
337337
* 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.
338338
* 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.
339-
* 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.
339+
* We rather provide a convenient 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.
340340
* 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.
341341
*
342342
* Currently the switch allows two different options:
@@ -792,9 +792,7 @@ static Properties readProperties(@NotNull File propertiesFile) throws CannotRead
792792
}
793793
}
794794

795-
static class CannotReadFileException
796-
extends Exception
797-
{
795+
static class CannotReadFileException extends Exception {
798796
private static final long serialVersionUID = -6290782570018307756L;
799797

800798
CannotReadFileException( Throwable cause )

0 commit comments

Comments
 (0)