Skip to content

Commit 6557ed6

Browse files
author
TheSnoozer
authored
Merge pull request #328 from TheSnoozer/master
Fix all SpotBugs
2 parents 14b5fad + 5083c86 commit 6557ed6

File tree

7 files changed

+41
-40
lines changed

7 files changed

+41
-40
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.base.Optional;
2222
import com.google.common.base.Preconditions;
2323

24-
import org.eclipse.jgit.api.Git;
2524
import org.eclipse.jgit.api.GitCommand;
2625
import org.eclipse.jgit.api.errors.GitAPIException;
2726
import org.eclipse.jgit.lib.ObjectId;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public DescribeResult(@NotNull String tagName) {
6060
this(tagName, false, Optional.<String>absent());
6161
}
6262

63-
public DescribeResult(@NotNull ObjectReader objectReader, String tagName, int commitsAwayFromTag, @Nullable ObjectId commitId) {
63+
public DescribeResult(@NotNull ObjectReader objectReader, String tagName, int commitsAwayFromTag, @NotNull ObjectId commitId) {
6464
this(objectReader, tagName, commitsAwayFromTag, commitId, false, Optional.<String>absent(), false);
6565
}
6666

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

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,36 @@ public JGitCommon(LoggerBridge log) {
5151
}
5252

5353
public Collection<String> getTags(Repository repo, final ObjectId headId) throws GitAPIException{
54-
RevWalk walk = null;
55-
try {
56-
Git git = Git.wrap(repo);
57-
walk = new RevWalk(repo);
58-
List<Ref> tagRefs = git.tagList().call();
59-
60-
final RevWalk finalWalk = walk;
61-
Collection<Ref> tagsForHeadCommit = Collections2.filter(tagRefs, new Predicate<Ref>() {
62-
@Override public boolean apply(Ref tagRef) {
63-
boolean lightweightTag = tagRef.getObjectId().equals(headId);
64-
65-
try {
66-
// TODO make this configurable (most users shouldn't really care too much what kind of tag it is though)
67-
return lightweightTag || finalWalk.parseTag(tagRef.getObjectId()).getObject().getId().equals(headId); // or normal tag
68-
} catch (IOException e) {
69-
return false;
70-
}
71-
}
72-
});
73-
74-
Collection<String> tags = Collections2.transform(tagsForHeadCommit, new Function<Ref, String>() {
75-
@Override public String apply(Ref input) {
76-
return input.getName().replaceAll("refs/tags/", "");
77-
}
78-
});
79-
80-
return tags;
81-
} finally {
82-
if (walk != null) {
54+
try (Git git = Git.wrap(repo)) {
55+
try(RevWalk walk = new RevWalk(repo)) {
56+
Collection<String> tags = getTags(git, headId, walk);
8357
walk.dispose();
58+
return tags;
8459
}
8560
}
8661
}
8762

63+
private Collection<String> getTags(final Git git, final ObjectId headId, final RevWalk finalWalk) throws GitAPIException{
64+
List<Ref> tagRefs = git.tagList().call();
65+
Collection<Ref> tagsForHeadCommit = Collections2.filter(tagRefs, new Predicate<Ref>() {
66+
@Override public boolean apply(Ref tagRef) {
67+
boolean lightweightTag = tagRef.getObjectId().equals(headId);
68+
try {
69+
// TODO make this configurable (most users shouldn't really care too much what kind of tag it is though)
70+
return lightweightTag || finalWalk.parseTag(tagRef.getObjectId()).getObject().getId().equals(headId); // or normal tag
71+
} catch (IOException e) {
72+
return false;
73+
}
74+
}
75+
});
76+
Collection<String> tags = Collections2.transform(tagsForHeadCommit, new Function<Ref, String>() {
77+
@Override public String apply(Ref input) {
78+
return input.getName().replaceAll("refs/tags/", "");
79+
}
80+
});
81+
return tags;
82+
}
83+
8884
public String getClosestTagName(@NotNull Repository repo){
8985
Map<ObjectId, List<DatedRevTag>> map = getClosestTagAsMap(repo);
9086
for(Map.Entry<ObjectId, List<DatedRevTag>> entry : map.entrySet()){
@@ -97,12 +93,13 @@ public String getClosestTagCommitCount(@NotNull Repository repo, RevCommit headC
9793
HashMap<ObjectId, List<String>> map = transformRevTagsMapToDateSortedTagNames(getClosestTagAsMap(repo));
9894
ObjectId obj = (ObjectId) map.keySet().toArray()[0];
9995

100-
RevWalk walk = new RevWalk(repo);
101-
RevCommit commit = walk.lookupCommit(obj);
102-
walk.dispose();
96+
try(RevWalk walk = new RevWalk(repo)){
97+
RevCommit commit = walk.lookupCommit(obj);
98+
walk.dispose();
10399

104-
int distance = distanceBetween(repo, headCommit, commit);
105-
return String.valueOf(distance);
100+
int distance = distanceBetween(repo, headCommit, commit);
101+
return String.valueOf(distance);
102+
}
106103
}
107104

108105
private Map<ObjectId, List<DatedRevTag>> getClosestTagAsMap(@NotNull Repository repo){

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ private File processGitDirFile(@NotNull File file) {
108108
// There should be just one line in the file, e.g.
109109
// "gitdir: /usr/local/src/parentproject/.git/modules/submodule"
110110
String line = reader.readLine();
111-
111+
if(line == null) {
112+
return null;
113+
}
112114
// Separate the key and the value in the string.
113115
String[] parts = line.split(": ");
114116

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ public interface ProcessRunner {
303303

304304
public static class NativeCommandException extends IOException
305305
{
306+
private static final long serialVersionUID = 3511033422542257748L;
306307
private final int exitCode;
307308
private final String command;
308309
private final File directory;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,17 @@ public void performReplacement(Properties properties, List<ReplacementProperty>
7171
}
7272

7373
private String performReplacement(ReplacementProperty replacementProperty, String content) {
74-
String result = performTransformationRules(replacementProperty, content, TransformationRule.ApplyEnum.BEFORE);
74+
String result = content;
7575
if(replacementProperty != null) {
76+
result = performTransformationRules(replacementProperty, result, TransformationRule.ApplyEnum.BEFORE);
7677
if(replacementProperty.isRegex()) {
7778
result = replaceRegex(result, replacementProperty.getToken(), replacementProperty.getValue());
7879
} else {
7980
result = replaceNonRegex(result, replacementProperty.getToken(), replacementProperty.getValue());
8081
}
82+
result = performTransformationRules(replacementProperty, result, TransformationRule.ApplyEnum.AFTER);
8183
}
82-
return performTransformationRules(replacementProperty, result, TransformationRule.ApplyEnum.AFTER);
84+
return result;
8385
}
8486

8587
private String performTransformationRules(ReplacementProperty replacementProperty, String content, TransformationRule.ApplyEnum forRule) {

src/main/java/pl/project13/maven/git/util/Pair.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public boolean equals(@Nullable Object o) {
5252
return false;
5353
}
5454

55-
Pair pair = (Pair) o;
55+
Pair<?,?> pair = (Pair<?,?>) o;
5656

5757
if (!first.equals(pair.first)) {
5858
return false;

0 commit comments

Comments
 (0)