Now it's time to add the PDF converter tool:
- Add another tool to the Pretty Printer tool-chain and set the name to "PDF Converter".
- Set the natureFilter to both.
- Set the command as "ps2pdf".
- Set the commandLinePattern to "${command} ${inputs} ${output}".
- Add an input type for the tool that takes .ps files as source.
- Use the buildVariable "PS_FILE" for this input.
- Set multipleOfType to false.
- Set primaryInput to true.
- Add an output type for the tool that outputs .pdf files. Set the primaryInputType for this output to be the id of the input type that you created in step 5.
- There is one last bit of housekeeping: Go back to the tool-chain node and set the targetTool attribute to be the id of the PDF Converter tool.
At this point, you have all your tools nicely defined, but still lack one crucial piece. The MBS needs to know what utility will actually do the build. In this case, you will use the GNU make utility. Luckily, CDT already includes a GNU makefile generator and a definition for a GNU Make builder that you can simply reuse. If you wished to use some other utility to do the build (nmake, shell scripts, batch files, and the like), you could define your own makefile generator and build definition. For now, you'll just specify that your tool-chain uses the existing GNU Make definitions. If you have access to the CDT source code, see org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml.
- Create a new builder node under the tool-chain.
- Set the name to "GNU Make".
- Set the superclass attribute to cdt.managedbuild.target.gnu.builder. This tells MBS that your builder inherits its attributes from CDT's builder, unless you specify different attributes here.
You should now have a working set of build definitions. If you switch to the plugin.xml tab of the manifest editor, you can see the resulting XML description of your plug-in, which should look something like Listing Three. Save your file and then build the workspace.
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <plugin> <extension id="ddj.example.prettyprinter.toolchain" name="Pretty-Printer" point="org.eclipse.cdt.managedbuilder.core.buildDefinitions"> <projectType id="ddj.example.prettyprinter.toolchain.projectType1" isAbstract="false" name="Pretty-Printer"> <configuration artifactExtension="pdf" cleanCommand="rm -f" description="default configuration" id="ddj.example.prettyprinter.toolchain.configuration1" name="Default"> <toolChain id="ddj.example.prettyprinter.toolchain.toolChain1" isAbstract="false" name="Pretty Printer Toolchain" targetTool="ddj.example.prettyprinter.toolchain.tool2"> <tool command="enscript" commandLinePattern="${command} ${flags} ${output_flag} ${output} ${inputs}" id="ddj.example.prettyprinter.toolchain.tool1" isAbstract="false" name="PostScript PrettyPrinter" natureFilter="both" outputFlag="-o"> <inputType id="ddj.example.prettyprinter.toolchain.inputType1" multipleOfType="true" name="C Sources" primaryInput="true" sourceContentType="org.eclipse.cdt.core.cSource"/> <inputType id="ddj.example.prettyprinter.toolchain.inputType2" multipleOfType="true" name="C++ Sources" primaryInput="true" sourceContentType="org.eclipse.cdt.core.cxxSource"/> <outputType buildVariable="PS_FILE" id="ddj.example.prettyprinter.toolchain.outputType1" name="PostScript Files" outputs="ps" outputNames="${BuildArtifactFileBaseName}.ps" primaryOutput="true"/> <optionCategory id="ddj.example.prettyprinter.toolchain.optionCategory.General" name="General" owner="ddj.example.prettyprinter.toolchain.tool1"/> <option category="ddj.example.prettyprinter.toolchain.optionCategory.General" command="--pretty-print" defaultValue="true" id="ddj.example.prettyprinter.toolchain.option.Pretty" isAbstract="false" name="Pretty-print source code" resourceFilter="project" valueType="boolean"/> <option category="ddj.example.prettyprinter.toolchain.optionCategory.General" command="--color" id="ddj.example.prettyprinter.toolchain.option.Color" isAbstract="false" name="Print in color" resourceFilter="project" defaultValue="true" valueType="boolean"/> </tool> <tool command="ps2pdf" commandLinePattern="${command} ${inputs} ${output}" id="ddj.example.prettyprinter.toolchain.tool2" isAbstract="false" name="PDF Converter" natureFilter="both"> <inputType buildVariable="PS_FILE" id="ddj.example.prettyprinter.toolchain.inputType3" multipleOfType="false" name="PostScript Files" primaryInput="true" sources="ps"/> <outputType id="ddj.example.prettyprinter.toolchain.outputType2" name="PDF Files" outputs="pdf" primaryInputType="ddj.example.prettyprinter.toolchain.inputType3" primaryOutput="true"/> </tool> <builder id="ddj.example.prettyprinter.toolchain.builder1" isAbstract="false" isVariableCaseSensitive="false" name="GNU Make" superClass="cdt.managedbuild.target.gnu.builder"/> </toolChain> </configuration> </projectType> </extension> </plugin>
You should now be able to debug the workspace as an Eclipse application; that is, by using Eclipse to debug itself with your new plug-in included.
- Select Debug... from the Run menu.
- Select Eclipse Application from the list of launch configuration types and press the New button. All of the default settings should be sufficient, so press the Debug button. Eclipse should then launch as a runtime-workbench.
If you're in the C/C++ Perspective in Eclipse, use the File>New>Managed Make C++ Project menu item to create a new project. You will see a New Project wizard. Specify a name and location for your project, then click Next. You then see a page that lets you select a project type (Figure 2). In the Project Type drop-down, select the Pretty Printer project type that you created and press Finish.
[Click image to view at full size]