You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/01/01 22:46:46 UTC

[maven] branch MNG-5222 created (now 6b2b742)

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

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


      at 6b2b742  [MNG-5222] - Maven 3 no longer logs warnings about deprecated plugin parameters

This branch includes the following new commits:

     new 6b2b742  [MNG-5222] - Maven 3 no longer logs warnings about deprecated plugin parameters

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-5222] - Maven 3 no longer logs warnings about deprecated plugin parameters

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

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

commit 6b2b742533786895edcc47413a5f3070edf2286a
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Mon Sep 9 00:36:13 2019 -0300

    [MNG-5222] - Maven 3 no longer logs warnings about deprecated plugin
    parameters
    
    - Added warning when setting deprecated parameter with value different
    than the default.
    - Stop using deprecated DebugConfigurationListener class.
---
 .../plugin/internal/DefaultMavenPluginManager.java |  6 +-
 .../internal/ValidatingConfigurationListener.java  | 79 ++++++++++++++++++++--
 2 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
index 8630471..40072c0 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
@@ -27,7 +27,6 @@ import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.monitor.logging.DefaultLog;
 import org.apache.maven.plugin.ContextEnabled;
-import org.apache.maven.plugin.DebugConfigurationListener;
 import org.apache.maven.plugin.ExtensionRealmCache;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MavenPluginManager;
@@ -67,7 +66,6 @@ import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException;
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
 import org.codehaus.plexus.component.configurator.ComponentConfigurator;
-import org.codehaus.plexus.component.configurator.ConfigurationListener;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
 import org.codehaus.plexus.component.repository.ComponentDescriptor;
@@ -624,10 +622,8 @@ public class DefaultMavenPluginManager
             // so that this method could entirely be handled by a plexus lookup?
             configurator = container.lookup( ComponentConfigurator.class, configuratorId );
 
-            ConfigurationListener listener = new DebugConfigurationListener( logger );
-
             ValidatingConfigurationListener validator =
-                new ValidatingConfigurationListener( mojo, mojoDescriptor, listener );
+                new ValidatingConfigurationListener( mojo, mojoDescriptor, logger );
 
             logger.debug(
                 "Configuring mojo '" + mojoDescriptor.getId() + "' with " + configuratorId + " configurator -->" );
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java
index 99b18af..f1879f2 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java
@@ -19,13 +19,16 @@ package org.apache.maven.plugin.internal;
  * under the License.
  */
 
+import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.Parameter;
+import org.apache.maven.shared.utils.logging.MessageUtils;
 import org.codehaus.plexus.component.configurator.ConfigurationListener;
+import org.codehaus.plexus.logging.Logger;
 
 /**
  * A configuration listener to help validate the plugin configuration. For instance, check for required but missing
@@ -39,14 +42,17 @@ class ValidatingConfigurationListener
 
     private final Object mojo;
 
-    private final ConfigurationListener delegate;
+    private final MojoDescriptor mojoDescriptor;
+
+    private final Logger logger;
 
     private final Map<String, Parameter> missingParameters;
 
-    ValidatingConfigurationListener( Object mojo, MojoDescriptor mojoDescriptor, ConfigurationListener delegate )
+    ValidatingConfigurationListener( Object mojo, MojoDescriptor mojoDescriptor, Logger logger )
     {
         this.mojo = mojo;
-        this.delegate = delegate;
+        this.mojoDescriptor = mojoDescriptor;
+        this.logger = logger;
         this.missingParameters = new HashMap<>();
 
         if ( mojoDescriptor.getParameters() != null )
@@ -68,21 +74,31 @@ class ValidatingConfigurationListener
 
     public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object target )
     {
-        delegate.notifyFieldChangeUsingSetter( fieldName, value, target );
+        if ( logger.isDebugEnabled() )
+        {
+            logger.debug( "  (s) " + fieldName + " = " + toString( value ) );
+        }
 
         if ( mojo == target )
         {
             notify( fieldName, value );
+
+            warnDeprecated( fieldName, value );
         }
     }
 
     public void notifyFieldChangeUsingReflection( String fieldName, Object value, Object target )
     {
-        delegate.notifyFieldChangeUsingReflection( fieldName, value, target );
+        if ( logger.isDebugEnabled() )
+        {
+            logger.debug( "  (f) " + fieldName + " = " + toString( value ) );
+        }
 
         if ( mojo == target )
         {
             notify( fieldName, value );
+
+            warnDeprecated( fieldName, value );
         }
     }
 
@@ -94,4 +110,57 @@ class ValidatingConfigurationListener
         }
     }
 
+    private void warnDeprecated( String fieldName, Object value )
+    {
+        Parameter parameter = mojoDescriptor.getParameterMap().get( fieldName );
+        String deprecated = parameter.getDeprecated();
+        if ( deprecated != null && !deprecated.isEmpty() )
+        {
+            if ( !toString( value ).equals( toString( parameter.getDefaultValue() ) ) )
+            {
+                StringBuilder sb = new StringBuilder( "  Parameter '" );
+                sb.append( fieldName ).append( '\'' );
+                if ( parameter.getExpression() != null )
+                {
+                    String userParam = parameter.getExpression().replace( "${", "'" ).replace( '}', '\'' );
+                    sb.append( " (User Parameter " ).append( userParam ).append( ")" );
+                }
+                sb.append( " is deprecated. " ).append( deprecated );
+
+                logger.warn( MessageUtils.buffer().warning( sb.toString() ).toString() );
+            }
+        }
+    }
+
+    /**
+     * Creates a human-friendly string representation of the specified object.
+     *
+     * @param obj The object to create a string representation for, may be <code>null</code>.
+     * @return The string representation, never <code>null</code>.
+     */
+    private String toString( Object obj )
+    {
+        String str;
+        if ( obj != null && obj.getClass().isArray() )
+        {
+            int n = Array.getLength( obj );
+            StringBuilder buf = new StringBuilder( 256 );
+            buf.append( '[' );
+            for ( int i = 0; i < n; i++ )
+            {
+                if ( i > 0 )
+                {
+                    buf.append( ", " );
+                }
+                buf.append( String.valueOf( Array.get( obj, i ) ) );
+            }
+            buf.append( ']' );
+            str = buf.toString();
+        }
+        else
+        {
+            str = String.valueOf( obj );
+        }
+        return str;
+    }
 }