Friday, January 14, 2011

Two Eclipse p2 repository operations to make you happy

On the integrations side of the Eclipse business I often happen to need two things:
1. add a random OSGi jar to repository
2. copy from one repository to another

Looking thru p2 manual it's not always entirely obvious how to do it, so here goes my take on the subject.
All my automation uses Ant, so I'll speak a bit of Ant now:

1. Add a random OSGi jar to repository

<p2.publish.featuresAndBundles
repository="file:/path/to/destination/repository" e.g. ${buildDirectory}/repo
publishArtifacts="true"
compress="true"
append="true"
source="/absolute/path/to/folder/with/jar" />

Few notes:
1. source attribute must be an absolute path.
2. source path must contain "features" and "plugins" directories. So if you have only one bundle, make sure to put it under plugins dir first.
3. make sure repository attribute is a URL, not plain path


2. Copy from one repository to another

<p2.mirror verbose="true">
<repository location="file:/path/to/destination/repository" />
<source>
<repository location="file:/path/to/source/repository" />
</source>
<iu id="pluginName" version="" />
</p2.mirror>

Notes:
1. Why not use p2.director? It copies only bundles for current architecture
2. Mirror task is still not perfect, but enough for most copying operations, it has some extra options, worth looking into.

Wednesday, January 12, 2011

Extending Eclipse Orion

Yesterday Eclipse E4 team announced Orion - an experimental Eclipse Web IDE. There's plenty of information about the project on Orion wiki.

Orion is a set of JavaScript and HTTP APIs that simplify common development part of rich applications, like file storage, preferences, authentication, dialogs, selection. Since it's coming from Eclipse, Orion is skewed towards IDE development, so from start it also includes text editor with some decent features, like JavaScript syntax highlighting and JSLint integration.
The project may go towards strengthening it's JS IDE feature set, as well as enhancing it's core side - extensibility, client APIs ...or do it all at once. In any case it's going to be fascinating journey!

So how to extend Orion? One can re-implement existing HTTP API in language other than Java; add more HTTP APIs, e.g. for task management, calendar, etc. Same with JavaScript API - it seems fairly easy to add more. Looking at this from classic Eclipse adopter point of view, I tried to add some GUI contribution that brings new functionality to existing Orion - let's say a PHP editor to complement the JS one. Naturally all without leaving Orion. I took following steps:
1. create new Orion bundle with new editor
2. install on Orion server
3. test and improve the contribution

Creating new bundle for Orion
Orion is technically a simple Equinox http server, so it's pretty straightforward. We need MANIFEST.MF with bundle description, plugin.xml that describes what web content should be published and the content itself.

New bundle structure, looking at it from Orion:

META-INF/MANIFEST.MF
Pretty much ,standard Eclipse plugin manifest.



plugin.xml
This one specifies that our bundle contains some static web content under /web directory and that it should be accessible in the container under /simple alias. Straightforward, thanks to Equinox.


Interestingly, at the moment Orion team decided to put all configuration in one bundle, so e.g. webeditor or webide JS code currently doesn't decide on it's own where will it appear, but instead a separate configuration bundle defines that.

Installing bundle into Orion
To install just created bundle, we need to figure out where is it stored and install it. By default Orion stores files in serverworkspace directory in it's home dir. On Mac this happens to be \Eclipse.app\Contents\MacOS\serverworkspace

In order to install bundle, it's best to use equinox osgi console - available in Orion thanks to the fact that it's equinox application. Orion docs mention something about server console, but I'm not entirely sure if this is the same, or some other console.
So first start Orion with osgi console:

./eclipse -console

and then, install the bundle:

osgi> install file:/Users/jacek/Downloads/eclipse-orion/eclipse.app/Contents/MacOS/serverworkspace/A
Bundle id is 75

osgi> start 75

I used absolute path from Orion workspace, to easily make updates later. Surprisingly my project dir is named "A" instead of it's real name. Another interesting thing is that there's no all the well known .project and .settings files. Web developers are going to like it, and I'm wondering where is this information stored currently.

Test and improve the contribution
So now that our bits are installed, let's see them:
http://localhost:8080/sample/index.html and yes! It works!

Curious mind would be interested what was the source of the index.html, that generated such nice "Hello [object Object]" message. I included some Orion Client API to check if it's available and yes, it is! From now on, further documentation can be found at Orion Client API wiki.

The source is following:
After updating the bundle contents - e.g. to turn this sample to real new PHP editor - there's another command required to make Orion see our changes. From osgi console type:

osgi> update org.eclipse.sample


The only thing that I was not able to figure out is how to actually add a link or other UI contribution to code editor, files navigator, or other existing UIs. At the moment user has to manually enter the URL to see my contribution. I'd be happy to hear how to do this, if you happen to know.