@@ -1674,25 +1674,33 @@ public class Zip extends MatchingTask {
}
}
/*
* This is a hacky construct to extend the zipFile method to
* support a new parameter (extra fields to preserve) without
* breaking subclasses that override the old method signature.
*/
private static ThreadLocal currentZipExtra = new ThreadLocal() {
protected Object initialValue() {
return null;
}
};
/**
* Adds a new entry to the archive, takes care of duplicates as well.
*
* @param in the stream to read data for the entry from. The
* caller of the method is responsible for closing the stream.
* @param zOut the stream to write to.
* @param vPath the name this entry shall have in the archive.
* @param lastModified last modification time for the entry.
* @param fromArchive the original archive we are copying this
* entry from, will be null if we are not copying from an archive.
* @param mode the Unix permissions to set.
*
* @since Ant 1.5.2
* @throws IOException on error
* Provides the extra fields for the zip entry currently being
* added to the archive - if any.
* @since Ant 1.8.0
*/
protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath,
long lastModified, File fromArchive, int mode)
throws IOException {
zipFile(in, zOut, vPath, lastModified, fromArchive, mode, null);
protected final ZipExtraField[] getCurrentExtraFields() {
return (ZipExtraField[]) currentZipExtra.get();
}
/**
* Sets the extra fields for the zip entry currently being
* added to the archive - if any.
* @since Ant 1.8.0
*/
protected final void setCurrentExtraFields(ZipExtraField[] extra) {
currentZipExtra.set(extra);
}
/**
@@ -1706,16 +1714,13 @@ public class Zip extends MatchingTask {
* @param fromArchive the original archive we are copying this
* entry from, will be null if we are not copying from an archive.
* @param mode the Unix permissions to set.
* @param extra ZipExtraFields to add
*
* @since Ant 1.8.0
* @since Ant 1.5.2
* @throws IOException on error
*/
protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath,
long lastModified, File fromArchive,
int mode, ZipExtraField[] extra)
long lastModified, File fromArchive, int mode)
throws IOException {
// fromArchive is used in subclasses overriding this method
if (entries.contains(vPath)) {
@@ -1784,6 +1789,7 @@ public class Zip extends MatchingTask {
}
ze.setUnixMode(mode);
ZipExtraField[] extra = getCurrentExtraFields();
if (extra != null) {
ze.setExtraFields(extra);
}
@@ -1802,6 +1808,34 @@ public class Zip extends MatchingTask {
addedFiles.addElement(vPath);
}
/**
* Adds a new entry to the archive, takes care of duplicates as well.
*
* @param in the stream to read data for the entry from. The
* caller of the method is responsible for closing the stream.
* @param zOut the stream to write to.
* @param vPath the name this entry shall have in the archive.
* @param lastModified last modification time for the entry.
* @param fromArchive the original archive we are copying this
* entry from, will be null if we are not copying from an archive.
* @param mode the Unix permissions to set.
* @param extra ZipExtraFields to add
*
* @since Ant 1.8.0
* @throws IOException on error
*/
protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath,
long lastModified, File fromArchive,
int mode, ZipExtraField[] extra)
throws IOException {
try {
setCurrentExtraFields(extra);
zipFile(in, zOut, vPath, lastModified, fromArchive, mode);
} finally {
setCurrentExtraFields(null);
}
}
/**
* Method that gets called when adding from <code>java.io.File</code> instances.
*