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