in src/main/org/apache/tools/ant/taskdefs/Zip.java [919:1014]
protected final void addResources(final FileSet fileset, final Resource[] resources,
final ZipOutputStream zOut)
throws IOException {
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.isEmpty() && !fullpath.isEmpty()) {
throw new BuildException(
"Both prefix and fullpath attributes must not be set on the same fileset.");
}
if (resources.length != 1 && !fullpath.isEmpty()) {
throw new BuildException(
"fullpath attribute may only be specified for filesets that specify a single file.");
}
if (!prefix.isEmpty()) {
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 (Resource resource : resources) {
String name;
if (fullpath.isEmpty()) {
name = resource.getName();
} else {
name = fullpath;
}
name = name.replace(File.separatorChar, '/');
if (name.isEmpty()) {
continue;
}
if (resource.isDirectory()) {
if (doFilesonly) {
continue;
}
final int thisDirMode = zfs != null && zfs.hasDirModeBeenSet()
? dirMode : getUnixMode(resource, zf, dirMode);
addDirectoryResource(resource, name, prefix,
base, zOut,
dirMode, thisDirMode);
} else { // !isDirectory
addParentDirs(base, name, zOut, prefix, dirMode);
if (dealingWithFiles) {
final File f = FILE_UTILS.resolveFile(base,
resource.getName());
zipFile(f, zOut, prefix + name, fileMode);
} else {
final int thisFileMode =
zfs != null && zfs.hasFileModeBeenSet()
? fileMode : getUnixMode(resource, zf,
fileMode);
addResource(resource, name, prefix,
zOut, thisFileMode, zf,
zfs == null
? null : zfs.getSrc(getProject()));
}
}
}
} finally {
if (zf != null) {
zf.close();
}
}
}