이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 5. Overriding rules


You can override core rules distributed with MTR or even custom rules. For example, you can change the matching conditions, effort, or hint text for a rule. This is done by making a copy of the original rule, marking it as a rule override, and making the necessary adjustments.

You can disable a rule by creating a rule override with an empty <rule> element.

5.1. Overriding a rule

You can override a core or custom rule.

Procedure

  1. Copy the XML file that contains the rule you want to override to the custom rules directory.

    Custom rules can be placed in <MTR_HOME>/rules, ${user.home}/.mtr/rules/, or a directory specified by the --userRulesDirectory command-line argument.

  2. Edit the XML file so that it contains only the <rule> elements for the rules that you want to override.

    Note

    Rules from the original ruleset that are not overridden by the new ruleset are run as normal.

  3. Ensure that you keep the same rule and ruleset IDs. When you copy the original rule XML, this ensures that the IDs match.
  4. Ensure that the target technology in the override ruleset matches one of the targets that you specified for running the analysis.
  5. Add the <overrideRules>true</overrideRules> element to the ruleset metadata.
  6. Update the rule definition.

    You can change anything in the rule definition. The new rule overrides the original rule in its entirety.

The following rule override example changes the effort of the weblogic-02000 rule in the weblogic ruleset from 1 to 3:

Rule override definition example

<?xml version="1.0"?>
<ruleset id="weblogic"
    xmlns="http://windup.jboss.org/schema/jboss-ruleset"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd"> 1
    <metadata>
        ...
        <overrideRules>true</overrideRules> 2
    </metadata>
    <rules>
        <rule id="weblogic-02000" xmlns="http://windup.jboss.org/schema/jboss-ruleset"> 3
            <when>
                <javaclass references="weblogic.utils.StringUtils.{*}"/>
            </when>
            <perform>
                <hint effort="3" category-id="mandatory" title="WebLogic StringUtils Usage"> 4
                    <message>Replace with the StringUtils class from Apache Commons.</message>
                    <link href="https://commons.apache.org/proper/commons-lang/" title="Apache Commons Lang"/>
                    <tag>weblogic</tag>
                </hint>
            </perform>
        </rule>
    </rules>
</ruleset>

1
Ensure that the ruleset id matches the original ruleset id.
2
Add <overrideRules>true</overrideRules> to the <metadata> section.
3
Ensure that the rule id matches the original rule id.
4
Updated effort.

When you run MTR, this rule overrides the original rule with the same rule ID. You can verify that the new rule was used by viewing the contents of the Rule Provider Executions Overview.

5.2. Disabling a rule

To disable a rule, create a rule override definition with an empty <rule> element according to the following example:

Rule override definition example to disable a rule

<?xml version="1.0"?>
<ruleset id="weblogic"
    xmlns="http://windup.jboss.org/schema/jboss-ruleset"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
    <metadata>
        ...
        <overrideRules>true</overrideRules>
    </metadata>
    <rules>
        <rule id="weblogic-02000" xmlns="http://windup.jboss.org/schema/jboss-ruleset">
        1
        </rule>
    </rules>
</ruleset>

1
The <rule> element is empty so that the weblogic-02000 rule in the weblogic ruleset is disabled.
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.