eclipse_building_blocks

45
Rahul Shukla

Upload: rahul-shukla

Post on 10-Aug-2015

18 views

Category:

Documents


0 download

TRANSCRIPT

Rahul Shukla

Understand Eclipse architecture and building blocks

Power of OSGI/Equinox

RCP architecture

Investigating RCP application

SWT

Bonus: We Will try to adopt good coding and design practice .

Eclipse is a Java IDE Language-aware editors,views…. Refactoring Support…. Integrated debugging Team Development Support Provides many features to ease Java

programming (and others, e.g. C/C++) ◦ Editor ◦ Debugger ◦ Source Control

◦ …

Eclipse is more than a Java IDE its an IDE frame

work for ex:

Eclipse+ JDT = Java IDE

Eclipse+CDT = C/C++ IDE

Eclipse+PDT=PHP IDE

Eclipse is more than an IDE framework it’s a Tools

framework

Plug-ins make Eclipse whatever you need it to be

For Example : BIRT , EMF , ……

Eclipse is more than a Tool Framework its an

application framework

Remove the IDE elements

General-purpose application framework

A Platform for Rich Clients

Is a very powerful and extensible IDE and Framework

Is Open Source

Has a community

Is supported by most of the industry

Has a large number of developers (>150)

Has significant financial backing

Are many 3rd-party Plug-ins, both free and commercial

Is continuing to expand and improve rapidly

Is free

Is a very powerful and extensible IDE and Framework

Is Open Source

Has a community

Is supported by most of the industry

Has a large number of developers (>150)

Has significant financial backing

Are many 3rd-party Plug-ins, both free and commercial

Is continuing to expand and improve rapidly

Is free

Menubars

Full drop down menus plus quick access to common

functions

Editor Pane

This is where we edit our source code

Perspective Switcher

We can switch between various perspectives here

Outline Pane

This contains a hierarchical view of a

source file

Package Explorer Pane

This is where our projects/files are listed

Miscellaneous Pane

Various components can appear in this pane – typically this contains a

console and a list of compiler problems

Task List Pane

This contains a list of “tasks” to

complete

Eclipse is a platform with a small runtime kernel

Everybody can contribute plug-ins

Creating opportunities for further extension makes it possible for the tool smith to benefit from the work of others

It has to be easy to install and manage plug-ins

The Eclipse plug-in architecture

Plug-in activation

The Eclipse platform

Plug-in set of contribution Smallest unit Of eclipse functionality

Example : SVN plugin

Extension Point – named entity for collection contributions

Extension – a contribution

Eclipse Plug-in

- Contributes to 1 or more extension points.

- Optionally declares new extension points

- Depends on a set of other plug-ins

- Optionally contains Java code libraries and other files

- May export Java-based APIs for downstream plug-ins

- Lives in its own plug-in subdirectory

Plug-in manifest - Manifest declares contribution

- It tells about the dependency

- Exposed feature

Plugin.xml ◦ in which we define extension

◦ Command , handler etc.

Contribution code is only loaded when it is needed

Eclipse Platform is the common base

Consist of several key components

SWT- generic low level graphics and widgets toolkit

Jface- UI frame work on the top of SWT for commonn UI Task

Workbench – UI personality of eclipse platform

A portable widget set ◦ OS – independent API

◦ Uses native widgets where available

◦ Emulates widgets where unavailable

◦ Simple , small , fasr

Supported platforms ◦ Win 32 , Win CE , Linux , Mac , Solaris and lots …

UI framework built on top of SWT ◦ Viewers

Model aware adapters for SWT widgets

Tree , tables lists , styled text ,……

◦ Dialog , Preference and Wizard

◦ Action

Location independent user commands

Contribute action to menu , tool bar , or status bar

Defines common user interface paradigm ◦ Workbech

◦ Views

◦ Editors

◦ Prespective

◦ Preference Pages

◦ Wizards

OSGI / Equinox

OSGi is a hot topic these days; all the major Java application server vendors have adopted OSGi as their base runtime, Eclipse has been

using OSGi as the basis of its modularity story and runtime for at least the past seven years,

and countless others have been using it in embedded and “under the covers” scenarios.

All with good reason.

OSGi defines a Java framework for building and executing modular software. Leverages Java’s class loading techology.

OSGi once stood for “Open Services Gateway initiative”, but now it’s just “OSGi”.

The OSGi Service Platform Core Specification describes a software deployment and configuration management architecture.

In OSGi parlance a software module is called a bundle. Application > Bundle > Package > Type > Method

OSGi enables the implementation of loosely coupled software modules.

OSGi enables the implementation of highly cohesive software modules.

OSGi enables dynamic installation, update and removal of software modules; no VM restart required.

But using the OSGi framework is not all that it takes…

Coupling is an outward view of the number of relationships between a bundle and other bundles in the system.

Bundles should be loosely coupled. A loosely coupled bundle is more likely to be

used, reused and tested. “Don’t make me inflate an entire universe!” Loosely coupled bundles are simpler to

understand, test, debug change, etc.

Cohesion is an inward view of the relevance of the elements of a bundle to one other.

In a highly cohesive bundle all parts are directly related to, and focused on, addressing a defined, narrowly focused topic.

Sadly, low cohesive bundles are rife.

Highly cohesive bundles require careful design to keep them small.

low cohesion is bad

DEMO Demo Time!

Follow the steps below to create a Hello World bundle using OSGi and Eclipse.

1. In Eclipse, click on File --> New --> Project. A New Project dialog will open.

2. In the New Project dialog, select Plug-in Project and click Next. The Plug-in Project dialog will open.

3. In the Plug-in Project dialog, enter the following values:

1. Project Name: com.osgi.sample.helloworld

2. Target Platform: OSGi framework --> Standard

3. Use default values for the remaining input and click Next. The Plug-in Context dialog will open.

4. Select the default values for the Plug-in Context dialog and click Next.

5. In the Templates dialog you'll find only one entry in Available Templates: Hello OSGi Bundle. Select it and click Finish.

As I mentioned earlier, the Eclipse IDE has an embedded Equinox OSGi container that you can use to execute or debug OSGi bundles. Follow these steps to execute the Hello World bundle:

1. Click on Run --> Run configuration…

2. Eclipse will open the dialog called "Create, manage and run configuration." In that dialog, double-click the Equinox OSGi Framework button and it will open a runtime configuration dialog box.

3. In that dialog, change the value of the Name field to Hello World Bundle.

4. You will notice that in the Plug-ins section under the Workspace plug-in there is an entry for the com.osgi.sample.helloworld plugin, which is checked. Under Target Platform, make sure that the checkbox next to the org.eclipse.osgi plugin is also checked.

Activator.java

If your bundle needs to be notified at the time of bundle startup or shutdown then you should create a class implementing the BundleActivator interface. Follow these rules when creating the class: ◦ The BundleActivator class must have a public

constructor that takes no parameters. The OSGi framework can create a BundleActivator object by calling Class.newInstance().

◦ The container will call the start() method of your Activator class to start the bundle.

◦ The bundle can take this opportunity to perform resource initialization such as getting a database connection for future use.

◦ The start() method takes one argument, the BundleContext object. This object allows bundles to interact with the framework by providing access to OSGi-container-related information. If an exception is thrown for a particular bundle the container will mark that bundle as stopped and will not put it into service.

◦ The container will call the stop() method of your Activator class to report that it is shutting down a bundle. You can use this opportunity to perform cleanup tasks such as releasing the database connection.

◦ Once your Activator class is ready you should relay its fully qualified name to the container using your MANIFEST.MF file.

The MANIFEST.MF file acts as deployment descriptor for your bundle. The format for this file is the same as that of a normal JAR file, so it consists of a set of headers with values. The OSGi specification defines a set of headers that you can use to describe your bundle to the OSGi container.

Bundle-SymbolicName

The Bundle-ManifestVersion header tells the OSGi container that this bundle follows the rules of the OSGi specification. A value of 2 means that the bundle is compliant with OSGi specification Release 4; a value of 1 means that it is compliant with Release 3 or earlier.

Bundle-Name The Bundle-Name header defines a short, human-readable name for the bundle. Bundle-SymbolicName The Bundle-SymbolicName header specifies a unique, non-localizable name for the bundle. This is the name you will use while referring a given bundle from other bundles.

Bundle-Version

The Bundle-Version header specifies the version of the bundle.

Bundle-Activator

The Bundle-Activator header specifies the name of the optional listener class to be notified of bundle start and stop events. In Listing 2 the value of this header is com.osgi.sample.helloworld.Activator.

Bundle-Vendor

The Bundle-Vendor header contains a human-readable description of the bundle vendor.

Bundle-Localization The Bundle-Localization header contains the location in the bundle where localization files can be found. The Hello World bundle doesn't contain any locale-specific files, but the eclipse IDE still generates this header. Import-Package

The Import-Package header defines imported packages for the bundle. You'll learn more about this when I discuss dependency management, later in the article.

The OSGi console is a command-line interface to the OSGi container. It allows you to do things like start, stop, install bundles, and update or delete bundles. In your Eclipse IDE, click the console view to give focus to that view, then click Enter and you will get an OSGi prompt

ss displays a list of installed bundles with the status of each bundle. It will display the bundle ID, short name, and status of the bundle.

start <bundleid> starts a bundle.

stop <bundleid> stops a bundle.

update <bundleid> updates a bundle with a new JAR file.

install <bundleURL> installs a new bundle into the OSGi container.

uninstall <bundleid> uninstalls already installed bundles from the OSGi container.

Questions ?