View Javadoc
1   package org.codehaus.mojo.natives.util;
2   
3   import org.codehaus.plexus.util.FileUtils;
4   import org.codehaus.plexus.util.StringUtils;
5   
6   import java.io.File;
7   import java.io.IOException;
8   import java.util.Arrays;
9   
10  /*
11   * Copyright 2001-2004 The Apache Software Foundation.
12   *
13   * Licensed under the Apache License, Version 2.0 (the "License");
14   * you may not use this file except in compliance with the License.
15   * You may obtain a copy of the License at
16   *
17   *      http://www.apache.org/licenses/LICENSE-2.0
18   *
19   * Unless required by applicable law or agreed to in writing, software
20   * distributed under the License is distributed on an "AS IS" BASIS,
21   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   * See the License for the specific language governing permissions and
23   * limitations under the License.
24   */
25  
26  public class FileSet
27  {
28      private File basedir;
29  
30      /** List of files, all relative to the basedir. */
31      private File[] files;
32  
33      private static final File[] EMPTY_FILE_ARRAY = new File[0];
34  
35      public FileSet( File basedir )
36      {
37          this( basedir, EMPTY_FILE_ARRAY );
38      }
39  
40      public FileSet( File basedir, File file )
41      {
42          this( basedir, new File[] { file } );
43      }
44  
45      public FileSet( File basedir, String includes, String excludes )
46          throws IOException
47      {
48          this.basedir = basedir;
49  
50          excludes = this.trimCommaSeparateString( excludes );
51  
52          includes = this.trimCommaSeparateString( includes );
53  
54          files = (File[]) FileUtils.getFiles( basedir, includes, excludes ).toArray( EMPTY_FILE_ARRAY );
55      }
56  
57      public FileSet( File basedir, File[] files )
58      {
59          if ( basedir == null )
60          {
61              throw new NullPointerException( "basedir must not be null" );
62          }
63  
64          if ( files == null )
65          {
66              throw new NullPointerException( "files must not be null" );
67          }
68  
69          this.basedir = basedir;
70          this.files = files;
71      }
72  
73      public File getBasedir()
74      {
75          return basedir;
76      }
77  
78      public File[] getFiles()
79      {
80          return this.files;
81      }
82  
83      public String toString()
84      {
85          return "basedir = " + basedir + "; files = " + Arrays.asList( files );
86      }
87  
88      // temp solution until plexus-util is fix
89  
90      private String trimCommaSeparateString( String in )
91      {
92          if ( in == null || in.trim().length() == 0 )
93          {
94              return "";
95          }
96  
97          StringBuffer out = new StringBuffer();
98  
99          String[] tokens = StringUtils.split( in, "," );
100         for ( int i = 0; i < tokens.length; ++i )
101         {
102             if ( i != 0 )
103             {
104                 out.append( "," );
105             }
106             out.append( tokens[i].trim() );
107         }
108 
109         return out.toString();
110     }
111 
112 }