You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2022/07/27 06:38:17 UTC

[maven-compiler-plugin] branch MCOMPILER-499_display_recompilation_causes created (now c4a87aa)

This is an automated email from the ASF dual-hosted git repository.

olamy pushed a change to branch MCOMPILER-499_display_recompilation_causes
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git


      at c4a87aa  apply changes from #129

This branch includes the following new commits:

     new 7a2bfef  Display recompilation causes
     new c4a87aa  apply changes from #129

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-compiler-plugin] 02/02: apply changes from #129

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch MCOMPILER-499_display_recompilation_causes
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git

commit c4a87aa4c8e4604cbfcd191fe7bceb5382df85a7
Author: Olivier Lamy <ol...@apache.org>
AuthorDate: Wed Jul 27 16:37:29 2022 +1000

    apply changes from #129
    
    Signed-off-by: Olivier Lamy <ol...@apache.org>
---
 .../org/apache/maven/plugin/compiler/AbstractCompilerMojo.java   | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

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 f2103a9..d9e5a6d 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -1545,7 +1545,7 @@ public abstract class AbstractCompilerMojo
         Set<File> staleSources =
             computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( staleMillis ) );
 
-        if ( getLog().isDebugEnabled() )
+        if ( getLog().isDebugEnabled() || showCompilationChanges )
         {
             for ( File f : staleSources )
             {
@@ -1949,12 +1949,7 @@ public abstract class AbstractCompilerMojo
             }
         }
 
-        String[] inputFileNames = new String[ inputFiles.size() ];
-        int i = 0;
-        for ( File inputFile : inputFiles )
-        {
-            inputFileNames[ i++ ] = inputFile.getAbsolutePath();
-        }
+        String[] inputFileNames = inputFiles.stream().map( File::getAbsolutePath ).toArray( String[]::new );
 
         DirectoryScanResult dsr = DirectoryScanner.diffFiles( oldInputFiles, inputFileNames );
 


[maven-compiler-plugin] 01/02: Display recompilation causes

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch MCOMPILER-499_display_recompilation_causes
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git

commit 7a2bfef5620187a230cdf01b3999a4e927aadd0b
Author: Loïc Ledoyen <lo...@mirakl.com>
AuthorDate: Mon May 30 11:33:45 2022 +0200

    Display recompilation causes
---
 .../plugin/compiler/AbstractCompilerMojo.java      | 100 +++++++++++++++++++--
 1 file changed, 93 insertions(+), 7 deletions(-)

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..f2103a9 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.IncrementalBuildHelper;
 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 @@ public abstract class AbstractCompilerMojo
 {
     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 @@ public abstract class AbstractCompilerMojo
     @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 @@ public abstract class AbstractCompilerMojo
 
                 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 );
                 }
@@ -1523,7 +1549,14 @@ public abstract class AbstractCompilerMojo
         {
             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 @@ public abstract class AbstractCompilerMojo
             {
                 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,52 @@ public abstract class AbstractCompilerMojo
         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 = new String[ inputFiles.size() ];
+        int i = 0;
+        for ( File inputFile : inputFiles )
+        {
+            inputFileNames[ i++ ] = inputFile.getAbsolutePath();
+        }
+
+        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;