|
61 | 61 | import org.apache.maven.shared.incremental.IncrementalBuildHelperRequest; |
62 | 62 | import org.apache.maven.shared.utils.ReaderFactory; |
63 | 63 | import org.apache.maven.shared.utils.StringUtils; |
| 64 | +import org.apache.maven.shared.utils.io.DirectoryScanResult; |
| 65 | +import org.apache.maven.shared.utils.io.DirectoryScanner; |
64 | 66 | import org.apache.maven.shared.utils.io.FileUtils; |
65 | 67 | import org.apache.maven.shared.utils.logging.MessageBuilder; |
66 | 68 | import org.apache.maven.shared.utils.logging.MessageUtils; |
@@ -101,6 +103,8 @@ public abstract class AbstractCompilerMojo |
101 | 103 | { |
102 | 104 | protected static final String PS = System.getProperty( "path.separator" ); |
103 | 105 |
|
| 106 | + private static final String INPUT_FILES_LST_FILENAME = "inputFiles.lst"; |
| 107 | + |
104 | 108 | static final String DEFAULT_SOURCE = "1.7"; |
105 | 109 |
|
106 | 110 | static final String DEFAULT_TARGET = "1.7"; |
@@ -561,6 +565,8 @@ public abstract class AbstractCompilerMojo |
561 | 565 | @Parameter( defaultValue = "true", property = "maven.compiler.createMissingPackageInfoClass" ) |
562 | 566 | private boolean createMissingPackageInfoClass = true; |
563 | 567 |
|
| 568 | + @Parameter( defaultValue = "false", property = "maven.compiler.showCompilationChanges" ) |
| 569 | + private boolean showCompilationChanges = false; |
564 | 570 | /** |
565 | 571 | * Resolves the artifacts needed. |
566 | 572 | */ |
@@ -876,14 +882,34 @@ else if ( CompilerConfiguration.CompilerReuseStrategy.ReuseSame.getStrategy().eq |
876 | 882 |
|
877 | 883 | incrementalBuildHelperRequest = new IncrementalBuildHelperRequest().inputFiles( sources ); |
878 | 884 |
|
| 885 | + DirectoryScanResult dsr = computeInputFileTreeChanges( incrementalBuildHelper, sources ); |
| 886 | + |
| 887 | + boolean idk = compiler.getCompilerOutputStyle() |
| 888 | + .equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) && !canUpdateTarget; |
| 889 | + boolean dependencyChanged = isDependencyChanged(); |
| 890 | + boolean sourceChanged = isSourceChanged( compilerConfiguration, compiler ); |
| 891 | + boolean inputFileTreeChanged = hasInputFileTreeChanged( dsr ); |
879 | 892 | // CHECKSTYLE_OFF: LineLength |
880 | | - if ( ( compiler.getCompilerOutputStyle().equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) && !canUpdateTarget ) |
881 | | - || isDependencyChanged() |
882 | | - || isSourceChanged( compilerConfiguration, compiler ) |
883 | | - || incrementalBuildHelper.inputFileTreeChanged( incrementalBuildHelperRequest ) ) |
| 893 | + if ( idk |
| 894 | + || dependencyChanged |
| 895 | + || sourceChanged |
| 896 | + || inputFileTreeChanged ) |
884 | 897 | // CHECKSTYLE_ON: LineLength |
885 | 898 | { |
886 | | - getLog().info( "Changes detected - recompiling the module!" ); |
| 899 | + String cause = idk ? "idk" : ( dependencyChanged ? "dependency" |
| 900 | + : ( sourceChanged ? "source" : "input tree" ) ); |
| 901 | + getLog().info( "Changes detected - recompiling the module! :" + cause ); |
| 902 | + if ( showCompilationChanges ) |
| 903 | + { |
| 904 | + for ( String fileAdded : dsr.getFilesAdded() ) |
| 905 | + { |
| 906 | + getLog().info( "\t+ " + fileAdded ); |
| 907 | + } |
| 908 | + for ( String fileRemoved : dsr.getFilesRemoved() ) |
| 909 | + { |
| 910 | + getLog().info( "\t- " + fileRemoved ); |
| 911 | + } |
| 912 | + } |
887 | 913 |
|
888 | 914 | compilerConfiguration.setSourceFiles( sources ); |
889 | 915 | } |
@@ -1519,11 +1545,18 @@ private boolean isSourceChanged( CompilerConfiguration compilerConfiguration, Co |
1519 | 1545 | Set<File> staleSources = |
1520 | 1546 | computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( staleMillis ) ); |
1521 | 1547 |
|
1522 | | - if ( getLog().isDebugEnabled() ) |
| 1548 | + if ( getLog().isDebugEnabled() || showCompilationChanges ) |
1523 | 1549 | { |
1524 | 1550 | for ( File f : staleSources ) |
1525 | 1551 | { |
1526 | | - getLog().debug( "Stale source detected: " + f.getAbsolutePath() ); |
| 1552 | + if ( showCompilationChanges ) |
| 1553 | + { |
| 1554 | + getLog().info( "Stale source detected: " + f.getAbsolutePath() ); |
| 1555 | + } |
| 1556 | + else |
| 1557 | + { |
| 1558 | + getLog().debug( "Stale source detected: " + f.getAbsolutePath() ); |
| 1559 | + } |
1527 | 1560 | } |
1528 | 1561 | } |
1529 | 1562 | return !staleSources.isEmpty(); |
@@ -1740,7 +1773,14 @@ protected boolean isDependencyChanged() |
1740 | 1773 | { |
1741 | 1774 | if ( hasNewFile( artifactPath, buildStartTime ) ) |
1742 | 1775 | { |
1743 | | - getLog().debug( "New dependency detected: " + artifactPath.getAbsolutePath() ); |
| 1776 | + if ( showCompilationChanges ) |
| 1777 | + { |
| 1778 | + getLog().info( "New dependency detected: " + artifactPath.getAbsolutePath() ); |
| 1779 | + } |
| 1780 | + else |
| 1781 | + { |
| 1782 | + getLog().debug( "New dependency detected: " + artifactPath.getAbsolutePath() ); |
| 1783 | + } |
1744 | 1784 | return true; |
1745 | 1785 | } |
1746 | 1786 | } |
@@ -1889,6 +1929,47 @@ private String getMavenCompilerPluginVersion() |
1889 | 1929 | return pomProperties.getProperty( "version" ); |
1890 | 1930 | } |
1891 | 1931 |
|
| 1932 | + private DirectoryScanResult computeInputFileTreeChanges( IncrementalBuildHelper ibh, Set<File> inputFiles ) |
| 1933 | + throws MojoExecutionException |
| 1934 | + { |
| 1935 | + File mojoConfigBase = ibh.getMojoStatusDirectory(); |
| 1936 | + File mojoConfigFile = new File( mojoConfigBase, INPUT_FILES_LST_FILENAME ); |
| 1937 | + |
| 1938 | + String[] oldInputFiles = new String[0]; |
| 1939 | + |
| 1940 | + if ( mojoConfigFile.exists() ) |
| 1941 | + { |
| 1942 | + try |
| 1943 | + { |
| 1944 | + oldInputFiles = FileUtils.fileReadArray( mojoConfigFile ); |
| 1945 | + } |
| 1946 | + catch ( IOException e ) |
| 1947 | + { |
| 1948 | + throw new MojoExecutionException( "Error reading old mojo status " + mojoConfigFile, e ); |
| 1949 | + } |
| 1950 | + } |
| 1951 | + |
| 1952 | + String[] inputFileNames = inputFiles.stream().map( File::getAbsolutePath ).toArray( String[]::new ); |
| 1953 | + |
| 1954 | + DirectoryScanResult dsr = DirectoryScanner.diffFiles( oldInputFiles, inputFileNames ); |
| 1955 | + |
| 1956 | + try |
| 1957 | + { |
| 1958 | + FileUtils.fileWriteArray( mojoConfigFile, inputFileNames ); |
| 1959 | + } |
| 1960 | + catch ( IOException e ) |
| 1961 | + { |
| 1962 | + throw new MojoExecutionException( "Error while storing the mojo status", e ); |
| 1963 | + } |
| 1964 | + |
| 1965 | + return dsr; |
| 1966 | + } |
| 1967 | + |
| 1968 | + private boolean hasInputFileTreeChanged( DirectoryScanResult dsr ) |
| 1969 | + { |
| 1970 | + return ( dsr.getFilesAdded().length > 0 || dsr.getFilesRemoved().length > 0 ); |
| 1971 | + } |
| 1972 | + |
1892 | 1973 | public void setTarget( String target ) |
1893 | 1974 | { |
1894 | 1975 | this.target = target; |
|
0 commit comments