vogella.de

Follow me on twitter
About Lars Vogel
Flattr this

Eclipse Source Code - Tutorial

Lars Vogel

Version 2.5

28.06.2010

Revision History
Revision 0.1 - 0.623.05.2008Lars Vogel
Created Article
Revision 0.7 - 0.818.02.2009Lars Vogel
bugfixes and enhancements
Revision 0.929.05.2009Lars Vogel
Updated to Eclipse 3.5
Revision 1.0 - 2.401.06.2009Lars Vogel
bugfixes and enhancements
Revision 2.528.06.2010Lars Vogel
Update to Eclipse 3.6 (Helios)

Eclipse Source Code Tutorial

This article explains how to get, navigate and access the Eclipse source code. It assumes that you are already familiar with using the Eclipse IDE and is based on Eclipse 3.5 (Eclipse Galileo).


Table of Contents

1. Eclipse Source Code
2. Import Plugins
3. Plugin Spy
3.1. Plugin Spy for UI parts
3.2. Plugin Spy for menus
3.3. SWT spy
4. Finding plugins
4.1. Open Plugin Artifact
4.2. Plugin Search
4.3. Java Search
5. Finding commands for keybindings
6. Debugging Eclipse
7. Version control
7.1. CVS
7.2. svn
7.3. git
8. Bugzilla and Mylyn
9. Thank you
10. Questions and Discussion
11. Links and Literature
11.1. Source Code
11.2. vogella Resources

1. Eclipse Source Code

Developers are frequently advised to read high-quality code. Eclipse is a powerful, extensible IDE for building general purpose applications. Some of the key player in creating Eclipse are also well known for their software architecture skills. By reading the Eclipse source code you you can learn a lot. It also helps to understand the Eclipse source code to address certain problems.

2. Import Plugins

The following describes how you can import Eclipse plugins from your Eclipse installation to review the code. The Eclipse distribution contains the source code for the core Eclipse projects, e.g. JDT. For other Eclipse projects you usually find a "SDK" bundle on the project update side which contains the source code.

To avoid "pollution" of your existing workspace, switch to a new workspace and select File -> Import. Select "Plug-ins and Fragments".

Make the following settings. Select "Binary projects". In Binary project you can read the source code but you cannot change it. They will also not be compiled therefore this setting will save memory and performance.

Add all plugins you would like to import and press "Finish".

You can you investigate the code of the imported plugins.

3. Plugin Spy

3.1. Plugin Spy for UI parts

The Plugin Spy gives you easily information about the running UI. Press Alt+Shift+F1 to get information about the current running Eclipse plugin / data types / screen. This way you can get immediately access to the plugin which is currently running.

Click on the active class or the contributing plugin to get to the class or the source code of the class.

3.2. Plugin Spy for menus

Press "Alt + Shift + F2" and select a menu to see who is contributing this menu.

Tip

To use the Eclipse Plugin Spy in your Eclipse RCP application include the plugin "org.eclipse.pde.runtime" into your application.

3.3. SWT spy

SWT spy for Eclipse is a tool that prints out information about the widget under the cursor. Currently, this includes style, layout and parent information. See SWT Tools for more information.

4. Finding plugins

4.1. Open Plugin Artifact

Use the shortcut "Ctrl+Shift+A" to search for an extension point. Definition and usage of an extension point use diffrent icons. For example to see which plugin defines the extension point "org.eclipse.menu.ui" enter it in the dialog and select the entry with the blue icon.

4.2. Plugin Search

Plugin Search allow you to search for extension points Select from the menu Search -> Search and then the tab "Plug-in Search". For example the following will search for all declaration (defining an extension) to the extension point "org.eclipse.debug.core.launchConfigurationTypes".

4.3. Java Search

You can also search for Java elements, e.g. methods. In the search menu select the tab "Java Search". For example you can search for method createInitialLayout

The search show all references. You can double-click on a search entry to navigate to the coding.

5. Finding commands for keybindings

Eclipse allows to trace a running Eclipse and to write information to the console. This can be used to identify which command is associated with a certain keybinding.

To use this create a runtime configuration which contains the Eclipse plugins you are interested in, e.g. include "org.eclipse.ui" and press add required plugins.

In the "Run Configuration" switch to the "Tracing" tab and set "Enable Tracing". Select the "org.eclipse.ui" plugin. Flag "debug".

Scroll down and select "trace/keybindings" and "trace/keybindings.verbose".

Make sure you have the -consoleLog flag maintained as an argument.

If you start now the Eclipse IDE then everytime you use a shortcut the calling Eclipse will display a trace which contains the commandId.

In your calling Eclipse you can now use Search (text) to find the handler / action which implements this command.

6. Debugging Eclipse

You can also debug the Eclipse IDE if you want to see how certain things are done. Use for example the Plugin Spy to find the class / plugin which you would like to invest. Put a breakpoint into the coding, for example in the constructor of the class or if the class shows UI elements "createPartControl". Create a Run Configuration which includes all Eclipse IDE plugins and run it.

If you now select Run -> Debug for your runtime configuration you can start debugging the interesting point.

7. Version control

Eclipse projects can use cvs and svn as version control system. Git support is in the making. The majority of the project still uses cvs.

7.1. CVS

To access the Eclipse CVS repositories open the "CVS Repositories" view via Window -> Show View -> Other -> CVS -> "CVS Repositories". Create a new entry in the view by right clicking and selecting "New" -> "Repository Location".

Copy the following string and paste it into the CVS view to create a new repository. You can validate the properties via right-mouse click on the entry -> Properties

				
:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse
			

Now can you browse the structure and check out code. Check out will create a local copy of the selected path into your workspace.

Not all Eclipse projects are in the same path. For example here are some connection strings.

Table 1. Access to some

ProjectDescription
Eclipse Main:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse
Eclipse PDE CVS repository:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse then find the folder pde
Eclipse Equinox CVS repository:pserver:anonymous@dev.eclipse.org:/cvsroot/rt

More information about cvs access can be found Eclipse cvs access

Tip

You can browse the CVS source code in the CVS online repository

Tip

Eclipse projects often provide "Project Set Files" (.psf) which allow to checkout a logical connected set of plugins directly from cvs. Via these files you can easily get a consistent working copy of a set of plugins. See Eclipse PSF Wiki for details and see Eclipse PDE contributor Guide for an example.

7.2. svn

The access of Eclipse code via svn is described in Eclipse svn access . For using svn with Eclipse you need the Eclipse subversive plugin. The installation of this plugin is described in Eclipse Subversive

.

7.3. git

The Eclipse code is currently mainly maintained in cvs but this source code is mirrored into Git repositories. You find the Git url for all projects at http://dev.eclipse.org/git/

Tip

Please note that the checkout via HTTP uses a different URL. You can switch to the HTTP urls on the webpage.

Please see Eclipse EGit Tutorial for details on how to use the EGit plugin for Eclipse or see Git Tutorial to learn how to use Git from the command line. .

8. Bugzilla and Mylyn

All known Eclipse bugs and feature requests are stored in a Bugzilla database Eclipse Bugs

The following explains how you could use Mylyn to work on Bugs and store your content in the bugreport.

Mylyn is a task management system and allows to store the context (source files) in a task. This way you can work on a certain task, switch to another tasks and return to the same tasks and all the files you worked on are re-opened. See the Mylyn Tutorial for installation and basic usage.

Mylyn has build in support for the Eclipse bug database. Just right click in the "Task List" view and select New -> Query

Select "Eclipse" and press Next. Select "Create query" and if you know the bug already "Create query using form".

Lets assume you want to see all bugs for Eclipse 3.6 in PDE - UI then you could maintain the following query.

If you now activate a task you can use Mylyn to work on Eclipse bugs.

9. Thank you

Thank you for practicing with this tutorial.

I maintain this tutorial in my private time. If you like the information please help me by using flattr or donating or by recommending this tutorial to other people.

Flattr this

10. Questions and Discussion

Before posting questions, please see the vogella FAQ . If you have questions or find an error in this article please use the www.vogella.de Google Group . I have created a short list how to create good questions which might also help you. .

11. Links and Literature

11.1. Source Code

Source Code of Examples