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:14:17 UTC
[maven] 01/01: [MNG-5222] Maven 3 no longer logs warnings about deprecated plugin parameters
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 c41ed514f29671af6797ff7b5cbb51d72cf102a2
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 | 131 +++++++++++++++++++++
.../MavenPluginConfigurationValidator.java | 39 ++++++
.../internal/ValidatingConfigurationListener.java | 2 -
4 files changed, 175 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..48e16c60c
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DeprecatedPluginValidator.java
@@ -0,0 +1,131 @@
+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;
+ }
+
+ mojoDescriptor.getParameters().stream()
+ .filter( parameter -> parameter.getDeprecated() != null )
+ .filter( Parameter::isEditable )
+ .forEach( parameter -> 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 );
}
}
-
}