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 projectArtifact.setFile( outputDirectory );
131 }
132
133 protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
134 {
135 SourceInclusionScanner scanner = null;
136
137 if ( includes.isEmpty() && excludes.isEmpty() )
138 {
139 scanner = new StaleSourceScanner( staleMillis );
140 }
141 else
142 {
143 if ( includes.isEmpty() )
144 {
145 includes.add( "**/*.java" );
146 }
147 scanner = new StaleSourceScanner( staleMillis, includes, excludes );
148 }
149
150 return scanner;
151 }
152
153 protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
154 {
155 SourceInclusionScanner scanner = null;
156
157 if ( includes.isEmpty() && excludes.isEmpty() )
158 {
159 includes = Collections.singleton( "**/*." + inputFileEnding );
160 scanner = new SimpleSourceInclusionScanner( includes, Collections.EMPTY_SET );
161 }
162 else
163 {
164 if ( includes.isEmpty() )
165 {
166 includes.add( "**/*." + inputFileEnding );
167 }
168 scanner = new SimpleSourceInclusionScanner( includes, excludes );
169 }
170
171 return scanner;
172 }
173
174 protected String getSource()
175 {
176 return source;
177 }
178
179 protected String getTarget()
180 {
181 return target;
182 }
183
184 protected String getCompilerArgument()
185 {
186 return compilerArgument;
187 }
188
189 protected Map<String, String> getCompilerArguments()
190 {
191 return compilerArguments;
192 }
193
194 protected File getGeneratedSourcesDirectory()
195 {
196 return generatedSourcesDirectory;
197 }
198
199 }