The Unified and Autonomous Development Platform
Use PathAndContent as interface
robin shine298d9edfb1be
diff --git a/commons.git/src/main/java/com/pmease/commons/git/PathAndContent.java b/commons.git/src/main/java/com/pmease/commons/git/PathAndContent.javaindex 95f09d0ae7..b52a0c2559 100644--- a/commons.git/src/main/java/com/pmease/commons/git/PathAndContent.java+++ b/commons.git/src/main/java/com/pmease/commons/git/PathAndContent.java@@ -2,27 +2,34 @@ package com.pmease.commons.git;import java.io.Serializable;-import com.google.common.base.Preconditions;+public interface PathAndContent extends Serializable {-public class PathAndContent implements Serializable {+ String getPath();- private static final long serialVersionUID = 1L;+ byte[] getContent();- private final String path;-- private final byte[] content;+ public static class Immutable implements PathAndContent {- public PathAndContent(String path, byte[] content) {- this.path = Preconditions.checkNotNull(GitUtils.normalizePath(path));- this.content = content;- }+ private static final long serialVersionUID = 1L;- public String getPath() {- return path;- }+ private final String path;++ private final byte[] content;++ public Immutable(String path, byte[] content) {+ this.path = path;+ this.content = content;+ }++ @Override+ public String getPath() {+ return path;+ }- public byte[] getContent() {- return content;+ @Override+ public byte[] getContent() {+ return content;+ }+}-}diff --git a/commons.git/src/test/java/com/pmease/commons/git/FileEditTest.java b/commons.git/src/test/java/com/pmease/commons/git/FileEditTest.javaindex 2dcf5f0f4c..a0371c1ab1 100644--- a/commons.git/src/test/java/com/pmease/commons/git/FileEditTest.java+++ b/commons.git/src/test/java/com/pmease/commons/git/FileEditTest.java@@ -95,7 +95,7 @@ public class FileEditTest extends AbstractGitTest {PersonIdent person = new PersonIdent(repo);FileEdit edit = new FileEdit("server/src/com/example/a/a.java",- new PathAndContent("client/c.java", "a".getBytes()));+ new PathAndContent.Immutable("client/c.java", "a".getBytes()));ObjectId newCommitId = edit.commit(repo, refName, oldCommitId, oldCommitId, person, "test rename");try (RevWalk revWalk = new RevWalk(repo)) {RevTree revTree = revWalk.parseCommit(newCommitId).getTree();@@ -125,7 +125,7 @@ public class FileEditTest extends AbstractGitTest {PersonIdent person = new PersonIdent(repo);FileEdit edit = new FileEdit("server/src/com/example/a",- new PathAndContent("client/c.java", "a".getBytes()));+ new PathAndContent.Immutable("client/c.java", "a".getBytes()));try {edit.commit(repo, refName, oldCommitId, oldCommitId, person, "test rename tree");assertTrue("A NotFileException should be thrown", false);@@ -151,7 +151,7 @@ public class FileEditTest extends AbstractGitTest {PersonIdent person = new PersonIdent(repo);FileEdit edit = new FileEdit("server/src/com/example/a/a.java",- new PathAndContent("client/a.java/a.java", "a".getBytes()));+ new PathAndContent.Immutable("client/a.java/a.java", "a".getBytes()));try {edit.commit(repo, refName, oldCommitId, oldCommitId, person, "test rename tree");assertTrue("A NotTreeException should be thrown", false);@@ -176,7 +176,7 @@ public class FileEditTest extends AbstractGitTest {ObjectId oldCommitId = repo.resolve(refName);PersonIdent person = new PersonIdent(repo);- FileEdit edit = new FileEdit(null, new PathAndContent("/server/src/com/example/c/c.java", "c".getBytes()));+ FileEdit edit = new FileEdit(null, new PathAndContent.Immutable("/server/src/com/example/c/c.java", "c".getBytes()));ObjectId newCommitId = edit.commit(repo, refName, oldCommitId, oldCommitId, person, "test add");try (RevWalk revWalk = new RevWalk(repo)) {@@ -189,7 +189,7 @@ public class FileEditTest extends AbstractGitTest {}oldCommitId = newCommitId;- edit = new FileEdit(null, new PathAndContent("/common/common.java", "common".getBytes()));+ edit = new FileEdit(null, new PathAndContent.Immutable("/common/common.java", "common".getBytes()));newCommitId = edit.commit(repo, refName, oldCommitId, oldCommitId, person, "test add");try (RevWalk revWalk = new RevWalk(repo)) {@@ -220,7 +220,7 @@ public class FileEditTest extends AbstractGitTest {ObjectId oldCommitId = repo.resolve(refName);PersonIdent person = new PersonIdent(repo);- FileEdit edit = new FileEdit(null, new PathAndContent("client/a.java", "a".getBytes()));+ FileEdit edit = new FileEdit(null, new PathAndContent.Immutable("client/a.java", "a".getBytes()));try {edit.commit(repo, refName, oldCommitId, oldCommitId, person, "test rename tree");assertTrue("An ObjectAlreadyExistException should be thrown", false);@@ -242,7 +242,7 @@ public class FileEditTest extends AbstractGitTest {ObjectId newCommitId = repo.resolve(refName);- FileEdit edit = new FileEdit(null, new PathAndContent("/server/src/com/example/c/c.java", "c".getBytes()));+ FileEdit edit = new FileEdit(null, new PathAndContent.Immutable("/server/src/com/example/c/c.java", "c".getBytes()));try {edit.commit(repo, refName, oldCommitId, oldCommitId, person, "test add");assertTrue("An ObsoleteCommitException should be thrown", false);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.javaindex 840f77d16b..e0b046171f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.java@@ -49,7 +49,7 @@ public abstract class EditSavePanel extends Panel {private final String oldPath;- private final IModel<PathAndContent> newFileModel;+ private final PathAndContent newFile;private final CancelListener cancelListener;@@ -62,14 +62,14 @@ public abstract class EditSavePanel extends Panel {private String detailCommitMessage;public EditSavePanel(String id, IModel<Repository> repoModel, String refName,- @Nullable String oldPath, @Nullable IModel<PathAndContent> newFileModel,+ @Nullable String oldPath, @Nullable PathAndContent newFile,ObjectId prevCommitId, @Nullable CancelListener cancelListener) {super(id);this.repoModel = repoModel;this.refName = refName;this.oldPath = oldPath;- this.newFileModel = newFileModel;+ this.newFile = newFile;this.cancelListener = cancelListener;this.prevCommitId = prevCommitId;}@@ -81,7 +81,6 @@ public abstract class EditSavePanel extends Panel {elseoldName = oldPath;- PathAndContent newFile = getNewFile();if (newFile == null) {return "Delete " + oldName;} else {@@ -180,7 +179,7 @@ public abstract class EditSavePanel extends Panel {protected void onSubmit(AjaxRequestTarget target, Form<?> form) {super.onSubmit(target, form);- if (newFileModel != null && StringUtils.isBlank(newFileModel.getObject().getPath())) {+ if (newFile != null && StringUtils.isBlank(newFile.getPath())) {EditSavePanel.this.error("Please specify file name.");target.add(feedback);return;@@ -194,7 +193,7 @@ public abstract class EditSavePanel extends Panel {commitMessage += "\n\n" + detailCommitMessage;User user = Preconditions.checkNotNull(GitPlex.getInstance(UserManager.class).getCurrent());- FileEdit edit = new FileEdit(oldPath, getNewFile());+ FileEdit edit = new FileEdit(oldPath, newFile);ObjectId newCommitId = null;while(newCommitId == null) {try {@@ -284,14 +283,6 @@ public abstract class EditSavePanel extends Panel {setOutputMarkupId(true);}- @Nullable- private PathAndContent getNewFile() {- if (newFileModel != null)- return newFileModel.getObject();- else- return null;- }-@Overridepublic void renderHead(IHeaderResponse response) {super.renderHead(response);@@ -313,8 +304,6 @@ public abstract class EditSavePanel extends Panel {@Overrideprotected void onDetach() {repoModel.detach();- if (newFileModel != null)- newFileModel.detach();super.onDetach();}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.javaindex 6a42dc47fe..f464ecd000 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.java@@ -15,7 +15,6 @@ import org.apache.wicket.markup.head.JavaScriptHeaderItem;import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.panel.Panel;-import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.request.IRequestParameters;import org.apache.wicket.request.cycle.RequestCycle;@@ -24,6 +23,7 @@ import org.apache.wicket.request.resource.JavaScriptResourceReference;import org.eclipse.jgit.lib.ObjectId;import com.google.common.base.Charsets;+import com.pmease.commons.git.GitUtils;import com.pmease.commons.git.PathAndContent;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.component.editsave.EditSavePanel;@@ -54,11 +54,11 @@ public abstract class FileEditPanel extends Panel {super(id);this.repoModel = repoModel;this.refName = refName;- this.oldPath = oldPath;+ this.oldPath = GitUtils.normalizePath(oldPath);this.content = content;this.prevCommitId = prevCommitId;- newPath = oldPath;+ newPath = this.oldPath;}@Override@@ -112,15 +112,20 @@ public abstract class FileEditPanel extends Panel {add(new WebMarkupContainer("preview"));- IModel<PathAndContent> newFileModel = new AbstractReadOnlyModel<PathAndContent>() {+ PathAndContent newFile = new PathAndContent() {@Override- public PathAndContent getObject() {- return new PathAndContent(newPath, content.getBytes(Charsets.UTF_8));+ public String getPath() {+ return newPath;}-++ @Override+ public byte[] getContent() {+ return content.getBytes(Charsets.UTF_8);+ }+};- add(editSavePanel = new EditSavePanel("save", repoModel, refName, oldPath, newFileModel, prevCommitId, null) {+ add(editSavePanel = new EditSavePanel("save", repoModel, refName, oldPath, newFile, prevCommitId, null) {@Overrideprotected void onCommitted(AjaxRequestTarget target, ObjectId newCommitId) {@@ -163,7 +168,7 @@ public abstract class FileEditPanel extends Panel {}public void onNewPathChange(AjaxRequestTarget target, String newPath) {- this.newPath = newPath;+ this.newPath = GitUtils.normalizePath(newPath);editSavePanel.onNewPathChange(target);target.appendJavaScript(String.format("gitplex.fileEdit.setMode('%s', '%s');",