O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Eclipse Plug-in Development

Book Description

Build modular applications on Eclipse by defining custom extension points and using OSGi services

In Detail

Mastering Eclipse Plug-in Development shows you how to build an extensible application using custom extension points and dynamic OSGi services in Eclipse. Dynamic design patterns such as whiteboard and extender are covered along with specific techniques to deal with native and legacy code.

This book dives right into the details and teaches you how to define new JFace wizards and extend Eclipse with custom extension points. Then the book moves quickly on to the details of how to define new commands for the Eclipse console and how to include native code in a plug-in. You will engage with modular application design patterns and Thread Context ClassLoaders before getting the details on how to create as well as manage P2 sites and write help documentation for an Eclipse plug-in.

What You Will Learn

  • Create a custom extension point to allow other plug-ins to contribute
  • Employ Declarative Services and Blueprint for dynamic OSGi contributions
  • Extend the Common Navigator Framework to provide nested content
  • Build commands to extend the built-in Gogo shell
  • Use fragments to contribute native code to plug-ins
  • Fix code using the service loader and wrap non-OSGi-friendly JARs
  • Discover how to build modular applications with decoupled design patterns

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Mastering Eclipse Plug-in Development
    1. Table of Contents
    2. Mastering Eclipse Plug-in Development
    3. Credits
    4. About the Author
    5. Acknowledgments
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    9. 1. Plugging in to JFace and the Common Navigator Framework
      1. JFace wizards
        1. Creating a feeds wizard
          1. Creating the classes
          2. Adding pages to the wizard
          3. Adding content to the page
          4. Testing the wizard
          5. Adding titles and images
          6. Adding help
          7. Finishing the wizard
          8. Adding the FeedWizard to the newWizards extension point
          9. Adding a progress monitor
        2. Showing a preview
      2. Common navigator
        1. Creating a content and label provider
        2. Integrating into Common Navigator
        3. Binding content navigators to views
        4. Adding commands to the common navigator
        5. Reacting to updates
        6. Optimizing the viewer updates
        7. Linking selection changes
          1. Opening an editor
          2. Finding the line
          3. Setting the selection
      3. Summary
    10. 2. Creating Custom Extension Points
      1. Extensions and extension points
        1. Creating an extension point
          1. Creating an IFeedParser interface
          2. Creating a MockFeedParser class
          3. Creating the extension point schema
          4. Using the extension point
            1. Caching extension points
          5. Integrating the extension with the content and label providers
          6. Showing a feed in the browser
          7. Implementing a real feed parser
          8. Adding support for Atom
          9. Making the parser namespace aware
          10. Priority and ordering
          11. Executable extensions and data
          12. Executable extension factories
        2. Using the extension registry outside of OSGi
          1. Using the extension registry cache
          2. Loading all extensions from the classpath
      2. Summary
    11. 3. Using OSGi Services to Dynamically Wire Applications
      1. Overview of services
      2. Registering a service programmatically
        1. Creating an activator
        2. Registering the service
        3. Priority of services
        4. Using the services
        5. Lazy activation of bundles
        6. Comparison of services and extension points
      3. Registering a service declaratively
        1. Declarative Services
          1. Properties and Declarative Services
          2. Service references in Declarative Services
          3. Multiple components and debugging Declarative Services
        2. Dynamic service annotations
          1. Processing annotations at Maven build time
        3. Blueprint
          1. Installing Gemini Blueprint
          2. Installing Aries Blueprint
          3. Using the Blueprint service
          4. Passing properties in Blueprint
          5. Bean references and properties
          6. Comparison of Blueprint and DS
      4. Dynamic services
        1. Resolving services each time
        2. Using a ServiceTracker
          1. Sorting services
          2. Filtering services
          3. Obtaining a BundleContext without using an activator
          4. A note on ServiceReference
        3. Dependent services
      5. Dynamic Service Configuration
        1. Installing Felix FileInstall
        2. Installing Config Admin
        3. Configuring Declarative Services
        4. Config Admin outside of DS
        5. Services and ManagedService
          1. Creating an EmptyFeedParser class
          2. Configuring the EmptyFeedParser
        6. Service factories
          1. Creating the EchoServer class
          2. Creating an EchoServiceFactory class
          3. Configuring EchoService
      6. Summary
    12. 4. Using the Gogo Shell and Commands
      1. Consoles in Equinox
        1. Host OSGi Console
        2. Running commands
        3. Variables and pipes
        4. Functions and scripts
        5. Literals and objects
        6. Calling and chaining methods
        7. Control flow
        8. Running Equinox from the command line
        9. Understanding osgi.bundles and config.ini
        10. Connecting remotely
        11. Securing the connection
          1. Creating a JAAS configuration
          2. Understanding the configuration options
          3. Launching the SSH daemon
      2. Extending the shell
        1. Adding commands from existing methods
          1. Getting a class from an existing instance
          2. Loading a class via a ClassLoader
        2. Writing commands in Java
          1. Creating the project
          2. Using Declarative Services to register the command
          3. Test the command
        3. Processing objects with console commands
          1. Adding the print bundles command
          2. Returning a list of bundles
          3. Processing a list with each
        4. Calling functions from commands
        5. Looping and iteration
      3. Summary
    13. 5. Native Code and Fragment Bundles
      1. Native code and Eclipse
        1. Creating a simple native library
          1. Mac OS X
          2. Linux
          3. Windows
        2. Loading the native library
        3. Library dependencies
        4. Native code patterns
      2. Native libraries in OSGi bundles
        1. Optional resolution of native code
        2. Multiple libraries for the same platform
        3. Multiple libraries with the same name
        4. Additional filters and constraints
      3. Reloading native libraries
      4. OSGi fragment bundles
        1. Adding native code with fragments
        2. Adding classes to a bundle
        3. Patching bundles with fragments
        4. Adding imports and exports with fragments
        5. Extension bundles
      5. Summary
    14. 6. Understanding ClassLoaders
      1. Overview of ClassLoaders
        1. ClassLoaders and inheritance
        2. ClassLoaders in web application servers
        3. ClassLoaders and garbage collection
        4. OSGi and ClassLoaders
        5. OSGi services and ClassLoaders
      2. ThreadContextClassLoaders
      3. Java ServiceLoader
        1. Problems with ServiceLoader, OSGi, and Eclipse
        2. Creating a service producer
        3. Downloading the required bundles
        4. Running the producer
        5. Creating a service consumer
        6. Running the consumer
      4. OSGi upgrade strategies
        1. Embedding the library directly
        2. Wrapping the library with bnd
        3. Upgrading the library to use services
        4. Dealing with class resolution issues
      5. Summary
    15. 7. Designing Modular Applications
      1. Semantic versioning
      2. Public APIs and version ranges
      3. Baselining and automatic versioning
        1. Eclipse API baselines
        2. Bnd baseline
        3. Bndtools
        4. Maven baselining
      4. Design patterns
        1. The whiteboard pattern
        2. The extender pattern
      5. Best practices
        1. Separate API and implementation
        2. Decouple packages
        3. Decouple services
        4. Prefer Import-Package to Require-Bundle
        5. Version packages and bundles
        6. Avoid split packages
        7. Import and export packages
        8. Avoid start ordering requirements
        9. Avoid long Activator start methods
        10. Use configuration admin for configuration
        11. Share services, not implementation
        12. Loosely coupled and highly cohesive
        13. Compile with the lowest level execution environment
        14. Avoid Class.forName
        15. Avoid DynamicImport-Package
        16. Avoid BundleActivator
        17. Consider thread safety
        18. Test in different frameworks
      6. Summary
    16. 8. Event-driven Applications with EventAdmin
      1. Understanding the OSGi EventAdmin service
        1. Sending e-mails
        2. Creating an event
        3. Posting an event
        4. Receiving an event
        5. Filtering events
        6. Threading and ordering of event delivery
        7. Comparison between EventAdmin and services
        8. Framework events
      2. Events and E4
        1. Sending events with E4
        2. Receiving events with E4
        3. Subscribing E4 EventHandlers directly
        4. Comparison between EventAdmin and IEventBroker
      3. Designing an event-based application
        1. Componentizing the application
        2. Identifying the channels
        3. Identifying the properties
        4. Mapping the channels to topics
        5. Simulating events
        6. Versioning and loose typing
        7. Event object contents
        8. Comparison with JMS
      4. Summary
    17. 9. Deploying and Updating with P2
      1. Eclipse P2
        1. Provisioning with the P2 director
        2. Installing content into existing applications
      2. Running P2 applications
        1. Launching the JVM
        2. Starting Equinox
      3. P2 repositories
        1. P2 artifacts and contents files
        2. Binary and packed files
        3. Creating P2 mirrors
        4. Generating P2 metadata
        5. Categorizing update sites
        6. Composite update sites
        7. The classic update manager
      4. Touchpoints
        1. Categorizing features with P2
        2. Adding update sites automatically
        3. Registering touchpoint actions
        4. Adding JVM or program arguments
        5. Custom touchpoints
      5. Summary
    18. 10. User Assistance in Eclipse
      1. Help pages in Eclipse
        1. Adding help pages
        2. Nested table of contents
        3. Anchors and links
        4. Linking to anchors in other plug-ins
        5. Conditional enablement
        6. Context-sensitive help
        7. Active help
        8. DocBook and Eclipse help
        9. Mylyn WikiText and Eclipse help
      2. Help Server and RCP
        1. Help and Eclipse 3.x
        2. Help and Eclipse 4.x
        3. Running an InfoCenter standalone
      3. Cheat sheets
        1. Creating a cheat sheet
        2. Adding commands
        3. Optional steps
        4. Responding to choice
        5. Composite cheat sheets
      4. Summary
    19. Index