[ 
https://issues.apache.org/jira/browse/MNG-7468?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17542221#comment-17542221
 ] 

ASF GitHub Bot commented on MNG-7468:
-------------------------------------

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


##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutionConfigurator.java:
##########
@@ -40,6 +51,7 @@
 public class DefaultMojoExecutionConfigurator
     implements MojoExecutionConfigurator
 {
+    private Logger logger = LoggerFactory.getLogger( getClass() );

Review Comment:
   Make it final, good habit.



##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutionConfigurator.java:
##########
@@ -108,4 +122,75 @@ private PluginExecution findPluginExecution( String 
executionId, Collection<Plug
         return null;
     }
 
+    private void checkUnKnownMojoConfigurationParameters( MojoExecution 
mojoExecution )
+    {
+        if ( mojoExecution.getConfiguration() == null || 
mojoExecution.getConfiguration().getChildCount() == 0 )
+        {
+            return;
+        }
+
+        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+        // in first step get parameter names of current goal
+        Set<String> parametersNamesGoal = 
mojoDescriptor.getParameters().stream()
+            .flatMap( this::getParameterNames )
+            .collect( Collectors.toSet() );
+
+        Set<String> unknownParameters = getUnknownParameters( mojoExecution, 
parametersNamesGoal );
+
+        if ( unknownParameters.isEmpty() )
+        {
+            return;
+        }
+
+        // second step get parameter names of all plugin goals
+        Set<String> parametersNamesAll = 
mojoDescriptor.getPluginDescriptor().getMojos().stream()
+            .flatMap( m -> m.getParameters().stream() )
+            .flatMap( this::getParameterNames )
+            .collect( Collectors.toSet() );

Review Comment:
   Why do you compare with all other goals too?



##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutionConfigurator.java:
##########
@@ -76,6 +88,8 @@ else if ( allowPluginLevelConfig )
             mojoConfiguration = Xpp3Dom.mergeXpp3Dom( 
mojoExecution.getConfiguration(), mojoConfiguration );
 
             mojoExecution.setConfiguration( mojoConfiguration );
+
+            checkUnKnownMojoConfigurationParameters( mojoExecution );

Review Comment:
   `Unknown`



##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutionConfigurator.java:
##########
@@ -108,4 +122,75 @@ private PluginExecution findPluginExecution( String 
executionId, Collection<Plug
         return null;
     }
 
+    private void checkUnKnownMojoConfigurationParameters( MojoExecution 
mojoExecution )
+    {
+        if ( mojoExecution.getConfiguration() == null || 
mojoExecution.getConfiguration().getChildCount() == 0 )
+        {
+            return;
+        }
+
+        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+        // in first step get parameter names of current goal
+        Set<String> parametersNamesGoal = 
mojoDescriptor.getParameters().stream()
+            .flatMap( this::getParameterNames )
+            .collect( Collectors.toSet() );
+
+        Set<String> unknownParameters = getUnknownParameters( mojoExecution, 
parametersNamesGoal );
+
+        if ( unknownParameters.isEmpty() )
+        {
+            return;
+        }
+
+        // second step get parameter names of all plugin goals
+        Set<String> parametersNamesAll = 
mojoDescriptor.getPluginDescriptor().getMojos().stream()
+            .flatMap( m -> m.getParameters().stream() )
+            .flatMap( this::getParameterNames )
+            .collect( Collectors.toSet() );
+
+        unknownParameters = getUnknownParameters( mojoExecution, 
parametersNamesAll );
+
+        unknownParameters.forEach(
+            name ->
+            {
+                MessageBuilder messageBuilder = MessageUtils.buffer()
+                    .warning( "Parameter '" )
+                    .warning( name )
+                    .warning( "' is unknown for plugin: '" )
+                    .warning( mojoExecution.getArtifactId() ).warning( ":" )
+                    .warning( mojoExecution.getVersion() ).warning( ":" )
+                    .warning( mojoExecution.getGoal() );

Review Comment:
   Is this consistent with other formats we use?





> Unsupported plugins parameters in configuration should be verified
> ------------------------------------------------------------------
>
>                 Key: MNG-7468
>                 URL: https://issues.apache.org/jira/browse/MNG-7468
>             Project: Maven
>          Issue Type: New Feature
>          Components: Plugins and Lifecycle
>            Reporter: Slawomir Jaranowski
>            Assignee: Slawomir Jaranowski
>            Priority: Major
>             Fix For: 3.9.0, 4.0.0-alpha-1, 4.0.0
>
>
> Currently we can provide any xml tags in plugin configuration even if plugin 
> Mojo doesn't support specific parameters.
> eg we can have:
> {code:xml}
> <plugin>
>     <artifactId>example-maven-plugin</artifactId>
>     <version>1.1.1</version>
>     <configuration>
>         <xxx>zzzz</xxx>
>     </configuration>
> </plugin>
> {code}
> With example configuration Mojo is executed without any warning.
> Simply if parameters is not supported - build should break with some of 
> invalid plugin configuration exception ...



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to