gnodet commented on code in PR #1157: URL: https://github.com/apache/maven-compiler-plugin/pull/1157#discussion_r4192590294
########## src/main/java/org/apache/maven/plugin/compiler/incremental/Sha256.java: ########## @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugin.compiler.incremental; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.HexFormat; + +/** + * SHA-256 hashing utility shared by the bytecode analyzer implementations. + */ +public final class Sha256 { + + private Sha256() {} + + /** + * Returns the first 16 hex characters of the SHA-256 hash of {@code input}. + * + * @param input the string to hash + * @return 16-character hex string + */ + public static String hash(String input) { + return hash(input.getBytes(StandardCharsets.UTF_8)); + } + + /** + * Returns the first 16 hex characters of the SHA-256 hash of {@code content}. + * + * @param content the bytes to hash + * @return 16-character hex string + */ + public static String hash(byte[] content) { + try { + var md = MessageDigest.getInstance("SHA-256"); + byte[] digest = md.digest(content); + return HexFormat.of().formatHex(digest).substring(0, 16); Review Comment: _Claude Code on behalf of Guillaume Nodet_ Acknowledged — the truncation is safe for change detection in this context. ########## pom.xml: ########## @@ -188,10 +188,88 @@ under the License. <excludes> <exclude>unit/**</exclude> </excludes> + <!-- + Tests run against the exploded classes directory, not the packaged JAR. + The JVM's multi-release JAR dispatch does not apply to directories, so + the JDK 24+ BytecodeAnalyzer override must be placed before the root stub + on the classpath. We prepend META-INF/versions/24/ via the classesDirectory parameter + so it is resolved before target/classes/ by the bootstrap class loader. + --> + <classesDirectory>${project.build.outputDirectory}/META-INF/versions/24</classesDirectory> + <additionalClasspathElements> + <additionalClasspathElement>${project.build.outputDirectory}</additionalClasspathElement> + </additionalClasspathElements> </configuration> </plugin> </plugins> </pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <executions> + <execution> + <id>enforce-java-build-version</id> + <goals> + <goal>enforce</goal> + </goals> + <configuration> + <rules> + <requireJavaVersion> + <!-- + Building this plugin requires JDK 25+ so that the java.lang.classfile + classes in src/main/java24/ can always be compiled (with release=24). + The compiled plugin JAR targets JDK 17 for main sources and JDK 24 + for the classfile-backed bytecode analyzer, and runs on any JVM >= 17. + --> + <version>[25,)</version> + </requireJavaVersion> + </rules> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <executions> + <execution> + <!-- + Compile the java.lang.classfile-based bytecode analyzer (JDK 24+ API) + into META-INF/versions/24/ to form a proper multi-release JAR. + On JDK 24+, the JVM automatically loads the versioned BytecodeAnalyzer + which delegates directly to ClassfileClassAnalyzer (no reflection needed). + On JDK < 24, the root BytecodeAnalyzer stub is loaded instead, which + reports isAvailable()=false and triggers a fallback to the timestamp strategy. + JDK 25 is required at build time so this execution always runs. + --> + <id>compile-java24</id> + <goals> + <goal>compile</goal> + </goals> + <phase>compile</phase> + <configuration> + <compileSourceRoots> + <compileSourceRoot>${project.basedir}/src/main/java24</compileSourceRoot> + </compileSourceRoots> + <release>24</release> + <outputDirectory>${project.build.outputDirectory}/META-INF/versions/24</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + <plugin> Review Comment: _Claude Code on behalf of Guillaume Nodet_ This is an intentional design decision — JDK 25+ is required at build time so that the java24 sources compile unconditionally. The plugin JAR still runs on JDK 17+. The JDK 25+ requirement is enforced in the base MRJAR PR (#1158). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
