Thursday, August 21, 2014

EASE - Eclipse Advanced Scripting Environment launched

It's been a while since I last wrote about EASE. Not writing about it does not mean that we were lazy. We applied for an official eclipse project and were busy setting up the infrastructure.

So please welcome the new Eclipse citizen: EASE.

What it does for you

EASE allows to write, maintain and execute scripts right within your IDE. Executed scripts run in the context of the Eclipse JRE, allowing to access all Java classes in your Eclipse universe. Thus you can manipulate and extend your IDE without the need to write plugins, pack them into features, export them into a p2 repository, install, restart, ...

As accessing Java code from script languages is typically an annoying task ("If I could write Java code I would do it in Java, why scripting?") EASE provides extension points to encapsulate typical actions into simple script commands. Basically it allows to create wrappers in the target script language to access Java methods. We already started writing some useful modules. The Modules Explorer view gives a short overview of the available commands (hint: try DND).

You already have a nice API to use? Great, just wrap() it from your script or register it via extension point.

Scripts may include other scripts using URIs. You could even access your scripts using http.To register script locations check your preferences in Preferences/Scripting.

Current UI integration gives access to a nice interactive shell to play around with, script recording and launch support.

Right, where do I get it from?

You find the update site locations on our webpage. We are focusing on Eclipse Luna, so if you are using something older and things do not work as expected, let us know.

Contribute? It's easier than you thought

Contribution is not only about writing code. Just test EASE and let us know what you think of it. Fill the bugtracker with ideas, design icons, write help, provide sample scripts - there are so many things that need a little care.

What's next

This summer we received a great contribution via Google Summer of Code. Martin Kloesch developed a Jython debugger which will be available on the update sites soon.

UI integration to bind scripts to menus and toolbars is basically working, but needs some tweaking.

A set of core modules needs to evolve. Currently we are playing around with the functions, but we need a stable script API for those modules rather soon.

... and I know we have to write lots of help and tutorials to make this project useful for you out there.


  1. Great job!

    But there are some problems with JDK 1.8.0 and Nashorn.
    When I run in the console:

    everything works fine but when I create script with the same content and try to run it via "Run As -> EASE Script" I've got the following error:

    at org.eclipse.ease.lang.javascript.nashorn.NashornScriptEngine.setVariable(
    at org.eclipse.ease.ui.launching.EaseLaunchDelegate.launch(
    at org.eclipse.ease.ui.launching.EaseLaunchDelegate.launch(
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(
    at org.eclipse.ease.ui.launching.EaseLaunchDelegate.launch(
    at org.eclipse.ease.ui.launching.EaseLaunchDelegate.launch(
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension.launch(
    at org.eclipse.debug.internal.ui.actions.LaunchShortcutAction.runWithEvent(
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(
    at org.eclipse.jface.action.ActionContributionItem.access$2(
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(
    at org.eclipse.swt.widgets.EventTable.sendEvent(

    My environment:

    java.vendor=Oracle Corporation
    BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=pl_PL
    Framework arguments: -product org.eclipse.epp.package.cpp.product
    Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.cpp.product

    When I use jdk1.7.0 and Rhino everything works as expected.

    1. created and fixed bug 442319.
      Please upgrade EASE after the next nightly build (in approx 8 hours) or select the rhino engine in your launch configuration (automatically created after the first contextual launch).

      Thanks for reporting.

    2. Now everything works fine. Thanks for really quick bug fix!

  2. I've been trying out EASE from the current nightly build and it looks promising. My goal at this point is to make an EASE script that takes takes a selected function name in a JavaScript file and inserts a template for a stub function for it before the currently defined function. However, I'm getting stuck on interacting with the editor and selections. Or maybe instead you can point me to an existing tutorial script that does something like that?

    As as step towards that, as a tutorial, could you please explain in detail how to make an EASE script in JavaScript to run in the Rhino Script Shell that takes the current selected text in the current Eclipse editor window (not the Rhino Script Shell), puts the text in a variable (like $selection), logs $selection to a console, and replaces the text in the editor with "'hello, ' + $selection"? Also, could your please explain how to hook that script up so it runs on an Eclipse hot key or some GUI widget to activate it while editing? That seems the minimum instructions needed to do many interesting scripts with EASE that could support refactoring, code insertion, and so on. I've been trying to use getSelection and convertSelection from the UI module to get the current selection, but so far no luck.

    1. Glad you like EASE. Generally it would be good, to post these questions to the forum or the mailing list, as others may benefit from your experiences/responses. But to answer your question:
      Just today I pushed a commit that allows to hook scripts into the UI using keywors in the script header. See this short sample:

      // ********************************************************************************
      // name : Display selection type
      // popup : enableFor(java.lang.Object)
      // ********************************************************************************
      var selection = getSelection();
      if (selection instanceof org.eclipse.jface.viewers.IStructuredSelection)
      selection = selection.getFirstElement();

      showInfoDialog("Selected class: " + selection.getClass().getName());

      Put this script to a monitored location (see preferences/scripting) and it will be available in any context menu. Now fire up an editor, select something and run the script from the context menu. You will get a TextSelection element, which you can query for the highlighted text.
      For your usecase I also added methods getActiveEditor()/-View() to the UI module. For replacement you are on your own. Guess the editor instance might have an API for that. You also have the selection, so there should be a way.

      Grab all these things from the next nightly build (approx 8 hours from now)

    2. Wow, thanks a lot! I just noticed your reply to my inital question; sorry did not see it sooner before my second reply below mentioning the four modules responding to your other comment. When I get something working, I'll post a summary of it to the forum or mailing list. Thanks again for such a useful tool. Eclipse has been needing this for a long time!

  3. To answer some of my own question, I've found a demo script in the org.eclipse.ease.core git repository that replaces the current selection with the date:

    And when in the Rhino Script Shell, after doing loadModule("TextEditorModule") which returns [null], when I try "getActiveEditor()", I get:

    ReferenceError: "getActiveEditor" is not defined.

    Although when I run it as an EASE script I get:
    Unable to find module "TextEditorModule"org.mozilla.javascript.EcmaError: ReferenceError: "getActiveEditor" is not defined.

    So, some progress.

    1. There is no such module as "TextEditorModule". You can see available modules in the dropdown list of the very first toolbar icon in the shell. Additional modules might be hidden, enable them in the preferences.

    2. Thanks for the reply. I guess that means the example code I found in the current source is out of date? I find similar issues when I try to run the other samples. It's too bad, as it seems those samples would do pretty much exactly what I wanted. I could not find functions they referenced in the code base defined anywhere either (like getActiveEditor), so maybe some modules like the TextEditorModule to do such things existed at some point and were removed? Or maybe that functionality was just renamed?

      When I was searching on getActiveEditor, I did see that function was used in parts of the code. It seems a useful snippet to get an active editor to do something with would be:

      However, for the Platform module I can load, there are only methods for adapt, executeCommand, getService, getSystemProperty, and runProcess. There is no choice for getWorkbench. Would I have to modify that module or write my own to get access to these functions? Or can I approach that some other way?

      The only four modules I see in the dropdown are the the System ones for Scripting Platform, Resources, UI. I did see one disabled module that I enabled under the preferences; that module is "Environment". However, it does not seem to supply a way to get the PlatformUI or Workbench. The Environment module does supply a "print" command which presumably could be used for logging, although I don't see where the output goes.

    3. Current available script samples are out of date.
      As stated above I added getActiveEditor() functionality to the UI module for you. Just wait for the build and update.
      To replace text see the eclipse FAQ:

      For further questions on this topic, please ask at the forum: