michael-o commented on a change in pull request #705:
URL: https://github.com/apache/maven/pull/705#discussion_r841205101



##########
File path: 
maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java
##########
@@ -80,18 +95,83 @@ public void notifyFieldChangeUsingReflection( String 
fieldName, Object value, Ob
     {
         delegate.notifyFieldChangeUsingReflection( fieldName, value, target );
 
-        if ( mojo == target )
+        if ( mojo == target && value != null )
         {
             notify( fieldName, value );
         }
     }
 
     private void notify( String fieldName, Object value )
     {
-        if ( value != null )
+        missingParameters.remove( fieldName );
+
+        if ( logger.isWarnEnabled() )
+        {
+            warnDeprecated( fieldName, value );
+        }
+    }
+
+    private void warnDeprecated( String fieldName, Object value )
+    {
+        Parameter parameter = mojoDescriptor.getParameterMap().get( fieldName 
);
+        String deprecated = parameter.getDeprecated();
+        if ( deprecated != null && !deprecated.isEmpty() )
+        {
+            Object defaultValue = evaluateValue( parameter.getDefaultValue() );
+            if ( !toString( value ).equals( toString( defaultValue ) ) )
+            {
+                StringBuilder sb = new StringBuilder( "  Parameter '" );
+                sb.append( fieldName ).append( '\'' );
+                if ( parameter.getExpression() != null )
+                {
+                    String userProperty = parameter.getExpression().replace( 
"${", "'" ).replace( '}', '\'' );
+                    sb.append( " (User Property " ).append( userProperty 
).append( ")" );
+                }
+                sb.append( " is deprecated. " ).append( deprecated );
+
+                logger.warn( MessageUtils.buffer().warning( sb.toString() 
).toString() );
+            }
+        }
+    }
+
+    private Object evaluateValue( String value )
+    {
+        try
         {
-            missingParameters.remove( fieldName );
+            return expressionEvaluator.evaluate( value );
         }
+        catch ( ExpressionEvaluationException e )
+        {
+            // should not happen here
+        }
+        return value;
     }
 
+    /**
+     * 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 static String toString( Object obj )
+    {
+        String str;
+        if ( obj != null && obj.getClass().isArray() )
+        {
+            int n = Array.getLength( obj );
+            StringBuilder buf = new StringBuilder( 256 );
+            StringJoiner sj = new StringJoiner( ", ", "[", "]" );
+            for ( int i = 0; i < n; i++ )
+            {
+                sj.add( String.valueOf( Array.get( obj, i ) ) );
+            }
+            buf.append( sj.toString() );

Review comment:
       Why do you need `buf` if there is only one append?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to