Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle-Plugin #92

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
38 changes: 38 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin-parent</artifactId>
<version>2.1.10-SNAPSHOT</version>
</parent>

<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin-common</artifactId>
<name>Git Commit Id Plugin Maven Common</name>

<dependencies>
<!-- JGit -->

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
</dependency>

<!-- Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>

<!-- Joda Time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@

package pl.project13.jgit;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.newLinkedList;
import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Sets.newHashSet;

import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.regex.Pattern;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.api.Status;
Expand All @@ -35,22 +47,19 @@
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevWalk;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import pl.project13.jgit.dummy.DatedRevTag;
import pl.project13.maven.git.GitDescribeConfig;
import pl.project13.maven.git.log.LoggerBridge;
import pl.project13.maven.git.log.StdOutLoggerBridge;
import pl.project13.maven.git.util.Pair;

import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.newLinkedList;
import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Sets.newHashSet;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;

/**
* Implements git's <pre>describe</pre> command.
Expand Down Expand Up @@ -115,7 +124,7 @@ public class DescribeCommand extends GitCommand<DescribeResult> {
*
* @param repo the {@link org.eclipse.jgit.lib.Repository} this command should interact with
*/
@NotNull
@Nonnull
public static DescribeCommand on(Repository repo) {
return new DescribeCommand(repo);
}
Expand All @@ -139,13 +148,13 @@ private void initDefaultLoggerBridge(boolean verbose) {
loggerBridge = new StdOutLoggerBridge(verbose);
}

@NotNull
@Nonnull
public DescribeCommand setVerbose(boolean verbose) {
loggerBridge.setVerbose(verbose);
return this;
}

@NotNull
@Nonnull
public DescribeCommand withLoggerBridge(LoggerBridge bridge) {
this.loggerBridge = bridge;
return this;
Expand All @@ -158,7 +167,7 @@ public DescribeCommand withLoggerBridge(LoggerBridge bridge) {
* <p/>
* <pre>true</pre> by default.
*/
@NotNull
@Nonnull
public DescribeCommand always(boolean always) {
this.alwaysFlag = always;
log("--always =", always);
Expand All @@ -176,7 +185,7 @@ public DescribeCommand always(boolean always) {
* <p/>
* <pre>false</pre> by default.
*/
@NotNull
@Nonnull
public DescribeCommand forceLongFormat(@Nullable Boolean forceLongFormat) {
if (forceLongFormat != null) {
this.forceLongFormat = forceLongFormat;
Expand All @@ -193,7 +202,7 @@ public DescribeCommand forceLongFormat(@Nullable Boolean forceLongFormat) {
* <p/>
* An <n> of 0 will suppress long format, only showing the closest tag.
*/
@NotNull
@Nonnull
public DescribeCommand abbrev(@Nullable Integer n) {
if (n != null) {
Preconditions.checkArgument(n < 41, String.format("N (commit abbres length) must be < 41. (Was:[%s])", n));
Expand Down Expand Up @@ -232,7 +241,7 @@ public DescribeCommand abbrev(@Nullable Integer n) {
* tags to be included in the search, enable this option.
* </p>
*/
@NotNull
@Nonnull
public DescribeCommand tags(@Nullable Boolean includeLightweightTagsInSearch) {
if (includeLightweightTagsInSearch != null) {
tagsFlag = includeLightweightTagsInSearch;
Expand All @@ -254,7 +263,7 @@ public DescribeCommand tags() {
*
* @return itself, after applying the settings
*/
@NotNull
@Nonnull
public DescribeCommand apply(@Nullable GitDescribeConfig config) {
if (config != null) {
always(config.isAlways());
Expand All @@ -275,7 +284,7 @@ public DescribeCommand apply(@Nullable GitDescribeConfig config) {
* @param dirtyMarker the marker name to be appended to the describe output when the workspace is dirty
* @return itself, to allow fluent configuration
*/
@NotNull
@Nonnull
public DescribeCommand dirty(@Nullable String dirtyMarker) {
Optional<String> option = Optional.fromNullable(dirtyMarker);
log("--dirty =", option.or(""));
Expand All @@ -290,7 +299,7 @@ public DescribeCommand dirty(@Nullable String dirtyMarker) {
* @param pattern the glob style pattern to match against the tag names
* @return itself, to allow fluent configuration
*/
@NotNull
@Nonnull
public DescribeCommand match(@Nullable String pattern) {
matchOption = Optional.fromNullable(pattern);
log("--match =", matchOption.or(""));
Expand Down Expand Up @@ -367,7 +376,7 @@ private DescribeResult createDescribeResult(ObjectReader objectReader, ObjectId
}
}

private static boolean foundZeroTags(@NotNull Map<ObjectId, List<String>> tags) {
private static boolean foundZeroTags(@Nonnull Map<ObjectId, List<String>> tags) {
return tags.isEmpty();
}

Expand All @@ -392,11 +401,11 @@ boolean findDirtyState(Repository repo) throws GitAPIException {
}

@VisibleForTesting
static boolean hasTags(ObjectId headCommit, @NotNull Map<ObjectId, List<String>> tagObjectIdToName) {
static boolean hasTags(ObjectId headCommit, @Nonnull Map<ObjectId, List<String>> tagObjectIdToName) {
return tagObjectIdToName.containsKey(headCommit);
}

RevCommit findHeadObjectId(@NotNull Repository repo) throws RuntimeException {
RevCommit findHeadObjectId(@Nonnull Repository repo) throws RuntimeException {
try {
ObjectId headId = repo.resolve("HEAD");

Expand All @@ -411,7 +420,7 @@ RevCommit findHeadObjectId(@NotNull Repository repo) throws RuntimeException {
}
}

private List<RevCommit> findCommitsUntilSomeTag(Repository repo, RevCommit head, @NotNull Map<ObjectId, List<String>> tagObjectIdToName) {
private List<RevCommit> findCommitsUntilSomeTag(Repository repo, RevCommit head, @Nonnull Map<ObjectId, List<String>> tagObjectIdToName) {
RevWalk revWalk = new RevWalk(repo);
try {
revWalk.markStart(head);
Expand All @@ -438,7 +447,7 @@ private List<RevCommit> findCommitsUntilSomeTag(Repository repo, RevCommit head,
* @return distance (number of commits) between the given commits
* @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>
*/
private int distanceBetween(@NotNull Repository repo, @NotNull RevCommit child, @NotNull RevCommit parent) {
private int distanceBetween(@Nonnull Repository repo, @Nonnull RevCommit child, @Nonnull RevCommit parent) {
RevWalk revWalk = new RevWalk(repo);

try {
Expand Down Expand Up @@ -491,7 +500,7 @@ private int distanceBetween(@NotNull Repository repo, @NotNull RevCommit child,
}
}

private static void seeAllParents(@NotNull RevWalk revWalk, RevCommit child, @NotNull Set<ObjectId> seen) throws IOException {
private static void seeAllParents(@Nonnull RevWalk revWalk, RevCommit child, @Nonnull Set<ObjectId> seen) throws IOException {
Queue<RevCommit> q = newLinkedList();
q.add(child);

Expand All @@ -508,7 +517,7 @@ private static void seeAllParents(@NotNull RevWalk revWalk, RevCommit child, @No
}

// git commit id -> its tag (or tags)
private Map<ObjectId, List<String>> findTagObjectIds(@NotNull Repository repo, boolean tagsFlag) {
private Map<ObjectId, List<String>> findTagObjectIds(@Nonnull Repository repo, boolean tagsFlag) {
Map<ObjectId, List<DatedRevTag>> commitIdsToTags = newHashMap();

RevWalk walk = new RevWalk(repo);
Expand Down Expand Up @@ -626,7 +635,7 @@ private String createMatchPattern() {
}

@VisibleForTesting
static String trimFullTagName(@NotNull String tagName) {
static String trimFullTagName(@Nonnull String tagName) {
return tagName.replaceFirst("refs/tags/", "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@

package pl.project13.jgit;

import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static com.google.common.collect.Lists.newArrayList;

import java.io.IOException;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;

import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;

/**
* Represents the result of a <code>git describe</code> command.
Expand All @@ -53,32 +55,32 @@ public class DescribeResult {

public static final DescribeResult EMPTY = new DescribeResult("");

public DescribeResult(@NotNull String tagName) {
public DescribeResult(@Nonnull String tagName) {
this(tagName, false, Optional.<String>absent());
}

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

public DescribeResult(@NotNull ObjectReader objectReader, @NotNull ObjectId commitId) {
public DescribeResult(@Nonnull ObjectReader objectReader, @Nonnull ObjectId commitId) {
this.objectReader = objectReader;

this.commitId = Optional.of(commitId);
this.abbreviatedObjectId = createAbbreviatedCommitId(objectReader, commitId, this.abbrev);
}

public DescribeResult(@NotNull ObjectReader objectReader, String tagName, int commitsAwayFromTag, ObjectId commitId, boolean dirty, String dirtyMarker) {
public DescribeResult(@Nonnull ObjectReader objectReader, String tagName, int commitsAwayFromTag, ObjectId commitId, boolean dirty, String dirtyMarker) {
this(objectReader, tagName, commitsAwayFromTag, commitId, dirty, Optional.of(dirtyMarker));
}

public DescribeResult(@NotNull ObjectReader objectReader, String tagName, int commitsAwayFromTag, ObjectId commitId, boolean dirty, Optional<String> dirtyMarker) {
public DescribeResult(@Nonnull ObjectReader objectReader, String tagName, int commitsAwayFromTag, ObjectId commitId, boolean dirty, Optional<String> dirtyMarker) {
this(objectReader, commitId, dirty, dirtyMarker);
this.tagName = Optional.of(tagName);
this.commitsAwayFromTag = commitsAwayFromTag;
}

public DescribeResult(@NotNull ObjectReader objectReader, @NotNull ObjectId commitId, boolean dirty, @NotNull Optional<String> dirtyMarker) {
public DescribeResult(@Nonnull ObjectReader objectReader, @Nonnull ObjectId commitId, boolean dirty, @Nonnull Optional<String> dirtyMarker) {
this.objectReader = objectReader;

this.commitId = Optional.of(commitId);
Expand All @@ -88,13 +90,13 @@ public DescribeResult(@NotNull ObjectReader objectReader, @NotNull ObjectId comm
this.dirtyMarker = dirtyMarker.or("");
}

public DescribeResult(@NotNull String tagName, boolean dirty, @NotNull Optional<String> dirtyMarker) {
public DescribeResult(@Nonnull String tagName, boolean dirty, @Nonnull Optional<String> dirtyMarker) {
this.tagName = Optional.of(tagName);
this.dirty = dirty;
this.dirtyMarker = dirtyMarker.or("");
}

@NotNull
@Nonnull
public DescribeResult withCommitIdAbbrev(int n) {
Preconditions.checkArgument(n >= 0, String.format("The --abbrev parameter must be >= 0, but it was: [%s]", n));
this.abbrev = n;
Expand Down Expand Up @@ -202,7 +204,7 @@ private String gPrefixedCommitId(String name) {
*
* @return the abbreviated commit id, possibly longer than the requested len (if it wouldn't be unique)
*/
private static Optional<AbbreviatedObjectId> createAbbreviatedCommitId(@NotNull ObjectReader objectReader, ObjectId commitId, int requestedLenght) {
private static Optional<AbbreviatedObjectId> createAbbreviatedCommitId(@Nonnull ObjectReader objectReader, ObjectId commitId, int requestedLenght) {
if(requestedLenght < 2) {
// 0 means we don't want to print commit id's at all
return Optional.absent();
Expand Down
Loading