Skip to content

The Unified and Autonomous Development Platform

Add builder to construct Commit object upgrade guava to latest (16.0.1)

steve567734b54390
diff --git a/commons.git/src/main/java/com/pmease/commons/git/Commit.java b/commons.git/src/main/java/com/pmease/commons/git/Commit.java
index 1cff3a5e61..60aa3e10e3 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/Commit.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/Commit.java
@@ -1,17 +1,24 @@
package com.pmease.commons.git;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringUtils;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+
@SuppressWarnings("serial")
public class Commit extends BriefCommit {
public static final String ZERO_HASH = "0000000000000000000000000000000000000000";
- private final String message;
+ private final String body;
private final String note;
@@ -19,25 +26,94 @@ public class Commit extends BriefCommit {
private final List<FileChange> fileChanges;
+ public static class Builder {
+ String hash;
+ String subject;
+ String body;
+ String note;
+ UserInfo author;
+ UserInfo committer;
+ List<String> parents = Lists.newArrayList();
+ List<FileChange> changes = Lists.newArrayList();
+
+ public Builder hash(String hash) {
+ this.hash = hash;
+ return this;
+ }
+
+ public Builder subject(String subject) {
+ this.subject = subject;
+ return this;
+ }
+
+ public Builder body(String body) {
+ if (!StringUtils.isBlank(body))
+ this.body = body;
+
+ return this;
+ }
+
+ public Builder note(String note) {
+ this.note = note;
+ return this;
+ }
+
+ public Builder author(UserInfo author) {
+ this.author = author;
+ return this;
+ }
+
+ public Builder committer(UserInfo committer) {
+ this.committer = committer;
+ return this;
+ }
+
+ public Builder parents(List<String> parents) {
+ this.parents = parents;
+ return this;
+ }
+
+ public Builder changes(List<FileChange> changes) {
+ this.changes = changes;
+ return this;
+ }
+
+ public Commit build() {
+ return new Commit(
+ checkNotNull(hash, "hash"),
+ checkNotNull(committer, "committer"),
+ checkNotNull(author, "author"),
+ checkNotNull(subject, "subject"),
+ body, note,
+ checkNotNull(parents, "parents"),
+ checkNotNull(changes, "changes"));
+ }
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
public Commit(String hash, UserInfo committer, UserInfo author,
- String subject, @Nullable String messageBody,
+ String subject, @Nullable String body,
@Nullable String note, List<String> parentHashes,
List<FileChange> fileChanges) {
super(hash, committer, author, subject);
- if (messageBody != null)
- message = subject + "\n\n" + messageBody;
- else
- message = subject;
+ this.body = body;
this.note = note;
this.parentHashes = new ArrayList<>(parentHashes);
this.fileChanges = new ArrayList<>(fileChanges);
}
public String getMessage() {
- return message;
+ return Strings.isNullOrEmpty(body) ? getSubject() : getSubject() + "\n" + body;
}
+ public @Nullable String getMessageBody() {
+ return body;
+ }
+
public @Nullable String getNote() {
return note;
}
diff --git a/gitop.web/pom.xml b/gitop.web/pom.xml
index 41261d371b..9f799e946b 100644
--- a/gitop.web/pom.xml
+++ b/gitop.web/pom.xml
@@ -208,6 +208,12 @@
</exclusions>
</dependency>
-->
+
+ <dependency>
+ <groupId>org.ocpsoft.prettytime</groupId>
+ <artifactId>prettytime</artifactId>
+ <version>3.2.4.Final</version>
+ </dependency>
</dependencies>