MCOMPILER 499 display recompilation causes (#143)
* Display recompilation causes
Signed-off-by: Olivier Lamy <olamy@apache.org>
Co-authored-by: Loïc Ledoyen <loic.ledoyen@mirakl.com>
diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index 6f27504..d9e5a6d 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -61,6 +61,8 @@
import org.apache.maven.shared.incremental.IncrementalBuildHelperRequest;
import org.apache.maven.shared.utils.ReaderFactory;
import org.apache.maven.shared.utils.StringUtils;
+import org.apache.maven.shared.utils.io.DirectoryScanResult;
+import org.apache.maven.shared.utils.io.DirectoryScanner;
import org.apache.maven.shared.utils.io.FileUtils;
import org.apache.maven.shared.utils.logging.MessageBuilder;
import org.apache.maven.shared.utils.logging.MessageUtils;
@@ -101,6 +103,8 @@
{
protected static final String PS = System.getProperty( "path.separator" );
+ private static final String INPUT_FILES_LST_FILENAME = "inputFiles.lst";
+
static final String DEFAULT_SOURCE = "1.7";
static final String DEFAULT_TARGET = "1.7";
@@ -561,6 +565,8 @@
@Parameter( defaultValue = "true", property = "maven.compiler.createMissingPackageInfoClass" )
private boolean createMissingPackageInfoClass = true;
+ @Parameter( defaultValue = "false", property = "maven.compiler.showCompilationChanges" )
+ private boolean showCompilationChanges = false;
/**
* Resolves the artifacts needed.
*/
@@ -876,14 +882,34 @@
incrementalBuildHelperRequest = new IncrementalBuildHelperRequest().inputFiles( sources );
+ DirectoryScanResult dsr = computeInputFileTreeChanges( incrementalBuildHelper, sources );
+
+ boolean idk = compiler.getCompilerOutputStyle()
+ .equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) && !canUpdateTarget;
+ boolean dependencyChanged = isDependencyChanged();
+ boolean sourceChanged = isSourceChanged( compilerConfiguration, compiler );
+ boolean inputFileTreeChanged = hasInputFileTreeChanged( dsr );
// CHECKSTYLE_OFF: LineLength
- if ( ( compiler.getCompilerOutputStyle().equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) && !canUpdateTarget )
- || isDependencyChanged()
- || isSourceChanged( compilerConfiguration, compiler )
- || incrementalBuildHelper.inputFileTreeChanged( incrementalBuildHelperRequest ) )
+ if ( idk
+ || dependencyChanged
+ || sourceChanged
+ || inputFileTreeChanged )
// CHECKSTYLE_ON: LineLength
{
- getLog().info( "Changes detected - recompiling the module!" );
+ String cause = idk ? "idk" : ( dependencyChanged ? "dependency"
+ : ( sourceChanged ? "source" : "input tree" ) );
+ getLog().info( "Changes detected - recompiling the module! :" + cause );
+ if ( showCompilationChanges )
+ {
+ for ( String fileAdded : dsr.getFilesAdded() )
+ {
+ getLog().info( "\t+ " + fileAdded );
+ }
+ for ( String fileRemoved : dsr.getFilesRemoved() )
+ {
+ getLog().info( "\t- " + fileRemoved );
+ }
+ }
compilerConfiguration.setSourceFiles( sources );
}
@@ -1519,11 +1545,18 @@
Set<File> staleSources =
computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( staleMillis ) );
- if ( getLog().isDebugEnabled() )
+ if ( getLog().isDebugEnabled() || showCompilationChanges )
{
for ( File f : staleSources )
{
- getLog().debug( "Stale source detected: " + f.getAbsolutePath() );
+ if ( showCompilationChanges )
+ {
+ getLog().info( "Stale source detected: " + f.getAbsolutePath() );
+ }
+ else
+ {
+ getLog().debug( "Stale source detected: " + f.getAbsolutePath() );
+ }
}
}
return !staleSources.isEmpty();
@@ -1740,7 +1773,14 @@
{
if ( hasNewFile( artifactPath, buildStartTime ) )
{
- getLog().debug( "New dependency detected: " + artifactPath.getAbsolutePath() );
+ if ( showCompilationChanges )
+ {
+ getLog().info( "New dependency detected: " + artifactPath.getAbsolutePath() );
+ }
+ else
+ {
+ getLog().debug( "New dependency detected: " + artifactPath.getAbsolutePath() );
+ }
return true;
}
}
@@ -1889,6 +1929,47 @@
return pomProperties.getProperty( "version" );
}
+ private DirectoryScanResult computeInputFileTreeChanges( IncrementalBuildHelper ibh, Set<File> inputFiles )
+ throws MojoExecutionException
+ {
+ File mojoConfigBase = ibh.getMojoStatusDirectory();
+ File mojoConfigFile = new File( mojoConfigBase, INPUT_FILES_LST_FILENAME );
+
+ String[] oldInputFiles = new String[0];
+
+ if ( mojoConfigFile.exists() )
+ {
+ try
+ {
+ oldInputFiles = FileUtils.fileReadArray( mojoConfigFile );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error reading old mojo status " + mojoConfigFile, e );
+ }
+ }
+
+ String[] inputFileNames = inputFiles.stream().map( File::getAbsolutePath ).toArray( String[]::new );
+
+ DirectoryScanResult dsr = DirectoryScanner.diffFiles( oldInputFiles, inputFileNames );
+
+ try
+ {
+ FileUtils.fileWriteArray( mojoConfigFile, inputFileNames );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error while storing the mojo status", e );
+ }
+
+ return dsr;
+ }
+
+ private boolean hasInputFileTreeChanged( DirectoryScanResult dsr )
+ {
+ return ( dsr.getFilesAdded().length > 0 || dsr.getFilesRemoved().length > 0 );
+ }
+
public void setTarget( String target )
{
this.target = target;