FileDocCategorySizeDatePackage
Unpack.javaAPI DocApache Ant 1.705977Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

Unpack

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

Fields Summary
protected File
source
protected File
dest
protected org.apache.tools.ant.types.Resource
srcResource
Constructors Summary
Methods Summary
public voidaddConfigured(org.apache.tools.ant.types.ResourceCollection a)
Set the source Archive resource.

param
a the archive 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());
    
private voidcreateDestFile(java.lang.String defaultExtension)

        String sourceName = source.getName();
        int len = sourceName.length();
        if (defaultExtension != null
            && len > defaultExtension.length()
            && defaultExtension.equalsIgnoreCase(
                sourceName.substring(len - defaultExtension.length()))) {
            dest = new File(dest, sourceName.substring(0,
                                                       len - defaultExtension.length()));
        } else {
            dest = new File(dest, sourceName);
        }
    
public voidexecute()
Execute the task.

throws
BuildException on error

        File savedDest = dest; // may be altered in validate
        try {
            validate();
            extract();
        } finally {
            dest = savedDest;
        }
    
protected abstract voidextract()
Do the uncompressing. This is to be overridden by subclasses.

protected abstract java.lang.StringgetDefaultExtension()
Get the extension. This is to be overridden by subclasses.

return
the default extension.

public voidsetDest(java.lang.String dest)

deprecated
since 1.5.x. setDest(String) is deprecated and is replaced with setDest(File) to make Ant's Introspection mechanism do the work and also to encapsulate operations on the type in its own class.
ant.attribute
ignore="true"
param
dest a String value

        log("DEPRECATED - The setDest(String) method has been deprecated."
            + " Use setDest(File) instead.");
        setDest(getProject().resolveFile(dest));
    
public voidsetDest(java.io.File dest)
The destination file or directory; optional.

param
dest destination file or directory

        this.dest = dest;
    
public voidsetSrc(java.lang.String src)

deprecated
since 1.5.x. setSrc(String) is deprecated and is replaced with setSrc(File) to make Ant's Introspection mechanism do the work and also to encapsulate operations on the type in its own class.
ant.attribute
ignore="true"
param
src a String value

        log("DEPRECATED - The setSrc(String) method has been deprecated."
            + " Use setSrc(File) instead.");
        setSrc(getProject().resolveFile(src));
    
public voidsetSrc(java.io.File src)
The file to expand; required.

param
src file to expand

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

param
src resource to expand

        if (!src.isExists()) {
            throw new BuildException("the archive doesn't exist");
        }
        if (src.isDirectory()) {
            throw new BuildException("the archive can't be a directory");
        }
        if (src instanceof FileResource) {
            source = ((FileResource) src).getFile();
        } else if (!supportsNonFileResources()) {
            throw new BuildException("Only FileSystem resources are"
                                     + " supported.");
        }
        srcResource = src;
    
protected booleansupportsNonFileResources()
Whether this task can deal with non-file resources.

This implementation returns false.

return
false for this task.
since
Ant 1.7

        return false;
    
private voidvalidate()

        if (srcResource == null) {
            throw new BuildException("No Src specified", getLocation());
        }

        if (dest == null) {
            dest = new File(source.getParent());
        }

        if (dest.isDirectory()) {
            String defaultExtension = getDefaultExtension();
            createDestFile(defaultExtension);
        }