S1258 Should not raise an issue for maven plugin code

In maven plugins development we use plexus component like:

import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;

@Component( role = MyComponent.class, hint = "hint-value" )
public class MyComponentImplementation implements MyComponent {

    @Requirement
    private InjectedComponent;
}

And next example, Maven mojo code:

import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name = "myMojo")
public class MyMojo extends AbstractMojo {
   
    @Parameter(property = "project", readonly = true, required = true)
    private MavenProject project;

    @Component
    private ProjectDependenciesResolver resolver;

    @Parameter(property = "my.skip", defaultValue = "false")
    private boolean skip;
}

I think that all class with annotation org.codehaus.plexus.component.annotations.Component and org.apache.maven.plugins.annotations.Mojo should be skipped because in this case we don’t define specific constructor for class which is managed by maven environment.

This rule is not in the default profile. Are you sure it makes sense to activate it if you use these libraries?

I have other classes in project which I want to analyze by this rule.
And I have one profile for other projects I don’t want to manage special profile for each project.

If nobody has any objection I can prepare fix for this rule to manage this case.

Hi,
Thanks for the feedback !
I extended this FP ticket https://jira.sonarsource.com/browse/SONARJAVA-3152 on S1258 to support the case you mention. Feel free to have a go at it with a PR, don’t forget to follow contribution guidelines.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.