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.apache.maven.artifact.Artifact;
23 import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
24 import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
25 import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
26
27 import java.io.File;
28 import java.util.Collections;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Set;
33
34
35
36
37
38
39
40
41
42
43
44
45 public class CompilerMojo
46 extends AbstractCompilerMojo
47 {
48
49
50
51
52
53
54
55 private List<String> compileSourceRoots;
56
57
58
59
60
61
62
63
64 private List<String> classpathElements;
65
66
67
68
69
70
71
72
73 private File outputDirectory;
74
75
76
77
78
79
80
81
82
83 private Artifact projectArtifact;
84
85
86
87
88
89
90 private Set<String> includes = new HashSet<String>();
91
92
93
94
95
96
97 private Set<String> excludes = new HashSet<String>();
98
99
100
101
102
103
104
105
106
107 private File generatedSourcesDirectory;
108
109
110 protected List<String> getCompileSourceRoots()
111 {
112 return compileSourceRoots;
113 }
114
115 protected List<String> getClasspathElements()
116 {
117 return classpathElements;
118 }
119
120 protected File getOutputDirectory()
121 {
122 return outputDirectory;
123 }
124
125 public void execute()
126 throws MojoExecutionException, CompilationFailureException
127 {
128 super.execute();
129
130 if ( outputDirectory.isDirectory() )
131 {
132 projectArtifact.setFile( outputDirectory );
133 }
134 }
135
136 protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
137 {
138 SourceInclusionScanner scanner = null;
139
140 if ( includes.isEmpty() && excludes.isEmpty() )
141 {
142 scanner = new StaleSourceScanner( staleMillis );
143 }
144 else
145 {
146 if ( includes.isEmpty() )
147 {
148 includes.add( "**/*.java" );
149 }
150 scanner = new StaleSourceScanner( staleMillis, includes, excludes );
151 }
152
153 return scanner;
154 }
155
156 protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
157 {
158 SourceInclusionScanner scanner = null;
159
160 if ( includes.isEmpty() && excludes.isEmpty() )
161 {
162 includes = Collections.singleton( "**/*." + inputFileEnding );
163 scanner = new SimpleSourceInclusionScanner( includes, Collections.EMPTY_SET );
164 }
165 else
166 {
167 if ( includes.isEmpty() )
168 {
169 includes.add( "**/*." + inputFileEnding );
170 }
171 scanner = new SimpleSourceInclusionScanner( includes, excludes );
172 }
173
174 return scanner;
175 }
176
177 protected String getSource()
178 {
179 return source;
180 }
181
182 protected String getTarget()
183 {
184 return target;
185 }
186
187 protected String getCompilerArgument()
188 {
189 return compilerArgument;
190 }
191
192 protected Map<String, String> getCompilerArguments()
193 {
194 return compilerArguments;
195 }
196
197 protected File getGeneratedSourcesDirectory()
198 {
199 return generatedSourcesDirectory;
200 }
201
202 }