metaInf = new DefaultMetaInf();
}
JarExporter exporter = new JarExporter(out);
exporter.open();
exporter.setProperties(metaInf.getProperties());
ProgressTracker tracker = null;
if (opts.getListener() != null) {
tracker = new ProgressTracker();
exporter.setVerbose(opts.getListener());
}
// merge
MetaInf inf = opts.getMetaInf();
ZipFile zip = new ZipFile(src.getFile(), ZipFile.OPEN_READ);
if (opts.getPostProcessor() == null) {
// no post processor, we keep all files except the properties
Enumeration e = zip.entries();
while (e.hasMoreElements()) {
ZipEntry entry = (ZipEntry) e.nextElement();
String path = entry.getName();
if (!path.equals(Constants.META_DIR + "/" + Constants.PROPERTIES_XML)) {
exporter.write(zip, entry);
}
}
} else {
Set<String> keep = new HashSet<String>();
keep.add(Constants.META_DIR + "/");
keep.add(Constants.META_DIR + "/" + Constants.NODETYPES_CND);
keep.add(Constants.META_DIR + "/" + Constants.CONFIG_XML);
keep.add(Constants.META_DIR + "/" + Constants.FILTER_XML);
Enumeration e = zip.entries();
while (e.hasMoreElements()) {
ZipEntry entry = (ZipEntry) e.nextElement();
String path = entry.getName();
if (!path.startsWith(Constants.META_DIR + "/") || keep.contains(path)) {
exporter.write(zip, entry);
}
}
}
zip.close();
// write updated properties
ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
inf.getProperties().storeToXML(tmpOut, "FileVault Package Properties", "utf-8");
exporter.writeFile(new ByteArrayInputStream(tmpOut.toByteArray()), Constants.META_DIR + "/" + Constants.PROPERTIES_XML);
if (tracker != null) {
tracker.track("A", Constants.META_DIR + "/" + Constants.PROPERTIES_XML);
}
if (opts.getPostProcessor() != null) {
opts.getPostProcessor().process(exporter);
}