You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/05/13 21:45:39 UTC

[maven] branch MNG-7468 created (now ff955011d)

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

sjaranowski pushed a change to branch MNG-7468
in repository https://gitbox.apache.org/repos/asf/maven.git


      at ff955011d [MNG-7468] Check unsupported plugins parameters in configuration

This branch includes the following new commits:

     new ff955011d [MNG-7468] Check unsupported plugins parameters in configuration

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 01/01: [MNG-7468] Check unsupported plugins parameters in configuration

Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MNG-7468
in repository https://gitbox.apache.org/repos/asf/maven.git

commit ff955011d02116153be6c7f552c1e9ba94ff9d84
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Fri May 13 23:42:44 2022 +0200

    [MNG-7468] Check unsupported plugins parameters in configuration
---
 .../maven/lifecycle/DefaultLifecycleExecutor.java  |  8 +-
 .../apache/maven/lifecycle/LifecycleExecutor.java  |  8 +-
 .../DefaultLifecycleExecutionPlanCalculator.java   | 87 +++++++++++++++++++---
 .../internal/LifecycleExecutionPlanCalculator.java | 13 +++-
 .../lifecycle/internal/builder/BuilderCommon.java  |  3 +-
 5 files changed, 99 insertions(+), 20 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
index c8b4c2d76..63d37c6be 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
@@ -39,6 +39,7 @@ import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
 import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.PluginNotFoundException;
@@ -118,7 +119,7 @@ public class DefaultLifecycleExecutor
         throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
         MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
         PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
-        PluginVersionResolutionException
+        PluginVersionResolutionException, PluginConfigurationException
     {
         List<TaskSegment> taskSegments =
             lifecycleTaskSegmentCalculator.calculateTaskSegments( session, Arrays.asList( tasks ) );
@@ -138,7 +139,7 @@ public class DefaultLifecycleExecutor
         throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
         MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
         PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
-        PluginVersionResolutionException
+        PluginVersionResolutionException, PluginConfigurationException
     {
         return calculateExecutionPlan( session, true, tasks );
     }
@@ -147,7 +148,8 @@ public class DefaultLifecycleExecutor
     public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
         throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
         PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         lifecycleExecutionPlanCalculator.calculateForkedExecutions( mojoExecution, session );
     }
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
index 04c602cfe..d20a5da95 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
@@ -24,6 +24,7 @@ import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
 import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.PluginNotFoundException;
@@ -67,13 +68,13 @@ public interface LifecycleExecutor
         throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
         MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
         PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
-        PluginVersionResolutionException;
+        PluginVersionResolutionException, PluginConfigurationException;
 
     MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks )
         throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
         MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
         PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
-        PluginVersionResolutionException;
+        PluginVersionResolutionException, PluginConfigurationException;
 
     void execute( MavenSession session );
 
@@ -81,7 +82,8 @@ public interface LifecycleExecutor
     void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
         throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
         PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException;
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException;
 
     // used by the site plugin 3.x
     List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java
index 036b94047..96e73442d 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java
@@ -28,6 +28,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -46,6 +47,7 @@ import org.apache.maven.plugin.BuildPluginManager;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
 import org.apache.maven.plugin.PluginNotFoundException;
 import org.apache.maven.plugin.PluginResolutionException;
@@ -61,6 +63,8 @@ import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
+import static java.util.Arrays.stream;
+
 
 /**
  * <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
@@ -129,7 +133,8 @@ public class DefaultLifecycleExecutionPlanCalculator
                                                       boolean setup )
         throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
         PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
-        NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
+        NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         lifecyclePluginResolver.resolveMissingPluginVersions( project, session );
 
@@ -149,7 +154,8 @@ public class DefaultLifecycleExecutionPlanCalculator
     public MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks )
         throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
         PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
-        NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
+        NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         return calculateExecutionPlan( session, project, tasks, true );
     }
@@ -157,7 +163,8 @@ public class DefaultLifecycleExecutionPlanCalculator
     private void setupMojoExecutions( MavenSession session, MavenProject project, List<MojoExecution> mojoExecutions )
         throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
         MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         Set<MojoDescriptor> alreadyPlannedExecutions = fillMojoDescriptors( session, project, mojoExecutions );
 
@@ -207,7 +214,8 @@ public class DefaultLifecycleExecutionPlanCalculator
                                     Set<MojoDescriptor> alreadyPlannedExecutions )
         throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
         MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         fillMojoDescriptor( session, project, mojoExecution );
 
@@ -310,8 +318,10 @@ public class DefaultLifecycleExecutionPlanCalculator
      *
      * @param mojoExecution The mojo execution whose configuration should be finalized, must not be {@code null}.
      */
-    private void finalizeMojoConfiguration( MojoExecution mojoExecution )
+    private void finalizeMojoConfiguration( MojoExecution mojoExecution ) throws PluginConfigurationException
     {
+        checkUnKnownMojoConfigurationParameters( mojoExecution );
+
         MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
 
         Xpp3Dom executionConfiguration = mojoExecution.getConfiguration();
@@ -358,6 +368,61 @@ public class DefaultLifecycleExecutionPlanCalculator
         mojoExecution.setConfiguration( finalConfiguration );
     }
 
+    private void checkUnKnownMojoConfigurationParameters( MojoExecution mojoExecution )
+        throws PluginConfigurationException
+    {
+        if ( mojoExecution.getConfiguration() == null || mojoExecution.getConfiguration().getChildCount() == 0 )
+        {
+            return;
+        }
+
+        // first stem get parameter names of current goal
+        Set<String> parametersNames = new HashSet<>();
+        for ( Parameter p : mojoExecution.getMojoDescriptor().getParameters() )
+        {
+            parametersNames.add( p.getName() );
+            if ( p.getAlias() != null )
+            {
+                parametersNames.add( p.getAlias() );
+            }
+        }
+
+        Set<String> unknownParameters = stream( mojoExecution.getConfiguration().getChildren() )
+            .map( Xpp3Dom::getName )
+            .filter( name -> !parametersNames.contains( name ) )
+            .collect( Collectors.toSet() );
+
+        if ( unknownParameters.isEmpty() )
+        {
+            return;
+        }
+
+        // second step get parameter names of all plugin goals
+        parametersNames.clear();
+        for ( MojoDescriptor md : mojoExecution.getMojoDescriptor().getPluginDescriptor().getMojos() )
+        {
+            for ( Parameter p : md.getParameters() )
+            {
+                parametersNames.add( p.getName() );
+                if ( p.getAlias() != null )
+                {
+                    parametersNames.add( p.getAlias() );
+                }
+            }
+        }
+
+        unknownParameters = stream( mojoExecution.getConfiguration().getChildren() )
+            .map( Xpp3Dom::getName )
+            .filter( name -> !parametersNames.contains( name ) )
+            .collect( Collectors.toSet() );
+
+        if ( !unknownParameters.isEmpty() )
+        {
+            String message = "Unknown plugin configuration parameters: " + unknownParameters;
+            throw new PluginConfigurationException( mojoExecution.getMojoDescriptor().getPluginDescriptor(), message );
+        }
+    }
+
     private Xpp3Dom getMojoConfiguration( MojoDescriptor mojoDescriptor )
     {
         return MojoDescriptorCreator.convert( mojoDescriptor );
@@ -367,7 +432,8 @@ public class DefaultLifecycleExecutionPlanCalculator
     public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
         throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
         PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         calculateForkedExecutions( mojoExecution, session, session.getCurrentProject(), new HashSet<>() );
     }
@@ -376,7 +442,8 @@ public class DefaultLifecycleExecutionPlanCalculator
                                             Collection<MojoDescriptor> alreadyPlannedExecutions )
         throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
         PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
 
@@ -423,7 +490,8 @@ public class DefaultLifecycleExecutionPlanCalculator
                                                           Collection<MojoDescriptor> alreadyPlannedExecutions )
         throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
         PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
 
@@ -570,7 +638,8 @@ public class DefaultLifecycleExecutionPlanCalculator
                                                      Collection<MojoDescriptor> alreadyPlannedExecutions )
         throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
         PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException
     {
         MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
 
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculator.java
index c5ed0f14e..7c0bf8f4e 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculator.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculator.java
@@ -26,6 +26,7 @@ import org.apache.maven.lifecycle.MavenExecutionPlan;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
 import org.apache.maven.plugin.PluginNotFoundException;
 import org.apache.maven.plugin.PluginResolutionException;
@@ -47,23 +48,27 @@ public interface LifecycleExecutionPlanCalculator
     MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks )
         throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
         PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
-        NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException;
+        NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException;
 
     MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks,
                                                boolean setup )
         throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
         PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
-        NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException;
+        NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException;
 
     void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
         throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
         PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException;
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException;
 
     void setupMojoExecution( MavenSession session, MavenProject project, MojoExecution mojoExecution,
                              Set<MojoDescriptor> alreadyPlannedExecutions )
         throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
         MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
-        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException;
+        LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException,
+        PluginConfigurationException;
 
 }
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java
index 63824e24a..a110f334c 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java
@@ -49,6 +49,7 @@ import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginConfigurationException;
 import org.apache.maven.plugin.PluginDescriptorParsingException;
 import org.apache.maven.plugin.PluginNotFoundException;
 import org.apache.maven.plugin.PluginResolutionException;
@@ -109,7 +110,7 @@ public class BuilderCommon
         throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
         PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
         NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException,
-        LifecycleExecutionException
+        LifecycleExecutionException, PluginConfigurationException
     {
         MavenExecutionPlan executionPlan =
             lifeCycleExecutionPlanCalculator.calculateExecutionPlan( session, project, taskSegment.getTasks() );