You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/02/17 23:31:03 UTC

[maven] branch maven-3.8.x_MNG-5222 updated (c41ed514f -> 8b6bcfbd0)

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

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


 discard c41ed514f [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters
     new 8b6bcfbd0 [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (c41ed514f)
            \
             N -- N -- N   refs/heads/maven-3.8.x_MNG-5222 (8b6bcfbd0)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../maven/plugin/internal/DeprecatedPluginValidator.java      | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)


[maven] 01/01: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters

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

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

commit 8b6bcfbd087cd0b0e6da3cfd601353a44eb93054
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.
    - Changed Logger to SLF4J.
    
    (cherry picked from commits c99028b9fb67158edc9f202ff8a178c9465430ba, 9ac2d08dc7dec66acc2c835710065b677190e700)
    
    Co-authored-by: Slawomir Jaranowski <s....@gmail.com>
---
 .../plugin/internal/DefaultMavenPluginManager.java |   5 +
 .../plugin/internal/DeprecatedPluginValidator.java | 134 +++++++++++++++++++++
 .../MavenPluginConfigurationValidator.java         |  39 ++++++
 .../internal/ValidatingConfigurationListener.java  |   2 -
 4 files changed, 178 insertions(+), 2 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 d5112e5b3..63ae1909d 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
@@ -164,6 +164,9 @@ public class DefaultMavenPluginManager
     @Requirement
     private PluginArtifactsCache pluginArtifactsCache;
 
+    @Requirement
+    private MavenPluginConfigurationValidator configurationValidator;
+
     private ExtensionDescriptorBuilder extensionDescriptorBuilder = new ExtensionDescriptorBuilder();
 
     private PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
@@ -594,6 +597,8 @@ public class DefaultMavenPluginManager
 
             ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution );
 
+            configurationValidator.validate( mojoDescriptor, pomConfiguration, expressionEvaluator );
+
             populateMojoExecutionFields( mojo, mojoExecution.getExecutionId(), mojoDescriptor, pluginRealm,
                                          pomConfiguration, expressionEvaluator );
 
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedPluginValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedPluginValidator.java
new file mode 100644
index 000000000..a7da41078
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedPluginValidator.java
@@ -0,0 +1,134 @@
+package org.apache.maven.plugin.internal;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.annotations.Component;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Print warnings if deprecated params of plugin are used in configuration.
+ *
+ * @author Slawomir Jaranowski
+ */
+
+@Component( role = MavenPluginConfigurationValidator.class )
+class DeprecatedPluginValidator implements MavenPluginConfigurationValidator
+{
+    private static final Logger LOGGER = LoggerFactory.getLogger( DeprecatedPluginValidator.class );
+
+    @Override
+    public void validate( MojoDescriptor mojoDescriptor,
+                          PlexusConfiguration pomConfiguration,
+                          ExpressionEvaluator expressionEvaluator )
+    {
+        if ( !LOGGER.isWarnEnabled() )
+        {
+            return;
+        }
+
+        if ( mojoDescriptor.getParameters() == null )
+        {
+            return;
+        }
+
+        for ( Parameter parameter : mojoDescriptor.getParameters() )
+        {
+            if ( parameter.getDeprecated() != null && parameter.isEditable() )
+            {
+                checkParameter( parameter, pomConfiguration, expressionEvaluator );
+            }
+        }
+    }
+
+    private static void checkParameter( Parameter parameter,
+                                        PlexusConfiguration pomConfiguration,
+                                        ExpressionEvaluator expressionEvaluator )
+    {
+        PlexusConfiguration config = pomConfiguration.getChild( parameter.getName(), false );
+
+        if ( isValueSet( config, expressionEvaluator ) )
+        {
+            logDeprecateWarn( parameter );
+        }
+    }
+
+    private static boolean isValueSet( PlexusConfiguration config,
+                                       ExpressionEvaluator expressionEvaluator )
+    {
+        if ( config == null )
+        {
+            return false;
+        }
+
+        // there are sub items ... so configuration is declared
+        if ( config.getChildCount() > 0 )
+        {
+            return true;
+        }
+
+        String strValue = config.getValue();
+
+        if ( strValue == null || strValue.isEmpty() )
+        {
+            return false;
+        }
+
+        // for declaration like @Parameter( property = "config.property" )
+        // the value will contains ${config.property}
+        try
+        {
+            return expressionEvaluator.evaluate( strValue ) != null;
+        }
+        catch ( ExpressionEvaluationException e )
+        {
+            // not important
+            // will be reported during Mojo fields populate
+        }
+
+        // fallback - in case of error in expressionEvaluator
+        return false;
+    }
+
+    private static void logDeprecateWarn( Parameter parameter )
+    {
+        StringBuilder sb = new StringBuilder();
+        sb.append( "Parameter '" );
+        sb.append( parameter.getName() );
+        sb.append( '\'' );
+        if ( parameter.getExpression() != null )
+        {
+            String userProperty = parameter.getExpression().replace( "${", "'" ).replace( '}', '\'' );
+            sb.append( " (user property " );
+            sb.append( userProperty );
+            sb.append( ")" );
+        }
+        sb.append( " is deprecated: " );
+        sb.append( parameter.getDeprecated() );
+
+        LOGGER.warn( MessageUtils.buffer().warning( sb.toString() ).toString() );
+    }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginConfigurationValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginConfigurationValidator.java
new file mode 100644
index 000000000..8252782d3
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginConfigurationValidator.java
@@ -0,0 +1,39 @@
+package org.apache.maven.plugin.internal;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
+/**
+ * Service responsible for validating plugin configuration.
+ *
+ * @author Slawomir Jaranowski
+ */
+interface MavenPluginConfigurationValidator
+{
+    /**
+     * Check mojo configuration.
+     */
+    void validate( MojoDescriptor mojoDescriptor,
+                   PlexusConfiguration pomConfiguration,
+                   ExpressionEvaluator expressionEvaluator );
+}
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 99b18af7c..c04f44821 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
@@ -36,7 +36,6 @@ import org.codehaus.plexus.component.configurator.ConfigurationListener;
 class ValidatingConfigurationListener
     implements ConfigurationListener
 {
-
     private final Object mojo;
 
     private final ConfigurationListener delegate;
@@ -93,5 +92,4 @@ class ValidatingConfigurationListener
             missingParameters.remove( fieldName );
         }
     }
-
 }