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

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

jorsol commented on code in PR #219:
URL: 
https://github.com/apache/maven-compiler-plugin/pull/219#discussion_r1433148927


##########
src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java:
##########
@@ -1842,6 +1851,48 @@ private boolean 
hasInputFileTreeChanged(IncrementalBuildHelper ibh, Set<File> in
         return inputTreeChanges.hasChanged();
     }
 
+    private static final int MAX_FILE_WALK_LIMIT = 20;
+
+    /**
+     * Performs a check on compiled class files to ensure that the bytecode 
version
+     * hasn't changed between runs.
+     *
+     * <p>This is limited to check a maximum of {@link #MAX_FILE_WALK_LIMIT}.
+     *
+     * @return true if a bytecode version differs from the actual release 
version.
+     */
+    private boolean hasBytecodeChanged() {
+        String currentVersion = getVersionRelease();
+        JavaVersion javaVersion = JavaVersion.parse(currentVersion).asMajor();
+
+        try (Stream<Path> walk = Files.walk(getOutputDirectory().toPath())) {
+            Map<Path, JavaClassfileVersion> pathVersionMap = walk.filter(file 
-> "class"
+                            
.equals(FileUtils.extension(file.getFileName().toString())))
+                    .limit(MAX_FILE_WALK_LIMIT)
+                    .collect(Collectors.toMap(Function.identity(), 
JavaClassfileVersion::of));

Review Comment:
   That's a really good approach, I'm making complex bytecode checks when 
simply storing the current JDK, and verifying next time would do the trick.
   
   Closing this in favor of that approach (will open a new PR later).





> Add new rebuild detection for bytecode changes
> ----------------------------------------------
>
>                 Key: MCOMPILER-561
>                 URL: https://issues.apache.org/jira/browse/MCOMPILER-561
>             Project: Maven Compiler Plugin
>          Issue Type: New Feature
>    Affects Versions: 3.11.0, 3.12.0
>            Reporter: Jorge Solórzano
>            Priority: Major
>
> If the source code changes the bytecode version, it should trigger a rebuild.



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

Reply via email to