第2章 ルールを使い始める
ルールを作成するか、クイックスタートを確認して、カスタム MTA ルールの作成を開始できます。
2.1. 最初の XML ルールの作成
本セクションでは、最初の MTA XML ベースのルールを作成してテストするプロセスを説明します。これは、すでに MTA がインストールされていることを前提としています。インストール手順は、『CLI ガイド』を参照してください。
この例では、アプリケーションが <class-loading>
要素を含む jboss-web.xml
ファイルの定義を行うインスタンスを検出するルールを記述します。また、コードの移行方法を説明するドキュメントへのリンクを提供します。
ルールのディレクトリー構造の作成
最初のルールと、テストに使用するデータファイルを含むディレクトリー構造を作成します。
mkdir -p /home/<USER_NAME>/migration-rules/rules mkdir -p /home/<USER_NAME>/migration-rules/data
$ mkdir -p /home/<USER_NAME>/migration-rules/rules
$ mkdir -p /home/<USER_NAME>/migration-rules/data
このディレクトリー構造は、生成された MTA レポートを保持するためにも使用されます。
ルールをテストするためのデータの作成
-
/home/<USER_NAME>/migration-rules/data/
サブディレクトリーにjboss-web.xml
ファイルを作成します。 以下の内容にコピーします。
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <!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>
<!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>
ルールの作成
MTA XML ベースのルールは、以下のルールパターンを使用します。
when(condition) perform(action) otherwise(action)
when(condition)
perform(action)
otherwise(action)
手順
/home/<USER_NAME>/migration-rules/rules/
ディレクトリーで、以下の内容が含まれるJBoss5-web-class-loading.windup.xml
という名前のファイルを作成します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow <?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="<SOURCE_VERSION_RANGE>"/> <targetTechnology id="<TARGET_ID>" versionRange="<TARGET_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>
<?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="<SOURCE_VERSION_RANGE>"/> <targetTechnology id="<TARGET_ID>" versionRange="<TARGET_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>
注記XML ファイル名には、
.windup.xml
または.mta.xml
拡張子が含まれている必要があります。それ以外の場合には、MTA は新しいルールを評価しません。ruleset および rule に一意の識別子を追加します。
-
<UNIQUE_RULESET_ID>
を、適切なルールセット ID (例:JBoss5-web-class-loading
) に置き換えます。 -
<UNIQUE_RULE_ID>
を、適切なルール ID (例:JBoss5-web-class-loading_001
) に置き換えます。
-
次のルールセットアドオン依存関係を追加します。
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <dependencies> <addon id="org.jboss.windup.rules,windup-rules-javaee,3.0.0.Final"/> <addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final"/> </dependencies>
<dependencies> <addon id="org.jboss.windup.rules,windup-rules-javaee,3.0.0.Final"/> <addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final"/> </dependencies>
ソースおよびターゲットのテクノロジーを追加します。
-
<SOURCE_ID>
をeap
に置き換えます。 -
<TARGET_ID>
をeap
に置き換えます。
-
ソースおよびターゲットのテクノロジーバージョンを設定します。
-
<SOURCE_VERSION_RANGE>
を(4,5)
に置き換えます。 -
<TARGET_VERSION_RANGE>
を(6,)
に置き換えます。
詳細は、Apache Maven 「version range specification」を参照してください。
-
when
条件を完了します。このルールは XML ファイルの一致をテストするため、ファイルの評価にはxmlfile
が使用されます。jboss-web
の子であるclass-loading
要素と一致するには、xpath 式jboss-web/class-loading
を使用します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow <when> <xmlfile matches="jboss-web/class-loading" /> </when>
<when> <xmlfile matches="jboss-web/class-loading" /> </when>
このルールの
perform
アクションを完了します。-
説明的なタイトルと作業レベル
1
を使用して分類を追加します。 ヒントに情報メッセージと、移行の詳細を説明するドキュメントへのリンクを提供します。
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <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>
<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>
-
説明的なタイトルと作業レベル
ルールは完了し、以下の例のようになるはずです。
<?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,3.0.0.Final"/> <addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final"/> </dependencies> <sourceTechnology id="eap" versionRange="(4,5)"/> <targetTechnology id="eap" versionRange="[6,)"/> </metadata> <rules> <rule id="JBoss5-web-class-loading_001"> <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>
<?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,3.0.0.Final"/>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final"/>
</dependencies>
<sourceTechnology id="eap" versionRange="(4,5)"/>
<targetTechnology id="eap" versionRange="[6,)"/>
</metadata>
<rules>
<rule id="JBoss5-web-class-loading_001">
<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>
ルールのインストール
MTA ルールは、ルールを適切なディレクトリーに配置してインストールされます。
JBoss5-web-class-loading.windup.xml
ファイルを <MTA_HOME>/rules/
ディレクトリーにコピーします。
cp /home/<USER_NAME>/migration-rules/rules/JBoss5-web-class-loading.windup.xml <MTA_HOME>/rules/
$ cp /home/<USER_NAME>/migration-rules/rules/JBoss5-web-class-loading.windup.xml <MTA_HOME>/rules/
ルールのテスト
端末を開き、以下のコマンドを実行して、テストファイルを入力引数として、出力レポートのディレクトリーとして渡します。
<MTA_HOME>/bin/mta-cli --sourceMode --input /home/<USER_NAME>/migration-rules/data --output /home/<USER_NAME>/migration-rules/reports --target eap:6
$ <MTA_HOME>/bin/mta-cli --sourceMode --input /home/<USER_NAME>/migration-rules/data --output /home/<USER_NAME>/migration-rules/reports --target eap:6
以下の結果が表示されるはずです。
Report created: /home/<USER_NAME>/migration-rules/reports/index.html Access it at this URL: file:///home/<USER_NAME>/migration-rules/reports/index.html
Report created: /home/<USER_NAME>/migration-rules/reports/index.html
Access it at this URL: file:///home/<USER_NAME>/migration-rules/reports/index.html
レポートの確認
レポートを確認して、予想される結果が表示されることを確認します。MTA レポートの詳細は、MTA の『CLI ガイド』の「レポートの確認」セクションを参照してください。
-
Web ブラウザーで
/home/<USER_NAME>/migration-rules/reports/index.html
を開きます。 ルールが実行されていることを確認します。
- 主な編集ページから、Rule providers execution overview リンクをクリックし、Rule Providers Execution Overview を開きます。
JBoss5-web-class-loading_001
ルールを探して、Status? がCondition met
で、Result? がsuccess
であることを確認します。図2.1 テストルール実行
ルールがテストデータと一致していることを確認します。
-
メインの発行ページから、この例の
データ
であるアプリケーションまたは入力フォルダーの名前をクリックします。 - Application Details レポートリンクをクリックします。
jboss-web.xml リンクをクリックして、ソースレポート を表示します。
<class-loading>
行が強調表示されており、カスタムルールからのヒントがインラインで表示されます。図2.2 ルール一致
ファイルの上部には、一致するルールの分類が表示されます。リンクアイコンを使用すると、そのルールの詳細を表示できます。この例では、
jboss-web.xml
ファイルが1
つのストーリーポイントを生成した別のルール (JBoss web application descriptor (jboss-web.xml)
) と一致することに注意してください。これは、カスタムルールから1
つのストーリーポイントと組み合わせて、このファイルの合計部分を2
にまとめます。
-
メインの発行ページから、この例の