Skip to content

The Unified and Autonomous Development Platform

Implement git tags page

steve3d842b33750a
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/GitopWebApp.java b/gitop.web/src/main/java/com/pmease/gitop/web/GitopWebApp.java
index 32353a7b45..0bf3582ee8 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/GitopWebApp.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/GitopWebApp.java
@@ -90,6 +90,7 @@ import com.pmease.gitop.web.page.project.source.branches.BranchesPage;
import com.pmease.gitop.web.page.project.source.commit.SourceCommitPage;
import com.pmease.gitop.web.page.project.source.commits.CommitsPage;
import com.pmease.gitop.web.page.project.source.contributors.ContributorsPage;
+import com.pmease.gitop.web.page.project.source.tags.GitArchiveResourceReference;
import com.pmease.gitop.web.page.project.source.tags.TagsPage;
import com.pmease.gitop.web.page.project.source.tree.SourceTreePage;
import com.pmease.gitop.web.page.project.stats.ProjectForksPage;
@@ -354,6 +355,7 @@ public class GitopWebApp extends AbstractWicketConfig {
// getSharedResources().add(RawBlobResourceReference.RAW_BLOB_RESOURCE, new RawBlobResource());
mountResource("rawblob/${user}/${project}/${objectId}", new RawBlobResourceReference());
+ mountResource("archive/${user}/${project}/${file}", new GitArchiveResourceReference());
}
public boolean isGravatarEnabled() {
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
index bc997533d4..76d7e28ce8 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
@@ -634,7 +634,8 @@ a.diffstat:hover { text-decoration: none; }
/**
* BRANCHES PAGE
*/
-.branches-page h2 { margin-top: 0;}
+h2.section-title { margin: 18px 0; font-size: 16px; }
+
.table-branches td.actions { text-align: right; vertical-align: middle; }
.table-branches p { margin: 0;}
.table-branches td.meta a { font-size: 16px; font-weight: bold; }
@@ -655,6 +656,19 @@ a.diffstat:hover { text-decoration: none; }
.statbar .ahead p { padding-left: 4px; }
.statbar .behind p { text-align: right; padding-right: 4px; }
+/*
+ * TAGS PAGE
+ */
+.table-tags { border-bottom: 1px solid #ddd; }
+.table-tags .meta h3 { margin: 0 0 6px; font-size: 16px; font-weight: bold; }
+.meta h3 a { color: #333; }
+.table-tags .meta pre { background: transparent; border-width: 0; border-radius: 0; border-color: #ddd; color: #555; padding: 8px 0; margin: 0; }
+.table-tags > tbody > tr > td { padding: 12px; }
+.table-tags td.date { color: #999; }
+.table-tags ul.list-inline { margin-bottom: 0; }
+.table-tags .list-inline a { color: #999; }
+.table-tags .list-inline a:hover { color: #09F; text-decoration: none; }
+.table-tags .avatar { width: 64px; height: 64px; }
/**
* GATE KEEPER SETTING PAGE
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/GitUtils.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/GitUtils.java
index 94734e964c..4b7187daf5 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/git/GitUtils.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/GitUtils.java
@@ -1,5 +1,6 @@
package com.pmease.gitop.web.git;
+import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
@@ -11,11 +12,13 @@ import org.eclipse.jgit.lib.Constants;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
import com.pmease.commons.git.RefInfo;
+import com.pmease.commons.git.UserInfo;
public class GitUtils {
@@ -75,4 +78,61 @@ public class GitUtils {
List<Commit> commits = git.log(null, revision, path, 1, 0);
return Iterables.getFirst(commits, null);
}
+
+ public static @Nullable String parseEmail(String mail) {
+ if (mail == null || mail.length() == 0)
+ return null;
+
+ if (mail.charAt(0) == '<')
+ mail = mail.substring(1, mail.length() - 1);
+
+ return mail;
+ }
+
+ /**
+ * Parse the original git raw date to Java date. The raw git date is in
+ * unix timestamp with timezone like:
+ * 1392312299 -0800
+ *
+ * @param input the input raw date string
+ * @return Java date
+ */
+ public static Date parseRawDate(String input) {
+ String[] pieces = Iterables.toArray(Splitter.on(" ").split(input), String.class);
+ long when = Long.valueOf(pieces[0]) * 1000;
+ return new Date(when);
+ }
+
+ /**
+ * Parse the raw user information into UserInfo object, the raw information
+ * should be in format <code>[name] [<email>] [epoch timezone]</code>, for
+ * example:
+ *
+ * Jacob Thornton <[email protected]> 1328060294 -0800
+ *
+ * @param raw
+ * @return
+ */
+ public static @Nullable UserInfo parseUserInfo(String raw) {
+ if (Strings.isNullOrEmpty(raw))
+ return null;
+
+ int pos1 = raw.indexOf('<');
+ if (pos1 <= 0)
+ throw new IllegalArgumentException("Raw " + raw);
+
+ String name = raw.substring(0, pos1 - 1);
+
+ int pos2 = raw.indexOf('>');
+ if (pos2 <= 0)
+ throw new IllegalArgumentException("Raw " + raw);
+
+ String time = raw.substring(pos2 + 1).trim();
+ Date date = parseRawDate(time);
+
+ String email = raw.substring(pos1 + 1, pos2 - 1);
+
+ return new UserInfo(name, email, date);
+ }
+
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ArchiveCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ArchiveCommand.java
new file mode 100644
index 0000000000..02108ff90b
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ArchiveCommand.java
@@ -0,0 +1,106 @@
+package com.pmease.gitop.web.git.command;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.List;
+
+import org.parboiled.common.Preconditions;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import com.pmease.commons.git.command.GitCommand;
+import com.pmease.commons.util.execution.Commandline;
+import com.pmease.commons.util.execution.LineConsumer;
+
+public class ArchiveCommand extends GitCommand<Void> {
+
+ public static enum Format {
+ TAR("tar"), TGZ("tgz"), TAR_GZ("tar.gz"), ZIP("zip");
+
+ private final String suffix;
+
+ Format(String suffix) {
+ this.suffix = suffix;
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+ }
+
+ private Format format = Format.ZIP;
+ private List<String> paths = Lists.newArrayList();
+ private String treeish;
+ private String prefix;
+ private String outputFile;
+
+ private final OutputStream output;
+
+ public ArchiveCommand(File repoDir, OutputStream output) {
+ super(repoDir);
+ this.output = output;
+ }
+
+ public ArchiveCommand format(Format format) {
+ this.format = format;
+ return this;
+ }
+
+ public ArchiveCommand path(String path) {
+ this.paths = Collections.singletonList(path);
+ return this;
+ }
+
+ public ArchiveCommand paths(List<String> paths) {
+ this.paths = paths;
+ return this;
+ }
+
+ public ArchiveCommand treeish(String treeish) {
+ this.treeish = treeish;
+ return this;
+ }
+
+ public ArchiveCommand prefix(String prefix) {
+ this.prefix = prefix;
+ return this;
+ }
+
+ public ArchiveCommand outputFile(String outputFile) {
+ this.outputFile = outputFile;
+ return this;
+ }
+
+ @Override
+ public Void call() {
+ Commandline cmd = cmd();
+
+ cmd.addArgs("archive");
+
+ applyArgs(cmd);
+
+ cmd.execute(output, new LineConsumer.ErrorLogger());
+
+ return null;
+ }
+
+ protected void applyArgs(Commandline cmd) {
+ cmd.addArgs("--format", format.suffix);
+ if (!Strings.isNullOrEmpty(prefix)) {
+ cmd.addArgs("--prefix=" + prefix);
+ }
+
+ if (!Strings.isNullOrEmpty(outputFile)) {
+ cmd.addArgs("-o", outputFile);
+ }
+
+ cmd.addArgs(Preconditions.checkArgNotNull(treeish, "treeish"));
+
+ if (!paths.isEmpty()) {
+ for (String each : paths) {
+ cmd.addArgs(each);
+ }
+ }
+ }
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/BranchForEachRefCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/BranchForEachRefCommand.java
index c0011eda64..418456c00a 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/BranchForEachRefCommand.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/BranchForEachRefCommand.java
@@ -1,7 +1,6 @@
package com.pmease.gitop.web.git.command;
import java.io.File;
-import java.util.Date;
import java.util.Map;
import com.google.common.base.Splitter;
@@ -11,6 +10,7 @@ import com.google.common.collect.Maps;
import com.pmease.commons.git.BriefCommit;
import com.pmease.commons.git.UserInfo;
import com.pmease.commons.util.execution.Commandline;
+import com.pmease.gitop.web.git.GitUtils;
public class BranchForEachRefCommand extends ForEachRefCommand<Map<String, BriefCommit>, BranchForEachRefCommand> {
@@ -52,7 +52,7 @@ public class BranchForEachRefCommand extends ForEachRefCommand<Map<String, Brief
Map<String, BriefCommit> branches = Maps.newLinkedHashMap();
@Override
- public Map<String, BriefCommit> getOutput() {
+ public Map<String, BriefCommit> getResult() {
return branches;
}
@@ -70,52 +70,20 @@ public class BranchForEachRefCommand extends ForEachRefCommand<Map<String, Brief
String refname = pieces[i++];
String sha = pieces[i++];
- UserInfo committer = new UserInfo(pieces[i++], parseEmail(pieces[i++]), parseDate(pieces[i++]));
- UserInfo author = new UserInfo(pieces[i++], parseEmail(pieces[i++]), parseDate(pieces[i++]));
+ UserInfo committer = new UserInfo(pieces[i++],
+ GitUtils.parseEmail(pieces[i++]),
+ GitUtils.parseRawDate(pieces[i++]));
+ UserInfo author = new UserInfo(pieces[i++],
+ GitUtils.parseEmail(pieces[i++]),
+ GitUtils.parseRawDate(pieces[i++]));
BriefCommit commit = new BriefCommit(sha, committer, author, subject);
branches.put(refname, commit);
}
}
- static String parseEmail(String mail) {
- if (mail.charAt(0) == '<')
- mail = mail.substring(1, mail.length() - 1);
-
- return mail;
- }
-
- static Date parseDate(String str) {
- String[] pieces = Iterables.toArray(Splitter.on(" ").split(str), String.class);
- long when = Long.valueOf(pieces[0]) * 1000;
- return new Date(when);
- }
-
@Override
protected BranchForEachRefCommand self() {
return this;
}
-
- public static void main(String[] args) {
- String line = "master|6c355beafdbd0a62add3a3d89825ca87cf8ecec0|Linus Torvalds|<[email protected]>|1372550568 -0700|Linus Torvalds|<[email protected]>|1372550568 -0700 Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc";
- int pos = line.indexOf('\t');
- if (pos <= 0)
- return;
-
- String first = line.substring(0, pos);
- String subject = line.substring(pos + 1);
- String[] pieces = Iterables.toArray(Splitter.on('|').split(first), String.class);
-
- int i = 0;
- String refname = pieces[i++];
- String sha = pieces[i++];
-
- UserInfo committer = new UserInfo(pieces[i++], parseEmail(pieces[i++]), parseDate(pieces[i++]));
- UserInfo author = new UserInfo(pieces[i++], parseEmail(pieces[i++]), parseDate(pieces[i++]));
- System.out.println(refname);
- System.out.println(sha);
- System.out.println(committer);
- System.out.println(author);
- System.out.println(subject);
- }
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/DiffTreeCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/DiffTreeCommand.java
index d685823485..8c65591cfe 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/DiffTreeCommand.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/DiffTreeCommand.java
@@ -1,13 +1,13 @@
package com.pmease.gitop.web.git.command;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
-import com.google.common.io.ByteStreams;
+import com.google.common.io.ByteSource;
import com.pmease.commons.util.execution.Commandline;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.Patch;
@@ -68,8 +68,7 @@ public class DiffTreeCommand extends AbstractDiffCommand<Patch, DiffTreeCommand>
try (ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE)) {
cmd.execute(out, errorLogger).checkReturnCode();
- try (ByteArrayInputStream in = ByteStreams.newInputStreamSupplier(
- out.toByteArray()).getInput()) {
+ try (InputStream in = ByteSource.wrap(out.toByteArray()).openBufferedStream()) {
patch.parse(in);
return patch;
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ForEachRefCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ForEachRefCommand.java
index 1c1809019f..f7fb46d357 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ForEachRefCommand.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ForEachRefCommand.java
@@ -63,7 +63,7 @@ public abstract class ForEachRefCommand<T, V extends ForEachRefCommand<T, V>> ex
ForEachRefOutputHandler<T> outputHandler = getOutputHandler();
cmd.execute(outputHandler, getErrorHandler());
- return outputHandler.getOutput();
+ return outputHandler.getResult();
}
protected LineConsumer getErrorHandler() {
@@ -99,5 +99,4 @@ public abstract class ForEachRefCommand<T, V extends ForEachRefCommand<T, V>> ex
public String getSort() {
return sort;
}
-
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ForEachRefOutputHandler.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ForEachRefOutputHandler.java
index 007731ede0..c77799bb3e 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ForEachRefOutputHandler.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ForEachRefOutputHandler.java
@@ -1,9 +1,15 @@
package com.pmease.gitop.web.git.command;
+import java.io.IOException;
+
+import com.google.common.io.LineProcessor;
import com.pmease.commons.util.execution.LineConsumer;
-public abstract class ForEachRefOutputHandler<T> extends LineConsumer {
+public abstract class ForEachRefOutputHandler<T> extends LineConsumer implements LineProcessor<T> {
- abstract public T getOutput();
-
+ @Override
+ public boolean processLine(String line) throws IOException {
+ consume(line);
+ return true;
+ }
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/LineListConsumer.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/LineListConsumer.java
new file mode 100644
index 0000000000..d58ba5059b
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/LineListConsumer.java
@@ -0,0 +1,20 @@
+package com.pmease.gitop.web.git.command;
+
+import java.util.List;
+
+import com.google.common.collect.Lists;
+import com.pmease.commons.util.execution.LineConsumer;
+
+public class LineListConsumer extends LineConsumer {
+
+ private final List<String> lines = Lists.newLinkedList();
+
+ @Override
+ public void consume(String line) {
+ lines.add(line);
+ }
+
+ public List<String> getLines() {
+ return lines;
+ }
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ListTagCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ListTagCommand.java
new file mode 100644
index 0000000000..35036292fd
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/ListTagCommand.java
@@ -0,0 +1,156 @@
+package com.pmease.gitop.web.git.command;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Objects;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.io.LineProcessor;
+import com.pmease.commons.git.Commit;
+import com.pmease.commons.git.UserInfo;
+import com.pmease.commons.git.command.GitCommand;
+import com.pmease.commons.util.execution.Commandline;
+import com.pmease.commons.util.execution.LineConsumer;
+import com.pmease.gitop.web.git.GitUtils;
+
+public class ListTagCommand extends GitCommand<Map<String, Commit>> {
+
+ public ListTagCommand(File repoDir) {
+ super(repoDir);
+ }
+
+ final static String LINE_SEPARATOR = "----g----i----t----o----p----";
+
+ static final String FORMAT = "%d|%H|%aN|%aE|%ad|%cN|%cE|%cd%n%s%n%b%n" + LINE_SEPARATOR;
+
+ @Override
+ public Map<String, Commit> call() {
+ Commandline cmd = cmd();
+ cmd.addArgs("log", "-q", "--no-walk", "--date-order", "--tags", "--decorate=short", "--date=raw");
+ cmd.addArgs("--format=" + FORMAT + "");
+
+ TagConsumer consumer = new TagConsumer();
+ cmd.execute(consumer , new LineConsumer.ErrorLogger());
+
+ return consumer.commits;
+ }
+
+ static enum State {
+ START, META, SUBJECT, BODY, SEPARATOR;
+
+ public State next() {
+ int i = ordinal() + 1;
+ if (i >= State.values().length) {
+ i = 0;
+ }
+ return State.values()[i];
+ }
+ }
+
+
+ public static class TagConsumer extends LineConsumer implements LineProcessor<Map<String, Commit>> {
+
+ private Commit.Builder currentBuilder;
+ private List<String> messageLines = Lists.newLinkedList();
+ private State state = State.START;
+ private List<String> currentNames = Lists.newArrayList();
+
+ final Map<String, Commit> commits = Maps.newLinkedHashMap();
+
+ private void onMeta(String line) {
+ String[] pieces = Iterables.toArray(Splitter.on("|").split(line), String.class);
+ int i = 0;
+ currentNames = parseTagNames(pieces[i++]);
+ currentBuilder.hash(pieces[i++]);
+ currentBuilder.author(new UserInfo(pieces[i++], GitUtils.parseEmail(pieces[i++]), GitUtils.parseRawDate(pieces[i++])));
+ currentBuilder.committer(new UserInfo(pieces[i++], GitUtils.parseEmail(pieces[i++]), GitUtils.parseRawDate(pieces[i++])));
+ }
+
+ private void onFinishBlock() {
+ // process previous
+ String body = Joiner.on("\n").join(messageLines);
+ currentBuilder.body(body);
+
+ Commit commit = currentBuilder.build();
+ for (String each : currentNames) {
+ commits.put(each, commit);
+ }
+
+ currentBuilder = Commit.builder();
+ messageLines = Lists.newLinkedList();
+ }
+
+ @Override
+ public void consume(String line) {
+ if (state == State.START) {
+ if (line.trim().startsWith("(tag: ")) {
+ state = State.META;
+ currentBuilder = Commit.builder();
+ } else
+ return;
+ }
+
+ if (Objects.equal(line, LINE_SEPARATOR)) {
+ state = State.SEPARATOR;
+ }
+
+ switch (state) {
+ case META:
+ onMeta(line);
+ break;
+
+ case SUBJECT:
+ currentBuilder.subject(line);
+ break;
+
+ case BODY:
+ messageLines.add(line);
+ return; // don't transform state, we may have multiple lines here
+
+ case SEPARATOR:
+ onFinishBlock();
+ break;
+
+ default:
+ return;
+ }
+
+ state = state.next();
+ }
+
+ @Override
+ public boolean processLine(String line) throws IOException {
+ consume(line);
+ return true;
+ }
+
+ @Override
+ public Map<String, Commit> getResult() {
+ return commits;
+ }
+ }
+
+ static final Pattern pTag = Pattern.compile("\\tag: (.*)");
+
+ static List<String> parseTagNames(final String name) {
+ String trimed = name.trim();
+ if (!trimed.startsWith("(tag: "))
+ throw new IllegalStateException("Tag name field: " + name);
+
+ trimed = trimed.substring(1, trimed.length() - 1);
+ String[] pieces = Iterables.toArray(Splitter.on(",").trimResults().omitEmptyStrings().split(trimed), String.class);
+ List<String> result = Lists.newArrayList();
+ for (String each : pieces) {
+ result.add(each.substring("tag: ".length()));
+ }
+
+ return result;
+ }
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/Tag.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/Tag.java
new file mode 100644
index 0000000000..ca1976be40
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/Tag.java
@@ -0,0 +1,117 @@
+package com.pmease.gitop.web.git.command;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.io.Serializable;
+
+import javax.annotation.Nullable;
+
+import com.google.common.base.Strings;
+import com.pmease.commons.git.UserInfo;
+
+public class Tag implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String name;
+ private final String hash;
+ private final String commitHash;
+ private final UserInfo tagger;
+ private final String subject;
+ private final String body;
+
+ public static class Builder {
+ private String name;
+ private String hash;
+ private String commitHash;
+ private UserInfo tagger;
+ private String subject;
+ private String body;
+
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder hash(String hash) {
+ this.hash = hash;
+ return this;
+ }
+
+ public Builder commitHash(String commitHash) {
+ this.commitHash = commitHash;
+ return this;
+ }
+
+ public Builder tagger(UserInfo tagger) {
+ this.tagger = tagger;
+ return this;
+ }
+
+ public Builder subject(String subject) {
+ this.subject = subject;
+ return this;
+ }
+
+ public Builder body(String body) {
+ this.body = body;
+ return this;
+ }
+
+ public Tag build() {
+ return new Tag(
+ checkNotNull(name),
+ checkNotNull(hash),
+ commitHash,
+ tagger,
+ checkNotNull(subject),
+ body);
+ }
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ Tag(String name, String hash, @Nullable String commitHash,
+ UserInfo tagger, String subject, @Nullable String body) {
+ this.name = name;
+ this.hash = hash;
+ this.commitHash = commitHash;
+ this.tagger = tagger;
+ this.subject = subject;
+ this.body = body;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getHash() {
+ return hash;
+ }
+
+ public String getCommitHash() {
+ return commitHash;
+ }
+
+ public UserInfo getTagger() {
+ return tagger;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public String getMessage() {
+ return Strings.isNullOrEmpty(body) ? subject : subject + "\n" + body;
+ }
+
+ public String getSha() {
+ return Strings.isNullOrEmpty(commitHash) ? hash : commitHash;
+ }
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/git/command/TagForEachRefCommand.java b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/TagForEachRefCommand.java
new file mode 100644
index 0000000000..018a83c495
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/git/command/TagForEachRefCommand.java
@@ -0,0 +1,119 @@
+package com.pmease.gitop.web.git.command;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jgit.lib.Constants;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Objects;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.pmease.commons.git.UserInfo;
+import com.pmease.commons.util.execution.Commandline;
+import com.pmease.gitop.web.git.GitUtils;
+
+public class TagForEachRefCommand extends ForEachRefCommand<Map<String, Tag>, TagForEachRefCommand> {
+
+ public TagForEachRefCommand(File repoDir) {
+ super(repoDir);
+ }
+
+ @Override
+ protected TagForEachRefCommand self() {
+ return this;
+ }
+
+ @Override
+ protected ForEachRefOutputHandler<Map<String, Tag>> getOutputHandler() {
+ return new TagOutputHandler();
+ }
+
+ @Override
+ protected void applyArgs(Commandline cmd) {
+ super.applyArgs(cmd);
+
+ if (Strings.isNullOrEmpty(getSort())) {
+ cmd.addArgs("--sort=-creatordate");
+ }
+
+ if (getPatterns().length == 0) {
+ cmd.addArgs(Constants.R_TAGS);
+ }
+ }
+
+ static final String BLOCK_SEPARATOR = "-----B-----L-----O-----C-----K-----";
+
+ private static final String FORMAT =
+ "%(refname)|" + // ref name
+ "%(objectname)|" + // ref sha-1
+ "%(*objectname)|" + //
+ "%(creator)|" +
+ "%0A%(contents:subject)" +
+ "%0A%(contents:body)" +
+ "%0A" + BLOCK_SEPARATOR;
+
+ static class TagOutputHandler extends ForEachRefOutputHandler<Map<String, Tag>> {
+ final Map<String, Tag> tags = Maps.newLinkedHashMap();
+
+ List<String> contents = Lists.newArrayList();
+
+ Tag.Builder builder = Tag.builder();
+
+ @Override
+ public Map<String, Tag> getResult() {
+ return tags;
+ }
+
+ @Override
+ public void consume(String line) {
+ if (Objects.equal(line, BLOCK_SEPARATOR)) {
+ onBlockFinish();
+ return;
+ }
+
+ if (line.startsWith(Constants.R_TAGS)) {
+ onMeta(line);
+ return;
+ }
+
+ contents.add(line);
+ }
+
+ void onMeta(String line) {
+ String[] pieces = Iterables.toArray(Splitter.on("|").split(line), String.class);
+ int i = 0;
+ String refname = pieces[i++].substring(Constants.R_TAGS.length());
+ builder.name(refname);
+ String hash1 = pieces[i++];
+ String hash2 = pieces[i++];
+ builder.hash(hash1);
+ builder.commitHash(hash2);
+
+ UserInfo tagger = GitUtils.parseUserInfo(pieces[i++]);
+ builder.tagger(tagger);
+ }
+
+ void onBlockFinish() {
+ builder.subject(contents.get(0));
+ builder.body(Joiner.on("\n").join(contents.subList(1, contents.size())));
+ Tag tag = builder.build();
+ tags.put(tag.getName(), tag);
+
+ // reset
+ builder = Tag.builder();
+ contents = Lists.newArrayList();
+ }
+ }
+
+
+ @Override
+ protected String getFormat() {
+ return FORMAT;
+ }
+
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/ImageBlobResource.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/ImageBlobResource.java
index f16752870f..7bd48238ae 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/ImageBlobResource.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/ImageBlobResource.java
@@ -1,7 +1,7 @@
package com.pmease.gitop.web.page.project.source.blob.renderer;
import java.awt.Dimension;
-import java.io.ByteArrayInputStream;
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.util.Iterator;
@@ -20,7 +20,7 @@ import org.apache.wicket.util.time.Time;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
-import com.google.common.io.ByteStreams;
+import com.google.common.io.ByteSource;
import com.google.common.io.Files;
import com.pmease.gitop.core.Gitop;
import com.pmease.gitop.core.manager.ProjectManager;
@@ -99,8 +99,7 @@ public class ImageBlobResource extends DynamicImageResource {
if (iter.hasNext()) {
ImageReader reader = iter.next();
- try (ByteArrayInputStream is = ByteStreams.newInputStreamSupplier(
- data).getInput()) {
+ try (BufferedInputStream is = (BufferedInputStream) ByteSource.wrap(data).openBufferedStream()) {
reader.setInput(data);
ImageInputStream stream = new MemoryCacheImageInputStream(is);
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/branches/BranchesPage.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/branches/BranchesPage.html
index 357646d0ad..180481b986 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/branches/BranchesPage.html
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/branches/BranchesPage.html
@@ -2,7 +2,7 @@
<wicket:extend>
<div class="padder">
<div class="page-heading">
- <h2>Branches</h2>
+ <h2 class="section-title">Branches</h2>
</div>
<wicket:container wicket:id="content"></wicket:container>
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/patch/HunkHeader.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/patch/HunkHeader.java
index 5e50494cf7..417570172c 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/patch/HunkHeader.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/patch/HunkHeader.java
@@ -11,7 +11,6 @@ import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.List;
-import org.apache.commons.io.IOUtils;
import org.eclipse.jgit.diff.Edit;
import org.eclipse.jgit.diff.EditList;
import org.eclipse.jgit.internal.JGitText;
@@ -21,7 +20,6 @@ import org.eclipse.jgit.util.RawParseUtils;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
-import com.google.common.io.ByteStreams;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.HunkLine.LineType;
import com.pmease.gitop.web.util.UniversalEncodingDetector;
@@ -251,14 +249,10 @@ public class HunkHeader {
}
public Charset getCharset() {
- ByteArrayInputStream bas = null;
- try {
- bas = ByteStreams.newInputStreamSupplier(file.buf).getInput();
+ try (ByteArrayInputStream bas = new ByteArrayInputStream(file.buf)) {
return UniversalEncodingDetector.detect(bas);
} catch (IOException e) {
throw Throwables.propagate(e);
- } finally {
- IOUtils.closeQuietly(bas);
}
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tags/TagsPage.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tags/TagsPage.html
index bd10fed378..d812416ae2 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tags/TagsPage.html
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tags/TagsPage.html
@@ -2,10 +2,41 @@
<wicket:extend>
<div class="padder">
<div class="page-heading">
- <h2>Tags</h2>
+ <h2 class="section-title">Tags</h2>
</div>
<wicket:container wicket:id="content"></wicket:container>
</div>
+
+ <wicket:fragment wicket:id="norecord">
+ <div class="alert alert-warning">
+ <h3>There aren't any tags yet</h3>
+ <p></p>
+ </div>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="tagsfrag">
+ <table class="table table-tags">
+ <tr wicket:id="tags">
+ <td class="date">
+ <p><span wicket:id="creator"></span></p>
+ <span wicket:id="date"></span>
+ </td>
+ <td class="meta">
+ <h3><span wicket:id="tagname"></span></h3>
+ <pre wicket:id="message"></pre>
+ <ul class="list-inline">
+ <li><a wicket:id="commitlink"><i class="icon icon-commit"></i> <span class="sha" wicket:id="hash"></span></a></li>
+ <li><a wicket:id="ziplink"><i class="icon icon-file-zip"></i> zip</a></li>
+ <li><a wicket:id="targzlink"><i class="icon icon-file-zip"></i> tar.gz</a></li>
+ </ul>
+ </td>
+ </tr>
+ </table>
+ <div class="btn-group" wicket:id="navigator">
+ <a class="btn btn-default" wicket:id="previouslink"><i class="icon icon-long-arrow-left"></i> Previous</a>
+ <a class="btn btn-default" wicket:id="nextlink">Next <i class="icon icon-long-arrow-right"></i></a>
+ </div>
+ </wicket:fragment>
</wicket:extend>
</html>
\ No newline at end of file
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tags/TagsPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tags/TagsPage.java
index de3475a9bc..2c5e6efce7 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tags/TagsPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/tags/TagsPage.java
@@ -1,19 +1,230 @@
package com.pmease.gitop.web.page.project.source.tags;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.AbstractLink;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.markup.html.link.ResourceLink;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
+import com.google.common.base.Objects;
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.pmease.gitop.model.Project;
+import com.pmease.gitop.web.component.label.AgeLabel;
+import com.pmease.gitop.web.component.link.GitPersonLink;
+import com.pmease.gitop.web.component.link.GitPersonLink.Mode;
+import com.pmease.gitop.web.git.GitUtils;
+import com.pmease.gitop.web.git.command.ArchiveCommand.Format;
+import com.pmease.gitop.web.git.command.Tag;
+import com.pmease.gitop.web.git.command.TagForEachRefCommand;
+import com.pmease.gitop.web.page.PageSpec;
import com.pmease.gitop.web.page.project.ProjectCategoryPage;
+import com.pmease.gitop.web.page.project.api.GitPerson;
+import com.pmease.gitop.web.page.project.source.commit.SourceCommitPage;
@SuppressWarnings("serial")
public class TagsPage extends ProjectCategoryPage {
+ private final IModel<Map<String, Tag>> tagsModel;
+
+ private String before;
+ private String after;
+
+ public static PageParameters newParams(Project project, String before, String after) {
+ PageParameters parameters = PageSpec.forProject(project);
+ if (!Strings.isNullOrEmpty(before)) {
+ parameters.add("before", before);
+ }
+
+ if (!Strings.isNullOrEmpty(after)) {
+ parameters.add("after", after);
+ }
+
+ return parameters;
+ }
+
public TagsPage(PageParameters params) {
super(params);
+
+ tagsModel = new LoadableDetachableModel<Map<String, Tag>>() {
+
+ @Override
+ protected Map<String, Tag> load() {
+ Map<String, Tag> map = new TagForEachRefCommand(getProject().code().repoDir()).call();
+ return map;
+ }
+
+ };
+
+ before = params.get("before").toString();
+ after = params.get("after").toString();
}
+ @Override
+ protected void onPageInitialize() {
+ super.onPageInitialize();
+
+ Map<String, Tag> tags = tagsModel.getObject();
+ if (tags.isEmpty()) {
+ Fragment frag = new Fragment("content", "norecord", this);
+ add(frag);
+ } else {
+ Fragment frag = new Fragment("content", "tagsfrag", this);
+ add(frag);
+
+ IModel<List<String>> tagNames = new AbstractReadOnlyModel<List<String>>() {
+
+ @Override
+ public List<String> getObject() {
+ return getTagsInRange();
+ }
+
+ };
+
+ frag.add(new ListView<String>("tags", tagNames) {
+
+ @Override
+ protected void populateItem(ListItem<String> item) {
+ String tagName = item.getModelObject();
+ Tag tag = getTagCommit(tagName);
+
+ if (tag.getTagger() == null) {
+ item.add(new WebMarkupContainer("creator").setVisibilityAllowed(false));
+ item.add(new WebMarkupContainer("date").setVisibilityAllowed(false));
+ } else {
+ item.add(new GitPersonLink("creator",
+ Model.of(GitPerson.of(tag.getTagger())),
+ Mode.AVATAR_ONLY).enableTooltip("right"));
+ item.add(new AgeLabel("date", Model.of(tag.getTagger().getDate())));
+ }
+
+ item.add(new Label("tagname", tagName));
+ item.add(new Label("message", tag.getMessage()));
+ AbstractLink commitLink = new BookmarkablePageLink<Void>("commitlink",
+ SourceCommitPage.class,
+ SourceCommitPage.newParams(getProject(), tag.getSha()));
+
+ item.add(commitLink);
+ commitLink.add(new Label("hash", GitUtils.abbreviateSHA(tag.getSha())));
+
+ item.add(new ResourceLink<Void>("ziplink",
+ new GitArchiveResourceReference(),
+ GitArchiveResourceReference.newParams(getProject(), tagName, Format.ZIP)));
+ item.add(new ResourceLink<Void>("targzlink",
+ new GitArchiveResourceReference(),
+ GitArchiveResourceReference.newParams(getProject(), tagName, Format.TAR_GZ)));
+ }
+
+ });
+
+ String rangeFirst = getFirstInRange();
+ String rangeLast = getLastInRange();
+ String first = getFirstInAll();
+ String last = getLastInAll();
+
+ WebMarkupContainer navigator = new WebMarkupContainer("navigator");
+ navigator.setVisibilityAllowed(
+ !Objects.equal(getTagsInRange(), getAllTagNames()));
+ frag.add(navigator);
+
+ navigator.add(new BookmarkablePageLink<Void>("previouslink",
+ TagsPage.class,
+ newParams(getProject(), null, rangeFirst)).setEnabled(!Objects.equal(first, rangeFirst)));
+ navigator.add(new BookmarkablePageLink<Void>("nextlink", TagsPage.class,
+ newParams(getProject(),rangeLast, null)).setEnabled(!Objects.equal(last, rangeLast)));
+ }
+ }
+
+ private List<String> getAllTagNames() {
+ return Lists.newArrayList(tagsModel.getObject().keySet());
+ }
+
+ private String getFirstInRange() {
+ List<String> tags = getTagsInRange();
+ return Iterables.getFirst(tags, null);
+ }
+
+ private String getLastInRange() {
+ List<String> tags = getTagsInRange();
+ return Iterables.getLast(tags, null);
+ }
+
+ private String getFirstInAll() {
+ Map<String, Tag> tags = tagsModel.getObject();
+ return Iterables.getFirst(tags.keySet(), null);
+ }
+
+ private String getLastInAll() {
+ Map<String, Tag> tags = tagsModel.getObject();
+ return Iterables.getLast(tags.keySet(), null);
+ }
+
+ static final int MAX_ROWS = 50;
+
+ static int findPosition(List<String> list, String str) {
+ if (Strings.isNullOrEmpty(str))
+ return -1;
+
+ for (int i = 0; i < list.size(); i++) {
+ if (Objects.equal(str, list.get(i)))
+ return i;
+ }
+
+ return -1;
+ }
+
+ private List<String> getTagsInRange() {
+ List<String> allTags = getAllTagNames();
+
+ int beforePos = findPosition(allTags, before);
+ int afterPos = findPosition(allTags, after);
+
+ List<String> result = Lists.newArrayList(allTags);
+ if (beforePos >= 0) {
+ int start = beforePos + 1;
+ int end = Math.max(start + MAX_ROWS, allTags.size());
+ result = allTags.subList(start, end);
+ }
+
+ if (afterPos >= 0) {
+ int start = Math.max(0, afterPos - MAX_ROWS);
+ result = allTags.subList(start, afterPos);
+ }
+
+ if (result.size() > MAX_ROWS) {
+ result = result.subList(0, MAX_ROWS);
+ }
+
+ return Lists.newArrayList(result);
+ }
+
+ Tag getTagCommit(String name) {
+ return tagsModel.getObject().get(name);
+ }
+
@Override
protected String getPageTitle() {
return getProject() + " - tags";
}
+ @Override
+ public void onDetach() {
+ super.onDetach();
+
+ if (tagsModel != null) {
+ tagsModel.detach();
+ }
+ }
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/service/FileBlob.java b/gitop.web/src/main/java/com/pmease/gitop/web/service/FileBlob.java
index 7011b2bb28..a1e68dc27d 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/service/FileBlob.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/service/FileBlob.java
@@ -16,7 +16,7 @@ import org.eclipse.jgit.util.RawParseUtils;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
-import com.google.common.io.CharStreams;
+import com.google.common.io.CharSource;
import com.pmease.gitop.core.Gitop;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.web.common.quantity.Data;
@@ -100,8 +100,7 @@ public class FileBlob implements Serializable {
}
try {
- return CharStreams.readLines(
- CharStreams.newReaderSupplier(getStringContent()));
+ return CharSource.wrap(getStringContent()).readLines();
} catch (IOException e) {
throw Throwables.propagate(e);
}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/util/DateUtils.java b/gitop.web/src/main/java/com/pmease/gitop/web/util/DateUtils.java
index dadb3380bf..ecfac614ab 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/util/DateUtils.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/util/DateUtils.java
@@ -16,6 +16,7 @@ import org.joda.time.chrono.ISOChronology;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;
+import org.ocpsoft.prettytime.PrettyTime;
import com.google.common.base.Preconditions;
import com.pmease.gitop.web.Constants;
@@ -56,7 +57,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
return formatDurationPart(months, DurationUnit.MONTH);
}
- if (weeks > 0) {
+ if (weeks > 0 && weeks * 7 >= days) {
return formatDurationPart(weeks, DurationUnit.WEEK);
}
@@ -113,7 +114,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
}
public static String formatAge(Date date) {
- return formatAge(new DateTime(date), DateTime.now());
+ return new PrettyTime().format(date);
+// return formatAge(new DateTime(date), DateTime.now());
}
public static String formatDate(Date date) {
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/util/UniversalEncodingDetector.java b/gitop.web/src/main/java/com/pmease/gitop/web/util/UniversalEncodingDetector.java
index 3ce3bb27d9..4aa32ceece 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/util/UniversalEncodingDetector.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/util/UniversalEncodingDetector.java
@@ -9,7 +9,6 @@ import org.apache.tika.metadata.Metadata;
import org.mozilla.universalchardet.UniversalDetector;
import com.google.common.base.Throwables;
-import com.google.common.io.ByteStreams;
/**
* Copied from tika UniversalEncodingDetector
@@ -58,7 +57,7 @@ public class UniversalEncodingDetector {
public static boolean isBinary(byte[] bytes) {
try {
- return isBinary(ByteStreams.newInputStreamSupplier(bytes).getInput());
+ return isBinary(new ByteArrayInputStream(bytes));
} catch (IOException e) {
throw Throwables.propagate(e);
}
diff --git a/gitop.web/src/test/java/com/pmease/gitop/web/util/CommandTest.java b/gitop.web/src/test/java/com/pmease/gitop/web/util/CommandTest.java
index 64cd56850c..db9d3d2ff0 100644
--- a/gitop.web/src/test/java/com/pmease/gitop/web/util/CommandTest.java
+++ b/gitop.web/src/test/java/com/pmease/gitop/web/util/CommandTest.java
@@ -8,7 +8,6 @@ import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.Charset;
-import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -17,19 +16,18 @@ import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.ExecuteStreamHandler;
import org.apache.commons.exec.ExecuteWatchdog;
-import org.junit.Test;
import com.google.common.base.Throwables;
+import com.google.common.io.ByteSource;
import com.google.common.io.ByteStreams;
-import com.google.common.io.CharStreams;
-import com.google.common.io.InputSupplier;
+import com.google.common.io.CharSource;
import com.pmease.gitop.web.common.quantity.Data;
public class CommandTest {
static final File gitDir = new File("/Users/zhenyu/temp/aaa/.git");
- @Test public void testCancel() throws ExecuteException, IOException {
+ public void testCancel() throws ExecuteException, IOException {
CommandLine cmd = new CommandLine("/usr/local/bin/git");
cmd.addArguments(new String[] { "cat-file", "-p"});
cmd.addArgument("82c4424d00d3ad7bf89e622141811b39b1052458:guava.jar");
@@ -72,19 +70,9 @@ public class CommandTest {
handleBinary(bufferedIn);
} else {
Charset charset = UniversalEncodingDetector.detect(bufferedIn);
- List<String> lines = CharStreams.readLines(
- CharStreams.newReaderSupplier(new InputSupplier<InputStream>() {
-
- @Override
- public InputStream getInput() throws IOException {
- return bufferedIn;
- }
-
- }, charset));
-
- for (String each : lines) {
- System.out.println(each);
- }
+ CharSource cs = ByteSource.wrap(ByteStreams.toByteArray(bufferedIn))
+ .asCharSource(charset);
+ System.out.println(cs.read());
}
}
}
diff --git a/gitop.web/src/test/java/com/pmease/gitop/web/util/TagParserTest.java b/gitop.web/src/test/java/com/pmease/gitop/web/util/TagParserTest.java
new file mode 100644
index 0000000000..0d186dbaf9
--- /dev/null
+++ b/gitop.web/src/test/java/com/pmease/gitop/web/util/TagParserTest.java
@@ -0,0 +1,24 @@
+package com.pmease.gitop.web.util;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.LineProcessor;
+import com.google.common.io.Resources;
+import com.pmease.commons.git.Commit;
+import com.pmease.gitop.web.git.command.ListTagCommand;
+
+public class TagParserTest {
+
+ @Test public void testTagParser() throws IOException {
+ URL url = Resources.getResource(TagParserTest.class, "tag.out");
+ LineProcessor<Map<String, Commit>> tagConsumer = new ListTagCommand.TagConsumer();
+ Resources.readLines(url, Charsets.UTF_8, tagConsumer);
+
+ System.out.println(tagConsumer.getResult().get("v3.0.3").getMessage());
+ }
+}