String prefix = "";
String fullpath = "";
int dirMode = ArchiveFileSet.DEFAULT_DIR_MODE;
int fileMode = ArchiveFileSet.DEFAULT_FILE_MODE;
ArchiveFileSet zfs = null;
if (fileset instanceof ArchiveFileSet) {
zfs = (ArchiveFileSet) fileset;
prefix = zfs.getPrefix(getProject());
fullpath = zfs.getFullpath(getProject());
dirMode = zfs.getDirMode(getProject());
fileMode = zfs.getFileMode(getProject());
}
if (prefix.length() > 0 && fullpath.length() > 0) {
throw new BuildException("Both prefix and fullpath attributes must"
+ " not be set on the same fileset.");
}
if (resources.length != 1 && fullpath.length() > 0) {
throw new BuildException("fullpath attribute may only be specified"
+ " for filesets that specify a single"
+ " file.");
}
if (prefix.length() > 0) {
if (!prefix.endsWith("/") && !prefix.endsWith("\\")) {
prefix += "/";
}
addParentDirs(null, prefix, zOut, "", dirMode);
}
ZipFile zf = null;
try {
boolean dealingWithFiles = false;
File base = null;
if (zfs == null || zfs.getSrc(getProject()) == null) {
dealingWithFiles = true;
base = fileset.getDir(getProject());
} else if (zfs instanceof ZipFileSet) {
zf = new ZipFile(zfs.getSrc(getProject()), encoding);
}
for (int i = 0; i < resources.length; i++) {
String name = null;
if (fullpath.length() > 0) {
name = fullpath;
} else {
name = resources[i].getName();
}
name = name.replace(File.separatorChar, '/');
if ("".equals(name)) {
continue;
}
if (resources[i].isDirectory()) {
if (doFilesonly) {
continue;
}
int thisDirMode = zfs != null && zfs.hasDirModeBeenSet()
? dirMode : getUnixMode(resources[i], zf, dirMode);
addDirectoryResource(resources[i], name, prefix,
base, zOut,
dirMode, thisDirMode);
} else { // !isDirectory
addParentDirs(base, name, zOut, prefix, dirMode);
if (dealingWithFiles) {
File f = FILE_UTILS.resolveFile(base,
resources[i].getName());
zipFile(f, zOut, prefix + name, fileMode);
} else {
int thisFileMode =
zfs != null && zfs.hasFileModeBeenSet()
? fileMode : getUnixMode(resources[i], zf,
fileMode);
addResource(resources[i], name, prefix,
zOut, thisFileMode, zf,
zfs == null
? null : zfs.getSrc(getProject()));
}
}
}
} finally {
if (zf != null) {