Skip to content

[MNG-5001] Block the option to set Mojo parameters marked as @readonly - #240

Closed
slachiewicz wants to merge 1 commit into
apache:masterfrom
slachiewicz:MNG-5001
Closed

slachiewicz wants to merge 1 commit into
apache:masterfrom
slachiewicz:MNG-5001

Conversation

@slachiewicz

Copy link
Copy Markdown
Member

No description provided.

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a parameter/system property to disable this check.
We could break builds

@rfscholte

Copy link
Copy Markdown
Contributor

I would do all parameter validation at once, so you only have to loop one time. This means that readonly and required check are done by the same method.

@slachiewicz

Copy link
Copy Markdown
Member Author

I would do all parameter validation at once, so you only have to loop one time. This means that readonly and required check are done by the same method.

Could You suggest where this should be combined? That was my initial idea but during testing i found issues that not all test pass.
We have one validation in ValidatingConfigurationListener and also in DefaultMavenPluginValidator.validateParameters for maps.

@rfscholte

Copy link
Copy Markdown
Contributor

I'd suggest to merge the code from

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 );
}
}
into
private void validateParameters( MojoDescriptor mojoDescriptor, PlexusConfiguration configuration,

@hboutemy

Copy link
Copy Markdown
Member

core IT prepared in MNG-5001 branch https://github.com/apache/maven-integration-testing/tree/MNG-5001
@slachiewicz can you create a branch on Maven core to test and finish this feature, please?

@hboutemy

Copy link
Copy Markdown
Member

@slachiewicz do you need help to finish this?

@slachiewicz

Copy link
Copy Markdown
Member Author

Let me try again, thx for ITs.

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remember to add a system property flag to disable temporary this check.

Otherwise adoption of 3.7.0 will be slower IMHO

if ( value != null && defaultValue != null && !Objects.equals( defaultValue, value ) )
{
invalidParameters.add( parameter );
logger.error( "Setting read-only parameter '" + parameter.getName() + "' to " + value );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please report mojo/plugin/execution id f possible

@hboutemy

Copy link
Copy Markdown
Member

happy to help: changing core is not easy
and doing it myself won't help getting more contribution

@slachiewicz
slachiewicz marked this pull request as draft October 10, 2021 13:08
@slachiewicz
slachiewicz deleted the MNG-5001 branch June 18, 2022 08:49
@jira-importer

Copy link
Copy Markdown

Resolve #7147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants