This sample demonstrates how to replace an MVS™ subproject's default builder with a new builder. The new builder can be used to change the way the subproject is built when a build action is requested.

To replace the default subproject builder with a different (user-defined) builder, right click the subproject and select the API Sample Actions > Replace Default Builder action.
This action causes the information in the XML file to be updated. The file may not be updated immediately, but the builder information will change the next time the file is written. At this point, the file will look similar to the following:

If you wish to restore the original (default) subproject builder, select the API Sample Actions > Restore Default Builder action.
Subproject builders in Rational® Developer for System z® are similar in concept to an incremental project builder in base Eclipse. They provide a means to build the contents of a subproject, creating new and/or updated build results. For example, all of the COBOL source files in the subproject may be processed by a COBOL compiler, and the resulting files (object, listing, executable, and so on) may be added to the subproject.
To define a custom project builder for a remote subproject, you need to create a class that implements the ILogicalSubProjectBuilder interface. Thus the SampleBuilder class contains the following:
public class SampleBuilder implements ILogicalSubProjectBuilder {
......
}
The ILogicalSubProjectBuilder interface is relatively simple. In SampleBuilder simply add a private field subproject for the subproject instance. This sample issues a println statement saying "Sample Builder called for subProject:" and includes the subproject's name.
The complete source code can be found in SampleBuilder.java.
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;
}
}
The complete source code can be found in AddSubProjectBuilderAction.java.
The action is contributed using standard Eclipse contribution mechanisms.
<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>
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;
}
}
The complete source code can be found in RemoveSubProjectBuilderAction.java.
The action is contributed using standard Eclipse contribution mechanisms.
<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>