Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request git-commit-id#328 from TheSnoozer/master
Browse files Browse the repository at this point in the history
Fix all SpotBugs
  • Loading branch information
TheSnoozer authored Sep 24, 2017
2 parents 14b5fad + 5083c86 commit 6557ed6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
1 change: 0 additions & 1 deletion src/main/java/pl/project13/jgit/DescribeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pl/project13/jgit/DescribeResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DescribeResult(@NotNull String tagName) {
this(tagName, false, Optional.<String>absent());
}

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

Expand Down
65 changes: 31 additions & 34 deletions src/main/java/pl/project13/jgit/JGitCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,36 @@ public JGitCommon(LoggerBridge log) {
}

public Collection<String> getTags(Repository repo, final ObjectId headId) throws GitAPIException{
RevWalk walk = null;
try {
Git git = Git.wrap(repo);
walk = new RevWalk(repo);
List<Ref> tagRefs = git.tagList().call();

final RevWalk finalWalk = walk;
Collection<Ref> tagsForHeadCommit = Collections2.filter(tagRefs, new Predicate<Ref>() {
@Override public boolean apply(Ref tagRef) {
boolean lightweightTag = tagRef.getObjectId().equals(headId);

try {
// TODO make this configurable (most users shouldn't really care too much what kind of tag it is though)
return lightweightTag || finalWalk.parseTag(tagRef.getObjectId()).getObject().getId().equals(headId); // or normal tag
} catch (IOException e) {
return false;
}
}
});

Collection<String> tags = Collections2.transform(tagsForHeadCommit, new Function<Ref, String>() {
@Override public String apply(Ref input) {
return input.getName().replaceAll("refs/tags/", "");
}
});

return tags;
} finally {
if (walk != null) {
try (Git git = Git.wrap(repo)) {
try(RevWalk walk = new RevWalk(repo)) {
Collection<String> tags = getTags(git, headId, walk);
walk.dispose();
return tags;
}
}
}

private Collection<String> getTags(final Git git, final ObjectId headId, final RevWalk finalWalk) throws GitAPIException{
List<Ref> tagRefs = git.tagList().call();
Collection<Ref> tagsForHeadCommit = Collections2.filter(tagRefs, new Predicate<Ref>() {
@Override public boolean apply(Ref tagRef) {
boolean lightweightTag = tagRef.getObjectId().equals(headId);
try {
// TODO make this configurable (most users shouldn't really care too much what kind of tag it is though)
return lightweightTag || finalWalk.parseTag(tagRef.getObjectId()).getObject().getId().equals(headId); // or normal tag
} catch (IOException e) {
return false;
}
}
});
Collection<String> tags = Collections2.transform(tagsForHeadCommit, new Function<Ref, String>() {
@Override public String apply(Ref input) {
return input.getName().replaceAll("refs/tags/", "");
}
});
return tags;
}

public String getClosestTagName(@NotNull Repository repo){
Map<ObjectId, List<DatedRevTag>> map = getClosestTagAsMap(repo);
for(Map.Entry<ObjectId, List<DatedRevTag>> entry : map.entrySet()){
Expand All @@ -97,12 +93,13 @@ public String getClosestTagCommitCount(@NotNull Repository repo, RevCommit headC
HashMap<ObjectId, List<String>> map = transformRevTagsMapToDateSortedTagNames(getClosestTagAsMap(repo));
ObjectId obj = (ObjectId) map.keySet().toArray()[0];

RevWalk walk = new RevWalk(repo);
RevCommit commit = walk.lookupCommit(obj);
walk.dispose();
try(RevWalk walk = new RevWalk(repo)){
RevCommit commit = walk.lookupCommit(obj);
walk.dispose();

int distance = distanceBetween(repo, headCommit, commit);
return String.valueOf(distance);
int distance = distanceBetween(repo, headCommit, commit);
return String.valueOf(distance);
}
}

private Map<ObjectId, List<DatedRevTag>> getClosestTagAsMap(@NotNull Repository repo){
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/pl/project13/maven/git/GitDirLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ private File processGitDirFile(@NotNull File file) {
// There should be just one line in the file, e.g.
// "gitdir: /usr/local/src/parentproject/.git/modules/submodule"
String line = reader.readLine();

if(line == null) {
return null;
}
// Separate the key and the value in the string.
String[] parts = line.split(": ");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public interface ProcessRunner {

public static class NativeCommandException extends IOException
{
private static final long serialVersionUID = 3511033422542257748L;
private final int exitCode;
private final String command;
private final File directory;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/pl/project13/maven/git/PropertiesReplacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ public void performReplacement(Properties properties, List<ReplacementProperty>
}

private String performReplacement(ReplacementProperty replacementProperty, String content) {
String result = performTransformationRules(replacementProperty, content, TransformationRule.ApplyEnum.BEFORE);
String result = content;
if(replacementProperty != null) {
result = performTransformationRules(replacementProperty, result, TransformationRule.ApplyEnum.BEFORE);
if(replacementProperty.isRegex()) {
result = replaceRegex(result, replacementProperty.getToken(), replacementProperty.getValue());
} else {
result = replaceNonRegex(result, replacementProperty.getToken(), replacementProperty.getValue());
}
result = performTransformationRules(replacementProperty, result, TransformationRule.ApplyEnum.AFTER);
}
return performTransformationRules(replacementProperty, result, TransformationRule.ApplyEnum.AFTER);
return result;
}

private String performTransformationRules(ReplacementProperty replacementProperty, String content, TransformationRule.ApplyEnum forRule) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pl/project13/maven/git/util/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean equals(@Nullable Object o) {
return false;
}

Pair pair = (Pair) o;
Pair<?,?> pair = (Pair<?,?>) o;

if (!first.equals(pair.first)) {
return false;
Expand Down

0 comments on commit 6557ed6

Please sign in to comment.