You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/05/16 17:47:40 UTC

[GitHub] [maven] michael-o commented on a diff in pull request #741: [MNG-7468] Check unsupported plugins parameters in configuration

michael-o commented on code in PR #741:
URL: https://github.com/apache/maven/pull/741#discussion_r874000540


##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java:
##########
@@ -358,6 +368,61 @@ private void finalizeMojoConfiguration( MojoExecution mojoExecution )
         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 );

Review Comment:
   Important question. Consider that you have a plugin with n mojos, they share some parameters, but goals have their own. I if do not configure the plugin in general I cannot select the mojo the config should go. Will this fail on a per usecase basis?



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org