Download - Introduction to Groovy Monkey
![Page 1: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/1.jpg)
Groovy Monkey
http://groovy.codehaus.org/Groovy+Monkey
![Page 2: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/2.jpg)
About MeJava Developer since 1999
Eclipse Plugin Developer since 2002Groovy Eclipse committer since 2005Author of Groovy Monkey
![Page 3: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/3.jpg)
About Me
“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
![Page 4: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/4.jpg)
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
![Page 5: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/5.jpg)
Why Groovy Monkey?
To be more productive with Eclipse, thats why.
![Page 6: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/6.jpg)
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
![Page 7: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/7.jpg)
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?
![Page 8: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/8.jpg)
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
![Page 9: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/9.jpg)
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
![Page 10: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/10.jpg)
What is Groovy Monkey? Bean Scripting framework
http://jakarta.apache.org/bsf/
Open source project that predates javax.script in Java 6.0
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)
![Page 11: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/11.jpg)
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
![Page 12: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/12.jpg)
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
![Page 13: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/13.jpg)
![Page 14: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/14.jpg)
Show me: How to install If not included in your Eclipse distribution, goto
the update site:
http://groovy-monkey.sourceforge.net/update
![Page 15: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/15.jpg)
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
![Page 16: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/16.jpg)
Show Me: A Script: Results
The amazing results of this script is: Drum Roll please......
Note: Wait for enthusiastic applause from audience
![Page 17: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/17.jpg)
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.
![Page 18: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/18.jpg)
Script Anatomy: Tags
Menu Determines where in the Monkey Menu the
script can be invoked/edited
![Page 19: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/19.jpg)
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**
![Page 20: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/20.jpg)
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.
![Page 21: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/21.jpg)
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
![Page 22: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/22.jpg)
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
![Page 23: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/23.jpg)
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.
![Page 24: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/24.jpg)
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
![Page 25: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/25.jpg)
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
![Page 26: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/26.jpg)
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
![Page 27: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/27.jpg)
“Batteries Included”
Groovy Monkey includes several things to hopefully simplify script writing:
Default DOM(s)
Default Bundles
Editor
Outline View
Sharing
![Page 28: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/28.jpg)
“Batteries Included”
Default DOM(s):
![Page 29: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/29.jpg)
“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
![Page 30: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/30.jpg)
“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.
![Page 31: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/31.jpg)
“Batteries Included”
Default Include-Bundles:
![Page 32: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/32.jpg)
“Batteries Included”
Groovy Monkey Editor: Code Completion
![Page 33: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/33.jpg)
“Batteries Included”
Groovy Monkey Editor: Popup commands
![Page 34: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/34.jpg)
“Batteries Included” Groovy Monkey Outline View
![Page 35: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/35.jpg)
“Batteries Included”
Sharing “A script that is kept to yourself is only useful
to you.” -- James E. Ervin from this presentation
![Page 36: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/36.jpg)
Future Plans Add Jython engine with support for
Include and Include-Bundle keywords
Add Glimmer library for GUI work in Ruby
Integrate with the new Plugin Spy coming in Eclipse 3.4
Allow scripts to be packaged in bundles
![Page 37: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/37.jpg)
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/
![Page 38: Introduction to Groovy Monkey](https://reader035.vdocuments.us/reader035/viewer/2022062319/55516274b4c9059f768b4fd8/html5/thumbnails/38.jpg)
Questions?