Plug-in Development 101: The Fundamentals

  

Testing and Debugging

The next step on our plug-in adventure involves testing and debugging. To test our plug-in, Eclipse and PDE have a notion of self-hosting. Self-hosting simply means that we're able to launch a new Eclipse with plug-ins we're currently working on in our workspace without actually having to export or deploy any plug-ins. To launch a new Eclipse, all you need to do is start another runtime workbench via the Overview page's Testing section (see the Launch an Eclipse application link within the Overview page). After a few seconds, you'll notice a new workbench pop-up with your plug-in's sample action visible in the toolbar.

Figure 10: Self-hosting in EclipseFigure 10: Self-hosting in Eclipse

To launch your self-hosted plug-in in debug mode, simply click the Launch an Eclipse application in debug mode link in the Testing section of the Overview page. To actually debug your plug-in, you need to set relevant breakpoints. If you're new to debugging in Eclipse, I recommend checking out the developerWorks article "Debugging with the Eclipse Platform" to help get you started (see Resources).

To set more fine-grained options about launching or debugging your plug-in, go to the Launch Configurations dialog, which can be invoked using the Run > Run Configurations... menu option. The relevant launch configuration type for your plug-in is called an "Eclipse Application" since what we're launching is indeed an Eclipse application (see Figure 11). Within the launch configuration, you can set things like arguments and have control over which JRE is used to launch your application.

Figure 11: Launch Configurations DialogFigure 11: Launch Configurations Dialog

Externalizing Strings

A common step in plug-in development is internationalization. Once you get to a point where your plug-in is useful and will be tested by multiple parties, you often get a request to make sure your plug-in is capable of running in a different language. Thankfully, the amount of work needed to externalize plug-in related strings is minimal. In PDE, there is a wizard that can be invoked via right-clicking on the Overview page of your plug-in and selecting the Externalize Strings... menu item. After the selection, a wizard will be presented that displays all the strings that are relevant to externalization.

Figure 12: The Externalize Strings WizardFigure 12: The Externalize Strings Wizard

In reality, this simply generates a plugin.properties file (that contains externalized strings) for your plug-in and adds the Bundle-Localization header to your MANIFEST.MF file. The Bundle-Localization header simply lets you define a name and optional location for your externalized strings. In this case, the Bundle-Localization is "plugin," which signifies that strings for various locales will be in files like plugin.properties (see Figure 13) plugin_fr.properties or plugin_de.properties. Anything after the underscore in the file name represents the locale.

Figure 13: The plugin.properties fileFigure 13: The plugin.properties file

That's it! That's all that's involved to get started in internationalizing our plug-in. For more information, I recommend reading these outdated yet still relevant articles from the Eclipse corner: "How to Internationalize your Eclipse Plug-In" and "How to Test Your Internationalized Eclipse Plug-In" (see Resources).

Article Type: 
How-to
0
Average: 2.4 (9 votes)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)