summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.archive/src
diff options
context:
space:
mode:
authorJonathan Nieder <jrn@google.com>2013-06-06 18:39:04 -0700
committerJonathan Nieder <jrn@google.com>2013-06-06 18:39:04 -0700
commit56cb2d925c93eadf03a551a2f40bbc9cb2b3241a (patch)
treeb42ae518cd96c0342b85f3313b744a50ddd47156 /org.eclipse.jgit.archive/src
parentebfe85d0374aee1992d01029c12338da3d67e26b (diff)
downloadjgit-56cb2d925c93eadf03a551a2f40bbc9cb2b3241a.tar.gz
jgit-56cb2d925c93eadf03a551a2f40bbc9cb2b3241a.zip
Pick default archive format based on filename suffix
Introduce a setFilename() method for ArchiveCommand so callers can specify the intended filename of the produced archive. If the filename ends with .tar, the format will default to tar; if .zip, zip; if .tar.gz, gzip-compressed tar; and so on. This doesn't affect "jgit archive" because it doesn't support the --output=<file> option yet. A later patch might do that. Change-Id: Ic0236a70f7aa7f2271c3ef11083b21ee986b4df5
Diffstat (limited to 'org.eclipse.jgit.archive/src')
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java10
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java11
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java11
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java11
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java10
5 files changed, 53 insertions, 0 deletions
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
index 228de7c379..23f4beda14 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
@@ -44,6 +44,9 @@ package org.eclipse.jgit.archive;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -57,6 +60,9 @@ import org.eclipse.jgit.lib.ObjectLoader;
* Unix TAR format (ustar + some PAX extensions).
*/
public class TarFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
+ private static final List<String> SUFFIXES =
+ Collections.unmodifiableList(Arrays.asList(".tar"));
+
public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
TarArchiveOutputStream out = new TarArchiveOutputStream(s, "UTF-8"); //$NON-NLS-1$
out.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
@@ -90,4 +96,8 @@ public class TarFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
loader.copyTo(out);
out.closeArchiveEntry();
}
+
+ public Iterable<String> suffixes() {
+ return SUFFIXES;
+ }
}
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java
index 9883118ea2..d3482d1813 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java
@@ -44,6 +44,9 @@ package org.eclipse.jgit.archive;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
@@ -55,6 +58,10 @@ import org.eclipse.jgit.lib.ObjectLoader;
* bzip2-compressed tarball (tar.bz2) format.
*/
public class Tbz2Format implements ArchiveCommand.Format<ArchiveOutputStream> {
+ private static final List<String> SUFFIXES =
+ Collections.unmodifiableList(Arrays.asList(
+ ".tar.bz2", ".tbz", ".tbz2"));
+
private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
@@ -68,4 +75,8 @@ public class Tbz2Format implements ArchiveCommand.Format<ArchiveOutputStream> {
throws IOException {
tarFormat.putEntry(out, path, mode, loader);
}
+
+ public Iterable<String> suffixes() {
+ return SUFFIXES;
+ }
}
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java
index 1c72bf8dcc..fe1350cbb0 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java
@@ -44,6 +44,9 @@ package org.eclipse.jgit.archive;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
@@ -55,6 +58,10 @@ import org.eclipse.jgit.lib.ObjectLoader;
* gzip-compressed tarball (tar.gz) format.
*/
public class TgzFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
+ private static final List<String> SUFFIXES =
+ Collections.unmodifiableList(Arrays.asList(
+ ".tar.gz", ".tgz"));
+
private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
@@ -68,4 +75,8 @@ public class TgzFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
throws IOException {
tarFormat.putEntry(out, path, mode, loader);
}
+
+ public Iterable<String> suffixes() {
+ return SUFFIXES;
+ }
}
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java
index d1547c683c..c09b0621a7 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java
@@ -44,6 +44,9 @@ package org.eclipse.jgit.archive;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
@@ -55,6 +58,10 @@ import org.eclipse.jgit.lib.ObjectLoader;
* Xz-compressed tar (tar.xz) format.
*/
public class TxzFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
+ private static final List<String> SUFFIXES =
+ Collections.unmodifiableList(Arrays.asList(
+ ".tar.xz", ".txz"));
+
private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
@@ -68,4 +75,8 @@ public class TxzFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
throws IOException {
tarFormat.putEntry(out, path, mode, loader);
}
+
+ public Iterable<String> suffixes() {
+ return SUFFIXES;
+ }
}
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java
index a0906d4dd5..00c962bc98 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java
@@ -44,6 +44,9 @@ package org.eclipse.jgit.archive;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
@@ -56,6 +59,9 @@ import org.eclipse.jgit.lib.ObjectLoader;
* PKWARE's ZIP format.
*/
public class ZipFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
+ private static final List<String> SUFFIXES =
+ Collections.unmodifiableList(Arrays.asList(".zip"));
+
public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
return new ZipArchiveOutputStream(s);
}
@@ -79,4 +85,8 @@ public class ZipFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
loader.copyTo(out);
out.closeArchiveEntry();
}
+
+ public Iterable<String> suffixes() {
+ return SUFFIXES;
+ }
}