You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/01/06 15:55:02 UTC

[maven] branch master updated: [MNG-5561] Plugin relocation loses configuration

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

michaelo 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 2670c00  [MNG-5561] Plugin relocation loses configuration
2670c00 is described below

commit 2670c007517d8d72c182df6e589fd9dc43692e26
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sat Dec 25 12:28:47 2021 +0100

    [MNG-5561] Plugin relocation loses configuration
    
    Previously, to locate plugin configuration in a project the plugin descriptor
    was read first and then the GA were extracted. This always worked because the
    GA from the model and the GA from plugin descriptor (plugin.xml) were identical.
    When a plugin is relocated the target artifact is read, thus its plugin
    descriptor as well. Naturally, the GA of new (relocated) does not correspond to
    the old (static) one in the model. Therefore, the configuration is not found.
    New approach is to use the original plugin GA to locate the configuration in
    the model regardless of the relocation.
    
    This closes #642
---
 .../lifecycle/internal/DefaultMojoExecutionConfigurator.java     | 4 ++--
 .../maven/lifecycle/internal/stub/BuildPluginManagerStub.java    | 2 +-
 .../apache/maven/lifecycle/internal/stub/MojoExecutorStub.java   | 9 ++++++---
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutionConfigurator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutionConfigurator.java
index e650813..89db25b 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutionConfigurator.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutionConfigurator.java
@@ -44,9 +44,9 @@ public class DefaultMojoExecutionConfigurator
     @Override
     public void configure( MavenProject project, MojoExecution mojoExecution, boolean allowPluginLevelConfig )
     {
-        String g = mojoExecution.getGroupId();
+        String g = mojoExecution.getPlugin().getGroupId();
 
-        String a = mojoExecution.getArtifactId();
+        String a = mojoExecution.getPlugin().getArtifactId();
 
         Plugin plugin = findPlugin( g, a, project.getBuildPlugins() );
 
diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java
index 133bcb3..cdb00fc 100644
--- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java
+++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java
@@ -42,7 +42,7 @@ public class BuildPluginManagerStub
     public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories,
                                              RepositorySystemSession session )
     {
-        return MojoExecutorStub.createMojoDescriptor( plugin.getKey() );
+        return MojoExecutorStub.createMojoDescriptor( plugin );
     }
 
     public ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor )
diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java
index f035351..feedd1e 100644
--- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java
+++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java
@@ -25,6 +25,7 @@ import org.apache.maven.lifecycle.internal.PhaseRecorder;
 import org.apache.maven.lifecycle.internal.ProjectIndex;
 import org.apache.maven.plugin.BuildPluginManager;
 import org.apache.maven.plugin.MavenPluginManager;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
@@ -67,12 +68,14 @@ public class MojoExecutorStub
     }
 
 
-    public static MojoDescriptor createMojoDescriptor( String mojoDescription )
+    public static MojoDescriptor createMojoDescriptor( Plugin plugin )
     {
         final PluginDescriptor descriptor = new PluginDescriptor();
-        descriptor.setArtifactId( mojoDescription );
+        descriptor.setGroupId( plugin.getGroupId() );
+        descriptor.setArtifactId( plugin.getArtifactId() );
+        descriptor.setPlugin( plugin );
+        descriptor.setVersion( plugin.getVersion() );
         final MojoDescriptor mojoDescriptor = new MojoDescriptor();
-        mojoDescriptor.setDescription( mojoDescription );
         mojoDescriptor.setPluginDescriptor( descriptor );
         return mojoDescriptor;
     }