Methods Summary |
---|
public void | addConfigured(org.apache.tools.ant.types.ResourceCollection a)Set the source resource.
if (a.size() != 1) {
throw new BuildException("only single argument resource collections"
+ " are supported as archives");
}
setSrcResource((Resource) a.iterator().next());
|
public void | execute()validate, then hand off to the subclass
validate();
Resource s = getSrcResource();
if (!s.isExists()) {
log("Nothing to do: " + s.toString()
+ " doesn't exist.");
} else if (zipFile.lastModified() < s.getLastModified()) {
log("Building: " + zipFile.getAbsolutePath());
pack();
} else {
log("Nothing to do: " + zipFile.getAbsolutePath()
+ " is up to date.");
}
|
public org.apache.tools.ant.types.Resource | getSrcResource()The source resource.
return src;
|
protected abstract void | pack()subclasses must implement this method to do their compression
|
public void | setDestfile(java.io.File zipFile)the required destination file.
setZipfile(zipFile);
|
public void | setSrc(java.io.File src)the file to compress; required.
setSrcResource(new FileResource(src));
|
public void | setSrcResource(org.apache.tools.ant.types.Resource src)The resource to pack; required.
if (src.isDirectory()) {
throw new BuildException("the source can't be a directory");
}
if (src instanceof FileResource) {
source = ((FileResource) src).getFile();
} else if (!supportsNonFileResources()) {
throw new BuildException("Only FileSystem resources are"
+ " supported.");
}
this.src = src;
|
public void | setZipfile(java.io.File zipFile)the required destination file.
this.zipFile = zipFile;
|
protected boolean | supportsNonFileResources()Whether this task can deal with non-file resources.
This implementation returns false.
return false;
|
private void | validate()validation routine
if (zipFile == null) {
throw new BuildException("zipfile attribute is required", getLocation());
}
if (zipFile.isDirectory()) {
throw new BuildException("zipfile attribute must not "
+ "represent a directory!", getLocation());
}
if (getSrcResource() == null) {
throw new BuildException("src attribute or nested resource is"
+ " required", getLocation());
}
|
private void | zipFile(java.io.InputStream in, java.io.OutputStream zOut)zip a stream to an output stream
byte[] buffer = new byte[8 * 1024];
int count = 0;
do {
zOut.write(buffer, 0, count);
count = in.read(buffer, 0, buffer.length);
} while (count != -1);
|
protected void | zipFile(java.io.File file, java.io.OutputStream zOut)zip a file to an output stream
zipResource(new FileResource(file), zOut);
|
protected void | zipResource(org.apache.tools.ant.types.Resource resource, java.io.OutputStream zOut)zip a resource to an output stream
InputStream rIn = resource.getInputStream();
try {
zipFile(rIn, zOut);
} finally {
rIn.close();
}
|