Fix: support custom <message> output for 9 enforcer rules that ignored getMessage() - #1004
Open
btpka3 wants to merge 1 commit into
Open
Fix: support custom <message> output for 9 enforcer rules that ignored getMessage()#1004btpka3 wants to merge 1 commit into
btpka3 wants to merge 1 commit into
Conversation
…tMessage() Several enforcer rules did not output the user-configured <message> when the rule failed. This meant users could not provide custom context or explanations for rule violations. Fixed the following rules to prepend getMessage() to the error output when set: - BannedPlugins - BannedRepositories - BanDuplicatePomDependencyVersions - BanDistributionManagement - RequireMatchingCoordinates - RequireExplicitDependencyScope - RequireProfileIdsExist - RequireSameVersions - RequirePrerequisite Also updated toString() methods to include getMessage() for better debugging support, and added setter methods where missing. Added/updated tests: - New TestBannedPlugins test class - Added custom message test to TestBannedRepositories - Added custom message test to TestRequireSameVersions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Several enforcer rules did not output the user-configured
<message>whenthe rule failed. This meant users could not provide custom context or
explanations for rule violations.
For example, with this configuration:
The custom message was silently ignored and only the default error details were shown.
Solution
Follow the existing pattern (already used by
AlwaysFail,BannedDependenciesBase, etc.)to prepend
getMessage()to the error output when set:Fixed Rules (9 total)
BannedPluginsgetMessage()BannedRepositoriesBanDuplicatePomDependencyVersionsBanDistributionManagementRequireMatchingCoordinatesRequireExplicitDependencyScopeRequireProfileIdsExistRequireSameVersionsRequirePrerequisiteTests
All 9 modified rules now have test coverage verifying the custom message is correctly prepended:
TestBannedPluginsTestBannedRepositoriesshouldOutputCustomMessageWhenBannedTestRequireSameVersionsshouldOutputCustomMessageWhenVersionsDifferBanDistributionManagementTestshouldOutputCustomMessageWhenBannedRequirePrerequisiteTestshouldOutputCustomMessageWhenPrerequisiteNotSetTestRequireExplicitDependencyScopeTestRequireProfileIdsExistTestRequireMatchingCoordinatesAll 259 tests pass with
mvn -pl enforcer-rules test.Checklist
mvn verifyto make sure basic checks pass.mvn -Prun-its verify).ICLA
ICLA has been submitted to secretary@apache.org and is pending approval.