380 likes | 547 Views
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,
E N D
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, I'm a user...” -- paraphrased from the founder of “Hair Club for Men” -- James E. Ervin About Me
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
Why Groovy Monkey? • To be more productive with Eclipse, thats why.
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
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?
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
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
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)
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
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
Show me: How to install • If not included in your Eclipse distribution, goto the update site: • http://groovy-monkey.sourceforge.net/update
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
Show Me: A Script: Results • The amazing results of this script is: • Drum Roll please...... Note: Wait for enthusiastic applause from audience
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.
Script Anatomy: Tags • Menu • Determines where in the Monkey Menu the script can be invoked/edited
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**
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.
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
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
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.
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
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
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
“Batteries Included” • Groovy Monkey includes several things to hopefully simplify script writing: • Default DOM(s) • Default Bundles • Editor • Outline View • Sharing
“Batteries Included” • Default DOM(s):
“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
“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.
“Batteries Included” • Default Include-Bundles:
“Batteries Included” • Groovy Monkey Editor: Code Completion
“Batteries Included” • Groovy Monkey Editor: Popup commands
“Batteries Included” • Groovy Monkey Outline View
“Batteries Included” • Sharing • “A script that is kept to yourself is only useful to you.” -- James E. Ervin from this presentation
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
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/