Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix message when building because of a clean state #242

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -933,30 +933,35 @@ public void execute() throws MojoExecutionException, CompilationFailureException
incrementalBuildHelperRequest = new IncrementalBuildHelperRequest().inputFiles(sources);

// Strategies used to detect modifications.
String immutableOutputFile = (compiler.getCompilerOutputStyle()
.equals(CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES)
&& !canUpdateTarget)
? "immutable single output file"
: null;
String dependencyChanged = isDependencyChanged() ? "changed dependency" : null;
String sourceChanged = isSourceChanged(compilerConfiguration, compiler) ? "changed source code" : null;
String inputFileTreeChanged = hasInputFileTreeChanged(incrementalBuildHelper, sources)
? "added or removed source files"
: null;

// Get the first cause for the rebuild compilation detection.
String cause = Stream.of(immutableOutputFile, dependencyChanged, sourceChanged, inputFileTreeChanged)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);

if (cause != null) {
getLog().info("Recompiling the module because of "
+ MessageUtils.buffer().strong(cause) + ".");
compilerConfiguration.setSourceFiles(sources);
} else {
getLog().info("Nothing to compile - all classes are up to date.");
return;
boolean cleanState = isCleanState(incrementalBuildHelper);
if (!cleanState) {
String immutableOutputFile = (compiler.getCompilerOutputStyle()
.equals(CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES)
&& !canUpdateTarget)
? "immutable single output file"
: null;
String dependencyChanged = isDependencyChanged() ? "changed dependency" : null;
String sourceChanged =
isSourceChanged(compilerConfiguration, compiler) ? "changed source code" : null;
String inputFileTreeChanged = hasInputFileTreeChanged(incrementalBuildHelper, sources)
? "added or removed source files"
: null;

// Get the first cause for the rebuild compilation detection.
String cause = Stream.of(
immutableOutputFile, dependencyChanged, sourceChanged, inputFileTreeChanged)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);

if (cause != null) {
getLog().info("Recompiling the module because of "
+ MessageUtils.buffer().strong(cause) + ".");
compilerConfiguration.setSourceFiles(sources);
} else {
getLog().info("Nothing to compile - all classes are up to date.");
return;
}
}
} catch (CompilerException e) {
throw new MojoExecutionException("Error while computing stale sources.", e);
Expand Down Expand Up @@ -1591,6 +1596,22 @@ private static List<String> removeEmptyCompileSourceRoots(List<String> compileSo
return newCompileSourceRootsList;
}

/**
*
*/
protected boolean isCleanState(IncrementalBuildHelper ibh) {
Path mojoConfigBase;
try {
mojoConfigBase = ibh.getMojoStatusDirectory().toPath();
} catch (MojoExecutionException e) {
// we cannot get the mojo status dir, so don't do anything beside logging
getLog().warn("Error reading mojo status directory.");
return false;
}
Path mojoConfigFile = mojoConfigBase.resolve(INPUT_FILES_LST_FILENAME);
return !Files.exists(mojoConfigFile);
}

/**
* We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own
* generated classes and if we got a file which is &gt;= the build-started timestamp, then we caught a file which
Expand Down
Loading