String action = doUpdate ? "Updating " : "Building ";
log(action + archiveType + ": " + zipFile.getAbsolutePath());
ZipOutputStream zOut = null;
try {
if (!skipWriting) {
zOut = new ZipOutputStream(zipFile);
zOut.setEncoding(encoding);
if (doCompress) {
zOut.setMethod(ZipOutputStream.DEFLATED);
} else {
zOut.setMethod(ZipOutputStream.STORED);
}
}
initZipOutputStream(zOut);
// Add the explicit filesets to the archive.
for (int i = 0; i < fss.length; i++) {
if (addThem[i].length != 0) {
addResources(fss[i], addThem[i], zOut);
}
}
if (doUpdate) {
addingNewFiles = false;
ZipFileSet oldFiles = new ZipFileSet();
oldFiles.setProject(getProject());
oldFiles.setSrc(renamedFile);
for (int i = 0; i < addedFiles.size(); i++) {
PatternSet.NameEntry ne = oldFiles.createExclude();
ne.setName((String) addedFiles.elementAt(i));
}
DirectoryScanner ds =
oldFiles.getDirectoryScanner(getProject());
((ZipScanner) ds).setEncoding(encoding);
String[] f = ds.getIncludedFiles();
Resource[] r = new Resource[f.length];
for (int i = 0; i < f.length; i++) {
r[i] = ds.getResource(f[i]);
}
if (!doFilesonly) {
String[] d = ds.getIncludedDirectories();
Resource[] dr = new Resource[d.length];
for (int i = 0; i < d.length; i++) {
dr[i] = ds.getResource(d[i]);
}
Resource[] tmp = r;
r = new Resource[tmp.length + dr.length];
System.arraycopy(dr, 0, r, 0, dr.length);
System.arraycopy(tmp, 0, r, dr.length, tmp.length);
}
addResources(oldFiles, r, zOut);
}
finalizeZipOutputStream(zOut);
// If we've been successful on an update, delete the
// temporary file
if (doUpdate) {
if (!renamedFile.delete()) {
log ("Warning: unable to delete temporary file "
+ renamedFile.getName(), Project.MSG_WARN);
}
}
success = true;
} finally {
// Close the output stream.
try {
if (zOut != null) {
zOut.close();
}
} catch (IOException ex) {
// If we're in this finally clause because of an
// exception, we don't really care if there's an
// exception when closing the stream. E.g. if it