The "One Laptop Per Child" project has a great device ready to ship, but there's no Java on there. Let's think about working together to put Java on OLPC!
Replies:
18 -
Pages:
2
[
12
| Next
]
Threads:
[
Previous
|
Next
]
Eclipse is designed as a modular platform, with the ability to install and use plug-ins to extend the core functionality. To achieve this, Eclipse is built upon OSGi, a open modular system for Java with six years of commercial use behind it. Although this is a necessary part of Eclipse's modularity, it's enhanced through the use of the extension registry and extensions/extension points.
In the
previous episode
, we looked at how to create a plug-in to place a button on the toolbar, such that when we clicked it it displayed a message “Hello, Eclipse World”. But how did that button get on the toolbar? The answer lies in Eclipse's extensions.
You can think of Eclipse as being something like a USB hub. There's a standard plug-in specification (OSGi/USB) which defines how the hub operates, and you can plug any device that you want into the hub. Some of these will be standard types – mice, keyboards and so on – and will work in the same way, regardless of what and how they actually operate. In our case, our toolbar buttton is like these USB devices; plug it in, and Eclipse instantly knows that the button is there, and so displays it on the toolbar. Unplug the device (or stop the plug-in) and Eclipse will remove the button. (You can even get more complex devices, such as a USB-to-FireWire converter that allows other devices to be plugged into it; we'll cover providing your own extension points in a future episode.) And, like USB, the whole process is dynamic, meaning that we can extend the capabilities of an Eclipse system at run-time.
Getting back to the toolbar buttton; how does Eclipse know whether we've plugged in a toolbar button, a menu, or an editor? The answer lies in another piece of meta-data that's provided in an Eclipse plug-in – the
plugin.xml
file. This contains a list of extension points provided or used by this plug-in; when the plug-in is installed, the extensions are registered with the
IExtensionRegistry
and events are sent to those interested that a new extension has been installed. (A similar event occurs when an extension is uninstalled.)
The Eclipse toolbar listens out for such extension installation, and when a new button is installed, displays the icon on the taskbar. When the icon is clicked on, the action class associated with the button is loaded and invoked. If the plug-in has not been started, then it's brought into life at this point, as long as it specifies the manifest header
Eclipse-AutoStart: true
(3.1+),
Eclipse-LazyStart: true
(3.2+) or
Bundle-ActivationPolicy: lazy
(3.3+).
The
format
of the
plugin.xml
file is a series of
<extension>
(or
<extensionPoint>
) elements. Each extension/extension point used has an associated
id
, which is normally a fully qualified name similar to that of a Java package; in the case of our toolbar button,
org.eclipse.ui.actionSets
. So, the overall structure looks like:
All extensions are defined in the same way; in effect, the
IExtensionRegistry
acts like a giant hashtable-of-lists where
org.eclipse.ui.actionSets
is the key, and there are zero-or-more entries in the list. Installing and uninstalling a plug-in has the side effect of adding/removing the entry from that list, with the associated events generated for dynamic code to listen to.
The children of the
<extension>
can be any (well-formed) content; it's up to the consumer of the extension point (e.g. the toolbar) to understand what is supplied. In the case of the
actionSets
extension, it looks like this:
The toolbar reads the action sets available, and displays icons in the toolbar (from the
/actionSet/action@icon
attribute). A proxy class is used to trigger the loading of the
helloworld.actions.SampleAction
, which implements
IWorkbenchWindowActionDelegate
, and control is passed via the
run(IAction)
method.
If you're interested, you can even see the list of actions that are installed in an Eclipse workbench using the following code, which you can paste into the code for the
SampleAction
's
run(IAction)
method:
We've covered the purpose of extensions and extension points in this episode; over the next few episodes, we'll be looking at some of the standard extension points that you can contribute to in Eclipse; and in a future episode, how you can define your own extension points for others to contribute towards.
If you have any comments or questions, please post them here.
Re: Getting started with Eclipse plug-ins: understanding extension points
Hi,
I have got one question about:
"And, like USB, the whole process is dynamic, meaning that we can extend the capabilities of an Eclipse system at run-time."
What this statement really mean ? Considering i wrote my own plugin adding my own button to the toolbar, i can't add my plugin and so my button to a current running Eclipse, since i need to restart the workbench and once the restart occurs my plugin.xml file is read and my button added... ?
Re: Getting started with Eclipse plug-ins: understanding extension points
Selva,
If your plug-in has been installed by the Update Manager, and you chose the (non-default) option to apply changes without restarting, then in fact your button would have been dynamically added to the tool bar.
Unfortunately, the dynamic installation capabilities of the runtime in Eclipse are under-utilized at the moment. The Update Manager is largely legacy code written before Eclipse 3.0. Dynamic installation was first possible in Eclipse 3.0, when the core runtime was ported to OSGi. Also, many users install plug-ins by copying them into the
plugins
directory, so there is no way for Eclipse to know that the new plug-in is available, since it does not continuously scan that directory.
However, the Update Manager is going to be rewritten (hopefully!) so more people will start to experience the dynamic capabilities of the engine.
Re: Getting started with Eclipse plug-ins: understanding extension points
They can be. That's what the 'Apply Changes' button is on the update manager's dialog once the bundles have been downloaded into the plugins directory.
The OSGi dynamic bunding are available now; however, there's few processes which are explicitly taking advantage of it for the sake of dynamic bundles. But that doesn't mean that they don't work in Eclipse.
Re: Getting started with Eclipse plug-ins: understanding extension points
> They can be. That's what the 'Apply Changes' button
> is on the update manager's dialog once the bundles
> have been downloaded into the plugins directory.
I agrree with you but why the update manager "advises me to restart" letting me think that the apply change button should or shouldn't (depending on a random parameter) work correctly ;o) ?
Re: Getting started with Eclipse plug-ins: understanding extension points
Do you say this because you think my question is useless or because the update manager team (I read that there is only one person half time) is stick by new features and bugs ?
Re: Getting started with Eclipse plug-ins: understanding extension points
It was a reasonable question to ask. The Apply changes should work; I believe that the dialog has been like that since it's been possible to update plugins dynamically with the update manager, but was left as 'restart' as the default in case it didn't work when it came out.
The problem is that the update manager is fairly old, and wasn't designed with dynamic OSGi bundles at the time, but rather, that it's been updated to deal with these on the fly. However, it's suffered from a few things; not the least of which is that no-one inside Eclipse uses the update manager (they all grab the latest nightlies/integration builds) and so it doesn't get a good workout.
In addition, there's not many people working on the update manager, so it's pretty much the same way in 3.3 as it was in 3.2. However, looking forward (3.4+) the Eclipse Provisioning/packaging Project is looking at new and innovative ways of storing the Eclipse plugins, so that (amongst other things) multiple installs of Eclipse can share the same plugin set, and a host of other neat things.
So the focus of problems has moved from fixing update manager to replacing it with a better model ... but it's not due for completion until December, so it won't be in the 3.3 stream at all.
Re: Getting started with Eclipse plug-ins: understanding extension points
I meant what I wrote, but I may be thinking in different terms to you
Basically, for extension points to work, the thing that defines the extension point (e.g. the one with the schema) needs to be compatible with the thing that defines the extension (e.g. the one with the longer entries in plugin.xml). Normally, the place where the extension point is defined (i.e. with the schema) is also the same place as the thing that processes the data supplied by other extensions; but in fact, because the extension registry is global, anyone can read (and do what they want) with extension points created by anyone.
In summary: they're more like peers than true producer/consumer, but I wouldn't get too hung up about the terminology. As long as you understand the difference between an extension point and an extension, you know how it fits together.
Re: Getting started with Eclipse plug-ins: understanding extension points
Problem in Running ?changed? Plug-in Hello World
1)In a fresh unziped Eclipse from :eclipse-rcp-europa-win32.zip generate Plug-in project Hello World by using Template: Hello, World.
2)Change in hello_world.actions/SampleAction.java
3)Use Source; Organize Imports (import org.eclipse.core.runtime.Platform;)
4)Run us; Eclipse aplication.
3)Close runtime and host Eclipse.
4)Start Eclipse again and in Error Log hava a series of messages (see file 070728ErrorLogeclipse-rcp-europa-win32.zip.log)
5)Delete the progect e.g. , clear Error Log and in empty workspace I have received the same messages after starting Eclipse:
!ENTRY org.eclipse.osgi 2 0 2007-07-28 14:30:11.734
!MESSAGE While loading class "org.eclipse.mylyn.internal.tasks.ui.ITaskHighlighter", thread "Thread[Worker-0,5,main]" timed out waiting (5000ms) for thread "Thread[Worker-1,5,main]" to finish starting bundle "update@plugins/org.eclipse.mylyn.tasks.ui_2.0.0.v20070627-1400.jar [140]". To avoid deadlock, thread "Thread[Worker-0,5,main]" is proceeding but "org.eclipse.mylyn.internal.tasks.ui.ITaskHighlighter" may not be fully initialized.
!STACK 0
org.osgi.framework.BundleException: State change in progress for bundle "update@plugins/org.eclipse.mylyn.tasks.ui_2.0.0.v20070627-1400.jar" by thread "Worker-1".
at org.eclipse.osgi.framework.internal.core.AbstractBundle.beginStateChange(AbstractBundle.java:1141)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:258)
.........................
Re: Getting started with Eclipse plug-ins: understanding extension points
Bear in mind that using < or > in EclipseZone is likely to cause problems, which is probably why everything is italicised in your post ...
These errors are basically race conditions in Mylar, and nothing to do with your application or extension points. You can solve this by running your app in a situation without the mylar bundles installed.
Getting started with Eclipse plug-ins: understanding extension points
At 6:32 PM on Apr 24, 2007, Alex Blewitt
wrote:
In the previous episode , we looked at how to create a plug-in to place a button on the toolbar, such that when we clicked it it displayed a message “Hello, Eclipse World”. But how did that button get on the toolbar? The answer lies in Eclipse's extensions.
You can think of Eclipse as being something like a USB hub. There's a standard plug-in specification (OSGi/USB) which defines how the hub operates, and you can plug any device that you want into the hub. Some of these will be standard types – mice, keyboards and so on – and will work in the same way, regardless of what and how they actually operate. In our case, our toolbar buttton is like these USB devices; plug it in, and Eclipse instantly knows that the button is there, and so displays it on the toolbar. Unplug the device (or stop the plug-in) and Eclipse will remove the button. (You can even get more complex devices, such as a USB-to-FireWire converter that allows other devices to be plugged into it; we'll cover providing your own extension points in a future episode.) And, like USB, the whole process is dynamic, meaning that we can extend the capabilities of an Eclipse system at run-time.
Getting back to the toolbar buttton; how does Eclipse know whether we've plugged in a toolbar button, a menu, or an editor? The answer lies in another piece of meta-data that's provided in an Eclipse plug-in – the
plugin.xmlfile. This contains a list of extension points provided or used by this plug-in; when the plug-in is installed, the extensions are registered with theIExtensionRegistryand events are sent to those interested that a new extension has been installed. (A similar event occurs when an extension is uninstalled.)The Eclipse toolbar listens out for such extension installation, and when a new button is installed, displays the icon on the taskbar. When the icon is clicked on, the action class associated with the button is loaded and invoked. If the plug-in has not been started, then it's brought into life at this point, as long as it specifies the manifest header
Eclipse-AutoStart: true(3.1+),Eclipse-LazyStart: true(3.2+) orBundle-ActivationPolicy: lazy(3.3+).The format of the
plugin.xmlfile is a series of<extension>(or<extensionPoint>) elements. Each extension/extension point used has an associated id , which is normally a fully qualified name similar to that of a Java package; in the case of our toolbar button,org.eclipse.ui.actionSets. So, the overall structure looks like:<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.actionSets">
...
</extension>
</plugin>
All extensions are defined in the same way; in effect, the
IExtensionRegistryacts like a giant hashtable-of-lists whereorg.eclipse.ui.actionSetsis the key, and there are zero-or-more entries in the list. Installing and uninstalling a plug-in has the side effect of adding/removing the entry from that list, with the associated events generated for dynamic code to listen to.The children of the
<extension>can be any (well-formed) content; it's up to the consumer of the extension point (e.g. the toolbar) to understand what is supplied. In the case of theactionSetsextension, it looks like this:<actionSet label="Sample Action Set" visible="true" id="helloworld.actionSet">
<action icon="icons/sample.gif" class="helloworld.actions.SampleAction"
label="&Sample Action" tooltip="Hello, Eclipse world"
menubarPath="sampleMenu/sampleGroup" toolbarPath="sampleGroup"
id="helloworld.actions.SampleAction"/>
<menu label="Sample &Menu" id="sampleMenu">
<separator name="sampleGroup"/>
</menu>
</actionSet>
The toolbar reads the action sets available, and displays icons in the toolbar (from the
/actionSet/action@iconattribute). A proxy class is used to trigger the loading of thehelloworld.actions.SampleAction, which implementsIWorkbenchWindowActionDelegate, and control is passed via therun(IAction)method.If you're interested, you can even see the list of actions that are installed in an Eclipse workbench using the following code, which you can paste into the code for the
SampleAction'srun(IAction)method:StringBuffer buffer = new StringBuffer(); IExtensionRegistry reg = Platform.getExtensionRegistry(); IConfigurationElement[] extensions = reg.getConfigurationElementsFor("org.eclipse.ui.actionSets"); for(int i=0;i<extensions.length;i++) { IConfigurationElement element = extensions[i]; IConfigurationElement[] children = element.getChildren("action"); for(int j=0;j<children.length;j++) { buffer.append(children[j].getAttribute("label")); buffer.append('\n'); } } MessageDialog.openInformation( window.getShell(), "Installed plugins", buffer.toString());We've covered the purpose of extensions and extension points in this episode; over the next few episodes, we'll be looking at some of the standard extension points that you can contribute to in Eclipse; and in a future episode, how you can define your own extension points for others to contribute towards.
If you have any comments or questions, please post them here.
18 replies so far (
Post your own)
Re: Getting started with Eclipse plug-ins: understanding extension points
Hi,I have got one question about:
"And, like USB, the whole process is dynamic, meaning that we can extend the capabilities of an Eclipse system at run-time."
What this statement really mean ? Considering i wrote my own plugin adding my own button to the toolbar, i can't add my plugin and so my button to a current running Eclipse, since i need to restart the workbench and once the restart occurs my plugin.xml file is read and my button added... ?
Manuel Selva
Re: Getting started with Eclipse plug-ins: understanding extension points
Selva,If your plug-in has been installed by the Update Manager, and you chose the (non-default) option to apply changes without restarting, then in fact your button would have been dynamically added to the tool bar.
Unfortunately, the dynamic installation capabilities of the runtime in Eclipse are under-utilized at the moment. The Update Manager is largely legacy code written before Eclipse 3.0. Dynamic installation was first possible in Eclipse 3.0, when the core runtime was ported to OSGi. Also, many users install plug-ins by copying them into the
pluginsdirectory, so there is no way for Eclipse to know that the new plug-in is available, since it does not continuously scan that directory.However, the Update Manager is going to be rewritten (hopefully!) so more people will start to experience the dynamic capabilities of the engine.
Neil
Re: Getting started with Eclipse plug-ins: understanding extension points
Thanks for your answer Neil.I can understand now. At this time the OSGi capabilities of dynamic binding of bundles are most of the time unused but will be in the near future ...
Manuel Selva
Re: Getting started with Eclipse plug-ins: understanding extension points
They can be. That's what the 'Apply Changes' button is on the update manager's dialog once the bundles have been downloaded into the plugins directory.The OSGi dynamic bunding are available now; however, there's few processes which are explicitly taking advantage of it for the sake of dynamic bundles. But that doesn't mean that they don't work in Eclipse.
Alex.
Re: Getting started with Eclipse plug-ins: understanding extension points
> They can be. That's what the 'Apply Changes' button> is on the update manager's dialog once the bundles
> have been downloaded into the plugins directory.
I agrree with you but why the update manager "advises me to restart" letting me think that the apply change button should or shouldn't (depending on a random parameter) work correctly ;o) ?
Re: Getting started with Eclipse plug-ins: understanding extension points
That's the least of the update manager's problems ...Alex.
Re: Getting started with Eclipse plug-ins: understanding extension points
Do you say this because you think my question is useless or because the update manager team (I read that there is only one person half time) is stick by new features and bugs ?Re: Getting started with Eclipse plug-ins: understanding extension points
It was a reasonable question to ask. The Apply changes should work; I believe that the dialog has been like that since it's been possible to update plugins dynamically with the update manager, but was left as 'restart' as the default in case it didn't work when it came out.The problem is that the update manager is fairly old, and wasn't designed with dynamic OSGi bundles at the time, but rather, that it's been updated to deal with these on the fly. However, it's suffered from a few things; not the least of which is that no-one inside Eclipse uses the update manager (they all grab the latest nightlies/integration builds) and so it doesn't get a good workout.
In addition, there's not many people working on the update manager, so it's pretty much the same way in 3.3 as it was in 3.2. However, looking forward (3.4+) the Eclipse Provisioning/packaging Project is looking at new and innovative ways of storing the Eclipse plugins, so that (amongst other things) multiple installs of Eclipse can share the same plugin set, and a host of other neat things.
So the focus of problems has moved from fixing update manager to replacing it with a better model ... but it's not due for completion until December, so it won't be in the 3.3 stream at all.
Hope that helps clarify my answer,
Alex.
Re: Getting started with Eclipse plug-ins: understanding extension points
Thanks for this clear answer. I've got all the infos missing to me to understand "dynamic aspect" of eclipse's plug ins ;o)Re: Getting started with Eclipse plug-ins: understanding extension points
The next episode in this series has been published.Re: Getting started with Eclipse plug-ins: understanding extension points
Hey Alex, thanks for the very informative article. Correct me if I'm wrong, but shouldn't this line:"... it's up to the consumer of the extension point (e.g. the toolbar) to understand what is supplied."
be replaced by something like this:
"... it's up to the provider of the extension point (e.g. the toolbar) to understand what is supplied."
I don't have my terminology backwards do I?
Re: Getting started with Eclipse plug-ins: understanding extension points
I meant what I wrote, but I may be thinking in different terms to youBasically, for extension points to work, the thing that defines the extension point (e.g. the one with the schema) needs to be compatible with the thing that defines the extension (e.g. the one with the longer entries in plugin.xml). Normally, the place where the extension point is defined (i.e. with the schema) is also the same place as the thing that processes the data supplied by other extensions; but in fact, because the extension registry is global, anyone can read (and do what they want) with extension points created by anyone.
In summary: they're more like peers than true producer/consumer, but I wouldn't get too hung up about the terminology. As long as you understand the difference between an extension point and an extension, you know how it fits together.
Alex.
Re: Getting started with Eclipse plug-ins: understanding extension points
Problem in Running ?changed? Plug-in Hello World1)In a fresh unziped Eclipse from :eclipse-rcp-europa-win32.zip generate Plug-in project Hello World by using Template: Hello, World.
2)Change in hello_world.actions/SampleAction.java
public void run(IAction action) {
MessageDialog.openInformation(
window.getShell(),
"HelloWorld Plug-in",
"Hello, Eclipse world");
}
to:
public void run(IAction action) {
StringBuffer buffer = new StringBuffer();
IExtensionRegistry reg = Platform.getExtensionRegistry();
IConfigurationElement[] extensions = reg.getConfigurationElementsFor("org.eclipse.ui.actionSets");
for(int i=0;i IConfigurationElement element = extensions ;
IConfigurationElement[] children = element.getChildren("action");
for(int j=0;j buffer.append(children[j].getAttribute("label"));
buffer.append('\n');
}
}
MessageDialog.openInformation(
window.getShell(),
"Installed plugins",
buffer.toString());
}
3)Use Source; Organize Imports (import org.eclipse.core.runtime.Platform;)
4)Run us; Eclipse aplication.
3)Close runtime and host Eclipse.
4)Start Eclipse again and in Error Log hava a series of messages (see file 070728ErrorLogeclipse-rcp-europa-win32.zip.log)
5)Delete the progect e.g. , clear Error Log and in empty workspace I have received the same messages after starting Eclipse:
!SESSION 2007-07-28 14:29:35.937 -----------------------------------------------
eclipse.buildId=I20070625-1500
java.version=1.5.0_04
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=bg_BG
Command-line arguments: -os win32 -ws win32 -arch x86
!ENTRY org.eclipse.osgi 2 0 2007-07-28 14:30:11.734
!MESSAGE While loading class "org.eclipse.mylyn.internal.tasks.ui.ITaskHighlighter", thread "Thread[Worker-0,5,main]" timed out waiting (5000ms) for thread "Thread[Worker-1,5,main]" to finish starting bundle "update@plugins/org.eclipse.mylyn.tasks.ui_2.0.0.v20070627-1400.jar [140]". To avoid deadlock, thread "Thread[Worker-0,5,main]" is proceeding but "org.eclipse.mylyn.internal.tasks.ui.ITaskHighlighter" may not be fully initialized.
!STACK 0
org.osgi.framework.BundleException: State change in progress for bundle "update@plugins/org.eclipse.mylyn.tasks.ui_2.0.0.v20070627-1400.jar" by thread "Worker-1".
at org.eclipse.osgi.framework.internal.core.AbstractBundle.beginStateChange(AbstractBundle.java:1141)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:258)
.........................
Re: Getting started with Eclipse plug-ins: understanding extension points
Bear in mind that using < or > in EclipseZone is likely to cause problems, which is probably why everything is italicised in your post ...These errors are basically race conditions in Mylar, and nothing to do with your application or extension points. You can solve this by running your app in a situation without the mylar bundles installed.
Alex.