Skip to content

NIFI-14073 Add PMD Plugin to contrib-check Profile#9581

Closed
exceptionfactory wants to merge 1 commit intoapache:mainfrom
exceptionfactory:NIFI-14073
Closed

NIFI-14073 Add PMD Plugin to contrib-check Profile#9581
exceptionfactory wants to merge 1 commit intoapache:mainfrom
exceptionfactory:NIFI-14073

Conversation

@exceptionfactory
Copy link
Contributor

Summary

NIFI-14073 Adds the Maven PMD Plugin to the set of plugins run as part of the contrib-check profile for verifying correctness and style of code changes.

The PMD project augments existing code style evaluation from Checkstyle and introduces tuned analysis rules for catching common problems.

Thanks to recent efforts to cleanup and standardize code across the repository, the changes in this pull request are limited to bringing a handful of classes in line with common rules. Most of these changes involve removing or annotating unused private fields, and bringing consistency to the use of generic types.

The plugin configuration uses the pmd-ruleset.xml, which is based on the default set of rules, but removes some that would have involved too many changes to existing code. The PMD configuration excludes code generated from ANTLR and JAXB plugins from evaluation.

Additional changes include simplifying the Maven options for the GitHub ci-workflow, removing the need for selective exclusion of certain modules. These adjustments make it easier to run the pmd:check goal without a large number of module exclusions.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using mvn clean install -P contrib-check
    • JDK 21

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

- Added standard PMD rules scoped to current project conventions
- Updated multiple classes to meet UseDiamondOperator rule requirements
- Applied selected SuppressWarnings to selected classes
- Streamlined ci-workflow build to avoid unnecessary exclusions
- Refactored assembly module phases to align with standard lifecycle behavior
@exceptionfactory
Copy link
Contributor Author

@dan-s1 Thanks for your recent working on standardizing use of the diamond operator for generic types. I included the UseDiamondOperator rule in the list of PMD rules, which enforces standardized usage. Adding the PMD plugin to the set of tools for evaluation will avoid regressions in this and other areas.

Copy link
Contributor

@pvillard31 pvillard31 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @exceptionfactory, great addition for maintaining good code quality.

@dan-s1
Copy link
Contributor

dan-s1 commented Dec 16, 2024

@dan-s1 Thanks for your recent working on standardizing use of the diamond operator for generic types. I included the UseDiamondOperator rule in the list of PMD rules, which enforces standardized usage. Adding the PMD plugin to the set of tools for evaluation will avoid regressions in this and other areas.

@exceptionfactory Thank you for the including this and thank you for contributing this PR to introduce the enforcement of these standard rules. It certainly brings an increased rigor to the code.
I am sorry I did not get a chance to review this PR but I was curios which rules "would have involved too many changes to existing code"? Is that something which can be taken on in future PRs?

@exceptionfactory
Copy link
Contributor Author

@dan-s1 For reference, here is the default ruleset configuration for the Maven PMD plugin:

https://github.com/apache/maven-pmd-plugin/blob/master/src/main/resources/rulesets/java/maven-pmd-plugin-default.xml

Most of the removed rulesets relate to unused elements and unnecessary syntax.

Removing unused values involves code changes in cases that may impact behavior, so that was the reason for removing some of those rules.

Removing unnecessary syntax should be safer in general, but touches more files.

Now that the PMD check is part of the main branch, we can certainly consider adding some of these rulesets on a case-by-case basis.

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.

3 participants