FileDocCategorySizeDatePackage
ArchiveFileSet.javaAPI DocApache Ant 1.7015142Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types

ArchiveFileSet

public abstract class ArchiveFileSet extends FileSet
A ArchiveFileSet is a FileSet with extra attributes useful in the context of archiving tasks. It includes a prefix attribute which is prepended to each entry in the output archive file as well as a fullpath ttribute. It also supports Unix file permissions for files and directories.
since
Ant 1.7

Fields Summary
private static final int
BASE_OCTAL
public static final int
DEFAULT_DIR_MODE
Default value for the dirmode attribute.
public static final int
DEFAULT_FILE_MODE
Default value for the filemode attribute.
private Resource
src
private String
prefix
private String
fullpath
private boolean
hasDir
private int
fileMode
private int
dirMode
private boolean
fileModeHasBeenSet
private boolean
dirModeHasBeenSet
Constructors Summary
public ArchiveFileSet()
Constructor for ArchiveFileSet


        
      
        super();
    
protected ArchiveFileSet(FileSet fileset)
Constructor using a fileset arguement.

param
fileset the fileset to use

        super(fileset);
    
protected ArchiveFileSet(ArchiveFileSet fileset)
Constructor using a archive fileset arguement.

param
fileset the archivefileset to use

        super(fileset);
        src = fileset.src;
        prefix = fileset.prefix;
        fullpath = fileset.fullpath;
        hasDir = fileset.hasDir;
        fileMode = fileset.fileMode;
        dirMode = fileset.dirMode;
        fileModeHasBeenSet = fileset.fileModeHasBeenSet;
        dirModeHasBeenSet = fileset.dirModeHasBeenSet;
    
Methods Summary
public voidaddConfigured(ResourceCollection a)
Set the source Archive file for the archivefileset. Prevents both "dir" and "src" from being specified.

param
a the archive as a single element Resource collection.

        checkChildrenAllowed();
        if (a.size() != 1) {
            throw new BuildException("only single argument resource collections"
                                     + " are supported as archives");
        }
        setSrcResource((Resource) a.iterator().next());
    
private voidcheckArchiveAttributesAllowed()
A check attributes for archiveFileSet. If there is a reference, and it is a ArchiveFileSet, the archive fileset attributes cannot be used. (Note, we can only see if the reference is an archive fileset if the project has been set).

        if (getProject() == null
            || (isReference()
                && (getRefid().getReferencedObject(
                        getProject())
                    instanceof ArchiveFileSet))) {
            checkAttributesAllowed();
        }
    
public java.lang.Objectclone()
Return a ArchiveFileSet that has the same properties as this one.

return
the cloned archiveFileSet
since
Ant 1.6

        if (isReference()) {
            return ((ArchiveFileSet) getRef(getProject())).clone();
        } else {
            return super.clone();
        }
    
protected voidconfigureFileSet(org.apache.tools.ant.types.ArchiveFileSet zfs)
A ArchiveFileset accepts another ArchiveFileSet or a FileSet as reference FileSets are often used by the war task for the lib attribute

param
zfs the project to use

        zfs.setPrefix(prefix);
        zfs.setFullpath(fullpath);
        zfs.fileModeHasBeenSet = fileModeHasBeenSet;
        zfs.fileMode = fileMode;
        zfs.dirModeHasBeenSet = dirModeHasBeenSet;
        zfs.dirMode = dirMode;
    
public intgetDirMode(org.apache.tools.ant.Project p)
Get the dir mode of the archive fileset

param
p the project to use
return
the mode

        if (isReference()) {
            return ((ArchiveFileSet) getRef(p)).getDirMode(p);
        }
        return dirMode;
    
public intgetDirMode()

return
the dir mode.
deprecated
since 1.7.

        return dirMode;
    
public org.apache.tools.ant.DirectoryScannergetDirectoryScanner(org.apache.tools.ant.Project p)
Return the DirectoryScanner associated with this FileSet. If the ArchiveFileSet defines a source Archive file, then a ArchiveScanner is returned instead.

param
p the project to use
return
a directory scanner

        if (isReference()) {
            return getRef(p).getDirectoryScanner(p);
        }
        if (src == null) {
            return super.getDirectoryScanner(p);
        }
        if (!src.isExists()) {
            throw new BuildException("the archive doesn't exist");
        }
        if (src.isDirectory()) {
            throw new BuildException("the archive can't be a directory");
        }
        ArchiveScanner as = newArchiveScanner();
        as.setSrc(src);
        super.setDir(p.getBaseDir());
        setupDirectoryScanner(as, p);
        as.init();
        return as;
    
public intgetFileMode(org.apache.tools.ant.Project p)
Get the mode of the archive fileset

param
p the project to use
return
the mode

        if (isReference()) {
            return ((ArchiveFileSet) getRef(p)).getFileMode(p);
        }
        return fileMode;
    
public intgetFileMode()

return
the file mode.
deprecated
since 1.7.

        return fileMode;
    
public java.lang.StringgetFullpath(org.apache.tools.ant.Project p)
Return the full pathname of the single entry in this fileset.

param
p the project to use
return
the full path

        if (isReference()) {
            return ((ArchiveFileSet) getRef(p)).getFullpath(p);
        }
        return fullpath;
    
public java.lang.StringgetFullpath()
Return the full pathname of the single entryZ in this fileset.

return
the full pathname.
deprecated
since 1.7.

        return fullpath;
    
public java.lang.StringgetPrefix(org.apache.tools.ant.Project p)
Return the prefix prepended to entries in the archive file.

param
p the project to use
return
the prefix

        if (isReference()) {
            return ((ArchiveFileSet) getRef(p)).getPrefix(p);
        }
        return prefix;
    
public java.lang.StringgetPrefix()
Return the prefix prepended to entries in the archive file.

return
the prefix.
deprecated
since 1.7.

        return prefix;
    
public java.io.FilegetSrc(org.apache.tools.ant.Project p)
Get the archive from which entries will be extracted.

param
p the project to use
return
the source file

        if (isReference()) {
            return ((ArchiveFileSet) getRef(p)).getSrc(p);
        }
        return getSrc();
    
public java.io.FilegetSrc()
Get the archive file from which entries will be extracted.

return
the archive in case the archive is a file, null otherwise.

        if (src instanceof FileResource) {
            return ((FileResource) src).getFile();
        }
        return null;
    
public booleanhasDirModeBeenSet()
Whether the user has specified the mode explicitly.

return
true if it has been set

        if (isReference()) {
            return ((ArchiveFileSet) getRef(getProject())).hasDirModeBeenSet();
        }
        return dirModeHasBeenSet;
    
public booleanhasFileModeBeenSet()
Whether the user has specified the mode explicitly.

return
true if it has been set

        if (isReference()) {
            return ((ArchiveFileSet) getRef(getProject())).hasFileModeBeenSet();
        }
        return fileModeHasBeenSet;
    
public voidintegerSetDirMode(int mode)
specify the user, group and other modes in the standard Unix fashion; optional, default=0755

We use the strange name so this method doesn't appear in IntrospectionHelpers list of attribute setters.

param
mode a int value
since
Ant 1.7

        dirModeHasBeenSet = true;
        this.dirMode = UnixStat.DIR_FLAG | mode;
    
public voidintegerSetFileMode(int mode)
specify the user, group and other modes in the standard Unix fashion; optional, default=0644

We use the strange name so this method doesn't appear in IntrospectionHelpers list of attribute setters.

param
mode a int value
since
Ant 1.7

        fileModeHasBeenSet = true;
        this.fileMode = UnixStat.FILE_FLAG | mode;
    
public booleanisFilesystemOnly()
Indicate whether this ResourceCollection is composed entirely of Resources accessible via local filesystem conventions. If true, all Resources returned from this ResourceCollection should be instances of FileResource.

return
whether this is a filesystem-only resource collection.
since
Ant 1.7

        return src == null;
    
public java.util.Iteratoriterator()
Fulfill the ResourceCollection contract.

return
Iterator of Resources.
since
Ant 1.7

        if (isReference()) {
            return ((ResourceCollection) (getRef(getProject()))).iterator();
        }
        if (src == null) {
            return super.iterator();
        }
        ArchiveScanner as = (ArchiveScanner) getDirectoryScanner(getProject());
        return as.getResourceFiles();
    
protected abstract ArchiveScannernewArchiveScanner()
Creates a scanner for this type of archive.

return
the scanner.

public voidsetDir(java.io.File dir)
Set the directory for the fileset.

param
dir the directory for the fileset
throws
BuildException on error

        checkAttributesAllowed();
        if (src != null) {
            throw new BuildException("Cannot set both dir and src attributes");
        } else {
            super.setDir(dir);
            hasDir = true;
        }
    
public voidsetDirMode(java.lang.String octalString)
A 3 digit octal string, specify the user, group and other modes in the standard Unix fashion; optional, default=0755

param
octalString a String value

        checkArchiveAttributesAllowed();
        integerSetDirMode(Integer.parseInt(octalString, BASE_OCTAL));
    
public voidsetFileMode(java.lang.String octalString)
A 3 digit octal string, specify the user, group and other modes in the standard Unix fashion; optional, default=0644

param
octalString a String value

        checkArchiveAttributesAllowed();
        integerSetFileMode(Integer.parseInt(octalString, BASE_OCTAL));
    
public voidsetFullpath(java.lang.String fullpath)
Set the full pathname of the single entry in this fileset. Prevents both prefix and fullpath from being specified

param
fullpath the full pathname of the single entry in this fileset.

        checkArchiveAttributesAllowed();
        if (!prefix.equals("") && !fullpath.equals("")) {
            throw new BuildException("Cannot set both fullpath and prefix attributes");
        }
        this.fullpath = fullpath;
    
public voidsetPrefix(java.lang.String prefix)
Prepend this prefix to the path for each archive entry. Prevents both prefix and fullpath from being specified

param
prefix The prefix to prepend to entries in the archive file.

        checkArchiveAttributesAllowed();
        if (!prefix.equals("") && !fullpath.equals("")) {
            throw new BuildException("Cannot set both fullpath and prefix attributes");
        }
        this.prefix = prefix;
    
public voidsetSrc(java.io.File srcFile)
Set the source Archive file for the archivefileset. Prevents both "dir" and "src" from being specified.

param
srcFile The archive from which to extract entries.

        setSrcResource(new FileResource(srcFile));
    
public voidsetSrcResource(Resource src)
Set the source Archive file for the archivefileset. Prevents both "dir" and "src" from being specified.

param
src The archive from which to extract entries.

        checkArchiveAttributesAllowed();
        if (hasDir) {
            throw new BuildException("Cannot set both dir and src attributes");
        }
        this.src = src;
    
public intsize()
Fulfill the ResourceCollection contract.

return
size of the collection as int.
since
Ant 1.7

        if (isReference()) {
            return ((ResourceCollection) (getRef(getProject()))).size();
        }
        if (src == null) {
            return super.size();
        }
        ArchiveScanner as = (ArchiveScanner) getDirectoryScanner(getProject());
        return as.getIncludedFilesCount();
    
public java.lang.StringtoString()
for file based zipfilesets, return the same as for normal filesets else just return the path of the zip

return
for file based archivefilesets, included files as a list of semicolon-separated filenames. else just the name of the zip.

        if (hasDir && getProject() != null) {
            return super.toString();
        } else if (src != null) {
            return src.getName();
        } else {
            return null;
        }