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/04/01 22:21:47 UTC

[GitHub] [maven] slawekjaranowski opened a new pull request #705: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

slawekjaranowski opened a new pull request #705:
URL: https://github.com/apache/maven/pull/705


   Following this checklist to help us incorporate your
   contribution quickly and easily:
   
    - [x] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MNG) filed
          for the change (usually before you start working on it).  Trivial changes like typos do not
          require a JIRA issue. Your pull request should address just this issue, without
          pulling in other changes.
    - [x] Each commit in the pull request should have a meaningful subject line and body.
    - [x] Format the pull request title like `[MNG-XXX] SUMMARY`, where you replace `MNG-XXX`
          and `SUMMARY` with the appropriate JIRA issue. Best practice is to use the JIRA issue
          title in the pull request title and in the first line of the commit message.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [x] Run `mvn clean verify` to make sure basic checks pass. A more thorough check will
          be performed on your pull request automatically.
    - [x] You have run the [Core IT][core-its] successfully.
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [x] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   [core-its]: https://maven.apache.org/core-its/core-it-suite/
   


-- 
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



[GitHub] [maven] michael-o commented on a change in pull request #705: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #705:
URL: https://github.com/apache/maven/pull/705#discussion_r841204414



##########
File path: maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java
##########
@@ -70,7 +85,7 @@ public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object
     {
         delegate.notifyFieldChangeUsingSetter( fieldName, value, target );
 
-        if ( mojo == target )
+        if ( mojo == target && value != null )

Review comment:
       Why this null check?




-- 
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



[GitHub] [maven] michael-o commented on a change in pull request #705: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

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

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



[GitHub] [maven] slawekjaranowski commented on pull request #705: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on pull request #705:
URL: https://github.com/apache/maven/pull/705#issuecomment-1086835519


   before merge commits will be squashed - I only wanted to show my change to original contributions. 


-- 
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



[GitHub] [maven] slawekjaranowski commented on a change in pull request #705: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on a change in pull request #705:
URL: https://github.com/apache/maven/pull/705#discussion_r841217441



##########
File path: maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java
##########
@@ -70,7 +85,7 @@ public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object
     {
         delegate.notifyFieldChangeUsingSetter( fieldName, value, target );
 
-        if ( mojo == target )
+        if ( mojo == target && value != null )

Review comment:
       Probably some my test ... not needed to move

##########
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 ) ) )

Review comment:
       In order to not print warning for params with default value with properties and not set in plugin configuration.

##########
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:
       code copied from `DebugConfigurationListener#toString` and use `StringJoiner` .. to fix

##########
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 );

Review comment:
       `deprecated` variable is taken from `parameter.getDeprecated();`
   all magic here is to prepare message like:
   ```
   [WARNING]   Parameter 'deprecatedParam2' (User Property 'config.deprecatedParam2') is deprecated.
   ```
   




-- 
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



[GitHub] [maven] michael-o commented on a change in pull request #705: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #705:
URL: https://github.com/apache/maven/pull/705#discussion_r841204414



##########
File path: maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java
##########
@@ -70,7 +85,7 @@ public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object
     {
         delegate.notifyFieldChangeUsingSetter( fieldName, value, target );
 
-        if ( mojo == target )
+        if ( mojo == target && value != null )

Review comment:
       Why move here?




-- 
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



[GitHub] [maven] michael-o commented on a change in pull request #705: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #705:
URL: https://github.com/apache/maven/pull/705#discussion_r841205390



##########
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 );

Review comment:
       You haven't even evaluated the content of `deprecated`, how do you know then?




-- 
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



[GitHub] [maven] michael-o commented on a change in pull request #705: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #705:
URL: https://github.com/apache/maven/pull/705#discussion_r841205299



##########
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 ) ) )

Review comment:
       Why does the dafault value matter?




-- 
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