Tuesday, August 24, 2010

Debuggable GSPs in SpringSource Tool Suite


A basic trick of Groovy Server Page debugging that seasoned Grails developers know is that by adding ?showSource=true to a URL for any of your GSPs you can view the Groovy translation of your GSP code.  For example, the vanilla create GSP (http://localhost:8080/TripPlanner/trip/create.gsp) gets rendered like this in the browser:


And altering the URL to this: http://localhost:8080/TripPlanner/trip/create.gsp?showSource=true, you can see the translated source:


There is a mapping between lines of code of the original GSP and the lines of code of the Groovy translation.  In fact, if you are using Grails 1.3.4 or above, and scroll to the bottom of the translation, you will see something like this:


 82: @org.codehaus.groovy.grails.web.transform.LineNumber(
  83:  lines = [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 11, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 17, 17, 18, 18, 19, 19, 20, 21, 23, 23, 23, 23, 25, 25, 26, 35, 35, 35, 35, 37, 37, 37, 39, 39, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  84:  sourceName = "create.gsp"
  85: )
  86: class ___LineNumberPlaceholder { }


This is the line mapping information and each element of the lines array maps a line from the translation (the array index) to a line in the original source code (the value at that index).  This is not particularly useful to humans, but it is to the SpringSource Tool Suite.

Using this information, STS is finally able to provide some debugging support for GSP files.  You can set a breakpoint at a line in your GSP editor, and the debugger will pause at that line when it is reached while rendering the page:



At this point, your GSP can be interacted with like any Groovy file.  For example, you can inspect the current state of variables in your page binding:



And you can execute values in the display view (using Java syntax only for now):



This feature has been fun to implement since it was my first foray into Eclipse's Java debug interface, but I am not sure how useful it is going to be.  Lines in a GSP are not executed sequentially.  Rather, many are executed out of order through closures inside of an invokeTag method call.  Also, I have not completely worked out how to determine if a breakpoint is at a valid location if Grails is not already running.  So, at this point it is possible to set a breakpoint on any blank line, but these breakpoints are only valid if they are set on a line containing a GSP tag or some other kinds of things.

But, I do hope this is useful to you and if you are interested in trying this new feature out, then you can download STS 2.5.0M3 and install the latest version of Grails tool support.  Enjoy!

Saturday, August 7, 2010

Groovy-PDE Redux

Up until recently, doing any PDE work with Groovy has been a bit of a kludge. First, you had to create a customCallBack.xml script. Inside this script you had to call out to a special groovy.jdtcompile ant task, using a magic set of classpath references. When this approach worked, it did so by first compiling your Java code (with errors of course since your groovy code is not touched), and then re-compiling all your code using the joint compiler provided by Groovy-Eclipse.

Not so pretty. It works for Groovy-Eclipse, but that is only because I know exactly what its limitations are and how to work around them.

A short while ago, I wrote about how we re-implemented PDE build for projects that use the AspectJ compiler. I've recently done the same for plugin projects that use Groovy.

Here's how it works:

  1. Install the latest dev snapshot of Groovy-Eclipse for Helios (you can write plugins that target Galileo (Eclipse 3.5), but you must use the Helios PDE builder to create the plugins).
  2. For each of your plugin projects, add the following to your build.properties file:
    sourceFileExtensions=*.java, *.groovy
    compilerAdapter=org.codehaus.groovy.eclipse.ant.GroovyCompilerAdapter
    compilerAdapter.useLog=true  # this ensures that exceptions are logged to the proper log file.
  3. Now you can run your PDE export (either headless or from within a running Eclipse using one of the Export wizards).

The only caveat is that each plugin project must contain at least one .java file or else the PDE builder will ignore that plugin. The problem is described in Bug 318951. Before this can be addressed, I need a patch committed to the javac task, described here: Apache Bug 48829 (please vote the bug up if you want to see this fixed!).

With that, creating Groovy-based Eclipse plugins now requires much, much less black magic.

Monday, July 5, 2010

AJDT 2.1.0 Released

I am pleased to announce the 2.1.0 release of the AspectJ Development Tools for Eclipse.

In addition to including AspectJ 1.6.9, this release includes a number of new features for making intertype declarations (ITDs) first class citizens in the editor. Java search now includes references and declarations of ITDs. Rename refactorings are now ITD-aware. And we have introduced the new pull-out refactoring, that can pull out your Java fields, methods, and constructors into an Aspect and convert them into an intertype declaration (this refactoring is the converse of the push-in refactoring that was introduced in 2.0.0.

AJDT 2.1.0 is available for Eclipse 3.5 and 3.6 from the following update sites:

http://download.eclipse.org/tools/ajdt/36/update

http://download.eclipse.org/tools/ajdt/35/update

For more details on the new features, please see the new and noteworthy.

Wednesday, June 30, 2010

Vancouver Eclipse Demo Camp 2010

Last night, 31 Eclipse developers from the Vancouver, BC area met up, listened to a few great talks, went for some beers, and had a great time. We had 8 speakers who surprisingly all stayed within their allotted time of 8 minutes (maybe it was a threat of a nerf gun that did it...I don't know). The pace was brisk and we heard lots of good things from lots of great developers from around Vancouver.

This year's Demo camp was sponsored by the Eclipse Foundation, SpringSource (a division of VMWare), and TaskTop.

Mik Kersten, Tasktop, Welcome and Eclipse Ecosystem Overview


Mik Kersten started the evening off with a brief introduction to some new features in the new Helios release. In addition to modernizing SWT to integrate better with Windows 7, and new Mylyn connectors, the most interesting new feature he described was the Eclipse Market Place. In the past, finding new content to install into your Eclipse installation required users to go to an external browser, find a link to an update site, and copy it into your update manager. Now, all this can be done transparently through the market place client from within Eclipse.

Kris De Volder, SpringSource, AspectJ and AJDT


Next up was Kris De Volder, a new colleague of mine that we snatched from the Computer Science Department at the University of British Columbia (UBC). He demoed some of his new work on AJDT, specifically the new Pull-Out refactoring that allows users to pull-out fields and methods from classes and convert them into intertype declarations. This will be available in the upcoming 2.1.0 release of AJDT.

He also demoed the Push-In refactoring, the converse of Pull-Out, which takes existing intertype declarations and pushes them into their target types. This is work that I did a short while ago and is described here.

Emerson Murphy-Hill, UBC, How Are People Using Eclipse?


Emerson showcased some of his research at UBC on how Eclipse is being used, or not used by developers. Some of the most surprising results of his research, in my opinion, are how little all of the various refactorings are used inside of Eclipse. And how the ones that are popular are not the ones that I personally use.

My personal favorites are rename (field, method, type, etc), extract (local, constant, and method), and convert local variable to field. Apparently, not many people use the last one. But (oddly, in my opinion), inline method seems to be quite popular---something I've never used.

David Dossot, MuleSoft, MuleSoft Tool Suite


David gave a brief tour of MuleIDE, which provides tool support for creating and managing your MuleSoft projects in Eclipse. David used MuleIDE to access road work data from the city of Vancouver and built a simple application to determine how many kilometers of roadwork are currently underway in Vancouver. Not bad for 8 minutes!

Alex Bradley, UBC, Source Code History at Your Fingertips


Do you use the "Show annotations" feature of CVS or SVN? I actually didn't know about this. Using "Show anotations" will add gutter markers on lines changed by recent commits to the source repository. Hovering over the annotations will provide extra information.

Alex showed his enhancements to the Java editor, which converted these annotations into semi-transparent overlays that co-exist with the source code. This is work that Alex has done for his master's thesis at UBC. I liked how his enhancements made version changes more explicit in the editor.

Nieraj Sing, SpringSource, Groovy language and Grails Support in the SpringSource Tool Suite


Nieraj is another new colleague of mine at SpringSource. He's a summer student from the University of Victoria. Nieraj showed his recent enhancements of Grails support in the SpringSource Tool Suite. He showed the Grails explorer view, which allows developers to view their Grails projects organized in a way that emphasizes artifacts and structure specific to Grails projects. He also showed his work on the Grails Plugin Manager, which allows developers to view, install, update, and uninstall Grails plugins into their projects.

Luke Evans, Indicee


Luke introduced the CAL programming language, a lazy-functional language developed by him and others when he worked at Business Objects (now SAP). He showed how programmers can use CAL to quickly and easily compose functions to manipulate streams of data in complex ways. It is this language that forms the core of the business reporting tool produced by his company, Indicee.

Bjorn Gustafsson, ProjectKoach


Finally, Bjorn showed ProjectKoach, an RCP application that brings agile planning into Eclipse. He showed how you can create sprints, manage tasks, integrate with version control, and integrate with bug trackers through Mylyn.

Sunday, June 27, 2010

No more handles?

I manage 4 Eclipse PDE builds on two different build servers. Three days ago, I started getting this same exception when running the JUnit tests for all 4 of the builds:

org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]
at org.eclipse.swt.SWT.error(SWT.java:3910)
at org.eclipse.swt.widgets.Display.createDisplay(Display.java:863)
at org.eclipse.swt.widgets.Display.create(Display.java:851)
at org.eclipse.swt.graphics.Device.(Device.java:152)
at org.eclipse.swt.widgets.Display.(Display.java:479)
at org.eclipse.swt.widgets.Display.(Display.java:470)
at org.eclipse.ui.internal.Workbench.createDisplay(Workbench.java:532)
at org.eclipse.ui.PlatformUI.createDisplay(PlatformUI.java:161)
at org.eclipse.ui.internal.ide.application.IDEApplication.createDisplay(IDEApplication.java:143)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:88)
at org.eclipse.test.UITestApplication.runApplication(UITestApplication.java:138)
at org.eclipse.test.UITestApplication.run(UITestApplication.java:60)
...


I was pulling my hair out trying to figure out why all four builds would be failing in the same exact way even though they span Eclipse versions (Galileo and Helios), and servers. All links I could track down seemed to imply that the root cause are SWT resources that are not properly disposed.

It turns out that solution was a bit more banal than that. There were no leaks in my code. Instead, this exception occurred because there was no virtual display available on the build servers for running the UI tests. Xvfb had shut down. After a restart of Xvfb, the tests are now running as expected.

Now, why Xvfb would happen to shut down on both servers at the same time still befuddles me, but the problem is fixed. I just hope that the next person who sees this problem doesn't also immediately think there is a resource leak, and pull their hair out to find it.

Saturday, May 15, 2010

Extending Groovy-Eclipse for use with Domain-Specific Languages Part II

A while ago, I wrote an article about how to extend Groovy-Eclipse for domain specific languages. It was always my intention to write a follow-up that included an example project. Thanks to some prodding on the mailing list, here it is, 5 months later. I finally have an example Groovy-Eclipse extension project available.

The code mostly speaks for itself, so if you are interested in how to extend Groovy-Eclipse, first read part I of this article, and then download the example project.

Here is the example plugin project that extends Groovy-Eclipse. Import this plugin into your Eclipse development workspace.

And here is a simple runtime project that uses all of the extensions provided in the plugin project. Import this project into your Eclipse runtime workspace. If you want to create your own project that uses this example, be sure to add the following project nature to your .project file:
org.codehaus.groovy.eclipse.example.nature
Once again, the code speaks for itself, so there is nothing more that I need to say about it. Enjoy!

Monday, May 10, 2010

Vancouver Eclipse Demo Camp 2010

The Vancouver Eclipse DemoCamp is on once again! This year, it is sponsored
by the Eclipse foundation ( http://eclipse.org ), Tasktop Technologies (
http://tasktop.com ), and others (see p.s.).   This June 29 come out and showcase your Eclipse
based products/tools/research to a crowd of local enthusiasts in a casual
environment. If you are interested in giving a short (10min) presentation,
please send us an email and add yourself to the wiki.

Those who just want to stop by for a beer and see what cool new Eclipse
based technology is being developed in your home town, please register by
adding your name to the wiki as well.

Date: June 29th 6:30pm
Location: TBD  (Likely Robson Square as usual)
After party: 8:00 (location TBD)
Keep an eye on the wiki page to see the finalized schedule

Last year, we had a great turnout with over 50 attendees and some amazing
demos.  It's an excellent opportunity to get to know the local Eclipse
community.  Hope to see you there!

Thanks,

Robert (Tasktop) and Andrew (SpringSource, a division of VMWare)

p.s. - In previous years, the event was fully funded by the Eclipse foundation, but
this year (in part, due to the world-wide success of these events), the
foundation no longer has the budget to provide the same level of funding. 
We are therefore looking sponsorship from the community. If your
company would like to foster the Vancouver Eclipse community, provide extra
branding for the event, and a dedicated speaker slot, please contact us.