ArchiveScanner (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.types, class: ArchiveScanner

# Class ArchiveScanner

java.lang.Object
org.apache.tools.ant.DirectoryScanner
org.apache.tools.ant.types.ArchiveScanner

All Implemented Interfaces:
  `FileScanner, ResourceFactory, SelectorScanner`

Direct Known Subclasses:
  `TarScanner, ZipScanner`

public abstract class ArchiveScanner extends DirectoryScanner
ArchiveScanner accesses the pattern matching algorithm in DirectoryScanner, which are protected methods that can only be accessed by subclassing. This implementation of FileScanner defines getIncludedFiles to return the matching archive entries.

Since:
  Ant 1.7

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected File`
  `srcFile`
  The archive file which should be scanned.

  ### Fields inherited from class DirectoryScanner

  `basedir, DEFAULTEXCLUDES, dirsDeselected, dirsExcluded, dirsIncluded, dirsNotIncluded, DOES_NOT_EXIST_POSTFIX, errorOnMissingDir, everythingIncluded, excludes, filesDeselected, filesExcluded, filesIncluded, filesNotIncluded, haveSlowResults, includes, isCaseSensitive, MAX_LEVELS_OF_SYMLINKS, selectors`
  Modifier and Type
  Field
  Description
  `protected File`
  `basedir`
  The base directory to be scanned.
  `protected static final String[]`
  `DEFAULTEXCLUDES`
  Deprecated.
  since 1.6.x.
  `protected Vector<String>`
  `dirsDeselected`
  The directories which matched at least one include and no excludes but which a selector discarded.
  `protected Vector<String>`
  `dirsExcluded`
  The directories which matched at least one include and at least one exclude.
  `protected Vector<String>`
  `dirsIncluded`
  The directories which matched at least one include and no excludes and were selected.
  `protected Vector<String>`
  `dirsNotIncluded`
  The directories which were found and did not match any includes.
  `static final String`
  `DOES_NOT_EXIST_POSTFIX`
  The end of the exception message if something that should be there doesn't exist.
  `protected boolean`
  `errorOnMissingDir`
  Whether a missing base directory is an error.
  `protected boolean`
  `everythingIncluded`
  Whether or not everything tested so far has been included.
  `protected String[]`
  `excludes`
  The patterns for the files to be excluded.
  `protected Vector<String>`
  `filesDeselected`
  The files which matched at least one include and no excludes and which a selector discarded.
  `protected Vector<String>`
  `filesExcluded`
  The files which matched at least one include and at least one exclude.
  `protected Vector<String>`
  `filesIncluded`
  The files which matched at least one include and no excludes and were selected.
  `protected Vector<String>`
  `filesNotIncluded`
  The files which did not match any includes or selectors.
  `protected boolean`
  `haveSlowResults`
  Whether or not our results were built by a slow scan.
  `protected String[]`
  `includes`
  The patterns for the files to be included.
  `protected boolean`
  `isCaseSensitive`
  Whether or not the file system should be treated as a case sensitive one.
  `static final int`
  `MAX_LEVELS_OF_SYMLINKS`
  default value for `maxLevelsOfSymlinks`
  `protected FileSelector[]`
  `selectors`
  Selectors that will filter which files are in our candidate list.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ArchiveScanner()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected abstract void`
  `fillMapsFromArchive(Resource archive, String encoding, Map<String,Resource> fileEntries, Map<String,Resource> matchFileEntries, Map<String,Resource> dirEntries, Map<String,Resource> matchDirEntries)`
  Fills the file and directory maps with resources read from the archive.
  `String[]`
  `getIncludedDirectories()`
  Returns the names of the directories which matched at least one of the include patterns and none of the exclude patterns.
  `int`
  `getIncludedDirsCount()`
  Override parent implementation.
  `String[]`
  `getIncludedFiles()`
  Returns the names of the files which matched at least one of the include patterns and none of the exclude patterns.
  `int`
  `getIncludedFilesCount()`
  Override parent implementation.
  `Resource`
  `getResource(String name)`
  Get the named Resource.
  `void`
  `init()`
  Initialize DirectoryScanner data structures.
  `boolean`
  `match(String path)`
  Matches a jar entry against the includes/excludes list, normalizing the path separator.
  `void`
  `scan()`
  Don't scan when we have no zipfile.
  `void`
  `setEncoding(String encoding)`
  Sets encoding of file names.
  `void`
  `setErrorOnMissingArchive(boolean errorOnMissingArchive)`
  Sets whether an error is thrown if an archive does not exist.
  `void`
  `setSrc(File srcFile)`
  Sets the srcFile for scanning.
  `void`
  `setSrc(Resource src)`
  Sets the src for scanning.
  `protected static final String`
  `trimSeparator(String s)`
  Remove trailing slash if present.

  ### Methods inherited from class DirectoryScanner

  `addDefaultExclude, addDefaultExcludes, addExcludes, clearResults, couldHoldIncluded, getBasedir, getDefaultExcludes, getDeselectedDirectories, getDeselectedFiles, getExcludedDirectories, getExcludedFiles, getNotFollowedSymlinks, getNotIncludedDirectories, getNotIncludedFiles, isCaseSensitive, isEverythingIncluded, isExcluded, isFollowSymlinks, isIncluded, isSelected, match, match, matchPath, matchPath, matchPatternStart, matchPatternStart, removeDefaultExclude, resetDefaultExcludes, scandir, setBasedir, setBasedir, setCaseSensitive, setErrorOnMissingDir, setExcludes, setFollowSymlinks, setIncludes, setMaxLevelsOfSymlinks, setSelectors, slowScan`
  Modifier and Type
  Method
  Description
  `static boolean`
  `addDefaultExclude(String s)`
  Add a pattern to the default excludes unless it is already a default exclude.
  `void`
  `addDefaultExcludes()`
  Add default exclusions to the current exclusions set.
  `void`
  `addExcludes(String[] excludes)`
  Add to the list of exclude patterns to use.
  `protected void`
  `clearResults()`
  Clear the result caches for a scan.
  `protected boolean`
  `couldHoldIncluded(String name)`
  Test whether or not a name matches the start of at least one include pattern.
  `File`
  `getBasedir()`
  Return the base directory to be scanned.
  `static String[]`
  `getDefaultExcludes()`
  Get the list of patterns that should be excluded by default.
  `String[]`
  `getDeselectedDirectories()`
  Return the names of the directories which were selected out and therefore not ultimately included.
  `String[]`
  `getDeselectedFiles()`
  Return the names of the files which were selected out and therefore not ultimately included.
  `String[]`
  `getExcludedDirectories()`
  Return the names of the directories which matched at least one of the include patterns and at least one of the exclude patterns.
  `String[]`
  `getExcludedFiles()`
  Return the names of the files which matched at least one of the include patterns and at least one of the exclude patterns.
  `String[]`
  `getNotFollowedSymlinks()`
  Absolute paths of all symbolic links or Windows junctions that haven't been followed but would have been followed had followsymlinks been true or maxLevelsOfSymlinks been bigger.
  `String[]`
  `getNotIncludedDirectories()`
  Return the names of the directories which matched none of the include patterns.
  `String[]`
  `getNotIncludedFiles()`
  Return the names of the files which matched none of the include patterns.
  `boolean`
  `isCaseSensitive()`
  Find out whether include exclude patterns are matched in a case sensitive way.
  `boolean`
  `isEverythingIncluded()`
  Return whether or not the scanner has included all the files or directories it has come across so far.
  `protected boolean`
  `isExcluded(String name)`
  Test whether or not a name matches against at least one exclude pattern.
  `boolean`
  `isFollowSymlinks()`
  Get whether or not a DirectoryScanner follows symbolic links or Windows junctions.
  `protected boolean`
  `isIncluded(String name)`
  Test whether or not a name matches against at least one include pattern.
  `protected boolean`
  `isSelected(String name, File file)`
  Test whether a file should be selected.
  `static boolean`
  `match(String pattern, String str)`
  Test whether or not a string matches against a pattern.
  `protected static boolean`
  `match(String pattern, String str, boolean isCaseSensitive)`
  Test whether or not a string matches against a pattern.
  `protected static boolean`
  `matchPath(String pattern, String str)`
  Test whether or not a given path matches a given pattern.
  `protected static boolean`
  `matchPath(String pattern, String str, boolean isCaseSensitive)`
  Test whether or not a given path matches a given pattern.
  `protected static boolean`
  `matchPatternStart(String pattern, String str)`
  Test whether or not a given path matches the start of a given pattern up to the first "**".
  `protected static boolean`
  `matchPatternStart(String pattern, String str, boolean isCaseSensitive)`
  Test whether or not a given path matches the start of a given pattern up to the first "**".
  `static boolean`
  `removeDefaultExclude(String s)`
  Remove a string if it is a default exclude.
  `static void`
  `resetDefaultExcludes()`
  Go back to the hardwired default exclude patterns.
  `protected void`
  `scandir(File dir, String vpath, boolean fast)`
  Scan the given directory for files and directories.
  `void`
  `setBasedir(File basedir)`
  Set the base directory to be scanned.
  `void`
  `setBasedir(String basedir)`
  Set the base directory to be scanned.
  `void`
  `setCaseSensitive(boolean isCaseSensitive)`
  Set whether or not include and exclude patterns are matched in a case sensitive way.
  `void`
  `setErrorOnMissingDir(boolean errorOnMissingDir)`
  Sets whether or not a missing base directory is an error
  `void`
  `setExcludes(String[] excludes)`
  Set the list of exclude patterns to use.
  `void`
  `setFollowSymlinks(boolean followSymlinks)`
  Set whether or not symbolic links or Windows junctions should be followed.
  `void`
  `setIncludes(String[] includes)`
  Set the list of include patterns to use.
  `void`
  `setMaxLevelsOfSymlinks(int max)`
  The maximum number of times a symbolic link or Windows junctions may be followed during a scan.
  `void`
  `setSelectors(FileSelector[] selectors)`
  Set the selectors that will select the filelist.
  `protected void`
  `slowScan()`
  Top level invocation for a slow scan.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### srcFile

    protected File srcFile
    The archive file which should be scanned.

- ## Constructor Details

  - ### ArchiveScanner

    public ArchiveScanner()

- ## Method Details

  - ### setErrorOnMissingArchive

    public void setErrorOnMissingArchive(boolean errorOnMissingArchive)
    Sets whether an error is thrown if an archive does not exist.
    Parameters:
      `errorOnMissingArchive` - true if missing archives cause errors, false if not.
    Since:
      Ant 1.8.0

  - ### scan

    public void scan()
    Don't scan when we have no zipfile.
    Specified by:
      `scan` in interface `FileScanner`
    Overrides:
      `scan` in class `DirectoryScanner`
    Since:
      Ant 1.7

  - ### setSrc

    public void setSrc(File srcFile)
    Sets the srcFile for scanning. This is the jar or zip file that is scanned for matching entries.
    Parameters:
      `srcFile` - the (non-null) archive file name for scanning

  - ### setSrc

    public void setSrc(Resource src)
    Sets the src for scanning. This is the jar or zip file that is scanned for matching entries.
    Parameters:
      `src` - the (non-null) archive resource

  - ### setEncoding

    public void setEncoding(String encoding)
    Sets encoding of file names.
    Parameters:
      `encoding` - the encoding format
    Since:
      Ant 1.6

  - ### getIncludedFiles

    public String[] getIncludedFiles()
    Returns the names of the files which matched at least one of the include patterns and none of the exclude patterns. The names are relative to the base directory.
    Specified by:
      `getIncludedFiles` in interface `FileScanner`
    Overrides:
      `getIncludedFiles` in class `DirectoryScanner`
    Returns:
      the names of the files which matched at least one of the include patterns and none of the exclude patterns.

  - ### getIncludedFilesCount

    public int getIncludedFilesCount()
    Override parent implementation.
    Overrides:
      `getIncludedFilesCount` in class `DirectoryScanner`
    Returns:
      count of included files.
    Since:
      Ant 1.7

  - ### getIncludedDirectories

    public String[] getIncludedDirectories()
    Returns the names of the directories which matched at least one of the include patterns and none of the exclude patterns. The names are relative to the base directory.
    Specified by:
      `getIncludedDirectories` in interface `FileScanner`
    Overrides:
      `getIncludedDirectories` in class `DirectoryScanner`
    Returns:
      the names of the directories which matched at least one of the include patterns and none of the exclude patterns.

  - ### getIncludedDirsCount

    public int getIncludedDirsCount()
    Override parent implementation.
    Overrides:
      `getIncludedDirsCount` in class `DirectoryScanner`
    Returns:
      count of included directories.
    Since:
      Ant 1.7

  - ### init

    public void init()
    Initialize DirectoryScanner data structures.

  - ### match

    public boolean match(String path)
    Matches a jar entry against the includes/excludes list, normalizing the path separator.
    Parameters:
      `path` - the (non-null) path name to test for inclusion
    Returns:
      `true` if the path should be included `false` otherwise.

  - ### getResource

    public Resource getResource(String name)
    Get the named Resource.
    Specified by:
      `getResource` in interface `ResourceFactory`
    Overrides:
      `getResource` in class `DirectoryScanner`
    Parameters:
      `name` - path name of the file sought in the archive
    Returns:
      the resource
    Since:
      Ant 1.5.2

  - ### fillMapsFromArchive

    protected abstract void fillMapsFromArchive(Resource archive, String encoding, Map<String,Resource> fileEntries, Map<String,Resource> matchFileEntries, Map<String,Resource> dirEntries, Map<String,Resource> matchDirEntries)
    Fills the file and directory maps with resources read from the archive.
    Parameters:
      `archive` - the archive to scan.
      `encoding` - encoding used to encode file names inside the archive.
      `fileEntries` - Map (name to resource) of non-directory resources found inside the archive.
      `matchFileEntries` - Map (name to resource) of non-directory resources found inside the archive that matched all include patterns and didn't match any exclude patterns.
      `dirEntries` - Map (name to resource) of directory resources found inside the archive.
      `matchDirEntries` - Map (name to resource) of directory resources found inside the archive that matched all include patterns and didn't match any exclude patterns.

  - ### trimSeparator

    protected static final String trimSeparator(String s)
    Remove trailing slash if present.
    Parameters:
      `s` - the file name to trim.
    Returns:
      the trimmed file name.