1 package org.codehaus.mojo.gwt.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.project.MavenProject;
27 import org.codehaus.plexus.util.DirectoryScanner;
28
29
30
31
32
33 public class TestTemplate
34 {
35
36
37
38 public interface CallBack
39 {
40
41
42
43
44
45 void doWithTest( File sourceDir, String test )
46 throws MojoExecutionException;
47 }
48
49
50
51
52
53
54
55
56 public TestTemplate( MavenProject project, String includes, String excludes, CallBack callBack )
57 throws MojoExecutionException
58 {
59 for ( String root : ( List < String > ) project.getTestCompileSourceRoots() )
60 {
61 File sourceDir = new File( root );
62 if ( !sourceDir.exists() )
63 {
64 continue;
65 }
66 DirectoryScanner scanner = new DirectoryScanner();
67 scanner.setBasedir( sourceDir );
68 if ( includes != null && !"".equals( includes ) )
69 {
70 scanner.setIncludes( includes.split( "," ) );
71 }
72 if ( excludes != null && !"".equals( excludes ) )
73 {
74 scanner.setExcludes( excludes.split( "," ) );
75 }
76 scanner.scan();
77 String[] files = scanner.getIncludedFiles();
78 for ( String file : files )
79 {
80 callBack.doWithTest( sourceDir, file );
81 }
82 }
83 }
84 }