Skip to content

Commit 8b1459b

Browse files
authored
Fix message when building because of a clean state (#242)
1 parent a4dcc9e commit 8b1459b

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

src/it/MCOMPILER-500-package-info-incr/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def logFile = new File( basedir, 'build.log' )
2020
assert logFile.exists()
2121
content = logFile.text
2222

23-
assert 1 == content.count( "Recompiling the module because of ")
23+
assert 0 == content.count( "Recompiling the module because of ")
2424
assert 1 == content.count( 'Nothing to compile - all classes are up to date.' )
2525

2626

src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -869,39 +869,43 @@ public void execute() {
869869
incrementalBuildHelper =
870870
new IncrementalBuildHelper(mojoStatusPath, sources, buildDirectory, getOutputDirectory());
871871

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+
}
896900
}
897-
}
898901

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.");
903906

904-
return;
907+
return;
908+
}
905909
}
906910
} catch (CompilerException e) {
907911
throw new MojoException("Error while computing stale sources.", e);
@@ -1475,6 +1479,22 @@ private static List<Path> removeEmptyCompileSourceRoots(List<Path> compileSource
14751479
}
14761480
}
14771481

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+
14781498
/**
14791499
* We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own
14801500
* generated classes and if we got a file which is &gt;= the build-started timestamp, then we caught a file which

0 commit comments

Comments
 (0)