Rational Developer for System z

MVS サブプロジェクト用の別のビルダーの指定

このサンプルは、MVS™ サブプロジェクトのデフォルト・ビルダーを新しいビルダーに置き換える方法を示します。新しいビルダーを使用すると、ビルド・アクションが要求されたときにサブプロジェクトをビルドする方法を変更できます。

サンプル・シナリオ

以下のトピックの指示に従って、新しい z/OS® プロジェクトと MVS サブプロジェクトを作成します。 新しいサブプロジェクトを作成すると、そのサブプロジェクトのさまざまな特性とプロパティーを維持した XML ファイルが作成されます。以下の図は、サブプロジェクトに続いて作成されるこの XML ファイルの一部を示しています。

DefaultBuilderXML のアートワーク

デフォルトのサブプロジェクト・ビルダーを別の (ユーザー定義の) ビルダーに置き換えるには、サブプロジェクトを右クリックして、「API サンプル・アクション」->「デフォルト・ビルダーの置換」アクションを選択します。

このアクションにより、XML ファイル内の情報が更新されます。 このファイルは、すぐに更新されない場合がありますが、次にファイルが書き込まれるときにはビルダー情報が変更されます。現時点では、ファイルは次の図のように表示されます。

SampleBuilderXML のアートワーク

オリジナル (デフォルト) のサブプロジェクト・ビルダーを復元するには、「API サンプル・アクション」->「デフォルト・ビルダーの復元」アクションを選択します。

サンプル・コードのウォークスルー

サブプロジェクト・ビルダーの定義

Rational® Developer for System z® のサブプロジェクト・ビルダーは、ベース Eclipse の増分プロジェクト・ビルダーに概念が似ています。これらは、新規作成や更新などのサブプロジェクトの内容を構築する手段を提供します。例えば、サブプロジェクト内のすべての COBOL ソース・ファイルを COBOL コンパイラーで処理すると、結果のファイル (オブジェクト、リスト、実行可能ファイルなど) はサブプロジェクトに追加されます。

リモート・サブプロジェクト用のカスタム・プロジェクト・ビルダーを定義するには、ILogicalSubProjectBuilder インターフェースを実装するクラスを作成する必要があります。 したがって、SampleBuilder クラスには、以下のコードが含まれます。

public class SampleBuilder implements ILogicalSubProjectBuilder {
   ......
}

ILogicalSubProjectBuilder インターフェースは、比較的簡単です。SampleBuilder では、サブプロジェクト・インスタンスの subproject 専用フィールドを追加するのみです。このサンプルは、「サブプロジェクト用にサンプル・ビルダーが呼び出された」ことを示す println ステートメントを発行し、サブプロジェクトの名前を組み込みます。

完全なソース・コードは、SampleBuilder.java で参照できます。

デフォルトのサブプロジェクト・ビルダーの置き換え

デフォルト・ビルダーの置換」メニュー項目は、AddSubProjectBuilderAction クラスによって実装されます。 その run(IAction) メソッドは、サブプロジェクトの getBuildSpec() メソッドを使用して IBuildCommand のリスト内で古いビルダーを検索し、さらに setBuildSpec(com.ibm.ftt.projects.core.logical.IBuildCommand newCommands) メソッドを使用して BuildSpec を更新することによって、サブプロジェクトの buildSpec を変更して、デフォルト・ビルダー・クラスの名前をサンプル・ビルダー・クラスの名前である SampleBuilder に置き換えます。
		IBuildCommand[] buildCommands = subProject.getBuildSpec();

		// look through the existing build commands for the "standard" 
		// RDz builder for MVS subprojects, and if found substitute the
		// sample builder in its place
		for (int i = 0; i < buildCommands.length; ++i) {
			if (buildCommands[i].getBuilderName().equals(IProjectCoreConstants.ZOS_BUILDER_ID)) {
				// copy the commands preceding the RDz builder
				IBuildCommand[] newCommands = new IBuildCommand[buildCommands.length];
				if (i > 0) {
					System.arraycopy(buildCommands, 0, newCommands, 0, i - 1);
				}
				// create a new command for the sample builder
				IBuildCommand buildCommand = getSubProject().newCommand();
				buildCommand.setBuilderName("com.ibm.ftt.api.samples.samplebuilder");
				// add the new command
				newCommands[i] = buildCommand;
				// copy the rest of the build commands
				if (i < buildCommands.length) {
					System.arraycopy(
						buildCommands,
						i + 1,
						newCommands,
						i,
						buildCommands.length - i - 1);
				}
				
				// store the new set of build commands
				subProject.setBuildSpec(newCommands);
				
				System.out.println("Sample builder replaces RDz builder");
				break;
			}
		}

完全なソース・コードは、AddSubProjectBuilderAction.java で参照できます。

アクションは、標準の Eclipse の機構を使用して提供されます。

       <objectContribution
         adaptable=“false”
         objectClass=“com.ibm.ftt.projects.core.logical.ILogicalSubProject”
         id=“com.ibm.ftt.api.samples.addbuilder”>
         <visibility>
            <not>
               <objectState
                     name=“projectBuilder”
                     value=“com.ibm.ftt.api.samples.samplebuilder”>
               </objectState>
            </not>
         </visibility>
         <action
            label=“
            class=“com.ibm.ftt.api.samples.builders.AddSubProjectBuilderAction”
            menubarPath=“com.ibm.ftt.api.samples.PopupMenu/group1”
            id=“com.ibm.ftt.api.samples.addbuilderaction”/>
      </objectContribution>

デフォルトのサブプロジェクト・ビルダーの復元

デフォルト・ビルダーの復元」メニュー項目は、RemoveSubProjectBuilderAction クラスによって実装されます。 その run(IAction) メソッドは、サブプロジェクトの getBuildSpec() メソッドを使用して IBuildCommand のリスト内で古いビルダーを検索し、さらに setBuildSpec(com.ibm.ftt.projects.core.logical.IBuildCommand newCommands) メソッドを使用して BuildSpec を更新することによって、サブプロジェクトの buildSpec を変更して、サンプル・ビルダー・クラスの名前である SampleBuilder をデフォルト・ビルダー・クラスの名前に置き換えます。
      
		IBuildCommand[] buildCommands = subProject.getBuildSpec();

		// look through the existing build commands for the sample 
		// builder, and if found substitute the "standard" RDz builder
		// in its place
		for (int i = 0; i < buildCommands.length; ++i) {
			if (buildCommands[i].getBuilderName().equals("com.ibm.ftt.api.samples.samplebuilder")) {
				// copy the commands preceding the sample builder
				IBuildCommand[] newCommands = new IBuildCommand[buildCommands.length];
				if (i > 0) {
					System.arraycopy(buildCommands, 0, newCommands, 0, i - 1);
				}
				// create a new command for the RDz builder
				IBuildCommand buildCommand = getSubProject().newCommand();
				buildCommand.setBuilderName(IProjectCoreConstants.ZOS_BUILDER_ID);
				// add the new command
				newCommands[i] = buildCommand;
				// copy the rest of the build commands
				if (i < buildCommands.length) {
					System.arraycopy(
						buildCommands,
						i + 1,
						newCommands,
						i,
						buildCommands.length - i - 1);
				}
				
				// store the new set of build commands
				subProject.setBuildSpec(newCommands);
				
				System.out.println("RDz builder replaces Sample builder");
				break;
			}
		}

完全なソース・コードは、RemoveSubProjectBuilderAction.java で参照できます。

アクションは、標準の Eclipse の機構を使用して提供されます。

                  <objectContribution
         adaptable=“false”
         objectClass=“com.ibm.ftt.projects.core.logical.ILogicalSubProject”
         id=“com.ibm.ftt.api.samples.removebuilder”>
         <filter
            value=“com.ibm.ftt.api.samples.samplebuilder”
            name=“projectBuilder”/>
         <action
            label=“
            class=“com.ibm.ftt.api.samples.builders.RemoveSubProjectBuilderAction”
            menubarPath=“com.ibm.ftt.api.samples.PopupMenu/group1”
            id=“com.ibm.ftt.api.samples.removebuilderaction”/>
      </objectContribution>

ご利用条件 | フィードバック

このインフォメーション・センターでは Eclipse テクノロジーが採用されています。(http://www.eclipse.org)