This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new f5abed9904 fix: resolve MojoDescriptorProcessorTest JARs from 
classpath instead of disk (#13982)
f5abed9904 is described below

commit f5abed990499707e2d423e0d3642e75ce0015ae9
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Nov 13 09:56:45 2026 +0100

    fix: resolve MojoDescriptorProcessorTest JARs from classpath instead of 
disk (#13982)
    
    The test was manually searching for dependency JARs on disk using
    hardcoded version strings and worktree/m2 path probing. This failed
    on CI where reactor artifacts are not installed to the local repo.
    
    Resolve the JARs (or target/classes directories in reactor builds)
    directly from the test classpath via Class.getProtectionDomain(), which
    works in all environments without any surefire system properties.
    
    Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
---
 impl/maven-plugin-mixin/pom.xml                    |  6 --
 .../processor/MojoDescriptorProcessorTest.java     | 70 ++++++----------------
 2 files changed, 17 insertions(+), 59 deletions(-)

diff --git a/impl/maven-plugin-mixin/pom.xml b/impl/maven-plugin-mixin/pom.xml
index 6f0c546126..a1fc41aaba 100644
--- a/impl/maven-plugin-mixin/pom.xml
+++ b/impl/maven-plugin-mixin/pom.xml
@@ -104,12 +104,6 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <systemPropertyVariables>
-            
<processor.worktree>${maven.multiModuleProjectDirectory}</processor.worktree>
-            <processor.version>${project.version}</processor.version>
-          </systemPropertyVariables>
-        </configuration>
       </plugin>
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
diff --git 
a/impl/maven-plugin-mixin/src/test/java/org/apache/maven/plugin/processor/MojoDescriptorProcessorTest.java
 
b/impl/maven-plugin-mixin/src/test/java/org/apache/maven/plugin/processor/MojoDescriptorProcessorTest.java
index 0faf1c1e2c..fbf9d111cf 100644
--- 
a/impl/maven-plugin-mixin/src/test/java/org/apache/maven/plugin/processor/MojoDescriptorProcessorTest.java
+++ 
b/impl/maven-plugin-mixin/src/test/java/org/apache/maven/plugin/processor/MojoDescriptorProcessorTest.java
@@ -31,11 +31,13 @@
 import javax.tools.ToolProvider;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.StringWriter;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -61,60 +63,25 @@
  */
 class MojoDescriptorProcessorTest {
 
-    /** Resolved classpath jars needed for compiling test sources. */
-    private static List<File> classpathJars;
+    private static List<Path> classpathEntries;
 
-    /** The processor JAR (contains the compiled MojoDescriptorProcessor). */
-    private static File processorJar;
+    private static Path processorEntry;
 
     @BeforeAll
     static void resolveClasspath() {
-        String version = System.getProperty("processor.version", 
"4.2.0-SNAPSHOT");
-
-        // Processor JAR — built from this module
-        processorJar = resolveFile(
-                "impl/maven-plugin-mixin/target/maven-plugin-mixin-" + version 
+ ".jar",
-                "maven-plugin-mixin/" + version + "/maven-plugin-mixin-" + 
version + ".jar");
-
-        // Annotation JARs needed on the compilation classpath
-        File apiCore = resolveFile(
-                "api/maven-api-core/target/maven-api-core-" + version + ".jar",
-                "maven-api-core/" + version + "/maven-api-core-" + version + 
".jar");
-        File apiAnnotations = resolveFile(
-                "api/maven-api-annotations/target/maven-api-annotations-" + 
version + ".jar",
-                "maven-api-annotations/" + version + "/maven-api-annotations-" 
+ version + ".jar");
-
-        classpathJars = List.of(apiCore, apiAnnotations);
+        processorEntry = classpathEntryOf(MojoDescriptorProcessor.class);
+        classpathEntries = List.of(
+                
classpathEntryOf(org.apache.maven.api.plugin.annotations.Mojo.class),
+                
classpathEntryOf(org.apache.maven.api.annotations.Nonnull.class));
     }
 
-    /**
-     * Try to resolve a JAR first from the Maven multi-module project build 
output, then from the local Maven repo.
-     *
-     * <p>In a Maven build, {@code maven.multiModuleProjectDirectory} points 
to the project root, so
-     * {@code worktreeRelative} is resolved against that directory to find 
freshly-compiled JARs.
-     * The {@code processor.worktree} system property can override the root 
for IDE / manual runs.</p>
-     */
-    private static File resolveFile(String worktreeRelative, String 
m2Relative) {
-        // Prefer the Maven multi-module project directory (set by Maven 
during build)
-        String worktreeBase =
-                System.getProperty("processor.worktree", 
System.getProperty("maven.multiModuleProjectDirectory", ""));
-        String m2Base = System.getProperty(
-                "processor.m2", System.getProperty("user.home") + 
"/.m2/repository/org/apache/maven");
-
-        if (worktreeRelative != null && !worktreeBase.isEmpty()) {
-            File f = new File(worktreeBase, worktreeRelative);
-            if (f.isFile()) {
-                return f;
-            }
-        }
-        if (m2Relative != null) {
-            File f = new File(m2Base, m2Relative);
-            if (f.isFile()) {
-                return f;
-            }
+    private static Path classpathEntryOf(Class<?> anchor) {
+        try {
+            return Paths.get(
+                    
anchor.getProtectionDomain().getCodeSource().getLocation().toURI());
+        } catch (URISyntaxException e) {
+            return fail("Cannot resolve classpath entry for " + 
anchor.getName() + ": " + e);
         }
-        fail("Cannot resolve JAR: worktree=" + worktreeRelative + " m2=" + 
m2Relative);
-        return null; // unreachable
     }
 
     // 
-------------------------------------------------------------------------
@@ -749,11 +716,8 @@ private CompilationResult compile(List<JavaFileObject> 
sources, Map<String, Stri
         StandardJavaFileManager stdFm = 
compiler.getStandardFileManager(diagnostics, null, null);
 
         try {
-            // Build classpath: maven-api-core + maven-api-annotations for the 
test sources
-            stdFm.setLocation(StandardLocation.CLASS_PATH, classpathJars);
-
-            // Processor path: the processor JAR
-            stdFm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, 
List.of(processorJar));
+            stdFm.setLocationFromPaths(StandardLocation.CLASS_PATH, 
classpathEntries);
+            
stdFm.setLocationFromPaths(StandardLocation.ANNOTATION_PROCESSOR_PATH, 
List.of(processorEntry));
 
         } catch (IOException e) {
             fail("Failed to configure file manager locations: " + 
e.getMessage());

Reply via email to