Book Image

Mastering Eclipse Plug-in Development

By : Alex Blewitt, Bandlem Limited
Book Image

Mastering Eclipse Plug-in Development

By: Alex Blewitt, Bandlem Limited

Overview of this book

Table of Contents (18 chapters)
Mastering Eclipse Plug-in Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Plugging in to JFace and the Common Navigator Framework
Index

Extending the shell


There are two different ways of extending the shell. One of them is to use the osgi:addcommand function that comes with Gogo. This allows one or more static methods from a class to be defined as functions in the console. Another way is to write custom Java classes and register them as OSGi services.

Adding commands from existing methods

In Java, the Integer class has a static method called toHexString, which converts an integer into its hexadecimal representation. Although this can be invoked via method calls, it is easier if it can be added as a command natively to the console.

The osgi:addcommand command takes a prefix (scope), a class object, and optionally a method to import. Without the last parameter, all public static methods will be added as commands.

Note

When Gogo starts, it runs the gosh_profile script that uses this technique to add the methods of the System class under the system scope.

Getting a class from an existing instance

There are two ways to acquire a class...