1 package org.codehaus.mojo.natives;
2
3 import java.io.File;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.codehaus.plexus.util.DirectoryScanner;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class NativeSources
38 {
39 private File directory;
40
41 private String[] fileNames = new String[0];
42
43 private boolean dependencyAnalysisParticipation = true;
44
45
46
47
48 private boolean deployable = false;
49
50
51
52
53 private String[] includes;
54
55
56
57
58 private String[] excludes;
59
60 public NativeSources()
61 {
62
63 }
64
65
66
67
68 public File getDirectory()
69 {
70 return this.directory;
71 }
72
73
74
75
76 public void setDirectory( File directory )
77 {
78 this.directory = directory;
79 }
80
81
82
83
84 public String[] getFileNames()
85 {
86 return this.fileNames;
87 }
88
89
90
91
92 public void setFileNames( String[] fileNames )
93 {
94 if ( fileNames == null )
95 {
96 this.fileNames = new String[0];
97 }
98
99 this.fileNames = fileNames;
100 }
101
102
103
104
105 public String[] getIncludes()
106 {
107 return this.includes;
108 }
109
110
111
112
113 public void setIncludes( String[] includes )
114 {
115 this.includes = includes;
116 }
117
118
119
120
121 public String[] getExcludes()
122 {
123 return this.excludes;
124 }
125
126
127
128
129 public void setExcludes( String[] excludes )
130 {
131 this.excludes = excludes;
132 }
133
134
135
136
137 public boolean getDependencyAnalysisParticipation()
138 {
139 return this.dependencyAnalysisParticipation;
140 }
141
142
143
144
145 public void setDependencyAnalysisParticipation( boolean flag )
146 {
147 this.dependencyAnalysisParticipation = flag;
148 }
149
150 public boolean isDeployable()
151 {
152 return deployable;
153 }
154
155 public void setDeployable( boolean deployable )
156 {
157 this.deployable = deployable;
158 }
159
160
161
162 public List getFiles()
163 {
164 String[] filePaths = new String[0];
165
166 if ( includes != null || excludes != null )
167 {
168 DirectoryScanner scanner = new DirectoryScanner();
169 scanner.setBasedir( this.directory );
170 scanner.setIncludes( includes );
171 scanner.setExcludes( excludes );
172 scanner.addDefaultExcludes();
173
174 scanner.scan();
175
176 filePaths = scanner.getIncludedFiles();
177 }
178
179 List files = new ArrayList( filePaths.length + this.fileNames.length );
180 for ( int i = 0; i < filePaths.length; ++i )
181 {
182 files.add( new File( this.directory, filePaths[i] ) );
183 }
184
185
186 for ( int i = 0; i < this.fileNames.length; ++i )
187 {
188 File file = new File( this.directory, this.fileNames[i] );
189
190 boolean found = false;
191
192 for ( int k = 0; k < filePaths.length; ++k )
193 {
194 if ( files.get( k ).equals( file ) )
195 {
196 found = true;
197 break;
198 }
199 }
200
201 if ( !found )
202 {
203 files.add( file );
204 }
205 }
206
207 return files;
208
209 }
210
211
212
213
214
215
216
217
218
219
220
221 public static File[] getAllSourceFiles( NativeSources[] sources )
222 {
223 if ( sources == null )
224 {
225 return new File[0];
226 }
227
228 List sourceFiles = new ArrayList();
229
230 for ( int i = 0; i < sources.length; ++i )
231 {
232 sourceFiles.addAll( sources[i].getFiles() );
233 }
234
235 return (File[]) sourceFiles.toArray( new File[sourceFiles.size()] );
236 }
237
238 public static File[] getIncludePaths( NativeSources[] sources )
239 {
240 if ( sources == null )
241 {
242 return new File[0];
243 }
244
245 List list = new ArrayList();
246
247 for ( int i = 0; i < sources.length; ++i )
248 {
249 if ( sources[i].getDependencyAnalysisParticipation() )
250 {
251 list.add( sources[i].getDirectory() );
252 }
253 }
254
255 return (File[]) list.toArray( new File[0] );
256 }
257
258 public static File[] getSystemIncludePaths( NativeSources[] sources )
259 {
260 if ( sources == null )
261 {
262 return new File[0];
263 }
264
265 List list = new ArrayList();
266
267 for ( int i = 0; i < sources.length; ++i )
268 {
269 if ( !sources[i].getDependencyAnalysisParticipation() )
270 {
271 list.add( sources[i].getDirectory() );
272 }
273 }
274
275 return (File[]) list.toArray( new File[0] );
276 }
277
278 }