public DirectoryScanner scan ( ) throws IllegalStateException { synchronized ( scanLock ) { if ( scanning ) { while ( scanning ) { try { scanLock . wait ( ) ; } catch ( InterruptedException e ) { continue ; } } if ( illegal != null ) { throw illegal ; } return this ; } scanning = true ; } try { synchronized ( this ) { illegal = null ; clearResults ( ) ; // set in/excludes to reasonable defaults if needed: boolean nullIncludes = ( includes == null ) ; includes = nullIncludes ? new String [ ] { "**" } : includes ; boolean nullExcludes = ( excludes == null ) ; excludes = nullExcludes ? new String [ 0 ] : excludes ; if ( basedir == null ) { // if no basedir and no includes, nothing to do: if ( nullIncludes ) { return this ; } } else { if ( ! basedir . exists ( ) ) { if ( errorOnMissingDir ) { illegal = new IllegalStateException ( "basedir " + basedir + " does not exist" ) ; } else { // Nothing to do - basedir does not exist return this ; } } if ( ! basedir . isDirectory ( ) ) { illegal = new IllegalStateException ( "basedir " + basedir + " is not a directory" ) ; } if ( illegal != null ) { throw illegal ; } } if ( isIncluded ( "" ) ) { if ( ! isExcluded ( "" ) ) { if ( isSelected ( "" , basedir ) ) { dirsIncluded . addElement ( "" ) ; } else { dirsDeselected . addElement ( "" ) ; } } else { dirsExcluded . addElement ( "" ) ; } } else { dirsNotIncluded . addElement ( "" ) ; } checkIncludePatterns ( ) ; clearCaches ( ) ; includes = nullIncludes ? null : includes ; excludes = nullExcludes ? null : excludes ; } } finally { synchronized ( scanLock ) { scanning = false ; scanLock . notifyAll ( ) ; } } return this ; }
Scan for files which match at least one include pattern and don t match any exclude patterns . If there are selectors then the files must pass muster there as well . Scans under basedir if set ; otherwise the include patterns without leading wildcards specify the absolute paths of the files that may be included .