use of org.apache.tools.ant.types.ZipFileSet in project ant by apache.
the class Zip method processGroupFilesets.
/**
* Process groupfilesets
*/
private void processGroupFilesets() {
// Add the files found in groupfileset to fileset
for (FileSet fs : groupfilesets) {
logWhenWriting("Processing groupfileset ", Project.MSG_VERBOSE);
final FileScanner scanner = fs.getDirectoryScanner(getProject());
final File basedir = scanner.getBasedir();
for (String file : scanner.getIncludedFiles()) {
logWhenWriting("Adding file " + file + " to fileset", Project.MSG_VERBOSE);
final ZipFileSet zf = new ZipFileSet();
zf.setProject(getProject());
zf.setSrc(new File(basedir, file));
add(zf);
filesetsFromGroupfilesets.add(zf);
}
}
}
use of org.apache.tools.ant.types.ZipFileSet in project ant by apache.
the class Zip method executeMain.
/**
* Build the zip file.
* This is called twice if doubleFilePass is true.
* @throws BuildException on error
*/
public void executeMain() throws BuildException {
checkAttributesAndElements();
// Renamed version of original file, if it exists
File renamedFile = null;
addingNewFiles = true;
processDoUpdate();
processGroupFilesets();
// collect filesets to pass them to getResourcesToAdd
final List<ResourceCollection> vfss = new ArrayList<>();
if (baseDir != null) {
final FileSet fs = (FileSet) getImplicitFileSet().clone();
fs.setDir(baseDir);
vfss.add(fs);
}
vfss.addAll(resources);
final ResourceCollection[] fss = vfss.toArray(new ResourceCollection[vfss.size()]);
boolean success = false;
try {
// can also handle empty archives
final ArchiveState state = getResourcesToAdd(fss, zipFile, false);
// quick exit if the target is up to date
if (!state.isOutOfDate()) {
return;
}
final File parent = zipFile.getParentFile();
if (parent != null && !parent.isDirectory() && !(parent.mkdirs() || parent.isDirectory())) {
throw new BuildException("Failed to create missing parent directory for %s", zipFile);
}
updatedFile = true;
if (!zipFile.exists() && state.isWithoutAnyResources()) {
createEmptyZip(zipFile);
return;
}
final Resource[][] addThem = state.getResourcesToAdd();
if (doUpdate) {
renamedFile = renameFile();
}
final String action = doUpdate ? "Updating " : "Building ";
if (!skipWriting) {
log(action + archiveType + ": " + zipFile.getAbsolutePath());
}
ZipOutputStream zOut = null;
try {
if (!skipWriting) {
zOut = new ZipOutputStream(zipFile);
zOut.setEncoding(encoding);
zOut.setUseLanguageEncodingFlag(useLanguageEncodingFlag);
zOut.setCreateUnicodeExtraFields(createUnicodeExtraFields.getPolicy());
zOut.setFallbackToUTF8(fallBackToUTF8);
zOut.setMethod(doCompress ? ZipOutputStream.DEFLATED : ZipOutputStream.STORED);
zOut.setLevel(level);
zOut.setUseZip64(zip64Mode.getMode());
}
initZipOutputStream(zOut);
// Add the explicit resource collections 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;
final ZipFileSet oldFiles = new ZipFileSet();
oldFiles.setProject(getProject());
oldFiles.setSrc(renamedFile);
oldFiles.setDefaultexcludes(false);
for (String addedFile : addedFiles) {
oldFiles.createExclude().setName(addedFile);
}
final DirectoryScanner ds = oldFiles.getDirectoryScanner(getProject());
((ZipScanner) ds).setEncoding(encoding);
Stream<String> includedResourceNames = Stream.of(ds.getIncludedFiles());
if (!doFilesonly) {
includedResourceNames = Stream.concat(includedResourceNames, Stream.of(ds.getIncludedDirectories()));
}
Resource[] r = includedResourceNames.map(ds::getResource).toArray(Resource[]::new);
addResources(oldFiles, r, zOut);
}
if (zOut != null) {
zOut.setComment(comment);
}
finalizeZipOutputStream(zOut);
// 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.
closeZout(zOut, success);
}
} catch (final IOException ioe) {
String msg = "Problem creating " + archiveType + ": " + ioe.getMessage();
// delete a bogus ZIP file (but only if it's not the original one)
if ((!doUpdate || renamedFile != null) && !zipFile.delete()) {
msg += " (and the archive is probably corrupt but I could not " + "delete it)";
}
if (doUpdate && renamedFile != null) {
try {
FILE_UTILS.rename(renamedFile, zipFile);
} catch (final IOException e) {
msg += " (and I couldn't rename the temporary file " + renamedFile.getName() + " back)";
}
}
throw new BuildException(msg, ioe, getLocation());
} finally {
cleanUp();
}
}
use of org.apache.tools.ant.types.ZipFileSet in project ant by apache.
the class War method setWebxml.
/**
* set the deployment descriptor to use (WEB-INF/web.xml);
* required unless <tt>update=true</tt>
* @param descr the deployment descriptor file
*/
public void setWebxml(File descr) {
deploymentDescriptor = descr;
if (!deploymentDescriptor.exists()) {
throw new BuildException("Deployment descriptor: does not exist.", deploymentDescriptor);
}
// Create a ZipFileSet for this file, and pass it up.
ZipFileSet fs = new ZipFileSet();
fs.setFile(deploymentDescriptor);
fs.setFullpath(XML_DESCRIPTOR_PATH);
super.addFileset(fs);
}
use of org.apache.tools.ant.types.ZipFileSet in project ci.ant by WASdev.
the class CompileJSPs method updateSourceWar.
private void updateSourceWar(File jspCompileDir) {
// Finally need to merge the compiled jsps in
War warTask = new War();
warTask.setProject(getProject());
warTask.setDestFile(war);
warTask.setUpdate(true);
ZipFileSet jspFiles = new ZipFileSet();
// The JSPs will be in the a well known location. The
// app name from server.xml and the war file name will
// be
// in the path, the war name minus the .war extension
// (if present) will also be used.
jspFiles.setDir(jspCompileDir);
warTask.addClasses(jspFiles);
warTask.setTaskName(getTaskName());
warTask.execute();
}
Aggregations