Categories
Eclipse

Query “Eclipse Community Forums” from online Help

There is a generally not-known feature in the Eclipse Help which allows to configure the scope of searches.

By default, whenever you perform a query, the search scope is restricted to your local help repository (i.e. Javadocs, API references, user guides contributed by plug-ins).
However, it is possible to add new “search engines” to this scope. For example, even if you don’t have (and I hope you don’t), every Galileo plug-in in your environement, you may want to search information in the whole Galileo help without leaving your workbench. This is as simple as:

  • Opening the search UI using “Help > Search” menu
  • From the query form, opening the “advanced settings” of your search scope
  • Adding a new search engine. Select the “Info Center” type, and use the following URL : http://help.eclipse.org/galileo.

Similarly, you can use any website allowing to perform queries through URL parameters (e.g. Google) as an Eclipse Help search engine.
That’s exactly what we are going to do in order to allow search on Eclipse Community Forums, the new & sexy Web UI on top of Eclipse newsgroups.

This time, you are going to add  a new “Web Search” search engine,

step1

and you will use the following URL pattern: http://www.eclipse.org/forums/index.php?SQ=0&t=search&srch={expression}&btn_submit=Search&field=subject

step2

And voila! Starting from now, you’ll have search results coming from the online Galileo info center and from the Eclipse Community Forums 😎

step3

step4

Categories
Eclipse

Model my PDE!

I’ve been working for quite a while on finding solutions to the problems we are having in PDE as soon as we need to add support for new OSGi headers, to create new editors for cheatsheet files, p2 categories, etc.

Declarative Services tooling is a good illustration of all these problems. As part of the Google Summer of Code 2008, Rafael Oliveira worked on the creation of some cool tooling to help people wanting to use OSGi Declarative Services. This tooling is great, and available in Eclipse Galileo as many of you may know but, unfortunately, it introduces a lot of boilerplate code (Java model of what a DS component is, Java model of what the textual representation of a DS component is, JFace label and content providers, etc.)

Indeed, since day 1 of PDE, despite the fact there is a sort of generic framework behind PDE (undo/redo support for operations done both programmatically or through the UI/text editors, compiler to check models consistency and create markers, outline, etc.), it is, and always has been kind of a pain to “instantiate” this framework for each new usecase.

People familiar with EMF, and modeling technologies in general, are probably thinking right now that the framework behind PDE should probably model-based, and of course they are right! That’s exactly the purpose of the ongoing “model my PDE” work being done in the PDE incubator. In this post, I will quickly explain what is currently available in HEAD of the project, further explanations may come in later posts (by the way, feel free to ask precisions on specific topics!).

Generic Forms editor

The org.eclipse.pde.emfforms bundle proposes some abstractions of what is generally needed to create a Forms editor for any kind of EObject. Thanks to EMF.Edit and Databinding framework, it makes it really simple –sometimes you won’t even need to write a single line of code– to create your UI and bind it to the model, display the errors on your model, show an outline, and stuff.

Since the project is still incubating, there is of course no clear API of this bundle at the moment, but if you need to quickly hack a model editor, you should probably have a look at it, and at the “exemplary” implementation which has been done for the “next-gen” DS Component editor.

A non-exhaustive list of the feature provided by this framework (coupled to the features of EMF/EMF.Edit/Databinding and Forms) would be:

  • full undo/redo support
  • full copy/paste support (both locally to the editor, and from an editor instance to another),
  • automatic refresh of the editor if the model is changed on disk,
  • model live-validation; displaying error(s) in front of the “guilty” controls, in the forms header, and on the nodes of the elements displayed in Master/Details blocks,
  • full drag&drop support in Master/Details blocks’ viewers,
  • generic Outline view,
  • generic Properties view,
  • … 😎

Extensibility

There are many OSGi vendors who work on their own implementation of the standard, and they obviously need tooling for these specificities. In an ideal world, they should be able to extend vanilla PDE instead of reinventing the wheel. We, at PDE, expose some APIs for people to do that (SpringSource Tool Suite proposes tooling for SpringDM, and it is built on top of PDE), but there are many things that are still internal. Our models, our editors, our compilers, are not really designed to be extensible. A model-based approach is the right solution to this lack of extensibility:

  • An EMF model is very easily extensible. In order to extend the “Declarative Services” model, create you own, let’s say scr-equinox.ecore, referencing just take the scr.core model. You can now have an EquinoxComponent, extending the standard Component, and bringing some nice Equinox-specific additions. When you will generate the corresponding Java code, you’ll end up with a model which will be 100% editable in the “legacy” Component editor.

scr-equinox-1.1

  • It is very easy to add new validation rules, either enhancing the EValidator generated by EMF, or, way better, using the EMF Validation framework which allows to contribute new rules in a declarative fashion. Not only it allows anybody to “plug” additional rules on top of an existing model, but it also avoids to clutter the model API with dependencies needed only for validation purposes. Indeed, to perform a meaningful validation of a Declarative Services component, you have to query JDT and PDE to check method signatures, visibility of referenced services, etc. For people interested in how an EMF Validation constraint extension, here is an example taken from the incubator code:
<extension point="org.eclipse.emf.validation.constraintProviders">
      <category
            id="org.eclipse.pde.ds.builder.validation"
            mandatory="true"
            name="Declarative Services Validation">
      </category>
      <constraintProvider cache="true">
         <package
               namespaceUri="http://www.osgi.org/xmlns/scr/v1.1.0">
         </package>
         <constraints
               categories="org.eclipse.pde.ds.builder.validation">
            <constraint
                  class="o.[...].ComponentMethodsAreValidAndAccessible"
                  id="o.[...].constraintComponentMethodsAreValidAndAccessible"
                  lang="Java"
                  mode="Live"
                  name="Components methods validation"
                  severity="ERROR"
                  statusCode="2">
               <message>
                  Method {0}: {1}
               </message>
               <target class="Component">
                  <event name="Set">
                     <feature name="activate">
                     </feature>
                  </event>
                  <!-- ... -->
               </target>
            </constraint>
         </constraints>
      </constraintProvider>
   </extension>
  • EMF allows to version models, and has solutions to ensure compatibility between an N-1 and an N model instance. This way, we could probably be a bit less shy when it comes to updating old APIs. Tooling would be written to handle models in version N, but APIs for N-1, N-2, etc. would still be available, and mappers to convert from N-X to N would be too.

Model-aware builder

In order to report errors to the end-user, the editor performs live validation (thus the nice Forms decorators in the screencast below), but there is also a specific builder (once again, designed to be extensible) listening for model changes, and calling EMF Validation behind the scene to check the consistency and create resource markers for every encountered problem.

Screencast

A screencast being IMHO worth a thousand words, here is a live demo of the DS Editor:

pde modeling

If you want to play with this  “experimental” tool, you can install in your SDK the experimental feature served by build.eclipse.org and corresponding to the result of continuous integration of the HEAD of the project, thanks to Hudson and Athena!

I guess the next important step is now to find an elegant way to propose a Source tab which, as you may have noticed, is almost the only feature being present in the Galileo editor and not in this prototype. Another important step will also be to write the Xtext grammar of an OSGi Manifest, and leverage this “EMF-Forms” framework to propose a cool and extensible editor on top of a Manifest 🙂

Categories
Eclipse

Retrouver le bundle auquel appartient une classeGiven a class, how to retrieve its bundle?

OSGI R4.2 (donc Equinox 3.5) introduit une nouveauté toute bête, mais particulièrement pratique. Il s’agit de la méthode org.osgi.framework.FrameworkUtil.getBundle(Class), qui permet de récupérer le bundle auquel appartient une classe donnée.

Plus précisément, cette méthode vous renverra le bundle qui a servi à résoudre ladite classe, ou null dans le cas où la classe n’a pas été chargée par le Framework (si c’est une classe du boot classpath par exemple…).

Ainsi, dès qu’il s’agira de récupérer des infos comme le numéro de version d’un bundle, ses headers, etc… sans avoir à passer par l’Activator (qui parfois n’existe d’ailleurs même pas…), vous savez ce qu’il vous restera à faire! En outre, qui dit Bundle, dit BundleContext, et cette méthode est donc également un moyen très simple de publier/consommer des services !.. 🙄OSGI R4.2 (thus Equinox 3.5) comes (well, will come, since the spec. is not final yet) with a new simple and handy utility: the org.osgi.framework.FrameworkUtil.getBundle(Class) static method, which allows to retrieve the bundle a given class belongs to.

More specifically, this method will give you the bundle who loaded the given class, or null if the class has not been loaded by the OSGi framework (e.g. if it is a class belonging to the boot classpath…).

Thus, whenever you want to access information such as the version of a bundle, its headers,  etc. without having to query its Activator (perhaps you don’t even have an Activator for this bundle…), you know what you’ve got to use! Of course, whoever says Bundle, means BundleContext, and this handy helper is also very convenient to easily publish/consume OSGi services on behalf of the bundle… 🙄