Skip to content

Commit 0f01f2f

Browse files
committed
Enable incremental mode by default, fix Mixed compile order
1 parent 2c9ef64 commit 0f01f2f

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

src/it/test_directory_with_class_name/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
<artifactId>@project.artifactId@</artifactId>
3131
<version>@project.version@</version>
3232
<configuration>
33-
<!--recompileMode>incremental</recompileMode-->
33+
<recompileMode>all</recompileMode>
3434
<args>
35-
<arg>-target:jvm-1.7</arg>
35+
<arg>-target:jvm-1.8</arg>
3636
</args>
3737
<javacArgs>
3838
<javacArg>-source</javacArg>
39-
<javacArg>1.7</javacArg>
39+
<javacArg>1.8</javacArg>
4040
<javacArg>-target</javacArg>
41-
<javacArg>1.7</javacArg>
41+
<javacArg>1.8</javacArg>
4242
</javacArgs>
4343
</configuration>
4444
</plugin>

src/main/java/sbt_inc/SbtIncrementalCompiler.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323
import java.util.Optional;
2424
import java.util.function.Function;
25+
import java.util.stream.Collectors;
2526

2627
public class SbtIncrementalCompiler {
2728

@@ -58,7 +59,7 @@ public SbtIncrementalCompiler(File libraryJar, File reflectJar, File compilerJar
5859

5960
compiler = new IncrementalCompilerImpl();
6061

61-
AnalyzingCompiler scalaCompiler = new AnalyzingCompiler(
62+
ScalaCompiler scalaCompiler = new AnalyzingCompiler(
6263
scalaInstance, // scalaInstance
6364
ZincCompilerUtil.constantBridgeProvider(scalaInstance, compilerBridgeJar), //provider
6465
ClasspathOptionsUtil.auto(), // classpathOptions
@@ -99,9 +100,14 @@ public DefinesClass definesClass(File classpathEntry) {
99100
}
100101

101102
public void compile(List<String> classpathElements, List<File> sources, File classesDirectory, List<String> scalacOptions, List<String> javacOptions) {
103+
List<File> fullClasspath = new ArrayList<>();
104+
fullClasspath.add(classesDirectory);
105+
for (String classpathElement : classpathElements) {
106+
fullClasspath.add(new File(classpathElement));
107+
}
102108

103109
Inputs inputs = compiler.inputs(
104-
classpathElements.stream().map(File::new).toArray(size -> new File[size]), //classpath
110+
fullClasspath.toArray(new File[]{}), //classpath
105111
sources.toArray(new File[]{}), // sources
106112
classesDirectory, // classesDirectory
107113
scalacOptions.toArray(new String[]{}), // scalacOptions

src/main/java/scala_maven/ScalaCompilerSupport.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@
1616
*/
1717
public 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" =&gt; all sources are recompiled,
31-
* "incremental" =&gt; 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();

src/main/java/scala_maven/ScalaContinuousCompileMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected final void doExecute() throws Exception {
137137
analysisCacheFile = FileUtils.fileOf(analysisCacheFile, useCanonicalPath);
138138
testAnalysisCacheFile = FileUtils.fileOf(testAnalysisCacheFile, useCanonicalPath);
139139

140-
if (useFsc && !INCREMENTAL.equals(recompileMode)) {
140+
if (useFsc && recompileMode != RecompileMode.incremental) {
141141
getLog().info("use fsc for compilation");
142142
scalaClassName = "scala.tools.nsc.CompileClient";
143143
if (!once) {

0 commit comments

Comments
 (0)