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 b4c4b4d2ca Preserve Maven 4 plugin accessor compatibility (fixes 
#14000) (#14014)
b4c4b4d2ca is described below

commit b4c4b4d2ca70d14e7a72952cc12c0853cf8bb3fe
Author: Sahil Jaiswal <[email protected]>
AuthorDate: Tue Nov 17 18:51:32 2026 +0530

    Preserve Maven 4 plugin accessor compatibility (fixes #14000) (#14014)
    
    * [MNG-14000] Preserve Maven 4 plugin accessor compatibility
    * [MNG-14000] Limit compatibility fix to MojoExecution getters
---
 .../java/org/apache/maven/api/MojoExecution.java   | 78 ++++++++++++++++++++++
 .../internal/impl/DefaultMojoExecutionTest.java    | 36 ++++++++++
 2 files changed, 114 insertions(+)

diff --git 
a/api/maven-api-core/src/main/java/org/apache/maven/api/MojoExecution.java 
b/api/maven-api-core/src/main/java/org/apache/maven/api/MojoExecution.java
index 1b0a6d3f03..74883dc8f1 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/MojoExecution.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/MojoExecution.java
@@ -23,6 +23,7 @@
 import org.apache.maven.api.annotations.Experimental;
 import org.apache.maven.api.annotations.Immutable;
 import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
 import org.apache.maven.api.model.PluginExecution;
 import org.apache.maven.api.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.api.xml.XmlNode;
@@ -46,6 +47,17 @@ public interface MojoExecution {
     @Nonnull
     Plugin plugin();
 
+    /**
+     * {@return the plugin that owns this execution}
+     *
+     * @deprecated Use {@link #plugin()} instead.
+     */
+    @Deprecated(since = "4.2.0", forRemoval = true)
+    @Nonnull
+    default Plugin getPlugin() {
+        return plugin();
+    }
+
     /**
      * {@return the {@code <execution>} element from the POM (or from the 
default lifecycle bindings)
      * that corresponds to this execution, or empty for a direct CLI invocation
@@ -60,10 +72,32 @@ public interface MojoExecution {
     @Nonnull
     Optional<PluginExecution> model();
 
+    /**
+     * {@return the execution element, or null if absent}
+     *
+     * @deprecated Use {@link #model()} instead.
+     */
+    @Deprecated(since = "4.2.0", forRemoval = true)
+    @Nullable
+    default PluginExecution getModel() {
+        return model().orElse(null);
+    }
+
     /** {@return the descriptor of the mojo being executed} */
     @Nonnull
     MojoDescriptor descriptor();
 
+    /**
+     * {@return the descriptor of the mojo being executed}
+     *
+     * @deprecated Use {@link #descriptor()} instead.
+     */
+    @Deprecated(since = "4.2.0", forRemoval = true)
+    @Nonnull
+    default MojoDescriptor getDescriptor() {
+        return descriptor();
+    }
+
     /**
      * {@return the execution identifier as declared in the POM, or empty for 
a direct CLI invocation
      * (e.g. {@code mvn groupId:artifactId:goal}) where no {@code <execution>} 
element is present}
@@ -71,18 +105,62 @@ public interface MojoExecution {
     @Nonnull
     Optional<String> executionId();
 
+    /**
+     * {@return the execution identifier, or null if absent}
+     *
+     * @deprecated Use {@link #executionId()} instead.
+     */
+    @Deprecated(since = "4.2.0", forRemoval = true)
+    @Nullable
+    default String getExecutionId() {
+        return executionId().orElse(null);
+    }
+
     /** {@return the goal being executed} */
     @Nonnull
     String goal();
 
+    /**
+     * {@return the goal being executed}
+     *
+     * @deprecated Use {@link #goal()} instead.
+     */
+    @Deprecated(since = "4.2.0", forRemoval = true)
+    @Nonnull
+    default String getGoal() {
+        return goal();
+    }
+
     /** {@return the lifecycle phase this execution is bound to, or empty for 
a direct CLI invocation} */
     @Nonnull
     Optional<String> lifecyclePhase();
 
+    /**
+     * {@return the lifecycle phase, or null if absent}
+     *
+     * @deprecated Use {@link #lifecyclePhase()} instead.
+     */
+    @Deprecated(since = "4.2.0", forRemoval = true)
+    @Nullable
+    default String getLifecyclePhase() {
+        return lifecyclePhase().orElse(null);
+    }
+
     /** {@return the merged configuration for this execution, if any} */
     @Nonnull
     Optional<XmlNode> configuration();
 
+    /**
+     * {@return the merged configuration, if any}
+     *
+     * @deprecated Use {@link #configuration()} instead.
+     */
+    @Deprecated(since = "4.2.0", forRemoval = true)
+    @Nonnull
+    default Optional<XmlNode> getConfiguration() {
+        return configuration();
+    }
+
     /**
      * {@return true if this mojo triggers a forked lifecycle execution}
      *
diff --git 
a/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultMojoExecutionTest.java
 
b/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultMojoExecutionTest.java
index e4591fe327..47dc3af79b 100644
--- 
a/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultMojoExecutionTest.java
+++ 
b/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultMojoExecutionTest.java
@@ -22,11 +22,13 @@
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -90,6 +92,7 @@ void cliInvocationPathExecutionIdAndLifecyclePhaseAreEmpty() {
         assertFalse(snapshot.model().isPresent(), "model should be empty when 
no plugin in model");
         assertFalse(snapshot.configuration().isPresent(), "configuration 
should be empty when not set");
         assertNotNull(snapshot.plugin().getRealm().classLoader());
+        assertLegacyAccessors(snapshot);
     }
 
     @Test
@@ -124,4 +127,37 @@ void snapshotDescriptorMatchesLegacyDescriptor() {
                 snapshot.descriptor(),
                 "descriptor must be a copy of the legacy V4 descriptor");
     }
+
+    @Test
+    void deprecatedGettersPreservePopulatedExecutionValues() {
+        InternalMavenSession session = mock(InternalMavenSession.class);
+        when(session.getService(Lookup.class)).thenReturn(mock(Lookup.class));
+        MojoExecution delegate = lifecycleExecution("compile", 
"default-compile", "compile");
+        org.apache.maven.model.PluginExecution model = new 
org.apache.maven.model.PluginExecution();
+        model.setId("default-compile");
+        org.apache.maven.model.Plugin plugin = new 
org.apache.maven.model.Plugin();
+        plugin.setGroupId("org.apache.maven.plugins");
+        plugin.setArtifactId("maven-test-plugin");
+        plugin.setVersion("1.0");
+        plugin.addExecution(model);
+        delegate.getMojoDescriptor().getPluginDescriptor().setPlugin(plugin);
+        delegate.setConfiguration(new Xpp3Dom("configuration"));
+
+        org.apache.maven.api.MojoExecution snapshot = new 
DefaultMojoExecution(session, delegate);
+
+        assertTrue(snapshot.model().isPresent());
+        assertTrue(snapshot.configuration().isPresent());
+        assertLegacyAccessors(snapshot);
+    }
+
+    @SuppressWarnings("removal")
+    private static void 
assertLegacyAccessors(org.apache.maven.api.MojoExecution snapshot) {
+        assertSame(snapshot.plugin(), snapshot.getPlugin());
+        assertEquals(snapshot.model().orElse(null), snapshot.getModel());
+        assertSame(snapshot.descriptor(), snapshot.getDescriptor());
+        assertEquals(snapshot.executionId().orElse(null), 
snapshot.getExecutionId());
+        assertEquals(snapshot.goal(), snapshot.getGoal());
+        assertEquals(snapshot.lifecyclePhase().orElse(null), 
snapshot.getLifecyclePhase());
+        assertEquals(snapshot.configuration(), snapshot.getConfiguration());
+    }
 }

Reply via email to