View Javadoc
1   package com.simpligility.maven.plugins.android.common;
2   
3   import org.codehaus.plexus.util.DirectoryScanner;
4   
5   import java.io.File;
6   
7   /**
8    * Retrieves the names of layout resource files.
9    */
10  public final class FileRetriever
11  {
12      private final String[] includes;
13  
14      /**
15       * @param includes      Ant-style include statements, for example <code>"** /*.aidl"</code> (but without the space
16       *                      in the middle).
17       */
18      public FileRetriever( String... includes )
19      {
20          this.includes = includes;
21      }
22  
23      /**
24       * Finds the files in the supplied folder that match the configured includes.
25       *
26       * @param baseDirectory Directory to find files in.
27       * @return <code>String[]</code> of the files' paths and names, relative to <code>baseDirectory</code>. Empty
28       *         <code>String[]</code> if <code>baseDirectory</code> does not exist.
29       */
30      public String[] getFileNames( File baseDirectory )
31      {
32          if ( !baseDirectory.exists() )
33          {
34              return new String[ 0 ];
35          }
36  
37          final DirectoryScanner directoryScanner = new DirectoryScanner();
38          directoryScanner.setBasedir( baseDirectory );
39          directoryScanner.setIncludes( includes );
40          directoryScanner.addDefaultExcludes();
41          directoryScanner.scan();
42  
43          return directoryScanner.getIncludedFiles();
44      }
45  }