Rational Developer for System z

Specifying a different builder for an MVS subproject

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.

Sample Scenario

Create a new z/OS® project and MVS subproject according to the instructions in the following topics: The act of creating a new subproject causes an XML file to be created in which various characteristics and properties of the subproject are maintained. The following illustration shows a portion of this XML file following creation of the subproject:

Artwork for DefaultBuilderXML

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 illustration:

Artwork for SampleBuilderXML

If you wish to restore the original (default) subproject builder, select the API Sample Actions > Restore Default Builder action.

Sample Code Walk-through

Subproject Builder Definition

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 code:

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.

Replacing the Default Subproject Builder

The Replace Default Builder menu item is implemented by the AddSubProjectBuilderAction class. Its run(IAction) method changes the subproject's buildSpec to replace the name of the default builder class with the name of the sample builder class SampleBuilder by using the subproject's getBuildSpec() method, finding the old builder in the list of IBuildCommands, and updating the BuildSpec using the subproject's setBuildSpec(com.ibm.ftt.projects.core.logical.IBuildCommand newCommands) method.
		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>

Restoring the Default Subproject Builder

The Restore Default Builder menu item is implemented by the RemoveSubProjectBuilderAction class. Its run(IAction) method changes the subproject's buildSpec to replace the name of the sample builder class SampleBuilder with the name of the default builder class by using the subproject's getBuildSpec() method, finding the old builder in the list of IBuildCommands, and updating the BuildSpec using the subproject's setBuildSpec(com.ibm.ftt.projects.core.logical.IBuildCommand newCommands) method.
      
		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>

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)