A little bit more...

Friday, April 20, 2007

The Architecture of Eclipse

Introduction

If explaining every bit in detail, you must be missed in the details and can’t see the architecture from a global perspective, nor will you be benifited in your practise. So I’m trying to explain the architecture based on senarios such as what will happen when you startup elipse, what will happen when an action that you contribute is fired, etc. I hope in such a way it will do help in your practice with Eclipse.

And, it is worthy to point out this is not an overview on the architecture of Eclipse for which there are tons of articles written about.

Startup of Eclipse

What will happen when the file eclipse.exe is executed.

Startup of Eclilpse begins by running a system specific executable binary file called eclilpse.exe which is located under the root directory of the eclipse installation. This executable will then lauches the org.eclipse.core.launcher.Main, located in startup.jar. After that the entry point of Main, that is static main method of Main is invoked. Below we will illustrate the calling path of important methods to demonstrate the post startup process of Eclipse.

Main.run( args )

Main.basicRun( args )

Main.getBootPath( .. ) : locate boot plugin ( in “plugin” directory of your eclispe installation ), within which Main.getDevPath( .. ) is called, within which Main.addBaseJars( .. ) is called, within which Main.readFrameworkExtensions( .. ) is called; invokeFramework( .. ): invoke EclipseStarter

the class EclipseStarter ( indicated by STARTER field ) is loaded by a URLClassLoader defined as an inner class with Main; EclipseStarter.run( .. ) is invoked in a reflective way

EclipseStarter.startup( .. ) : starts the platform and sets it up to run a single application

OSGi.new( .. ) : an instance of OSGi service platform is created

OSGi.launch() : start the OSGi framework

Framework.launch()

SystemBundle.resume() : SystemBundle subclasses Bundle to provide a system Bundle so that the framework can be represented as bundle

StartLevelManager.launch( .. ) : StartLevelManager is the startLevel service implementation for the OSGi spec

StartLevelManager.doSetStartLevel( .. )

StartLevelManager.incFWSL( .. )

StartLevelManager.getInstalledBundles( .. ) : Build an array of all installed bundles to be launch; StartLevelManager.loadInstalledBundles( .. ) : Load all bundles; StartLevelManager.resumeBundles( .. )

Framework.systemBundle.context.start() : Framework. :SystemBundle. :BundleContextImpl.start(), start the system bundle, BundleContextImpl.start() calls bundle’s BundleActivator.start()

BundleHost.loadBundleActivator() : Load and instantiate bundle’s BundleActivator class

BundleContextImpl.startActivator( .. ) : calls the start method of a BundleActivator which you have to extend when you create a plug-in.

Eclispe can also be started from with a client ( which is not part of the current Eclipse platform ), say, written in java, by using the EclispeStarter class located in org.eclipse.core.runtime.adaptor.

Action delegate and proxy

What will happen when your contributed action is fired.

Adding an action in a programatic way is different from adding it via contribution to an action extension point. For the former case, you have to implement some special API to create an action directly, while for the latter case you will have to only implement IActionDelegate+ which enables the lazy loading of the action.

At startup the registry is read and a PluginAction( extends Action, implements *Selection*Listener, IPluginContribution ) is created for each action extension point. The instance of PluginAction is an action proxy which directly represent an action in run time but doesn’t do the job a real action does. When the action that the action proxy represents is fired, the real action( the action delegate ) is created by the action proxy. After that point the action proxy delegate everything that is requested to the real action, the action delegate. This mechanism makes it possible to load the action extension lazily which is called lazy loading.

Following depicts the flow of action proxy and delegate:

read from registry ( IExtensionRegistry ) -> a PluginAction created for each action extension point ( while the action is fired -> an action delegate created -> action is delegated )

Contribute an Extension

to be continued…

Extension Pattern

Adapter pattern is extensively used in Eclipse to contribute extensions ( different from extensions to extension point ) to type or instance. This mechanism is enabled mainly by implementing IAdaptable and IAdapterFactory. For the detailed explanation with examples, please refer to Chapter 31 of the book Contributing to Eclipse: Principles, Patterns, and Plugins (Paperback).

Resources

  1. The Architecture of Eclipse. This article refers to and linked to a lot of valuable resources.
  2. A First Look at Eclipse Plug-In Programming. Contains a very detailed comparsion between Sun’s awt and swing and Eclipse’s SWT and JFace and anatomy of the process of Eclispe startup.
  3. About the OSGi Service Platform - Technical Whitepaper Revision 4.0
  4. org.eclipse.osgi_3.2.2.R32X_v20070118.jar : org.eclipse.core.runtime.adaptor.EclipseStarter.class source code, org.eclipse.osgi.framework.internal.core.AbstractBundle.class source code, org.eclipse.osgi.framework.internal.core.BundleContextImpl.class source code, org.eclipse.osgi.framework.internal.core.BundleHost.class source code, org.eclipse.osgi.framework.internal.core.Framework.class source code, org.eclipse.osgi.framework.internal.core.OSGi.class source code, org.eclipse.osgi.framework.internal.core.StartLevelManager.class source code, org.eclipse.osgi.framework.internal.core.SystemBundle.class source code, org.osgi.framework.BundleActivator.class source code.
  5. org.eclipse.ui.workbench_3.2.2.M20070119-0800.jar source code.
  6. eclipse 3.2.2 startup.jar : org.eclilpse.core.launcher.Main.class source code.
  7. Contributing to Eclipse: Principles, Patterns, and Plugins (Paperback)
  8. Eclipse Help

to be continued…

Technorati : , , , , , ,
Del.icio.us : , , , , , ,

No comments:

About Me

My photo
I'm finishing my master degree in Software Engineering, Computer Science. I believe and have been following what Forrest Gump's Mam said: you have to do the best with what god gave you.