24
Extending Eclipse Kai-Uwe M Kai-Uwe M ä ä tzel tzel IBM OTI Labs Zurich IBM OTI Labs Zurich [email protected] [email protected] www.eclipse.org

Extending Eclipse

  • Upload
    zuri

  • View
    34

  • Download
    1

Embed Size (px)

DESCRIPTION

www.eclipse.org. Extending Eclipse. Kai-Uwe M ä tzel IBM OTI Labs Zurich [email protected]. Overview. Eclipse is more than a Java IDE it has an open, extensible architecture built out of layers of plug-ins everybody can contribute plug-ins - PowerPoint PPT Presentation

Citation preview

Page 1: Extending Eclipse

Extending Eclipse

Kai-Uwe MKai-Uwe MäätzeltzelIBM OTI Labs ZurichIBM OTI Labs Zurich

[email protected][email protected]

www.eclipse.org

Page 2: Extending Eclipse

Overview

■ Eclipse is more than a Java IDEEclipse is more than a Java IDE– it has an open, it has an open, extensibleextensible architecture architecture – built out of layers of plug-insbuilt out of layers of plug-ins everybody can contribute plug-inseverybody can contribute plug-ins ““in many ways Eclipse is the Emacs for the 21st in many ways Eclipse is the Emacs for the 21st

century” – Martin Fowlercentury” – Martin Fowler

■ Social implications:Social implications:– every programmer can be a tool smithevery programmer can be a tool smith– creating opportunities for further extension makes it creating opportunities for further extension makes it

possible for the tool smith to benefit from the work of possible for the tool smith to benefit from the work of othersothers

it has to be easy to install and manage plug-insit has to be easy to install and manage plug-ins

Page 3: Extending Eclipse

Platform vs. Extensible IDE

PlatformPlatform Extensible IDEExtensible IDE

Run-time

Plug-ins IDE

Plug-ins

Eclipse is a platform with a small runtime kernel

Page 4: Extending Eclipse

Eclipse Plug-in Architecture

■ Plug-in - Plug-in - smallest unit of Eclipse functionsmallest unit of Eclipse function– Big example: HTML editorBig example: HTML editor– Small example: Action to create zip filesSmall example: Action to create zip files

■ Extension point Extension point - named entity for - named entity for collecting “contributions”collecting “contributions”– Example: extension point for workbench Example: extension point for workbench

preference UIpreference UI

■ Extension - Extension - a contributiona contribution– Example: specific HTML editor preferencesExample: specific HTML editor preferences

Plug-in

ExtensionPoint

Extensions

ExtensionInterface

Page 5: Extending Eclipse

Eclipse Plug-in Architecture

■ Each plug-inEach plug-in– Contributes to 1 or more extension pointsContributes to 1 or more extension points– Optionally declares new extension pointsOptionally declares new extension points– Depends on a set of other plug-insDepends on a set of other plug-ins– Contains Java code libraries and other filesContains Java code libraries and other files– May export Java-based APIs for downstream plug-insMay export Java-based APIs for downstream plug-ins– Lives in its own plug-in subdirectoryLives in its own plug-in subdirectory

■ Details spelled out in the Details spelled out in the plug-in manifestplug-in manifest– Manifest declares contributionsManifest declares contributions– Code implements contributions and provides APICode implements contributions and provides API– plugin.xml file in root of plug-in subdirectoryplugin.xml file in root of plug-in subdirectory

Page 6: Extending Eclipse

Tip of the Iceberg

Implementationof plug-in contributions

Declarative definitionof plug-in contributions

startup time: O(#used plug-ins), not O(# installed plug-ins)

Page 7: Extending Eclipse

Plug-in Manifest

<plugin id = “com.example.tool“ version = “2.1.0” name = “Example Plug-in Tool" class = "com.example.tool.ToolPlugin"> <requires> <import plugin = "org.eclipse.core.resources“ version=“2.0.0”/> <import plugin = "org.eclipse.ui“ version = “2.0.1”/> </requires> <runtime> <library name = “tool.jar"/> </runtime> <extension point = "org.eclipse.ui.preferencepages"> <page id = "com.example.tool.preferences" icon = "icons/knob.gif" title = “Tool Knobs" class = "com.example.tool.ToolPreferenceWizard“/> </extension> <extension-point name = “Frob Providers“ id = "com.example.tool.frobProvider"/></plugin>

Declare contributionthis plug-in makes

Declare new extension point open to contributions from other plug-ins

Location of plug-in’s code

Other plug-ins needed

Plug-in identification

plugin.xml

Page 8: Extending Eclipse

Configurers

Extenders

Extenders “Plus”

Publishers

Users

Der Plan

Page 9: Extending Eclipse

Extender: Contribute an Icon View

■ Goal: a plug-in to view the standard Eclipse imagesGoal: a plug-in to view the standard Eclipse images■ Steps:Steps:

– read extension point specificationsread extension point specifications– use Plug-in Development Tools to create a plug-in use Plug-in Development Tools to create a plug-in

project and to declare the extensionproject and to declare the extension– use the Java Development Tools to implement the use the Java Development Tools to implement the

extensionextension

Page 10: Extending Eclipse

Extender: Plug-in Development

■ Extenders use PDE to implement plug-insExtenders use PDE to implement plug-ins

■ PDE = Plug-in development environmentPDE = Plug-in development environment

■ Built on top of the Eclipse Platform and JDTBuilt on top of the Eclipse Platform and JDT

■ Specialized PDE editor for plug-in manifest filesSpecialized PDE editor for plug-in manifest files

■ Templates for new plug-insTemplates for new plug-ins

■ PDE runs and debugs another Eclipse workbenchPDE runs and debugs another Eclipse workbench

Page 11: Extending Eclipse

Extender: Development Workspace

■ Plug-ins correspond to Java projectsPlug-ins correspond to Java projects

■ Source projects “projects you are working on”Source projects “projects you are working on”– consist of plug-in manifest, sourceconsist of plug-in manifest, source– source can be changed and compiledsource can be changed and compiled

■ Binary projects “projects you are browsing only”Binary projects “projects you are browsing only”– consist of plug-in manifest, plug-in jar, source jarconsist of plug-in manifest, plug-in jar, source jar– source can be inspectedsource can be inspected– must not be compiledmust not be compiled– small foot printsmall foot print

■ Project’s build class path is derived from the required Project’s build class path is derived from the required plug-insplug-ins

Page 12: Extending Eclipse

Extender: Deploying a Plug-in

■ Development time:Development time:– the plug-in code isn’t packaged as a JAR the plug-in code isn’t packaged as a JAR – executed in a special development mode by PDEexecuted in a special development mode by PDE faster turn-aroundfaster turn-around

■ Deploy:Deploy:– package plug-in code as JARspackage plug-in code as JARs deployed plug-in can be installed into a run-time deployed plug-in can be installed into a run-time

EclipseEclipse■ How to:How to:

– describe deployable contents in describe deployable contents in build.propertiesbuild.properties– generate Ant script with PDEgenerate Ant script with PDE– run Antrun Ant

source.imageview.jar = src/build.properties

Page 13: Extending Eclipse

Extender Principles

■ Learn from existing extension point Learn from existing extension point implementationsimplementations

■ Relevance rule: only contribute when you can Relevance rule: only contribute when you can successfully operatesuccessfully operate– you are not the only contributor…you are not the only contributor…

■ Declare the package prefixes your plug-in contains Declare the package prefixes your plug-in contains to speed-up class loadingto speed-up class loading

<runtime> <library name="runtime.jar"> <packages prefixes="org.eclipse.core"/> </library></runtime>

Page 14: Extending Eclipse

Extender Plus: Open up your Plug-in

■ Define an extension point in the manifest fileDefine an extension point in the manifest file

– define an extension point schema (optional) define an extension point schema (optional)

■ Define an extension interfaceDefine an extension interface

■ Load the defined extensions on demand from the Load the defined extensions on demand from the plug-in registryplug-in registry lazy creationlazy creation

<extension-point id=“imageFilters" name=“Image Filters"/>

public interface IImageFilter { Image filter(Image image);}

Page 15: Extending Eclipse

Extender Plus: Extension Interface

■ Plug-in APlug-in A– Declares extension point P (Declares extension point P (org.demo.imageFilterorg.demo.imageFilter))– Declares interface I (Declares interface I (org.demo.views.IImageFilterorg.demo.views.IImageFilter) for P) for P

■ Plug-in BPlug-in B– Implements interface I with its own class C (Implements interface I with its own class C (GreyFilterGreyFilter))– Contributes class C to extension point PContributes class C to extension point P

■ Plug-in A instantiates C and calls its I methodsPlug-in A instantiates C and calls its I methods

■ Typical arrangementTypical arrangementplug-in A plug-in B

class Cinterface I

extensionpoint P extension

contributes

creates, calls

implements

Page 16: Extending Eclipse

Consuming an Extension Point

■ Define the extensionDefine the extension

■ Implement the extension interfaceImplement the extension interface

<extension point="org.demo.imageFilters"> <imageFilter class=“myplugin.GreyFilter"/></extension>

public class GreyFilter implements IImageFilter { public Image filter(Image image) {…}}

Demo

Page 17: Extending Eclipse

Extension Points Principles

■ Whenever possible - let others contribute to your Whenever possible - let others contribute to your contributionscontributions

■ Contributions are additions to EclipseContributions are additions to Eclipse– ““add, don’t replace”add, don’t replace”

■ Lazy loading rule: load extensions only when they Lazy loading rule: load extensions only when they are about to be calledare about to be called

■ Contributions do notContributions do not– override existing behavioroverride existing behavior– remove or replace existing componentremove or replace existing component– harm existing or future contributionsharm existing or future contributions

Page 18: Extending Eclipse

Extension Points Principles

■ Extension point providers must…Extension point providers must…– cope with multiple contributionscope with multiple contributions

• support user arbitration when there are conflicting support user arbitration when there are conflicting contributionscontributions

• allow for additive behaviorallow for additive behavior– protect their code when creating extensionsprotect their code when creating extensions

■ Make your published API explicitMake your published API explicit– internal classes should be in internal packagesinternal classes should be in internal packages

Page 19: Extending Eclipse

Publisher: Install/Update

■ FeaturesFeatures group plug-ins into installable chunks group plug-ins into installable chunks– Feature manifest fileFeature manifest file

■ Plug-ins and features bear version identifiersPlug-ins and features bear version identifiers– major . minor . servicemajor . minor . service– Multiple versions may co-exist on diskMultiple versions may co-exist on disk

■ Features downloadable from web siteFeatures downloadable from web site– Using Eclipse Platform update managerUsing Eclipse Platform update manager– Obtain and install new plug-insObtain and install new plug-ins– Obtain and install updates to existing plug-insObtain and install updates to existing plug-ins

Page 20: Extending Eclipse

Publisher: Create a Feature■ Feature describesFeature describes

– Contained plug-ins and their versionsContained plug-ins and their versions– Pre-requisite plug-ins for the featurePre-requisite plug-ins for the feature

<feature id="org.demo.imageviewfeature“ version="1.0.0"> <requires> <import plugin="org.eclipse.core.resources"/> <import plugin="org.eclipse.ui"/> </requires> <plugin id="org.demo.imageview" download-size="0" install-size="0" version="1.0.0"/></feature>

Page 21: Extending Eclipse

Publisher: Create an Update Site

■ An update site An update site – is any URL addressable locationis any URL addressable location– contains zips for the feature and plug-ins contains zips for the feature and plug-ins – version information encoded in the zip nameversion information encoded in the zip name– contents described by a site.xml filecontents described by a site.xml file

<site> <feature url="features/org.demo.imageview_1.0.3.jar“> <category name=“demos" /> </feature> <category-def name=“demos" label=“Demo Plugins"> <description>Eclipse Demo Plugins</description> </category-def></site>

Page 22: Extending Eclipse

Publisher Principles

■ Once you have invited others to contribute try hard Once you have invited others to contribute try hard to keep your API stableto keep your API stable

■ API stability “work arounds”API stability “work arounds”– deprecate and forwarddeprecate and forward– start over in a new packagestart over in a new package– extension interfacesextension interfaces

Page 23: Extending Eclipse

Closing the Circle

■ Now that we have published a plug-in with Now that we have published a plug-in with extension points we have closed the circle:extension points we have closed the circle:

Extenders can now extend the extensions!Extenders can now extend the extensions!

Page 24: Extending Eclipse

Plug-in Architecture - Summary

■ All functionality provided by plug-insAll functionality provided by plug-ins– Includes all aspects of Eclipse Platform itselfIncludes all aspects of Eclipse Platform itself

■ Contributions via extension pointsContributions via extension points– Extensions are created lazilyExtensions are created lazily

■ Packaged into separately installable featuresPackaged into separately installable features– DownloadableDownloadable