FileDocCategorySizeDatePackage
Pack.javaAPI DocApache Ant 1.706027Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

Pack

public abstract class Pack extends org.apache.tools.ant.Task
Abstract Base class for pack tasks.
since
Ant 1.5

Fields Summary
protected File
zipFile
protected File
source
private org.apache.tools.ant.types.Resource
src
Constructors Summary
Methods Summary
public voidaddConfigured(org.apache.tools.ant.types.ResourceCollection a)
Set the source resource.

param
a the resource to pack as a single element Resource collection.

        if (a.size() != 1) {
            throw new BuildException("only single argument resource collections"
                                     + " are supported as archives");
        }
        setSrcResource((Resource) a.iterator().next());
    
public voidexecute()
validate, then hand off to the subclass

throws
BuildException on error

        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.ResourcegetSrcResource()
The source resource.

return
the source.
since
Ant 1.7

        return src;
    
protected abstract voidpack()
subclasses must implement this method to do their compression

public voidsetDestfile(java.io.File zipFile)
the required destination file.

param
zipFile the destination file

        setZipfile(zipFile);
    
public voidsetSrc(java.io.File src)
the file to compress; required.

param
src the source file

        setSrcResource(new FileResource(src));
    
public voidsetSrcResource(org.apache.tools.ant.types.Resource src)
The resource to pack; required.

param
src resource to expand

        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 voidsetZipfile(java.io.File zipFile)
the required destination file.

param
zipFile the destination file

        this.zipFile = zipFile;
    
protected booleansupportsNonFileResources()
Whether this task can deal with non-file resources.

This implementation returns false.

return
false.
since
Ant 1.7

        return false;
    
private voidvalidate()
validation routine

throws
BuildException if anything is invalid

        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 voidzipFile(java.io.InputStream in, java.io.OutputStream zOut)
zip a stream to an output stream

param
in the stream to zip
param
zOut the output stream
throws
IOException

        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 voidzipFile(java.io.File file, java.io.OutputStream zOut)
zip a file to an output stream

param
file the file to zip
param
zOut the output stream
throws
IOException on error

        zipResource(new FileResource(file), zOut);
    
protected voidzipResource(org.apache.tools.ant.types.Resource resource, java.io.OutputStream zOut)
zip a resource to an output stream

param
resource the resource to zip
param
zOut the output stream
throws
IOException on error

        InputStream rIn = resource.getInputStream();
        try {
            zipFile(rIn, zOut);
        } finally {
            rIn.close();
        }