File basedir = scanner.getBasedir();
for (int j = 0; j < files.length; j++) {
log("Adding file " + files[j] + " to fileset",
Project.MSG_VERBOSE);
ZipFileSet zf = new ZipFileSet();
zf.setSrc(new File(basedir, files[j]));
filesets.addElement(zf);
filesetsFromGroupfilesets.addElement(zf);
}
}
// collect filesets to pass them to getResourcesToAdd
Vector vfss = new Vector();
if (baseDir != null) {
FileSet fs = (FileSet) getImplicitFileSet().clone();
fs.setDir(baseDir);
vfss.addElement(fs);
}
for (int i = 0; i < filesets.size(); i++) {
FileSet fs = (FileSet) filesets.elementAt(i);
vfss.addElement(fs);
}
FileSet[] fss = new FileSet[vfss.size()];
vfss.copyInto(fss);
boolean success = false;
try {
Resource[][] addThem = getResourcesToAdd(fss, zipFile, false);
// quick exit if the target is up to date
// can also handle empty archives
if (isEmpty(addThem)) {
return;
}
if (doUpdate) {
renamedFile =
fileUtils.createTempFile("zip", ".tmp",
fileUtils.getParentFile(zipFile));
try {
if (!zipFile.renameTo(renamedFile)) {
throw new BuildException("Unable to rename old file "
+ "to temporary file");
}
} catch (SecurityException e) {
throw new BuildException("Not allowed to rename old file "
+ "to temporary file");
}
}
String action = doUpdate ? "Updating " : "Building ";
log(action + archiveType + ": " + zipFile.getAbsolutePath());
ZipOutputStream zOut =
new ZipOutputStream(new FileOutputStream(zipFile));
zOut.setEncoding(encoding);
try {
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.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());
String[] f = ds.getIncludedFiles();
Resource[] r = new Resource[f.length];
for (int i = 0; i < f.length; i++) {
r[i] = ds.getResource(f[i]);
}