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 | 9 | 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 | 9 | private Set<String> includes = new HashSet<String>(); |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | 9 | 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 | 27 | return compileSourceRoots; |
113 | |
} |
114 | |
|
115 | |
protected List<String> getClasspathElements() |
116 | |
{ |
117 | 21 | return classpathElements; |
118 | |
} |
119 | |
|
120 | |
protected File getOutputDirectory() |
121 | |
{ |
122 | 34 | return outputDirectory; |
123 | |
} |
124 | |
|
125 | |
public void execute() |
126 | |
throws MojoExecutionException, CompilationFailureException |
127 | |
{ |
128 | 9 | super.execute(); |
129 | |
|
130 | 8 | if ( outputDirectory.isDirectory() ) |
131 | |
{ |
132 | 7 | projectArtifact.setFile( outputDirectory ); |
133 | |
} |
134 | 8 | } |
135 | |
|
136 | |
protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis ) |
137 | |
{ |
138 | 8 | SourceInclusionScanner scanner = null; |
139 | |
|
140 | 8 | if ( includes.isEmpty() && excludes.isEmpty() ) |
141 | |
{ |
142 | 6 | scanner = new StaleSourceScanner( staleMillis ); |
143 | |
} |
144 | |
else |
145 | |
{ |
146 | 2 | if ( includes.isEmpty() ) |
147 | |
{ |
148 | 0 | includes.add( "**/*.java" ); |
149 | |
} |
150 | 2 | scanner = new StaleSourceScanner( staleMillis, includes, excludes ); |
151 | |
} |
152 | |
|
153 | 8 | return scanner; |
154 | |
} |
155 | |
|
156 | |
protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding ) |
157 | |
{ |
158 | 5 | SourceInclusionScanner scanner = null; |
159 | |
|
160 | 5 | if ( includes.isEmpty() && excludes.isEmpty() ) |
161 | |
{ |
162 | 4 | includes = Collections.singleton( "**/*." + inputFileEnding ); |
163 | 4 | scanner = new SimpleSourceInclusionScanner( includes, Collections.EMPTY_SET ); |
164 | |
} |
165 | |
else |
166 | |
{ |
167 | 1 | if ( includes.isEmpty() ) |
168 | |
{ |
169 | 0 | includes.add( "**/*." + inputFileEnding ); |
170 | |
} |
171 | 1 | scanner = new SimpleSourceInclusionScanner( includes, excludes ); |
172 | |
} |
173 | |
|
174 | 5 | return scanner; |
175 | |
} |
176 | |
|
177 | |
protected String getSource() |
178 | |
{ |
179 | 8 | return source; |
180 | |
} |
181 | |
|
182 | |
protected String getTarget() |
183 | |
{ |
184 | 8 | return target; |
185 | |
} |
186 | |
|
187 | |
protected String getCompilerArgument() |
188 | |
{ |
189 | 8 | return compilerArgument; |
190 | |
} |
191 | |
|
192 | |
protected Map<String, String> getCompilerArguments() |
193 | |
{ |
194 | 8 | return compilerArguments; |
195 | |
} |
196 | |
|
197 | |
protected File getGeneratedSourcesDirectory() |
198 | |
{ |
199 | 8 | return generatedSourcesDirectory; |
200 | |
} |
201 | |
|
202 | |
} |