Customize Checkstyle Rules
The starter project for customizing Checkstyle rules can be downloaded from IDA Resources page.
ODM Customization
Software Prerequisites
- IBM® Operational Decision Manager
- For large BAW projects (e.g., the twx size is greater than 100MB), at least 4GB of memory is required for the ODM server.
Prerequisite
You have installed Rule Designer in your local environment, and Checkstyle Rule Projects have been in your local workspace.
Workflow checkstyle rule projects overview
The Workflow checkstyle rule projects include CheckstyleBOM, CheckstyleRules, CheckstyleRulesCore, and CheckstyleRulesCustomized. Their dependency relationships are as follows:
Workflow checkstyle rules customization
Override core checkstyle rules
To rewrite any core checkstyle rule, please do not update the core rule itself. Instead, you should copy the rule into the checksOverride rule package of the CheckstyleRulesCustomized project and then update the copy. Take overriding a core checkstyle rule check-app-with-too-many-bpd as an example:
-
Review the content of the core rule check-app-with-too-many-bpd. If the process app has more than 5 BPDs, then a checkstyle warning message will be generated.
-
Run the Workflow checkstyle asset against an updated sample file sample-updated.twx and verify in the final checkstyle report that there is a warning message Too many BPDs.
-
In Rule Designer, copy the rule check-app-with-too-many-bpd from rule project CheckstyleRulesCore to rule package checksOverride in rule project CheckstyleRulesCustomized.
-
Update the rule check-app-with-too-many-bpd in CheckstyleRulesCustomized and change the number 5 to 10.
-
In the properties window of the rule check-app-with-too-many-bpd, select the core rule (with the same name) to override.
-
Redeploy the ruleset to your target server, e.g., on IBM Cloud.
-
Rerun the Workflow checkstyle asset against the updated sample file sample-updated.twx and verify in the final checkstyle report that there is no warning message Too many BPDs.
Write custom checkstyle rules
To write customized checkstyle rules, put the new rules in rule package customized in rule project CheckstyleRulesCustomized. Create artifact-based rule package if necessary.
Take writing a customized checkstyle rule check-service-name-contain-test as an example:
-
Add a new rule check-service-name-contain-test that will check if a Workflow service name contains test into in package customized in rule project CheckstyleRulesCustomized.
-
Check that the asset provides the utility function does not match the naming convention in its CheckstyleRulesBOM project.
-
Redeploy the ruleset to your target server, e.g., on IBM Cloud.
-
Rerun the Workflow checkstyle asset against the updated sample file sample-updated.twx and verify in the final checkstyle report that there is a warning message The service with the word ‘Test’ (not case-sensitive) in its name.
Embedded Rules Customization
Embedded rules overview
After decompressing the embedded-checkstyle-rules.zip, the embedded rules folders include init, checks, and score.
Folder | Description |
---|---|
init | Including a thresholds initialization rule. |
checks | Specific rules for executing checkstyle, including folders like app, businessobject, casesolution, businessobject, casetype, coachview, migrate, process, service, variable, webservice. |
score | Including rules for calculating the score and setting the score bound. |
Customization can be done by directly modifying the rule file. For example, modify some thresholds by modifying the values in init/init-thresholds.drl.
Modify the lower and upper bounds by modifying the values in score/configure-score-health-bound.drl.
Override embedded rules
-
After modifying the rules, repackage the customized rules into a ZIP file.
-
Click the Administrator tab, then switch to the Settings tab.
-
Scroll to the Checkstyle section, choose EMBEDDED as the Engine, and switch on the Enable Custom Rules.
-
Click the Upload Custom Rules button to upload the custom rules ZIP file.
-
Click the Save button in Settings to save the configuration and rerun Checkstyle.