Windup Rules Development Guide


Red Hat JBoss Migration Toolkit 2.5

Create Custom Rules for Windup

Windup Team

Abstract

This guide describes how to create custom Rules for Windup.

Chapter 1. Introduction

This guide is for engineers, consultants, and others who plan to create custom XML-based rules for Windup.

If you are new to Windup, it is recommended that you start with the Windup User Guide. It provides detailed information about system requirements and detailed instructions on how to install and execute Windup. It also contains tips to optimize performance and provides links to other sources of information about Windup.

If you would like to contribute to the Windup source code base or provide Java-based rule add-ons, see the Windup Wiki.

Chapter 2. Get Started

2.1. Create Your First XML Rule

Overview

This topic guides you through the process of creating and testing your first Windup XML-based rule.

Windup XML-base rules use the following familiar rule pattern:

when(condition)
    perform(action)
otherwise(action)
Copy to Clipboard Toggle word wrap

Ruleset and Rule XML elements are covered in more detail here: XML Rule Construction.

Additional details about creating XML rules, with example syntax, can be found here: Create a Basic XML Rule.

As you create your first rule, refer to the Rules Schema for valid XML syntax.

Rule Example Description

In this example, you write a rule to discover instances where an application defines a jboss-web.xml file containing a <class-loading> element and provide a link to the documentation that describes how to migrate the code.

Create the Directory Structure for the Rule
  1. Create a directory structure to contain your first rule and the data file to use for testing.

    $ mkdir -p migration-rules/rules
    $ mkdir -p migration-rules/data
    Copy to Clipboard Toggle word wrap
  2. This directory structure will also be used to hold the generated Windup reports.
Create Data to Test the Rule
  1. Use your favorite editor or IDE to create a jboss-web.xml file in the ~/migration-rules/data/ subdirectory.
  2. Copy in the following content.

    <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 4.2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
    <jboss-web>
        <class-loading java2ClassLoadingCompliance="false">
            <loader-repository>
                seam.jboss.org:loader=@projectName@
                <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
            </loader-repository>
        </class-loading>
    </jboss-web>
    Copy to Clipboard Toggle word wrap
Create the Rule
  1. Use your favorite editor or IDE to create an XML file in the ~/migration-rules/rules/ subdirectory named JBoss5-web-class-loading.windup.xml. Copy in the following content.

    <?xml version="1.0"?>
    <ruleset id="UNIQUE_RULESET_ID"
        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>
            <description>
                <!-- Ruleset Description -->
            </description>
            <dependencies>
                <!-- Ruleset Dependencies -->
            </dependencies>
            <sourceTechnology id="SOURCE_ID" versionRange="VERSION_RANGE"/>
            <targetTechnology id="TARGET_ID" versionRange="VERSION_RANGE"/>
            <tag>Reviewed-2015-05-01</tag>
        </metadata>
        <rules>
            <rule id="UNIQUE_RULE_ID">
                <when>
                    <!-- Test for a condition here -->
                </when>
                <perform>
                    <!-- Perform an action -->
                </perform>
            </rule>
         </rules>
    </ruleset>
    Copy to Clipboard Toggle word wrap
    Note

    Windup identifies files with the .windup.xml extension as XML-based rules, so be sure to use this naming convention, otherwise the rule will not be evaluated!

  2. Add the unique identifier for the ruleset and rule.

    • Replace the UNIQUE_RULESET_ID with the file name: "JBoss5-web-class-loading"
    • Replace the UNIQUE_RULE_ID with the ruleset ID appended with '_001': "JBoss5-web-class-loading_001"
  3. Add the following ruleset addon dependencies.

    <addon id="org.jboss.windup.rules,windup-rules-javaee,2.5.0.Final"/>
    <addon id="org.jboss.windup.rules,windup-rules-java,2.5.0.Final"/>
    Copy to Clipboard Toggle word wrap
  4. Add the source and target technologies.

    • Replace the sourceTechnology SOURCE_ID with: "eap"
    • Replace the targetTechnology TARGET_ID with: "eap"
    • Replace the sourceTechnology VERSION_RANGE with: "(4,5)"
    • Replace the targetTechnology VERSION_RANGE with: "[6,)"
  5. Complete the when condition.

    • Because this rule finds jboss-web.xml files containing the class-loading element, we use xmlfile to evaluate the files.
    • To match on the class-loading element that is a child of jboss-web, use the xpath expression "jboss-web/class-loading".

      <when>
          <xmlfile matches="jboss-web/class-loading" />
      </when>
      Copy to Clipboard Toggle word wrap
  6. Complete the perform action for this rule.

    • Add a classification and descriptive title.
    • Assign a level of effort of "1" to this task.
    • Provide a hint with an informative message and a link to documentation that describes the migration details.

      <perform>
          <iteration>
              <classification title="JBoss Web Application Descriptor" effort="1"/>
              <hint title="JBoss Web XML class-loading element is no longer valid">
                <message>
                  The class-loading element is no longer valid in the jboss-web.xml file.
                </message>
                <link href="https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.4/html-single/Migration_Guide/index.html#Create_or_Modify_Files_That_Control_Class_Loading_in_JBoss_Enterprise_Application_Platform_6" title="Create or Modify Files That Control Class Loading in JBoss EAP 6"/>
              </hint>
          </iteration>
      </perform>
      Copy to Clipboard Toggle word wrap
  7. The rule is now complete and should look like the following example.

    <?xml version="1.0"?>
    <ruleset id="JBoss5-web-class-loading"
        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>
            <description>
                This ruleset looks for the class-loading element in a jboss-web.xml file, which is no longer valid in JBoss EAP 6
            </description>
             <dependencies>
                <addon id="org.jboss.windup.rules,windup-rules-javaee,2.5.0.Final"/>
                <addon id="org.jboss.windup.rules,windup-rules-java,2.5.0.Final"/>
            </dependencies>
            <sourceTechnology id="eap" versionRange="(4,5)"/>
            <targetTechnology id="eap" versionRange="[6,)"/>
        </metadata>
        <rules>
            <rule id="JBoss5-web-class-loading_1000">
                <when>
                    <xmlfile matches="jboss-web/class-loading" />
                </when>
                <perform>
                    <iteration>
                        <classification title="JBoss Web Application Descriptor" effort="1"/>
                        <hint title="JBoss Web XML class-loading element is no longer valid">
                          <message>
                            The class-loading element is no longer valid in the jboss-web.xml file.
                          </message>
                          <link href="https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.4/html-single/Migration_Guide/index.html#Create_or_Modify_Files_That_Control_Class_Loading_in_JBoss_Enterprise_Application_Platform_6" title="Create or Modify Files That Control Class Loading in JBoss EAP 6"/>
                        </hint>
                    </iteration>
                </perform>
            </rule>
         </rules>
    </ruleset>
    Copy to Clipboard Toggle word wrap
Install the Rule

A Windup rule is installed simply by copying the rule to the appropriate folder.

Copy the JBoss5-web-class-loading.windup.xml file to your ${user.home}/.windup/rules/ directory.

For Linux or Mac: ~/.windup/rules/
For Windows: "\Documents and Settings\USER_NAME\.windup\rules\" or "\Users\USER_NAME\.windup\rules\"
Copy to Clipboard Toggle word wrap
Test the Rule
  1. Open a terminal and navigate to the WINDUP_HOME directory.
  2. Type the following command to test the rule in Windup, passing the test file as an input argument and a directory for the output report.

    For Linux:    bin/windup --sourceMode --input ~/migration-rules/data --output ~/migration-rules/reports --source eap --target eap
    For Windows:  bin\windup.bat --sourceMode --input migration-rules\data --output migration-rules\reports --source eap --target eap
    Copy to Clipboard Toggle word wrap
  3. You should see this result.

    ***SUCCESS*** Windup report created: /home/your-username/migration-rules/reports/index.html
                  Access it at this URL: file:///home/your-username/migration-rules/reports/index.html
    Copy to Clipboard Toggle word wrap
Review the Reports

Access the report at ~/migration-rules/reports/index.html to be sure it provides the expected results.

  1. The Overview page displays the Name of the input folder, "data", along with the Effort of "1 Story Points".

    Application List

    Overview

  2. Click on the "data" link under the Name column to see the Report Index page and review the migration summary.

    ReportIndex

    Overview

  3. Click on the Application Details link to view the application report. This report displays a link for the name of the file, "jboss-web.xml", along with warnings and 1 Story Points.

    Application Details Report

    Overview

  4. Drill down into Source Report file detail by clicking on the jboss-web.xml file link. This report provides information about the file and summarizes the story points. It also highlights the <class-loading> line in the jboss-web.xml file, provides the message "The class-loading element is no longer valid in the jboss-web.xml file.", and provides a link to the Create or Modify Files That Control Class Loading in JBoss EAP 6 topic in the JBoss EAP 6 Migration Guide. Click on the link to be sure the link is valid.

    Overview

  5. Return to the Overview Page and click on the "All Rule" link to view the Rule Provider Executions report. Find the 'JBoss5-web-class-loading' rule in the report and verify that the Status shows "Condition met" and the Result shows "success".

Chapter 3. Create and Test XML Rules

3.1. XML Rule Construction

This section describes the basic construction of XML rules. All XML rules are defined as elements within rulesets.

3.1.1. Rulesets

A ruleset is a group of one or more rules that targets a specific area of migration. This is the basic structure of the <ruleset> element.

  • <ruleset id="UNIQUE_RULESET_ID">: Defines this as a Windup ruleset and gives it a unique ruleset ID.

    • <metadata>: The metadata about the ruleset.

      • <description>: The description of the ruleset.
      • <dependencies/>: The rule add-ons required by this ruleset.
      • <sourceTechnology/>: The source technology.
      • <targetTechnology/>: The target technology.
      • <overrideRules>true|false</overrideRules>: Indicates that rules in this ruleset override rules with the same ID from the core ruleset distributed with Windup. Both the ruleset id and the rule id must match a rule within the core ruleset or the rule will be ignored. This is "false" by default.
    • <rules>: Contains the individual rules.

      • <rule id="UNIQUE_RULE_ID">: Defines the rule and gives it a unique ID. It is recommended to include the ruleset ID as part of the rule ID, for example, UNIQUE_RULESET_ID_UNIQUE_RULE_ID. One or more rules can be defined for a ruleset.

        • <when>: The condition or conditions to match on. For a detailed description of the elements allowed in a <when>, see XML Rule - When Condition Syntax.
        • <perform>: The action to be performed when the rule condition is matched. For a detailed description of the elements allowed in a <perform>, see XML Rule - Perform Action Syntax.
        • <otherwise>: The action to be performed when the rule condition is not matched. This element takes the same child elements as the <perform> element.
        • <where>: Matches on a string pattern.
      • <file-mapping/>: Maps an extension to a graph type.
      • <package-mapping/>: Maps from a package pattern (regular expression) to a organization name.

3.1.2. Predefined Rules

Windup provides some predefined rules for common migration requirements, for example, mapping files extensions to a particular file type. The following is an example of the predefined "XmlFileMappings" rule.

<?xml version="1.0"?>
    <ruleset id="XmlFileMappings"
        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>
            <description>
                This ruleset maps files to the Model.
            </description>
            <dependencies>
                <addon id="org.jboss.windup.rules.files.FileMappingHandler"/>
            </dependencies>
            <sourceTechnology id="eap" versionRange="(4,5)"/>
            <targetTechnology id="eap" versionRange="[6,)"/>
            <tag>reviewed-2015-05-27</tag>
        </metadata>
        <rules>
            <file-mapping from=".*\.tld$" to="XmlFileModel"/>
            <file-mapping from=".*\.bpel$" to="XmlFileModel"/>
            <file-mapping from=".*\.wsdl$" to="XmlFileModel"/>
            <file-mapping from=".*\.wsdd$" to="XmlFileModel"/>
            <file-mapping from=".*\.bpelex$" to="XmlFileModel"/>
            <file-mapping from=".*\.mon$" to="XmlFileModel"/>
            <file-mapping from=".*\.xmi$" to="XmlFileModel"/>
            <file-mapping from=".*\.export$" to="XmlFileModel"/>
            <file-mapping from=".*\.import$" to="XmlFileModel"/>
            <file-mapping from=".*\.bcfg$" to="XmlFileModel"/>
            <file-mapping from=".*\.map$" to="XmlFileModel"/>
            <file-mapping from=".*\.brg$" to="XmlFileModel"/>
            <file-mapping from=".*\.brgt$" to="XmlFileModel"/>
            <file-mapping from=".*\.ruleset$" to="XmlFileModel"/>
            <file-mapping from=".*\.module$" to="XmlFileModel"/>
            <file-mapping from=".*\.modulex$" to="XmlFileModel"/>
            <file-mapping from=".*\.composite$" to="XmlFileModel"/>
            <file-mapping from=".*\.requirements$" to="XmlFileModel"/>
          </rules>
        </ruleset>
Copy to Clipboard Toggle word wrap

3.2. Create a Basic XML Rule

You can create a Windup rule using Java, XML, or Groovy. This topic describes how to create a rule using XML.

3.2.1. Prerequisites

3.2.2. File Naming Convention for XML Rules

You must name the file containing an XML rule with the .windup.xml extension. Windup identifies files with this extension as XML-base rules, so be sure to use this naming convention, otherwise the rule will not be evaluated!

3.2.3. Basic XML Rule Template

XML rules consist of conditions and actions and follow the familiar "if/then/else" construct:

when(condition)
    perform(action)
otherwise(action)
Copy to Clipboard Toggle word wrap

The following is the basic syntax for XML rules.

<?xml version="1.0"?>
<ruleset id="unique-ruleset-id"
    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>
        <!-- Metadata about the rule including a description,
             source technology, target technology, and any
             add-on dependencies -->
    </metadata>
    <rules>
        <rule id="unique-ruleset-id-01000">
            <when>
                <!-- Test a condition... -->
            </when>
            <perform>
                <!-- Perform this action when condition is satisfied -->
            </perform>
            <otherwise>
                <!-- Perform this action when condition is not satisfied -->
            </otherwise>
        </rule>
    <rules>
</ruleset>
Copy to Clipboard Toggle word wrap

3.2.4. Create the Ruleset Metadata

The XML ruleset metadata element provides additional information about the ruleset such as a description, the source and target technologies, and add-on dependencies. The metadata also allows for specification of tags, which allow you to provide additional information about a ruleset. For more information about ruleset metadata, see XML Rule Construction.

Example:

<ruleset id=”unique-ruleset-id”
    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>
        <description>
                This is the description.
        </description>
        <dependencies>
                <addon id="org.jboss.windup.rules,windup-rules-javaee,2.0.1.Final"/>
                <addon id="org.jboss.windup.rules,windup-rules-java,2.0.0.Final"/>
        </dependencies>
        <sourceTechnology id="weblogic" versionRange="(10,12]"/>
        <sourceTechnology id="ejb" versionRange="(2,3]"/>
        <targetTechnology id="eap" versionRange="(5,6]"/>
        <targetTechnology id="ejb" versionRange="(2,3]"/>
        <tag>require-stateless</tag>
        <tag>require-nofilesystem-io</tag>
        <executeAfter>AfterRulesetId</executeAfter>
        <executeBefore>BeforeRulesetId</executeBefore>
    </metadata>
    <rules>
    </rules>
</ruleset>
Copy to Clipboard Toggle word wrap

3.2.5. Create the Rule

Individual rules are contained within a <rules> element and consist of one or more conditions and actions.

3.2.5.1. Create the Rule When Condition

The XML rule <when> element tests for a condition. The following is a list of valid <when> conditions.

Expand
ElementDescription

<true>

Always match.

<or>

<and>

<not>

These are the standard logical operators.

<javaclass>

Test for a match in a Java class.

<javaclass-ignore>

Exclude javaclass which you would like to ignore in processing discovery.

<xmlfile>

Test for a match in an XML file.

<project>

Test for project characteristics, such as dependencies.

<filecontent>

Find strings or text within files, for example, properties files.

<file-mapping>

Define file names to internal stored File model.

<package-mapping>

Define package names to organization or libraries.

The specific syntax is dependent on whether you are creating a rule to evaluate Java class, an XML file, a project, or file content and is described in more detail here: XML Rule - When Condition Syntax

3.2.5.2. Create the Rule Perform Action

The XML rule <perform> element performs the action when the condition is met. Operations allowed in this section of the rule include the classification of application resources, in-line hints for migration steps, links to migration information, and project lineitem reporting. The following is a list of valid <peform> actions.

Expand
ElementDescription

<classification>

This operation adds metadata that is intended to apply to the entire file. For example, if the Java Class is a JMS Message Listener, you might want to add a Classification with the title "JMS Message Listener". Information that would apply to the entire file would go here. Also, if an effort level is set, that information would apply to the entire file.

<link>

Provides an HTML link to additional information or documentation that provides more information about the migration task.

<hint>

This operation adds metadata to a line within the file. For example, if the rule were set to apply to all instances of "javax.jms.TextMessage.setText(java.lang.String)" this would highlight every instance of that method call. This is frequently used when there is detailed information to attach that applies at the line level. Each time this operation is fired, the effort level will be added. In our example, if the effort level were 3 and there were 4 instances of "javax.jms.TextMessage.setText(java.lang.String)", then this would add 9 total story points. Whether or not to apply effort at this level or in a classification depends upon the amount of effort required during the migration.

<xslt>

Specify how to transform an XML file.

<lineitem>

This provides a high level message that will appear in the application overview page.

<iteration>

Specify to iterate over an implicit or explicit variable defined within the rule.

The syntax is described in more detail here: XML Rule - Perform Action Syntax.

3.3. XML Rule - When Condition Syntax

Conditions allowed in the when portion of a rule must extend GraphOperation and currently include evaluation of Java classes, XML files, projects, and file content. Because XML rules are modeled after the Java-based rule add-ons, links to JavaDocs for the related Java classes are provided for a better understanding of how they behave.

The complete XML rule schema is located here: http://windup.jboss.org/schema/windup-jboss-ruleset.xsd

The following sections describe the more common XML when rule conditions.

3.3.1.  Syntax

3.3.1.1. Summary

Use the <javaclass> element to find imports, methods, variable declarations, annotations, class implementations, and other items related to Java classes. For a better understanding of the <javaclass> condition, see the JavaDoc for the JavaClass class.

The following is an example of a rule that tests for WebLogic-specific Apache XML packages.

<rule id="weblogic-03000">
    <when>
        <javaclass references="weblogic.apache.xml.{*}" />
    </when>
    <perform>
        <hint title="WebLogic Specific Apache XML Package" effort="1" severity="mandatory">
            <message>
                Code using this package should be replaced with code using the org.apache.xml package from [Apache
                Xerces](http://xerces.apache.org/).
            </message>
        </hint>
    </perform>
</rule>
Copy to Clipboard Toggle word wrap
3.3.1.2. Construct a Element
3.3.1.2.1.  Element Attributes
Expand
Attribute NameTypeDescription

references

CLASS_NAME

The package or class name to match on. Wildcard characters can be used.

Tip

For performance reasons, you should not start the reference with wildcard characters. For example, use weblogic.apache.xml.{*} instead of {web}.apache.xml.{*}.

Example:

references="weblogic.apache.xml.{*}"
Copy to Clipboard Toggle word wrap

matchesSource

STRING

An exact regex to match. This is useful to distinguish hard-coded strings.

Example:

matchesSource="log4j.logger"
Copy to Clipboard Toggle word wrap

as

VARIABLE_NAME

A variable name assigned to the rule so that it can be used as a reference in later processing. See the from attribute below. (Optional)

Example:

as="MyEjbRule"
Copy to Clipboard Toggle word wrap

from

VARIABLE_NAME

Begin the search query with the filtered result from a previous search identified by its as VARIABLE_NAME. (Optional)

Example:

from="MyEjbRule"
Copy to Clipboard Toggle word wrap

in

PATH_FILTER

Used to filter input files matching this regex (regular expression) naming pattern. Wildcard characters can be used. (Optional)

Example:

in="{*}File1"
Copy to Clipboard Toggle word wrap
3.3.1.2.2.  Child Elements
Expand
Child ElementDescription

<location>

The location where the reference was found in a Java class. Location can refer to annotations, field and variable declarations, imports, and methods. For the complete list of valid values, see the JavaDoc for TypeReferenceLocation.

Example:

<location>IMPORT</location>
Copy to Clipboard Toggle word wrap

<annotation-literal>

Match on literal values inside of annotations.

The below example would match on @MyAnnotation(myvalue="test").

<javaclass references="org.package.MyAnnotation">
    <location>ANNOTATION</location>
    <annotation-literal name="myvalue" pattern="test"/>
</javaclass>
Copy to Clipboard Toggle word wrap

Note that in this case, the <javaclass> refers to an annotation (MyAnnotation), so the top-level annotation filter, <annotation-literal> must specify the name attribute. If the <javaclass> referred to a class that is annotated, then the top-level annotation filter used would be <annotation-type>.

<annotation-type>

Match on a particular annotation type. You can supply subconditions to be matched against the annotation elements.

The below example would match on a Calendar field declaration annotated with @MyAnnotation(myvalue="test").

<javaclass references="java.util.Calendar">
    <location>FIELD_DECLARATION</location>
    <annotation-type pattern="org.package.MyAnnotation">
        <annotation-literal name="myvalue" pattern="test"/>
    </annotation-type>
</javaclass>
Copy to Clipboard Toggle word wrap

<annotation-list>

Match on an item in an array within an annotation. If an array index is not specified, the condition will be matched if it applies to any item in the array. You can supply subconditions to be matched against this element.

The below example would match on @MyAnnotation(mylist={"one","two"}).

<javaclass references="org.package.MyAnnotation" >
    <location>ANNOTATION</location>
    <annotation-list name="mylist">
        <annotation-literal pattern="two"/>
    </annotation-list>
</javaclass>
Copy to Clipboard Toggle word wrap

Note that in this case, the <javaclass> refers to an annotation (MyAnnotation), so the top-level annotation filter, <annotation-list> must specify the name attribute. If the <javaclass> referred to a class that is annotated, then the top-level annotation filter used would be <annotation-type>.

3.3.2.  Syntax

3.3.2.1. Summary

Use the <xmlfile> element to find information in XML files. For a better understanding of the <xmlfile> condition, see the XmlFile JavaDoc.

The following is an example of a rule that tests for an XML file.

<rule id="UNIQUE_RULE_ID">
    <when>
        <xmlfile matches="/w:web-app/w:resource-ref/w:res-auth[text() = 'Container']">
            <namespace prefix="w" uri="http://java.sun.com/xml/ns/javaee"/>
        </xmlfile>
    </when>
    <perform>
        <hint title="Title for Hint from XML">
            <message>Container Auth</message>
        </hint>
        <xslt description="Example XSLT Conversion" extension="-converted-example.xml"
              template="/exampleconversion.xsl"/>
    </perform>
</rule>
Copy to Clipboard Toggle word wrap
3.3.2.2. Construct an Element
3.3.2.2.1.  Element Attributes
Expand
Attribute NameTypeDescription

matches

XPATH

Match on an XML file condition. (Optional)

Example:

matches="/w:web-app/w:resource-ref/w:res-auth[text() = 'Container']"
Copy to Clipboard Toggle word wrap

xpathResultMatch

XPATH_RESULT_STRING

Return results that match the given regex. (Optional)

Example:

<xmlfile matches="//foo/text()"
  xpathResultMatch="Text from foo."/>
Copy to Clipboard Toggle word wrap

as

VARIABLE_NAME

A variable name assigned to the rule so that it can be used as a reference in later processing. See the from attribute below. (Optional)

Example:

as="MyEjbRule"
Copy to Clipboard Toggle word wrap

in

PATH_FILTER

Used to filter input files matching this regex (regular expression) naming pattern. Wildcard characters can be used. (Optional)

Example:

in="{*}File1"
Copy to Clipboard Toggle word wrap

from

VARIABLE_NAME

Begin the search query with the filtered result from a previous search identified by its as VARIABLE_NAME. (Optional)

Example:

from="MyEjbRule"
Copy to Clipboard Toggle word wrap

public-id

PUBLIC_ID

The DTD public-id regex. (Optional)

Example:

public-id="public"
Copy to Clipboard Toggle word wrap

The matches attribute may use several built-in custom XPath functions, which may have useful side effects, like setting the matched value on the rule variables stack.

Expand
FunctionDescription

windup:matches()

Match a XPath expression against a string, possibly containing Windup parameterization placeholders.

Example:

matches="windup:matches(//foo/@class, '{javaclassname}'"
Copy to Clipboard Toggle word wrap

This will match all <foo/> elements with a class attribute and store their value into javaclassname parameter for each iteration.

3.3.2.2.3.  Child Elements
Expand
Child ElementDescription

<namespace>

The namespace referenced in XML files. This element contains 2 optional attributes: The prefix and the uri.

Example:

<namespace prefix="abc" uri="http://maven.apache.org/POM/4.0.0"/>
Copy to Clipboard Toggle word wrap

3.3.3.  Syntax

3.3.3.1. Summary

Use the <project> element to query the Maven POM file for the project characteristics. For a better understanding of the <project> condition, see the JavaDoc for the Project class.

The following is an example of a rule that checks for a JUnit dependency version between 2.0.0.Final and 2.2.0.Final.

<rule id="UNIQUE_RULE_ID">
    <when>
        <project>
            <artifact groupId="junit" artifactId="junit" from="2.0.0.Final" to="2.2.0.Final"/>
        </project>
    </when>
    <perform>
        <lineitem message="The project uses junit with the version between 2.0.0.Final and 2.2.0.Final"/>
    </perform>
</rule>
Copy to Clipboard Toggle word wrap
3.3.3.2. Construct a Element
3.3.3.2.1.  Element Attributes

The <project> element is used to match against the project’s Maven POM file. You can use this condition to query for dependencies of the project. It does not have any attributes itself.

3.3.3.2.2.  Child Elements
Expand
Child ElementDescription

<artifact>

Subcondition used within <project> to query against project dependencies. The <artifact> element attributes are described below.

3.3.3.2.3.  Element Attributes
Expand
Attribute NameTypeDescription

groupId

PROJECT_GROUP_ID

Match on the project <groupId> of the dependency.

artifactId

PROJECT_ARTIFACT_ID

Match on the project <artifactId> of the dependency.

fromVersion

FROM_VERSION

Specify the lower version bound of the artifact. For example 2.0.0.Final.

toVersion

TO_VERSION

Specify the upper version bound of the artifact. For example 2.2.0.Final.

3.3.4.  Syntax

3.3.4.1. Summary

Use the <filecontent> element to find strings or text within files, for example, a line in a Properties file. For a better understanding of the <filecontent> condition, see the JavaDoc for the FileContent class.

3.3.4.2. Construct a Element
3.3.4.2.1.  Element Attributes
Expand
Attribute NameTypeDescription

pattern

String

Match the file contents against the provided parameterized string.

filename

String

Match the file names against the provided parameterized string.

as

VARIABLE_NAME

A variable name assigned to the rule so that it can be used as a reference in later processing. See the from attribute below.

Example:

as="MyEjbRule"
Copy to Clipboard Toggle word wrap

from

VARIABLE_NAME

Begin the search query with the filtered result from a previous search identified by its as VARIABLE_NAME. (Optional)

Example:

from="MyEjbRule"
Copy to Clipboard Toggle word wrap

3.3.5.  Syntax

3.3.5.1. Summary

Use the <file> element to find the existence of files with a specific name, for example, an ibm-webservices-ext.xmi file. For a better understanding of the <file> condition, see the JavaDoc for the File class.

3.3.5.2. Construct a Element
3.3.5.2.1.  Element Attributes
Expand
Attribute NameTypeDescription

filename

String

Match the file names against the provided parameterized string.

as

VARIABLE_NAME

A variable name assigned to the rule so that it can be used as a reference in later processing. See the from attribute below.

Example:

as="MyEjbRule"
Copy to Clipboard Toggle word wrap

from

VARIABLE_NAME

Begin the search query with the filtered result from a previous search identified by its as VARIABLE_NAME. (Optional)

Example:

from="MyEjbRule"
Copy to Clipboard Toggle word wrap

3.4. XML Rule - Perform Action Syntax

Operations available in the perform section of the rule include the classification of application resources, in-line hints for migration steps, links to migration information, and project lineitem reporting. Because XML rules are modeled after the Java-based rule add-ons, links to JavaDocs for the related Java classes are provided for a better understanding of how they behave.

The complete XML rule schema is located here: http://windup.jboss.org/schema/windup-jboss-ruleset.xsd

The following sections describe the more common XML rule perform actions.

3.4.1. Classification Syntax

3.4.1.1. Summary

The classification element is used to identify or classify application resources that match the rule. It provides a title that is displayed in the report, a level of effort, and it can also provide links to additional information about how to migrate this resource classification. For a better understanding of the classification action, see the JavaDoc for the Classification class.

The following is an example of a rule that classifies a resource as a WebLogic EAR application deployment descriptor file.

Example:

<rule id="XmlWebLogicRules_10vvyf">
    <when>
        <xmlfile as="default" matches="/*[local-name()='weblogic-application']"></xmlfile>
    </when>
    <perform>
        <iteration>
            <classification title="Weblogic EAR Application Descriptor" effort="3"/>
        </iteration>
    </perform>
</rule>
Copy to Clipboard Toggle word wrap
3.4.1.2. classification Element: Attributes
Expand
Attribute NameTypeDescription

title

STRING

Title this resource using the specified string.

Example:

title="JBoss Seam Components"
Copy to Clipboard Toggle word wrap

effort

BYTE

The level of effort assigned to this resource. (Optional)

Example:

effort="2"
Copy to Clipboard Toggle word wrap

severity

STRING

Whether this classification is "mandatory" or "optional". (Optional)

Example:

severity="mandatory"
Copy to Clipboard Toggle word wrap

of

VARIABLE_NAME

Create a new classification for the given reference. (Optional)

Example:

of="MySeamRule"
Copy to Clipboard Toggle word wrap
3.4.1.3. classification Element: Child Elements
Expand
Child ElementDescription

<link>

Provides a link URI and text title for additional information.

Example:

<classification title="Websphere Startup Service" effort="4">
   <link href="http://docs.oracle.com/javaee/6/api/javax/ejb/Singleton.html" title="EJB3.1 Singleton Bean"/>
   <link href="http://docs.oracle.com/javaee/6/api/javax/ejb/Startup.html" title="EJB3.1 Startup Bean"/>
</classification>
Copy to Clipboard Toggle word wrap

<tag>

Provides additional custom information for the classification.

Example:

<tag>Seam3</tag>
Copy to Clipboard Toggle word wrap

<description>

Description of this resource

Example:

<description>JBoss Seam components must be replaced</description>
Copy to Clipboard Toggle word wrap

3.4.3. Hint Syntax

3.4.3.1. Summary

The hint element is used to provide a hint or inline information about how to migrate a section of code. For a better understanding of the hint action, see the JavaDoc for the Hint class.

The following is an example of a rule that creates a hint.

Example:

<rule id="WebLogicWebServiceRules_8jyqn">
    <when>
        <javaclass references="weblogic.wsee.connection.transport.http.HttpTransportInfo.setUsername({*})" as="default">
            <location>METHOD</location>
        </javaclass>
    </when>
    <perform>
        <iteration>
            <hint title="Proprietary web-service" severity="mandatory" effort="3">
                <message>Replace proprietary web-service authentication with JAX-WS standards.</message>
                <link href="http://java-x.blogspot.com/2009/03/invoking-web-services-through-proxy.html" title="JAX-WS Proxy Password Example"/>
            </hint>
        </iteration>
    </perform>
</rule>
Copy to Clipboard Toggle word wrap
3.4.3.2. hint Element: Attributes
Expand
Attribute NameTypeDescription

title

STRING

Title this hint using the specified string. Title is a required attribute.

Example:

title="JBoss Seam Component Hint"
Copy to Clipboard Toggle word wrap

severity

STRING

Whether this hint is "mandatory" or "optional". (Optional)

Example:

severity="mandatory"
Copy to Clipboard Toggle word wrap

in

VARIABLE_NAME

Create a new Hint in the FileLocationModel resolved by the given variable. (Optional)

Example:

in="Foo"
Copy to Clipboard Toggle word wrap

effort

BYTE

The level of effort assigned to this resource. (Optional)

Example:

effort="2"
Copy to Clipboard Toggle word wrap
3.4.3.3. hint Element: Child Elements
Expand
Child ElementDescription

<message>

A message describing the migration hint.

Example:

<message>EJB 2.0 is deprecated</message>
Copy to Clipboard Toggle word wrap

<link>

Identify or classify links to informational content. See the section on Link Syntax for details.

Example:

<link href="http://docs.oracle.com/javaee/6/api/" title="Java Platform, Enterprise Edition 6
API Specification" />
Copy to Clipboard Toggle word wrap

<tag>

Define a custom tag for this hint.

Example:

<tag>Needs review</tag>
Copy to Clipboard Toggle word wrap

3.4.4. XSLT Syntax

3.4.4.1. Summary

The xslt element specifies how to transform an XML file. For a better understanding of the xslt action, see the JavaDoc for the XSLTTransformation class.

The following is an example of rule that defines an XSLT action.

Example:

<rule id="XmlWebLogicRules_6bcvk">
    <when>
        <xmlfile as="default" matches="/weblogic-ejb-jar"/>
    </when>
    <perform>
        <iteration>
            <classification title="Weblogic EJB XML" effort="3"/>
            <xslt title="JBoss EJB Descriptor (Windup-Generated)" template="transformations/xslt/weblogic-ejb-to-jboss.xsl" extension="-jboss.xml"/>
        </iteration>
    </perform>
</rule>
Copy to Clipboard Toggle word wrap
3.4.4.2. xslt Element: Attributes
Expand
Attribute NameTypeDescription

of

STRING

Create a new transformation for the given reference. (Optional)

Example:

of="testVariable_instance"
Copy to Clipboard Toggle word wrap

title

STRING

Sets the title for this XSLTTransformation in the report.

Example:

title="XSLT Transformed Output"
Copy to Clipboard Toggle word wrap

extension

STRING

Sets the extension for this XSLTTransformation.

Example:

extension="-result.html"
Copy to Clipboard Toggle word wrap

template

STRING

Sets the XSL template.

Example:

template="simpleXSLT.xsl"
Copy to Clipboard Toggle word wrap

effort

BYTE

The level of effort required for the transformation. (Optional)

3.4.4.3. xslt Element: Child Elements
Expand
Child ElementDescription

<xslt-parameter>

Specify XSLTTransformation parameters as property value pairs

Example:

<xslt-parameter property="title" value="EJB Transformation"/>
Copy to Clipboard Toggle word wrap

3.4.5. Lineitem Syntax

3.4.5.1. Summary

The lineitem element is used to provide general migration requirements for the application, such as the need to replace deprecated libraries or the need to resolve potential class loading issues. This information is displayed on the project or application overview page. For a better understanding of the lineitem action, see the JavaDoc for the Lineitem class.

The following is an example of a rule that creates a lineitem message.

Example:

<rule id="weblogic_servlet_annotation_1000">
    <when>
        <javaclass references="weblogic.servlet.annotation.WLServlet" as="default">
            <location>ANNOTATION</location>
        </javaclass>
    </when>
    <perform>
        <hint effort="1">
            <message>Replace the proprietary WebLogic @WLServlet annotation with the Java EE 6 standard @WebServlet annotation.</message>
            <link href="https://access.redhat.com/articles/1249423" title="Migrate WebLogic Proprietary Servlet Annotations" />
            <lineitem message="Proprietary WebLogic @WLServlet annotation found in file."/>
        </hint>
    </perform>
</rule>
Copy to Clipboard Toggle word wrap
3.4.5.2. lineitem Element: Attributes
Expand
Attribute NameTypeDescription

message

STRING

A lineitem message

Example:

message="Proprietary code found."
Copy to Clipboard Toggle word wrap

3.4.6. Iteration Syntax

3.4.6.1. Summary

The iteration element specifies to iterate over an implicit or explicit variable defined within the rule. For a better understanding of the iteration action, see the JavaDoc for the Iteration class.

The following is an example of a rule that performs an iteration.

Example:

<rule id="jboss-eap5-xml-19000">
    <when>
        <xmlfile as="jboss-app" matches="/jboss-app"/>
        <xmlfile as="jboss-app-no-DTD" matches="/jboss-app" public-id=""/>
    </when>
    <perform>
        <iteration over="jboss-app">
            <classification title="JBoss application Descriptor" effort="5"/>
        </iteration>
        <iteration over="jboss-app-no-DTD">
            <classification title="JBoss application descriptor with missing DTD" effort="5"/>
        </iteration>
        <iteration over="jboss-app-no-DTD">
            <xslt title="JBoss application descriptor - JBoss 5 (Windup-generated)" template="transformations/xslt/jboss-app-to-jboss5.xsl" extension="-jboss5.xml"/>
        </iteration>
    </perform>
</rule>
Copy to Clipboard Toggle word wrap
3.4.6.2. iteration Element: Attributes
Expand
Attribute NameTypeDescription

over

VARIABLE_NAME

Iterate over the condition identified by this VARIABLE_NAME.

Example:

over="jboss-app"
Copy to Clipboard Toggle word wrap
3.4.6.3. iteration Element: Child Elements
Expand
Child ElementDescription

<iteration>

Child elements include a when condition, along with the actions iteration, classification, hint, xslt, lineitem, and otherwise.

3.5. Test an XML Rule in Windup

3.5.1. Add the Rule to Windup

A Windup rule is installed simply by copying the rule to the appropriate Windup folder. Windup scans for rules, which are files that end with either *.windup.groovy or .windup.xml, in the following locations:

  • Copy the rule to a directory specified by the --userRulesDirectory argument on the Windup command line.
  • Copy the rule to the WINDUP_HOME/rules/ directory. WINDUP_HOME is the directory where you install and run the Windup executable.
  • Copy the rule to the ${user.home}/.windup/rules/ directory. This directory is created by Windup the first time it is executed and contains rules, add-ons, and the Windup log.

    For Linux or Mac:   ~/.windup/rules/
    For Windows: "\Documents and Settings\USER_NAME\.windup\rules\"  -or-  "\Users\USER_NAME\.windup\rules\"
    Copy to Clipboard Toggle word wrap

3.5.2. Test the XML Rule

  1. Test the XML rule against your application file by running Windup in a terminal.

    The command uses this syntax:

    WINDUP_HOME/bin/windup [--sourceMode] --input INPUT_ARCHIVE_OR_FOLDER --output OUTPUT_REPORT_DIRECTORY --target TARGET_TECHNOLOGY --packages PACKAGE_1 PACKAGE_2 PACKAGE_N
    Copy to Clipboard Toggle word wrap

    You should see the following result:

    ***SUCCESS*** Windup report created: OUTPUT_REPORT_DIRECTORY/index.html
    Copy to Clipboard Toggle word wrap

3.5.3. Additional Resources

3.6. Overriding Rules

You can override core rules distributed with Windup or even custom-written rules. For example, you might want to change the matching conditions, effort, or hint text for a rule. This is done by making a custom copy of the original rule, marking it as a rule override, and making the necessary adjustments. You can also disable a rule in this same manner.

3.6.1. Override a Rule

You can override a rule using the following steps.

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

    Custom rules can be placed in either WINDUP_HOME/rules, ${user.home}/.windup/rules/, or the directory specified by the --userRulesDirectory command-line argument.

  2. Edit the XML file and only keep the <rule> elements for the rules that you want to override.

    Note that the rules from the original ruleset that are not overridden in the new ruleset will be executed 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. Add the <overrideRules>true</overrideRules> entry to the ruleset metadata.
  5. Make the adjustments to the rule as necessary.

    You can change anything in the rule definition. This rule will override the entire original rule.

The below is an example of an overridden rule. Notice the <overrideRules>true</overrideRules> element in the ruleset metadata. The rule and ruleset IDs match the original. This rule override simply changed the effort needed from a 1 to a 3.

<?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">
            <when>
                <javaclass references="weblogic.utils.StringUtils.{*}"/>
            </when>
            <perform>
                <hint effort="3" severity="mandatory" title="WebLogic StringUtils Usage">
                    <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>
Copy to Clipboard Toggle word wrap

When you run Windup, this rule will now be used in place of the original rule with the matching rule ID. You can verify that the new rule was used by viewing the contents of the Rule Provider Executions Report.

3.6.2. Disable a Rule

To disable a rule, follow the same steps as above to override a rule, except just provide an empty <rule> element.

<?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">
            <!-- Empty so that the original rule is disabled -->
        </rule>
    </rules>
</ruleset>
Copy to Clipboard Toggle word wrap

Chapter 4. Additional Resources

4.1. Review the Existing Windup XML Rules

Windup XML-based rules are located on GitHub at the following location: https://github.com/windup/windup-rulesets/tree/master/rules.

Instructions to fork and clone the Windup rulesets repository to your local machine are provided on the Wiki.

Rules are grouped by target platform and function. When you create a new rule, it is helpful to find a rule that is similar to the one you need and use it as a starting template.

New rules are continually added, so it is a good idea to check back frequently to review the updates.

Chapter 5. Appendix

5.1. Rule Story Points

5.1.1. What are Story Points?

Story Points are an abstract metric commonly used in Scrum Agile software development methodology to estimate the level of effort needed to implement a feature or change.

Windup uses story points to express the level of effort needed to migrate particular application constructs, and in a sum, the application as a whole. It does not necessarily translate to man-hours, but the value should be consistent across tasks.

5.1.2. How Story Points are Estimated in Rules

Estimating the level of effort for the story points for a rule can be tricky. The following are the general guidelines Windup uses when estimating the level of effort required for a rule.

Expand
Level of EffortStory PointsDescription

Information

0

An informational warning with very low or no priority for migration.

Trivial

1

The migration is a trivial change or a simple library swap with no or minimal API changes.

Complex

3

The changes required for the migration task are complex, but have a documented solution.

Redesign

5

The migration task requires a redesign or a complete library change, with significant API changes.

Rearchitecture

7

The migration requires a complete rearchitecture of the component or subsystem.

Unknown

13

The migration solution is not known and may need a complete rewrite.

5.1.3. Task Severity

In addition to the level of effort, migration tasks can be assigned a severity that indicates whether the task must be completed or can be postponed.

Mandatory
The task must be completed for a successful migration. If the changes are not made, the resulting application will not build or run successfully. Examples include replacement of proprietary APIs that are not supported in the target platform.
Optional
If the migration task is not completed, the application should work, but the results may not be the optimal. If the change is not made at the time of migration, it is recommended to put it on the schedule soon after migration is completed. An example of this would be the upgrade of EJB 2.x code to EJB 3.

5.2. About the WINDUP_HOME Variable

This documentation uses the WINDUP_HOME replaceable value to denote the path to the Windup distribution. When you encounter this value in the documentation, be sure to replace it with the actual path to your Windup installation.

  • If you download and install the latest distribution of Windup from the JBoss Nexus repository, WINDUP_HOME refers to the windup-distribution-2.5.0-Final folder extracted from the downloaded ZIP file.
  • If you build Windup from GitHub source, WINDUP_HOME refers to the windup-distribution-2.5.0-Final folder extracted from the windup-distribution/target/windup-distribution-2.5.0-Final.zip file.

Legal Notice

Copyright © 2017 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat Software Collections is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat