1 package org.apache.maven.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
23 import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
24 import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
25
26 import java.io.File;
27 import java.util.Collections;
28 import java.util.HashSet;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32
33
34
35
36
37
38
39
40
41
42
43 public class TestCompilerMojo
44 extends AbstractCompilerMojo
45 {
46
47
48
49
50
51
52 private boolean skip;
53
54
55
56
57
58
59
60
61 private List compileSourceRoots;
62
63
64
65
66
67
68
69
70 private List classpathElements;
71
72
73
74
75
76
77
78
79 private File outputDirectory;
80
81
82
83
84
85
86 private Set testIncludes = new HashSet();
87
88
89
90
91
92
93 private Set testExcludes = new HashSet();
94
95
96
97
98
99
100 private String testSource;
101
102
103
104
105
106
107 private String testTarget;
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 private Map testCompilerArguments;
123
124
125
126
127
128
129
130
131
132
133
134
135 private String testCompilerArgument;
136
137 public void execute()
138 throws MojoExecutionException, CompilationFailureException
139 {
140 if ( skip )
141 {
142 getLog().info( "Not compiling test sources" );
143 }
144 else
145 {
146 super.execute();
147 }
148 }
149
150 protected List getCompileSourceRoots()
151 {
152 return compileSourceRoots;
153 }
154
155 protected List getClasspathElements()
156 {
157 return classpathElements;
158 }
159
160 protected File getOutputDirectory()
161 {
162 return outputDirectory;
163 }
164
165 protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
166 {
167 SourceInclusionScanner scanner = null;
168
169 if ( testIncludes.isEmpty() && testExcludes.isEmpty() )
170 {
171 scanner = new StaleSourceScanner( staleMillis );
172 }
173 else
174 {
175 if ( testIncludes.isEmpty() )
176 {
177 testIncludes.add( "**/*.java" );
178 }
179 scanner = new StaleSourceScanner( staleMillis, testIncludes, testExcludes );
180 }
181
182 return scanner;
183 }
184
185 protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
186 {
187 SourceInclusionScanner scanner = null;
188
189 if ( testIncludes.isEmpty() && testExcludes.isEmpty() )
190 {
191 testIncludes = Collections.singleton( "**/*." + inputFileEnding );
192 scanner = new SimpleSourceInclusionScanner( testIncludes, Collections.EMPTY_SET );
193 }
194 else
195 {
196 if ( testIncludes.isEmpty() )
197 {
198 testIncludes.add( "**/*." + inputFileEnding );
199 }
200 scanner = new SimpleSourceInclusionScanner( testIncludes, testExcludes );
201 }
202
203 return scanner;
204 }
205
206 protected String getSource()
207 {
208 return testSource == null ? source : testSource;
209 }
210
211 protected String getTarget()
212 {
213 return testTarget == null ? target : testTarget;
214 }
215
216 protected String getCompilerArgument()
217 {
218 return testCompilerArgument == null ? compilerArgument : testCompilerArgument;
219 }
220
221 protected Map getCompilerArguments()
222 {
223 return testCompilerArguments == null ? compilerArguments : testCompilerArguments;
224 }
225
226 }