Skip to content

Conversation

@franciscoovazevedo
Copy link
Contributor

Fix PMD Parameter Value Parsing

Issue Description

The PMD configuration generator was incorrectly handling parameter values, resulting in empty or missing properties in the generated XML configuration. Rules that should have included property values were being output without their required properties.

Before Fix (incorrect output):

<rule ref="category/pom/errorprone.xml/InvalidDependencyTypes"/>

After Fix (correct output with properties):

<rule ref="category/pom/errorprone.xml/InvalidDependencyTypes">
    <properties>
        <property name="validTypes" value="pom,jar,maven-plugin,ejb,war,ear,rar,par"/>
    </properties>
</rule>

Fix

  • Modified the parameter value handling to correctly use default values when the explicitly specified value is empty
  • Ensured property values are properly included in the generated XML configuration
  • Removed debug logs to clean up the code for production use

The PMD ruleset generator now correctly includes all parameter values in the generated configuration files.

@codacy-production
Copy link

codacy-production bot commented May 19, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 57e38da1 (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (57e38da) Report Missing Report Missing Report Missing
Head commit (ce79db8) 4678 1462 31.25%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#126) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes handling of PMD rule parameters by using default values when explicit values are empty and correctly including properties or emitting a simple <rule/> when no parameters remain. It also removes debug logging for production readiness.

  • Use Default when Value is empty and skip parameters without any value
  • Update generateRuleXML to emit a self-closing tag if no properties
  • Clean up stray debug prints in tests

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tools/pmdConfigCreator.go Apply default parameter values, filter out empty/version, and shorten rules without props
tools/pmdConfigCreator_test.go Add tests for empty vs non-empty parameters, but retain debug prints and a skipped default test
Comments suppressed due to low confidence (2)

tools/pmdConfigCreator_test.go:5

  • The import of "fmt" is only used for debug prints in tests; remove it once debug statements are removed.
import (
	"encoding/xml"
+   	"fmt"

tools/pmdConfigCreator_test.go:382

  • Skipping this test leaves default-value handling unverified; either re-enable it or add a new test to cover the default fallback behavior.
t.Skip("Skipping test related to default values")

Comment on lines 298 to 300
// Debug output
fmt.Printf("Generated XML:\n%s\n", obtainedConfig)

Copy link

Copilot AI May 19, 2025

Choose a reason for hiding this comment

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

This debug print of the generated XML should be removed to keep test output clean.

Suggested change
// Debug output
fmt.Printf("Generated XML:\n%s\n", obtainedConfig)
// (No replacement lines; the debug print is removed entirely)

Copilot uses AI. Check for mistakes.
},
}

fmt.Println("Test input:")
Copy link

Copilot AI May 19, 2025

Choose a reason for hiding this comment

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

Debug logging in this test is no longer needed; consider removing these fmt.Println calls.

Copilot uses AI. Check for mistakes.
@franciscoovazevedo franciscoovazevedo merged commit 44f78ac into main May 20, 2025
10 checks passed
@alerizzo alerizzo deleted the pmd-config-creator-fix branch June 3, 2025 09:45
@machadoit machadoit restored the pmd-config-creator-fix branch October 12, 2025 14:40
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.

4 participants