16
16
*/
17
17
public abstract class ScalaCompilerSupport extends ScalaSourceMojoSupport {
18
18
19
- public static final String ALL = "all" ;
20
- public static final String INCREMENTAL = "incremental" ;
19
+ public enum RecompileMode {
20
+ /**
21
+ * all sources are recompiled
22
+ */
23
+ all ,
24
+
25
+ /**
26
+ * incrementally recompile modified sources and other affected sources
27
+ */
28
+ incremental
29
+ }
21
30
22
31
/**
23
32
* Keeps track of if we get compile errors in incremental mode
@@ -26,14 +35,10 @@ public abstract class ScalaCompilerSupport extends ScalaSourceMojoSupport {
26
35
27
36
/**
28
37
* Recompile mode to use when sources were previously compiled and there is at
29
- * least one change:
30
- * "all" => all sources are recompiled,
31
- * "incremental" => incrementally recompile modified sources and other affected
32
- * sources.
33
- *
38
+ * least one change, see {@link RecompileMode}.
34
39
*/
35
- @ Parameter (property = "recompileMode" , defaultValue = "all " )
36
- protected String recompileMode = ALL ;
40
+ @ Parameter (property = "recompileMode" , defaultValue = "incremental " )
41
+ protected RecompileMode recompileMode ;
37
42
38
43
/**
39
44
* notifyCompilation if true then print a message "path: compiling"
@@ -43,7 +48,7 @@ public abstract class ScalaCompilerSupport extends ScalaSourceMojoSupport {
43
48
*
44
49
*/
45
50
@ Parameter (property = "notifyCompilation" , defaultValue = "true" )
46
- private boolean notifyCompilation = true ;
51
+ private boolean notifyCompilation ;
47
52
48
53
abstract protected File getOutputDir () throws Exception ;
49
54
@@ -90,13 +95,9 @@ protected void doExecute() throws Exception {
90
95
}
91
96
92
97
protected int compile (List <File > sourceRootDirs , File outputDir , File analysisCacheFile , List <String > classpathElements , boolean compileInLoop ) throws Exception , InterruptedException {
93
- if (!compileInLoop && INCREMENTAL .equals (recompileMode )) {
94
- // TODO - Do we really need this duplicated here?
95
- if (!outputDir .exists ()) {
96
- outputDir .mkdirs ();
97
- }
98
+ if (!compileInLoop && recompileMode == RecompileMode .incremental ) {
98
99
// if not compileInLoop, invoke incrementalCompile immediately
99
- return incrementalCompile (classpathElements , sourceRootDirs , outputDir , analysisCacheFile , compileInLoop );
100
+ return incrementalCompile (classpathElements , sourceRootDirs , outputDir , analysisCacheFile , false );
100
101
}
101
102
102
103
long t0 = System .currentTimeMillis ();
@@ -119,7 +120,7 @@ protected int compile(List<File> sourceRootDirs, File outputDir, File analysisCa
119
120
}
120
121
long t1 = System .currentTimeMillis ();
121
122
122
- if (compileInLoop && INCREMENTAL . equals ( recompileMode ) ) {
123
+ if (compileInLoop && recompileMode == RecompileMode . incremental ) {
123
124
// if compileInLoop, do not invoke incrementalCompile when there's no change
124
125
int retCode = incrementalCompile (classpathElements , sourceRootDirs , outputDir , analysisCacheFile , compileInLoop );
125
126
_lastCompileAt = t1 ;
@@ -173,7 +174,7 @@ protected List<File> getFilesToCompile(List<File> sourceRootDirs, long lastSucce
173
174
// (restore how it work in 2.11 and failed in 2.12)
174
175
//TODO a better behavior : if there is at least one .scala to compile then add all .java, if there is at least one .java then add all .scala (because we don't manage class dependency)
175
176
List <File > files = new ArrayList <>(sourceFiles .size ());
176
- if (_lastCompileAt > 0 || (! ALL . equals ( recompileMode ) && (lastSuccessfullCompileTime > 0 ))) {
177
+ if (_lastCompileAt > 0 || (recompileMode != RecompileMode . all && (lastSuccessfullCompileTime > 0 ))) {
177
178
ArrayList <File > modifiedScalaFiles = new ArrayList <File >(sourceFiles .size ());
178
179
ArrayList <File > modifiedJavaFiles = new ArrayList <File >(sourceFiles .size ());
179
180
ArrayList <File > allJavaFiles = new ArrayList <File >(sourceFiles .size ());
@@ -252,6 +253,11 @@ protected int incrementalCompile(List<String> classpathElements, List<File> sour
252
253
return -1 ;
253
254
}
254
255
256
+ // TODO - Do we really need this duplicated here?
257
+ if (!outputDir .exists ()) {
258
+ outputDir .mkdirs ();
259
+ }
260
+
255
261
if (incremental == null ) {
256
262
File libraryJar = getLibraryJar ();
257
263
File reflectJar = getReflectJar ();
0 commit comments