[ 
https://issues.apache.org/jira/browse/MCOMPILER-381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17779691#comment-17779691
 ] 

ASF GitHub Bot commented on MCOMPILER-381:
------------------------------------------

slawekjaranowski commented on code in PR #181:
URL: 
https://github.com/apache/maven-compiler-plugin/pull/181#discussion_r1372383137


##########
src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java:
##########
@@ -876,37 +874,33 @@ public void execute() throws MojoExecutionException, 
CompilationFailureException
 
                 incrementalBuildHelperRequest = new 
IncrementalBuildHelperRequest().inputFiles(sources);
 
-                DirectoryScanResult dsr = 
computeInputFileTreeChanges(incrementalBuildHelper, sources);
-
-                boolean immutableOutputFile = 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 (immutableOutputFile || dependencyChanged || sourceChanged 
|| inputFileTreeChanged)
-                // CHECKSTYLE_ON: LineLength
-                {
-                    String cause = immutableOutputFile
-                            ? "immutable single output file"
-                            : (dependencyChanged
-                                    ? "changed dependency"
-                                    : (sourceChanged ? "changed source code" : 
"added or removed source files"));
-                    getLog().info("Recompiling the module because of " + cause 
+ ".");
-                    if (showCompilationChanges) {
-                        for (String fileAdded : dsr.getFilesAdded()) {
-                            getLog().info("\t+ " + fileAdded);
-                        }
-                        for (String fileRemoved : dsr.getFilesRemoved()) {
-                            getLog().info("\t- " + fileRemoved);
-                        }
-                    }
-
+                // Strategies used to detect modifications.
+                Supplier<String> immutableOutputFile = () -> 
(compiler.getCompilerOutputStyle()
+                                        
.equals(CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES)
+                                && !canUpdateTarget)
+                        ? "immutable single output file"
+                        : null;
+                Supplier<String> dependencyChanged = () -> 
isDependencyChanged() ? "changed dependency" : null;
+                Supplier<String> sourceChanged =
+                        () -> isSourceChanged(compilerConfiguration, compiler) 
? "changed source code" : null;
+                Supplier<String> inputFileTreeChanged =
+                        () -> 
hasInputFileTreeChanged(computeInputFileTreeChanges(incrementalBuildHelper, 
sources))
+                                ? "added or removed source files"
+                                : null;
+
+                // Lazy evaluation of the incremental compilation detection.
+                String cause = Stream.of(immutableOutputFile, 
dependencyChanged, sourceChanged, inputFileTreeChanged)

Review Comment:
   +1 for lazy evaluation





> Refactoring needed for isDependencyChanged / Using fileExtensions 
> (AbstractCompilerMojo)
> ----------------------------------------------------------------------------------------
>
>                 Key: MCOMPILER-381
>                 URL: https://issues.apache.org/jira/browse/MCOMPILER-381
>             Project: Maven Compiler Plugin
>          Issue Type: Improvement
>    Affects Versions: 3.8.1
>            Reporter: Karl Heinz Marbaise
>            Priority: Minor
>             Fix For: 3.12.0
>
>
> The code in the class AbstractCompilerMojo has a method 
> {{isDependencyChanged}} which uses the attribute {{fileExtensions}} which is 
> being changed within the {{isDependencyChanged}} method. This attribute is 
> also being used by the method {{hasNewFile}} which is a kind of confusing (a 
> control via a global variable).
> Furthermore a change in {{isDependencyChanged}} where replacing {{".class"}} 
> with {{"class"}} results in a [fail which is described here|MCOMPILER-379]. 
> It should be investigated how this code can be made more clear and maybe 
> easier to understand.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to