Tuesday 28 January 2014

Eclipse Groovy REPL - Open TeamMentor Article in multiple formats

Part of the new TeamMentor Fortify Eclipse plugin v1.6.0 (update site hereinstallation instructions here) is a really powerful TeamMentor and Eclipse API which can be easily accessed via the included Groovy REPL.

In this first post (of several in this topic) I will show how to use the APIs to Open TeamMentor Article in multiple formats

The first step is to open the Util - Write Script (TeamMentor DSL) view (which is the name of the provided Groovy REPL) using the TeamMentor menu (note that the Advanced mode features config property needs to be checked, or the Advanced and Debug Features sub-menu will not be visible):

.... alternatively if you are using Kepler, you can use the 'Quick Access' search bar to find that view. Just search for 'Team..' and you should see the view Write TeamMentor Script

This is what the Groovy REPL script UI looks like:

...which when executed using the default script, will open up a browser window with TeamMentor's guidance for 'Cross-Site Scripting' (which is what the command openArticle('Cross-Site Scripting') will do:

The command openArticle('Cross-Site Scripting')  can be executed in that environment because it is being automatically mapped to the tm.teammentor.TeamMentor class (see code here).

This is probably easier to understand using the groovy code sample below (gist), where:

1) the tm.teammentor.* package is imported
2) an TeamMentorAPI object is created
3) the open_Article method from TeamMentorAPI is called:

A really nice helper feature that this Eclipse Plugin has is the ObjectBrowser (see code here) which provides a nice Table view of any Java object.

To see it in action (inside the Groovy REPL) just use the syntax show({target object}).

For example here is how to see the details of the teamMentor variable (which is an instance of the tm.teammentor.TeamMentor class):
After execution, a new Object Browser view should appear, which can be placed anywhere on the Eclipse UI, and on the screenshot below it is placed under the Groovy REPL window:

The ObjectBrowser allows the easy view of all fields and getters:

Expanding the special _methods node, will show the current public and private methods of the selected object (which can be quite down the original object tree)

Note how in the image above we can see that there are a number of view_* methods for the TeamMentorAPI class: view_Article , view_Content, view_Html, view_Jsonp, view_Raw

Let's see them in action:

view_Article (shows fully formatted article's content with edit links if the current user has edit privileges). Note that this is the same result as calling openArticle(...) shown above

view_Html (shows article's HTML with just a simple TM banner)

view_Contents (shows article's raw content, which in this case was written in Markdown)

view_Raw (shows article's XML content, which is an exact copy of the article's xml file saved to disk)

view_Jsonp (shows an article's raw content (i.e. XML file) in javascript JSONP format (making it easier to consume from Javascript)

Wrapping up this post, note how there are other TeamMentor specific methods available: set TM server, login into TM, set Session ID, etc: