-
Notifications
You must be signed in to change notification settings - Fork 167
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
[MCOMPILER-499] Display recompilation causes #129
Closed
ledoyen
wants to merge
1
commit into
apache:master
from
ledoyen:feature/display_recompilation_causes
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,6 +60,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; | ||||||
|
@@ -100,6 +102,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"; | ||||||
|
@@ -560,6 +564,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. | ||||||
*/ | ||||||
|
@@ -875,14 +881,34 @@ else if ( CompilerConfiguration.CompilerReuseStrategy.ReuseSame.getStrategy().eq | |||||
|
||||||
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 ); | ||||||
} | ||||||
|
@@ -1515,7 +1541,14 @@ private boolean isSourceChanged( CompilerConfiguration compilerConfiguration, Co | |||||
{ | ||||||
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(); | ||||||
|
@@ -1760,7 +1793,14 @@ protected boolean isDependencyChanged() | |||||
{ | ||||||
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; | ||||||
} | ||||||
} | ||||||
|
@@ -1909,6 +1949,52 @@ private String getMavenCompilerPluginVersion() | |||||
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() ]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simply replace the block with a single line. yup even Maven can use modern syntax 😜 |
||||||
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; | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we cannot see it in this GH ui diff but we go in this path only
if ( getLog().isDebugEnabled() )
this must be changed to something suchif ( !staleSources.isEmpty() && (getLog().isDebugEnabled() || showCompilationChanges))
I guess the idea is to display those files when using
-Dmaven.compiler.showCompilationChanges=true
but without using full debug with-X