1616*/
1717public abstract class ScalaCompilerSupport extends ScalaSourceMojoSupport {
1818
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+ }
2130
2231 /**
2332 * Keeps track of if we get compile errors in incremental mode
@@ -26,14 +35,10 @@ public abstract class ScalaCompilerSupport extends ScalaSourceMojoSupport {
2635
2736 /**
2837 * 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}.
3439 */
35- @ Parameter (property = "recompileMode" , defaultValue = "all " )
36- protected String recompileMode = ALL ;
40+ @ Parameter (property = "recompileMode" , defaultValue = "incremental " )
41+ protected RecompileMode recompileMode ;
3742
3843 /**
3944 * notifyCompilation if true then print a message "path: compiling"
@@ -43,7 +48,7 @@ public abstract class ScalaCompilerSupport extends ScalaSourceMojoSupport {
4348 *
4449 */
4550 @ Parameter (property = "notifyCompilation" , defaultValue = "true" )
46- private boolean notifyCompilation = true ;
51+ private boolean notifyCompilation ;
4752
4853 abstract protected File getOutputDir () throws Exception ;
4954
@@ -90,13 +95,9 @@ protected void doExecute() throws Exception {
9095 }
9196
9297 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 ) {
9899 // if not compileInLoop, invoke incrementalCompile immediately
99- return incrementalCompile (classpathElements , sourceRootDirs , outputDir , analysisCacheFile , compileInLoop );
100+ return incrementalCompile (classpathElements , sourceRootDirs , outputDir , analysisCacheFile , false );
100101 }
101102
102103 long t0 = System .currentTimeMillis ();
@@ -119,7 +120,7 @@ protected int compile(List<File> sourceRootDirs, File outputDir, File analysisCa
119120 }
120121 long t1 = System .currentTimeMillis ();
121122
122- if (compileInLoop && INCREMENTAL . equals ( recompileMode ) ) {
123+ if (compileInLoop && recompileMode == RecompileMode . incremental ) {
123124 // if compileInLoop, do not invoke incrementalCompile when there's no change
124125 int retCode = incrementalCompile (classpathElements , sourceRootDirs , outputDir , analysisCacheFile , compileInLoop );
125126 _lastCompileAt = t1 ;
@@ -173,7 +174,7 @@ protected List<File> getFilesToCompile(List<File> sourceRootDirs, long lastSucce
173174 // (restore how it work in 2.11 and failed in 2.12)
174175 //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)
175176 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 ))) {
177178 ArrayList <File > modifiedScalaFiles = new ArrayList <File >(sourceFiles .size ());
178179 ArrayList <File > modifiedJavaFiles = new ArrayList <File >(sourceFiles .size ());
179180 ArrayList <File > allJavaFiles = new ArrayList <File >(sourceFiles .size ());
@@ -252,6 +253,11 @@ protected int incrementalCompile(List<String> classpathElements, List<File> sour
252253 return -1 ;
253254 }
254255
256+ // TODO - Do we really need this duplicated here?
257+ if (!outputDir .exists ()) {
258+ outputDir .mkdirs ();
259+ }
260+
255261 if (incremental == null ) {
256262 File libraryJar = getLibraryJar ();
257263 File reflectJar = getReflectJar ();
0 commit comments