You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2020/12/27 17:49:02 UTC
[maven] 02/04: [MNG-5001] Block the option to set Mojo parameters
marked as @readonly
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch MNG-5001
in repository https://gitbox.apache.org/repos/asf/maven.git
commit ecaad5ddd874832e71870d0b20f02cac5a9f5101
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Apr 5 16:46:16 2019 +0200
[MNG-5001] Block the option to set Mojo parameters marked as @readonly
---
.../maven/plugin/PluginParameterException.java | 2 +-
.../plugin/internal/DefaultMavenPluginManager.java | 35 +++++++++++++++++++++-
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterException.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterException.java
index eaf02ec..e69f555 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterException.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterException.java
@@ -43,7 +43,7 @@ public class PluginParameterException
public PluginParameterException( MojoDescriptor mojo, List<Parameter> parameters )
{
super( mojo.getPluginDescriptor(), "The parameters " + format( parameters ) + " for goal "
- + mojo.getRoleHint() + " are missing or invalid" );
+ + mojo.getRoleHint() + " are missing, read-only or invalid" );
this.mojo = mojo;
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 7c77ee8..788aadd 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
@@ -627,6 +627,8 @@ public class DefaultMavenPluginManager
logger.debug(
"Configuring mojo '" + mojoDescriptor.getId() + "' with " + configuratorId + " configurator -->" );
+ validateReadOnlyParameters( mojoDescriptor, configuration );
+
configurator.configureComponent( mojo, configuration, expressionEvaluator, pluginRealm, validator );
logger.debug( "-- end configuration --" );
@@ -719,7 +721,6 @@ public class DefaultMavenPluginManager
{
continue;
}
-
Object value = null;
PlexusConfiguration config = configuration.getChild( parameter.getName(), false );
@@ -742,6 +743,7 @@ public class DefaultMavenPluginManager
+ configuration.getName() + "'";
throw new ComponentConfigurationException( configuration, msg, e );
}
+
}
if ( value == null && ( config == null || config.getChildCount() <= 0 ) )
@@ -756,6 +758,37 @@ public class DefaultMavenPluginManager
}
}
+ private void validateReadOnlyParameters( MojoDescriptor mojoDescriptor, PlexusConfiguration configuration )
+ throws PluginParameterException
+ {
+ if ( mojoDescriptor.getParameters() == null )
+ {
+ return;
+ }
+
+ List<Parameter> invalidParameters = new ArrayList<>();
+
+ for ( Parameter parameter : mojoDescriptor.getParameters() )
+ {
+ PlexusConfiguration config = configuration.getChild( parameter.getName(), false );
+ if ( config != null && !parameter.isEditable() )
+ {
+ String value = config.getValue( null );
+ String defaultValue = config.getAttribute( "default-value", null );
+ if ( value != null && defaultValue != null && !Objects.equals( defaultValue, value ) )
+ {
+ invalidParameters.add( parameter );
+ logger.error( "Setting read-only parameter '" + parameter.getName() + "' to " + value );
+ }
+ }
+ }
+
+ if ( !invalidParameters.isEmpty() )
+ {
+ throw new PluginParameterException( mojoDescriptor, invalidParameters );
+ }
+ }
+
public void releaseMojo( Object mojo, MojoExecution mojoExecution )
{
if ( mojo != null )