summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorDavid Ostrovsky <david@ostrovsky.org>2015-02-15 20:31:29 +0100
committerDavid Ostrovsky <david@ostrovsky.org>2015-02-20 01:40:06 +0100
commitc0c4c6f09ac1d601a5d9fe9855e36e4b96b10335 (patch)
treeca02a75898d38203c510efef4037553e597691b4 /org.eclipse.jgit.test/tst
parent6c1f7393882baf8464859136a70199ea96fcae0f (diff)
downloadjgit-c0c4c6f09ac1d601a5d9fe9855e36e4b96b10335.tar.gz
jgit-c0c4c6f09ac1d601a5d9fe9855e36e4b96b10335.zip
ArchiveCommand: Allow to pass options to underlying stream
Current ArchiveCommand design doesn't allow to pass in options to underlying stream implementations. To overcome this, client has to implement custom format implementation (it cannot be derived from the existing one, because the classes are marked as final), and set the options using ThreadLocal, before the method ArchiveOutputStream createArchiveOutputStream(OutputStream s) is get called. This change extends the ArchiveCommand.Format by allowing to pass option map during creation of ArchiveOutputStream. ArchiveCommand is extended correspondingly. That way client can easily pass options to the underlying streams: Map<String, Object> level = ImmutableMap.<String, Object> of( "level", new Integer(9)); new ArchiveCommand(repo) .setFormat("zip") .setFormatOptions(level) .setTree(tree) .setPaths(paths) .setPrefix(prefix) .setOutputStream(sidebandOut) .call(); Change-Id: I1d92a1e5249117487da39d19c7593e4b812ad97a Signed-off-by: David Ostrovsky <david@ostrovsky.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
index 8cdf6a6c0d..44e70885ba 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import java.beans.Statement;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
@@ -58,6 +59,7 @@ import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.util.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -138,10 +140,17 @@ public class ArchiveCommandTest extends RepositoryTestCase {
git.add().addFilepattern(".").call();
git.commit().setMessage("updated file").call();
- git.archive().setOutputStream(new MockOutputStream())
- .setFormat(format.SUFFIXES.get(0)).setTree(first)
+ Map<String, Object> options = new HashMap<>();
+ Integer opt = Integer.valueOf(42);
+ options.put("foo", opt);
+ MockOutputStream out = new MockOutputStream();
+ git.archive().setOutputStream(out)
+ .setFormat(format.SUFFIXES.get(0))
+ .setFormatOptions(options)
+ .setTree(first)
.setPaths("file_1.txt").call();
+ assertEquals(opt.intValue(), out.getFoo());
assertEquals(UNEXPECTED_ARCHIVE_SIZE, 1, format.size());
assertEquals(UNEXPECTED_FILE_CONTENTS, "content_1_1", format.getByPath("file_1.txt"));
}
@@ -192,6 +201,22 @@ public class ArchiveCommandTest extends RepositoryTestCase {
public MockOutputStream createArchiveOutputStream(OutputStream s)
throws IOException {
+ return createArchiveOutputStream(s,
+ Collections.<String, Object> emptyMap());
+ }
+
+ public MockOutputStream createArchiveOutputStream(OutputStream s,
+ Map<String, Object> o) throws IOException {
+ for (Map.Entry<String, Object> p : o.entrySet()) {
+ try {
+ String methodName = "set"
+ + StringUtils.capitalize(p.getKey());
+ new Statement(s, methodName, new Object[] { p.getValue() })
+ .execute();
+ } catch (Exception e) {
+ throw new IOException("cannot set option: " + p.getKey(), e);
+ }
+ }
return new MockOutputStream();
}
@@ -205,7 +230,17 @@ public class ArchiveCommandTest extends RepositoryTestCase {
}
}
- private class MockOutputStream extends OutputStream {
+ public class MockOutputStream extends OutputStream {
+
+ private int foo;
+
+ public void setFoo(int foo) {
+ this.foo = foo;
+ }
+
+ public int getFoo() {
+ return foo;
+ }
@Override
public void write(int b) throws IOException {