1 / 38

Groovy Monkey

http://groovy.codehaus.org/Groovy+Monkey. Groovy Monkey. Java Developer since 1999 Eclipse Plugin Developer since 2002 Groovy Eclipse committer since 2005 Author of Groovy Monkey . About Me. “I am not just the author of Groovy Monkey,

alaina
Download Presentation

Groovy Monkey

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. http://groovy.codehaus.org/Groovy+Monkey Groovy Monkey

  2. Java Developer since 1999 Eclipse Plugin Developer since 2002 Groovy Eclipse committer since 2005 Author of Groovy Monkey About Me

  3. “I am not just the author of Groovy Monkey, I'm a user...” -- paraphrased from the founder of “Hair Club for Men” -- James E. Ervin About Me

  4. Agenda • Why Groovy Monkey? • What is Groovy Monkey? • I'm from Missouri, Show Me.... • Anatomy of a script • Script Examples • ...Batteries Included • Future plans • Monkey Resources • Q&A

  5. Why Groovy Monkey? • To be more productive with Eclipse, thats why.

  6. Why Groovy Monkey? • Wanted a tool to facilitate the following: • Eclipse API Exploration • Self hosting is too slow and cumbersome • Plugin creation is too much overhead for exploration • The Eclipse API is complex • Task Automation • To add functionality too small to be a plugin • Rapid prototyping with path to a plugin • In case the small grows big

  7. Why Groovy Monkey? • Found Eclipse Monkey but it was too limiting: • Could only write scripts in ECMAScript (JavaScript)‏ • There is a nice library called Bean Scripting Framework, so why not let everyone play? • Everything runs in the UI Thread • Why not use the Eclipse Jobs API? • Could only invoke code exposed through a DOM • What about installed bundles? • How about adding library jars?

  8. Why Groovy Monkey? • I am a power Eclipse User and Plugin developer and I want my life to be easier: • I want to be able to quickly try parts of the Eclipse API without the overhead of a plugin • I want to be able to write quick/reusable functionality (i.e. task automation) to make my life with Eclipse easier • I want to be able to translate the quick and dirty work eventually into a proper plugin

  9. What is Groovy Monkey? • Groovy Monkey is a branch/port of the Eclipse Monkey tool based on: • Apache Bean Scripting Framework • The Eclipse Jobs API • OSGi framework

  10. What is Groovy Monkey? • Bean Scripting framework • http://jakarta.apache.org/bsf/ • Monkey predates javax.script in Java 6.0 • I don't hate Macintosh people • Provides scripting engines for the most used scripting languages • Allows Groovy Monkey scripts to be written in Groovy, Beanshell and Ruby (soon hopefully Python as well)‏

  11. What is Groovy Monkey? • The Eclipse Jobs API is the native Eclipse platform support for threading. Allows for three types: • Job: Ordinary job thread, provides a progress monitor and status in the progress view • WorkspaceJob: Batches updates to resource listeners until after the job is complete • UIJob: Runs in the SWT UI Thread

  12. What is Groovy Monkey? • The OSGi framework packages components in bundles, which are uniquely identified. Groovy Monkey leverages the OSGi container by: • Groovy Monkey can add the classloader of any bundle on the workbench to a script's classloader • Allows Groovy Monkey to do white box introspection of running bundles/plugins

  13. Show me: How to install • If not included in your Eclipse distribution, goto the update site: • http://groovy-monkey.sourceforge.net/update

  14. Show Me: A Script • A script has two parts, the metadata and then the script body. /* * Menu: Open Dialog > Groovy * Script-Path: /EclipseMonkeyScripts/monkey/OpenDialog_Groovy.gm * Kudos: ervinja * License: EPL 1.0 * Job: UIJob */ org.eclipse.jface.dialogs.MessageDialog.openInformation( window.getShell(), 'Monkey Dialog', 'Hello World from Groovy' )‏ • Right click to run the script from within Eclipse

  15. Show Me: A Script: Results • The amazing results of this script is: • Drum Roll please...... Note: Wait for enthusiastic applause from audience

  16. Anatomy of a Script • Script is composed of two parts: • Script Metadata Header • This is the portion that is specific to monkey • Tags serve to setup classloader and configure script • Script Body • Vital obviously, but Monkey delegates this to the BSFEngine for the given language.

  17. Script Anatomy: Tags • Menu • Determines where in the Monkey Menu the script can be invoked/edited

  18. Script Anatomy: Tags • 'Lang' • The first tag I added to Monkey • By default is set to 'Groovy' • Valid entries are: • Groovy *(default)‏ • Beanshell • Ruby • Python**

  19. Script Anatomy: Tags • Lang cont'd: • Maps to a BSFEngine implementation that is wrapped in an extension point: • net.sf.groovyMonkey.lang • List of supported languages is not hardcoded • Additional language support can be easily plugged in if the BSFEngine implementation can be found.

  20. Script Anatomy: Tags • Job • The most important part of Groovy Monkey over Eclipse Monkey, running scripts in separate threads. • By default a script is run inside an Eclipse 'Job' • Valid Entries: • Job* (default) – org.eclipse.core.runtime.Job • WorkspaceJob – org.eclipse.core.resources.WorkspaceJob • UIJob - org.eclipse.ui.progress.UIJob

  21. Script Anatomy: Tags • Job cont'd • Allows us to bind (more on this under DOMs) a progress monitor to the script • Script writer can provide progress and allow cancellation • Scripts become Eclipse Jobs, which means that they can be monitored in the progress view. • One gotcha, UIJob is provided as a convenience, it is best to use it sparingly

  22. Script Anatomy: Tags • Exec-Mode tag: • Complementary to the Job tag • Allows jobs to be run the the foreground or in the background • Valid values: • background* (default) • foreground – Eclipse pops up a modal dialog box to show the progress of the script.

  23. Script Anatomy: Tags • Include • Allows you to include elements in the workspace in the classloader of the script. • Allows you to try new third party jars immediately and makes Groovy Monkey a more general scripting tool • Can add a jar in the workspace or a class folder • Syntax: • * Include: /MonkeyScripts/commons-http-client.jar

  24. Script Anatomy: Tags • Include-Bundle • This is what makes Eclipse API exploration and plugin rapid prototyping possible. • You specify the bundle identifier for a bundle loaded in the workbench and its classloader is added to the classloader of the script. • There are a number of bundles included by default* • Syntax: • * Include-Bundle: org.eclipse.ui.ide

  25. Script Anatomy: Tags • DOM • net.sf.groovyMonkey.dom • An extension provided by a bundle, that provides an API for script writers • They get bound to variable names in the script at runtime. • First step from script to full blown bundle. • There are a set of DOM(s) included by default • Syntax: • * DOM: net.sf.groovyMonkey.dom.console

  26. “Batteries Included” • Groovy Monkey includes several things to hopefully simplify script writing: • Default DOM(s)‏ • Default Bundles • Editor • Outline View • Sharing

  27. “Batteries Included” • Default DOM(s):

  28. “Batteries Included” • DOM(s) included by default: • bsf: maps to org.apache.bsf.util.BSFFunctions • bundleDOM: Access to the bundle and bundles installed in the workbench • bundlerDOM: Utility DOM to allow you to build/package plugins from your workspace • jface: Access to the SWTBuilder in groovy for UI work • metadata: Access to the ScriptMetadata instance that contains the information defined in the metadata header of the script

  29. “Batteries Included” • DOM(s) included by default cont'd: • monitor: Access to the IProgressMonitor the Script's Job is using. • project: Legacy DOM • resources: Legacy DOM • runnerDOM: Cool DOM that allows you to invoke other scripts in the workspace. • window: Access to the IWorkspaceWindow in the current Eclipse workbench. • workspace: Access to the IWorkspace instance representing the current Eclipse workspace.

  30. “Batteries Included” • Default Include-Bundles:

  31. “Batteries Included” • Groovy Monkey Editor: Code Completion

  32. “Batteries Included” • Groovy Monkey Editor: Popup commands

  33. “Batteries Included” • Groovy Monkey Outline View

  34. “Batteries Included” • Sharing • “A script that is kept to yourself is only useful to you.” -- James E. Ervin from this presentation

  35. Future Plans • Add Jython engine with support for Include and Include-Bundle keywords • Add Glimmer library for GUI work in Ruby • Integrate with Plugin Spy • Allow scripts to be packaged in bundles

  36. Monkey Resources • http://iacobus.blogspot.com/ • http://groovy.codehaus.org/Groovy+Monkey • http://sourceforge.net/projects/groovy-monkey • http://eclipse.dzone.com/news/introduction-scripting-eclipse • http://jakarta.apache.org/bsf/

  37. Questions?

More Related