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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class FileSet
27 {
28 private File basedir;
29
30
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
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 }