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