Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce2010-08-23 14:07:48 -0400
committerShawn O. Pearce2010-08-23 14:09:56 -0400
commitaf208f276361c058f71abf5ae155ba51704b99e9 (patch)
treea747b4d178e74bb9effa91a50b6cbc9670dd5431 /org.eclipse.egit.core.test
parentf01b3b007c43adc1ac7c9b3c876453a868f85bbe (diff)
downloadegit-af208f276361c058f71abf5ae155ba51704b99e9.tar.gz
egit-af208f276361c058f71abf5ae155ba51704b99e9.tar.xz
egit-af208f276361c058f71abf5ae155ba51704b99e9.zip
Remove ObjectWriter and replace it with ObjectInserter
JGit won't support the deprecated ObjectWriter API anymore, so we have to use the newer ObjectInserter style throughout EGit. Change-Id: I95e2c705af5d7ff6c2e7da78ec3a60a1c718708e Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java38
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java36
2 files changed, 49 insertions, 25 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
index 9113b8cd9..155d150d1 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
@@ -27,7 +28,7 @@ import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileTreeEntry;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
@@ -55,7 +56,7 @@ public class HistoryTest extends GitTestCase {
private File gitDir;
private Repository thisGit;
private Tree tree;
- private ObjectWriter objectWriter;
+ private ObjectInserter inserter;
@Before
public void setUp() throws Exception {
@@ -67,17 +68,17 @@ public class HistoryTest extends GitTestCase {
thisGit = new FileRepository(gitDir);
workDir = thisGit.getWorkTree();
thisGit.create();
- objectWriter = new ObjectWriter(thisGit);
+ inserter = thisGit.newObjectInserter();
tree = new Tree(thisGit);
Tree projectTree = tree.addTree("Project-1");
File project1_a_txt = createFile("Project-1/A.txt","A.txt - first version\n");
addFile(projectTree,project1_a_txt);
- projectTree.setId(objectWriter.writeTree(projectTree));
+ projectTree.setId(inserter.insert(Constants.OBJ_TREE, projectTree.format()));
File project1_b_txt = createFile("Project-1/B.txt","B.txt - first version\n");
addFile(projectTree,project1_b_txt);
- projectTree.setId(objectWriter.writeTree(projectTree));
- tree.setId(objectWriter.writeTree(tree));
+ projectTree.setId(inserter.insert(Constants.OBJ_TREE, projectTree.format()));
+ tree.setId(inserter.insert(Constants.OBJ_TREE, tree.format()));
CommitBuilder commit = new CommitBuilder();
commit.setAuthor(new PersonIdent(jauthor, new Date(0L), TimeZone
.getTimeZone("GMT+1")));
@@ -85,7 +86,7 @@ public class HistoryTest extends GitTestCase {
.getTimeZone("GMT+1")));
commit.setMessage("Foo\n\nMessage");
commit.setTreeId(tree.getTreeId());
- ObjectId commitId = objectWriter.writeCommit(commit);
+ ObjectId commitId = inserter.insert(commit);
tree = new Tree(thisGit);
projectTree = tree.addTree("Project-1");
@@ -93,8 +94,8 @@ public class HistoryTest extends GitTestCase {
File project1_b_v2_txt = createFile("Project-1/B.txt","B.txt - second version\n");
addFile(projectTree,project1_b_v2_txt);
- projectTree.setId(objectWriter.writeTree(projectTree));
- tree.setId(objectWriter.writeTree(tree));
+ projectTree.setId(inserter.insert(Constants.OBJ_TREE, projectTree.format()));
+ tree.setId(inserter.insert(Constants.OBJ_TREE, tree.format()));
commit = new CommitBuilder();
commit.setAuthor(new PersonIdent(jauthor, new Date(0L), TimeZone
.getTimeZone("GMT+1")));
@@ -103,7 +104,8 @@ public class HistoryTest extends GitTestCase {
commit.setMessage("Modified");
commit.setParentId(commitId);
commit.setTreeId(tree.getTreeId());
- commitId = objectWriter.writeCommit(commit);
+ commitId = inserter.insert(commit);
+ inserter.flush();
RefUpdate lck = thisGit.updateRef("refs/heads/master");
assertNotNull("obtained lock", lck);
@@ -115,8 +117,22 @@ public class HistoryTest extends GitTestCase {
operation.execute(null);
}
+ @Override
+ public void tearDown() throws Exception {
+ if (inserter != null) {
+ inserter.release();
+ }
+ super.tearDown();
+ }
+
private void addFile(Tree t,File f) throws IOException {
- ObjectId id = objectWriter.writeBlob(f);
+ ObjectId id;
+ FileInputStream in = new FileInputStream(f);
+ try {
+ id = inserter.insert(Constants.OBJ_BLOB, in.getChannel().size(), in);
+ } finally {
+ in.close();
+ }
t.addEntry(new FileTreeEntry(t,id,f.getName().getBytes("UTF-8"),false));
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
index 312bc0ce8..f0cddc272 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
@@ -28,7 +28,7 @@ import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileTreeEntry;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
@@ -71,7 +71,7 @@ public class ConnectProviderOperationTest extends GitTestCase {
project.createSourceFolder();
IFile fileA = project.getProject().getFolder("src").getFile("A.java");
String srcA = "class A {\n" + "}\n";
- fileA.create(new ByteArrayInputStream(srcA.getBytes()), false, null);
+ fileA.create(new ByteArrayInputStream(srcA.getBytes("UTF-8")), false, null);
Repository thisGit = new FileRepository(gitDir);
thisGit.create();
@@ -79,18 +79,26 @@ public class ConnectProviderOperationTest extends GitTestCase {
Tree prjTree = rootTree.addTree(project.getProject().getName());
Tree srcTree = prjTree.addTree("src");
FileTreeEntry entryA = srcTree.addFile("A.java");
- ObjectWriter writer = new ObjectWriter(thisGit);
- entryA.setId(writer.writeBlob(fileA.getRawLocation().toFile()));
- srcTree.setId(writer.writeTree(srcTree));
- prjTree.setId(writer.writeTree(prjTree));
- rootTree.setId(writer.writeTree(rootTree));
- CommitBuilder commit = new CommitBuilder();
- commit.setTreeId(rootTree.getTreeId());
- commit.setAuthor(new PersonIdent("J. Git", "j.git@egit.org", new Date(
- 60876075600000L), TimeZone.getTimeZone("GMT+1")));
- commit.setCommitter(commit.getAuthor());
- commit.setMessage("testNewUnsharedFile\n\nJunit tests\n");
- ObjectId id = writer.writeCommit(commit);
+
+ ObjectId id;
+ ObjectInserter inserter = thisGit.newObjectInserter();
+ try {
+ entryA.setId(inserter.insert(Constants.OBJ_BLOB, srcA.getBytes("UTF-8")));
+ srcTree.setId(inserter.insert(Constants.OBJ_TREE, srcTree.format()));
+ prjTree.setId(inserter.insert(Constants.OBJ_TREE, prjTree.format()));
+ rootTree.setId(inserter.insert(Constants.OBJ_TREE, rootTree.format()));
+ CommitBuilder commit = new CommitBuilder();
+ commit.setTreeId(rootTree.getTreeId());
+ commit.setAuthor(new PersonIdent("J. Git", "j.git@egit.org",
+ new Date(60876075600000L), TimeZone.getTimeZone("GMT+1")));
+ commit.setCommitter(commit.getAuthor());
+ commit.setMessage("testNewUnsharedFile\n\nJunit tests\n");
+ id = inserter.insert(commit);
+ inserter.flush();
+ } finally {
+ inserter.release();
+ }
+
RefUpdate lck = thisGit.updateRef("refs/heads/master");
assertNotNull("obtained lock", lck);
lck.setNewObjectId(id);

Back to the top