BT

Book Review:"Eclipse 4 Plug-in Development by Example"

Posted by Charles Humble on Aug 07, 2013 |

Regular InfoQ Java contributor Dr. Alex Blewitt recently published "Eclipse 4 Plug-in Development by Example" via Packt publishing. Using Java as its language, the book provides a thorough tutorial for would-be Eclipse plug-in developers. In addition, with later chapters covering both build automation and detailed coverage of the Eclipse 4 model, it is likely to provide a useful resource for more experienced Eclipse-orientated developers.

In terms of structure the book includes step-by-step instructions, along with more detailed explanations as to how the examples works, multiple choice questions to help you gauge your understanding, and suggestions as to experiments you can do to consolidate what you've learnt. It is well written - both clear and concise - and manages to convey a huge amount of information in a relatively compact form.

After talking you through the business of setting up Eclipse and Java, the book heads into the traditional "Hello World" example, using the Eclipse plug-in wizard to create a sample plug-in, launch it and debug it.

From here, the next four chapters concentrate on UI, starting with an example using Eclipse's Standard Widget Toolkit (SWT), and then using JFace, which offers an MVC architecture and a higher level of abstraction. The JFace examples cover building viewers for structured data using both table-based and tree-based views, interacting with the user via menus and progress managers, and storing preferences.

Later chapters should prove useful to more experienced developers as well as beginners, starting with a detailed overview of the Eclipse 4 model. This represents a significant change from Eclipse 3.x, with the user interface now being represented using the Eclipse Modeling Framework. There's good information on the differences between Eclipse 3 and 4, and details on the different approaches developers can use to build plug-ins that will run on both versions of the platform.

Other topics include automating builds using Maven Tycho, which has become the de-facto standard for building Eclipse plug-ins, automating unit testing with JUnit, and user interface testing with SWTBot, combining plug-ins into features, and generating and registering update sites.

I spoke to Alex to find out more about it.

InfoQ: Who is the book aimed at?

Although the book's title is 'Eclipse 4 Plug-in Development by Example for beginners', and the code samples and exercises go into a lot of detail, I hope the book will be useful for existing Eclipse plug-in developers as well. For one, the Eclipse 4 model may be new to even seasoned Eclipse developers, and I hope that the chapter specifically dedicated to working with the E4 model is a useful starting point to explore and cover what the differences are in Eclipse 4.x and Eclipse 3.x. There's also the goal of covering the best practice; for example, ensuring that Commands and Handlers are covered (along with how to migrate any deprecated actions).

The chapter on Tycho builds may also be of interest to existing Eclipse plug-in developers, as it shows how to migrate an existing PDE plug-in to the newer Tycho build.

InfoQ: What prompted you to write it?

Eclipse 4 is a relatively new paradigm and the way in which plug-ins are glued into the IDE has changed significantly. Many of the tutorials you can find on the internet are based on Eclipse 3 (or even Eclipse 2) and so you find tutorials that talk about creating Actions as a way of contributing menu items, for example. I wanted to write a book which was definitively up-to-date and covered the current best practices, as well as highlighting those things (like Actions) which people may still be using based on older technology.
 
On a personal note, I've always wanted to write a book, and my areas of expertise include Eclipse, OSGi and Git. It was something I worked through with Packt as a suggestion after being a reviewer for their Jenkins book. With the recent transition of Eclipse to the 4.x stream and being able to release synchronised with the Eclipse 4.3 release, it seemed like the ideal opportunity.

InfoQ: I was really impressed with the debugging information in the text - using Step Filters and conditional breakpoints, detecting resource leaks in SWT and so on.  Something you particularly wanted to cover?

The book was written for beginners and, as such, they may not have had much experience with debugging generally. I wanted to cover not just the basics but also some of the more useful techniques for debugging Java and plug-in programs. Quite often these tips aren't immediately obvious and only come through finding out about it in some other means, so by covering it in the book hopefully I can share my experience with others in that regard. 

Because SWT uses manual resource management, it's easy to code something that leaks without realising it. Many users will have seen the 'No more handles' error at some point and blamed Eclipse, but in reality it's the tragedy of the commons; all it takes is one leaking plug-in to slowly eat through the available resources and ultimately the Eclipse runtime will grind to a halt. So I wanted to cover how to debug and detect leaks, and more importantly, how to avoid them in the first place by using one of the resource registries. 

InfoQ: You mentioned Tycho earlier. What is it, and how does it compare to what Eclipse developers did before?

Tycho is a Maven-based build system pioneered by Sonatype for developing Eclipse plug-ins in a reproducible way. Eclipse has always been slightly special in compiling plug-ins, because the OSGi programming model sets up filters between JARs; so when a.jar depends on b.jar, it may not necessarily be able to see all of b.jar's packages. Eclipse has historically always used Ant as the basis of the PDE build – in fact, when you build an Eclipse plug-in in the IDE it will generate and then auto-delete a build.xml file, and the 'build.properties' is actually fed directly into an Ant build.

Unfortunately Ant based builds were always difficult to debug, and the way that dependencies were resolved was complex and difficult to set up. Maven, on the other hand, is the de-facto standard build tool for both Java and other applications and has a built-in dependency resolution and caching mechanism that enables a standardised build to run on any machine.

Tycho is a set of Maven plug-ins that emulate the Ant-based build of before, but resolve and use P2 dependencies from a P2 repository (rather than the Central Repository). The plug-in can pick up and use the build.properties file and understand PDE's file layouts, and invoke the Eclipse compiler (with the necessary OSGi filters in place) to result in a compiled plug-in. There are separate plug-ins for materialising a product, feature or repository, so it's possible to take any existing PDE plug-ins, throw away the complex Ant builds and replace them with a few relatively simple Tycho plug-ins.

The best part is that the Eclipse platform is moving towards fully building with Tycho as part of the Common Build Infrastructure. It's now possible to check out the Eclipse platform and perform a build and only need Maven on the command line. Together with the move to use Gerrit (and in the future, GitHub pull requests) for receiving contributions, it makes Eclipse a much more open community and will encourage more developers to contribute fixes.

InfoQ: Eclipse 4.x represents a significant shift from Eclipse 3.x in terms of how the UI model works.  In the book you cover the options developers have at present for supporting both the 3.x and 4.x lines.  I know this is something that members of the Eclipse Foundation are continuing to work on.  Are you able to give us some idea as to what we might see in the area when Luna comes out (scheduled for Summer 2014)?

The release of Eclipse 4.2 (Juno) was the first production release based on E4, where the standard packages from the Eclipse download page were built on the E4 platform. Although prior builds had been made available for users to test, this was the first wide scale test and it became apparent that there were some performance issues which needed to be addressed (covered by InfoQ earlier).

The Eclipse 4.3 (Kepler) release is really a step forward in the performance of the underlying E4 platform, but at its heart the new model is mainly targeted at RCP developers who need fine grain control over the look and feel of the application environment. Many Eclipse IDE plug-ins still offer compatibility with the Eclipse 3.x APIs, and until the minimum requirement becomes 4.2 (which will probably happen more after 4.4 comes out) it's quite likely that many of them will continue to rely on the Eclipse 3.x compatibility layer in the Eclipse 4.x versions.

There are still some aspects of the Eclipse 4.x model which don't yet match how IDE plug-ins work; for example, if you're building a plug-in (as opposed to an application) it's trick to have your model merged in with the application model at installation time (and similarly tricky to undo afterwards). Some of these features will be needed before plug-ins can fully adopt the native E4 APIs.

I'd expect to see Luna being the starting point for some of the E4 changes which will allow pure IDE plug-ins to be written against the E4 model. We already have some reverse E4 compatibility layers (which allow you to write an E4 component and host it within the Eclipse 3.x APIs) but these are an optional download, tightly coupled with the Eclipse 4.x version and not available as part of the standard download. Once that gets merged in as part of the platform, I'd expect to see more people working with it and evolving the APIs forwards.

Finally, there's also support in Luna for the upcoming OSGi R6 release, which under the covers is going to expand on standardising several low-level aspects of the runtime, and the Luna Equinox implementation is migrating away from some of its decade old processing hooks to move to more standardised OSGi runtimes. But a lot of this will be hidden from the average Eclipse plug-in user.

InfoQ: Finally, are there any other books or resources you'd recommend to people who want to take advantage of everything the Eclipse ecosystem has to offer?

There's the Eclipse Foundation YouTube channel which has a number of video demos and podcasts, and also the Eclipse Marketplace at http://marketplace.eclipse.org is the go-to site for finding Eclipse plug-ins. If you want to do E4 development, the E4 tools site published there will have the right version for the appropriate platform, since it's not easy to find on the main Eclipse site. Finally, a great site for tutorials of both Eclipse and other platforms is Lars Vogel's http://www.vogella.com site. Lars has been a great supporter (and contributor/committer) of E4, and many of the things I learned whilst writing the book were influenced by his coverage of the E4 platform.

Packt have made a sample chapter available.  Alex has also written a blog post about his experience of writing the book.

About the Book Author

Dr Alex Blewitt works at an investment bank in London, but still finds the time to catch up with the latest OSGi and Eclipse news. Despite having previously been an editor for EclipseZone and a nominee for Eclipse Ambassador in 2007, his day-to-day role involves neither Eclipse nor Java. What little time he has left over, he spends with his young family and has been known to take them flying if the weather's nice.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT