From 1547eaf7c57e93b3ff7fb9d2450fe3e87ba614ed Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 3 Dec 2012 09:55:02 -0800 Subject: [RFC] archive: Switch to commons-compress as ZIP archiver The Apache Commons Compress library provides a similar interface to java.util.zip with some features not found in java.util.zip, including support for inclusion of metadata (file mode and symlink targets) and support for multiple file formats (zip, .tar.xz, etc). Use it, in preparation for making use of these features. No functional change intended yet. A previous version of this patch used plexus-archiver. That is a heavier-weight dependency and offers a less convenient interface. Thanks to James Moger and Chris Aniszczyk for advice. Change-Id: Id01146950bb9c18dae0169311e3cde2c3bfa675e --- org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'org.eclipse.jgit.pgm/src/org/eclipse') diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java index 786524eca2..ec937a3cc3 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java @@ -46,9 +46,9 @@ package org.eclipse.jgit.pgm; import java.lang.String; import java.lang.System; import java.text.MessageFormat; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.ObjectLoader; @@ -69,7 +69,7 @@ class Archive extends TextBuiltin { final TreeWalk walk = new TreeWalk(db); final ObjectReader reader = walk.getObjectReader(); final MutableObjectId idBuf = new MutableObjectId(); - final ZipOutputStream out = new ZipOutputStream(outs); + final ZipArchiveOutputStream out = new ZipArchiveOutputStream(outs); if (tree == null) throw die(CLIText.get().treeIsRequired); @@ -87,11 +87,12 @@ class Archive extends TextBuiltin { continue; walk.getObjectId(idBuf, 0); - final ZipEntry entry = new ZipEntry(name); + final ZipArchiveEntry entry = new ZipArchiveEntry(name); final ObjectLoader loader = reader.open(idBuf); entry.setSize(loader.getSize()); - out.putNextEntry(entry); + out.putArchiveEntry(entry); loader.copyTo(out); + out.closeArchiveEntry(); if (mode != FileMode.REGULAR_FILE) System.err.println(MessageFormat.format( // -- cgit v1.2.3