@@ -869,39 +869,43 @@ public void execute() {
869
869
incrementalBuildHelper =
870
870
new IncrementalBuildHelper (mojoStatusPath , sources , buildDirectory , getOutputDirectory ());
871
871
872
- List <String > added = new ArrayList <>();
873
- List <String > removed = new ArrayList <>();
874
- boolean immutableOutputFile = compiler .getCompilerOutputStyle ()
875
- .equals (CompilerOutputStyle .ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES )
876
- && !canUpdateTarget ;
877
- boolean dependencyChanged = isDependencyChanged ();
878
- boolean sourceChanged = isSourceChanged (compilerConfiguration , compiler );
879
- boolean inputFileTreeChanged = incrementalBuildHelper .inputFileTreeChanged (added , removed );
880
- // CHECKSTYLE_OFF: LineLength
881
- if (immutableOutputFile || dependencyChanged || sourceChanged || inputFileTreeChanged )
882
- // CHECKSTYLE_ON: LineLength
883
- {
884
- String cause = immutableOutputFile
885
- ? "immutable single output file"
886
- : (dependencyChanged
887
- ? "changed dependency"
888
- : (sourceChanged ? "changed source code" : "added or removed source files" ));
889
- getLog ().info ("Recompiling the module because of " + cause + "." );
890
- if (showCompilationChanges ) {
891
- for (String fileAdded : added ) {
892
- getLog ().info ("\t + " + fileAdded );
893
- }
894
- for (String fileRemoved : removed ) {
895
- getLog ().info ("\t - " + fileRemoved );
872
+ // Strategies used to detect modifications.
873
+ boolean cleanState = isCleanState (incrementalBuildHelper );
874
+ if (!cleanState ) {
875
+ List <String > added = new ArrayList <>();
876
+ List <String > removed = new ArrayList <>();
877
+ boolean immutableOutputFile = compiler .getCompilerOutputStyle ()
878
+ .equals (CompilerOutputStyle .ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES )
879
+ && !canUpdateTarget ;
880
+ boolean dependencyChanged = isDependencyChanged ();
881
+ boolean sourceChanged = isSourceChanged (compilerConfiguration , compiler );
882
+ boolean inputFileTreeChanged = incrementalBuildHelper .inputFileTreeChanged (added , removed );
883
+ // CHECKSTYLE_OFF: LineLength
884
+ if (immutableOutputFile || dependencyChanged || sourceChanged || inputFileTreeChanged )
885
+ // CHECKSTYLE_ON: LineLength
886
+ {
887
+ String cause = immutableOutputFile
888
+ ? "immutable single output file"
889
+ : (dependencyChanged
890
+ ? "changed dependency"
891
+ : (sourceChanged ? "changed source code" : "added or removed source files" ));
892
+ getLog ().info ("Recompiling the module because of " + cause + "." );
893
+ if (showCompilationChanges ) {
894
+ for (String fileAdded : added ) {
895
+ getLog ().info ("\t + " + fileAdded );
896
+ }
897
+ for (String fileRemoved : removed ) {
898
+ getLog ().info ("\t - " + fileRemoved );
899
+ }
896
900
}
897
- }
898
901
899
- compilerConfiguration .setSourceFiles (
900
- sources .stream ().map (Path ::toFile ).collect (Collectors .toSet ()));
901
- } else {
902
- getLog ().info ("Nothing to compile - all classes are up to date." );
902
+ compilerConfiguration .setSourceFiles (
903
+ sources .stream ().map (Path ::toFile ).collect (Collectors .toSet ()));
904
+ } else {
905
+ getLog ().info ("Nothing to compile - all classes are up to date." );
903
906
904
- return ;
907
+ return ;
908
+ }
905
909
}
906
910
} catch (CompilerException e ) {
907
911
throw new MojoException ("Error while computing stale sources." , e );
@@ -1475,6 +1479,22 @@ private static List<Path> removeEmptyCompileSourceRoots(List<Path> compileSource
1475
1479
}
1476
1480
}
1477
1481
1482
+ /**
1483
+ *
1484
+ */
1485
+ protected boolean isCleanState (IncrementalBuildHelper ibh ) {
1486
+ Path mojoConfigBase ;
1487
+ try {
1488
+ mojoConfigBase = ibh .getMojoStatusDirectory ();
1489
+ } catch (MojoException e ) {
1490
+ // we cannot get the mojo status dir, so don't do anything beside logging
1491
+ getLog ().warn ("Error reading mojo status directory." );
1492
+ return false ;
1493
+ }
1494
+ Path mojoConfigFile = mojoConfigBase .resolve (INPUT_FILES_LST_FILENAME );
1495
+ return !Files .exists (mojoConfigFile );
1496
+ }
1497
+
1478
1498
/**
1479
1499
* We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own
1480
1500
* generated classes and if we got a file which is >= the build-started timestamp, then we caught a file which
0 commit comments