Hints on getting started with CDT plug-ins
On a good day I decided that it would be very convenient if I could add some “New project” templates to eclipse. The basics are documented fairly well in the eclipse documentation. It even provides an example. With the aid of some basic tutorials on eclipse plug-in development I was able to come a long way. Not far enough. I failed to get the example working. After some more google-ing and finding my way, I learned that a good approach is to take a look at the source code of other templates. especially of those that are provided standard in Eclipse CDT. This finally gave me my first added template. By the time I did this, I also installed a lot of GNU ARM Eclipse Project templates. With the effect that my own template was difficult to find in a long list. So I came to the unfortunate insight that I could develop a “New Project Wizard” that only showed my own templates. So I did!. Finally I thought it is a hassle to setup a new workspace every time I create a new one. Could this be automated a bit. Of course. So I set out writing a plug-in that was able to discover some tools within Windows and set their paths in variables within Eclipse. The good news is: I did it and it works. The bad news: I lost a week of my life. I write this in the hope that others undertaking the same or similar enterprise can learn and only loose a couple of days of their lives. I am not the only one struggling with this. I fully under scribe the quote of this guy justinmreina on stackoverflow.com “It is AMAZING how hard this stuff is to find” when discussing adding specific build or compiler settings with templates.
2. Follow tutorials
There are some really good tutorials on Eclipse plug-in development written. Notably a series of 24 posts by cvalcarcel and the famous Vogella.de tutorials. In another post (link to be added) I provide a list of links to those. The thing is: This requires very careful reading. But only after gaining experience one starts to understand the significance of certain casual remarks. I followed the cvalcarcel tutorial up to step 5. I am not interested in the other UI aspects in the later posts. Yet I believe there is an error in step 2, which is luckily refactored in step 3 so issue solved. Something with a replaced string without the definition of the string.
What the tutorial did not tell
No schema found
When adding an extension to an extension point, a common task is to add attributes to this extension. It can happen that the attribute you are looking for is not in the list. The top-bar of the manifest editor tells “No schema found”: This means that eclipse was looking for the sources of the extension point and did not find them. Make sure that:
- Eclipse SDK
- C/C++ Development Tools SDK
Are installed. Both can be installed from main menu Help -> Install new software. For the first the eclipse update site needs to be selected to find it, and for the second the regular Juno/Luna releases site, under “Programming Languages”.
Add dependencies first
When trying to extend an extension point on the extensions tab, but the extension does not show up in the search list, you probably first have to add the parent package at the Dependencies tab.
3. New Project Templates for CDT
As said, I did not get the example to work, despite good instructions from help.eclipse.org. My advice, find yourself a set of example templates (as jar files) and import them in a workspace for reference. Source code of the CDT provided templates can be found in CDT repository in org.eclipse.cdt.managedbuilder.gnu.ui
Find org.eclipse.cdt.managedbuilder.gnu.ui*.jar, or get source code from git.eclipse.org Check out templates/projecttemplates/* and plugin.xml.
GNU ARM Eclipse has a lot of templates, but it is surrounded by a complete infrastructure and java extensions. So it is more difficult to use for teaching purposes.
Some simple inspiration can be taken from my Picos ARM templates for LPC8xx projects in github.
Setting project properties from the template
The template can set include folders, include or library paths and a lot more project properties. What can be set at the project properties page in the UI can also be set from a template. The only questionis how do you know what it is called. The bes tanswer is: Reverse engineering. Look into source code. Try to see what gets changed in eclipse and workspace internal files when you enter something unique in the UI. At stackoverflow.com, in the second answer to a question, justinmreina gives a brief very helpful tutorial reverse engineering.
Adding a template for makefiles
In the Eclipse Template Extnesion point it is nicely documented that there are three predefined values for projectType:
projectType – This attribute is a project type id referring to the cdt project type that the template will be associated with. Project types are contributed to the org.eclipse.cdt.managedbuilder.core.buildDefinitions extension-point. This attribute is mandatory. CDT pre-defines the following values of the build artifact type property:
- “org.eclipse.cdt.build.core.buildArtefactType.exe” – to represent executable
- “org.eclipse.cdt.build.core.buildArtefactType.staticLib” – to represent static library
- “org.eclipse.cdt.build.core.buildArtefactType.sharedLib” – to represent shared library
But what about the fourth standard category: Makefile projects? The projectType can also be set to: projectType=”org.eclipse.cdt.build.makefile.projectType”
Type of widgets for template user defined wizard pages
I was not able to figure out whether it is possible to show a input field conditionally, for example first field is a boolean checkmark, and if unchecked, hide/disable the next input string field. I also could not figure out whether I could evaluate variables within the template based on input in the wizard. What I did find was a list of possible Widgets to use in the template through an eclipse test class: http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/tree/core/org.eclipse.cdt.ui.tests/resources/projectTemplates/testWidgets/template.xml
4. Other CDT Plug-ins
One might come to the insight that it would be need to set a variable or environment variable in the workspace by a plug-in extension. After a lot of tracing/stepping through the Preferences page code, and searching the internet I have to conclude: All public interfaces can only read environment variables. there is no public API to set environment variables. This is confirmed by some forum posts: http://stackoverflow.com/questions/6186754/eclipse-cdt-how-to-save-project-wide-environment-variables-programmatically-pe https://www.eclipse.org/forums/index.php/t/812519/