groovy monkey

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

Upload: samara

Post on 07-Jan-2016

33 views

Category:

Documents


0 download

DESCRIPTION

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, - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Groovy Monkey

Groovy Monkey

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

Page 2: Groovy Monkey

About MeJava Developer since 1999

Eclipse Plugin Developer since 2002Groovy Eclipse committer since 2005Author of Groovy Monkey

Page 3: 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

Page 4: Groovy Monkey

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: Groovy Monkey

Why Groovy Monkey?

To be more productive with Eclipse, thats why.

Page 6: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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)

Page 11: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey
Page 14: Groovy Monkey

Show me: How to install If not included in your Eclipse distribution, goto

the update site:

http://groovy-monkey.sourceforge.net/update

Page 15: Groovy Monkey

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: Groovy Monkey

Show Me: A Script: Results

The amazing results of this script is: Drum Roll please......

Note: Wait for enthusiastic applause from audience

Page 17: Groovy Monkey

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: Groovy Monkey

Script Anatomy: Tags

Menu Determines where in the Monkey Menu the

script can be invoked/edited

Page 19: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

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: Groovy Monkey

“Batteries Included”

Groovy Monkey includes several things to hopefully simplify script writing:

Default DOM(s)

Default Bundles

Editor

Outline View

Sharing

Page 28: Groovy Monkey

“Batteries Included”

Default DOM(s):

Page 29: Groovy Monkey

“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: Groovy Monkey

“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: Groovy Monkey

“Batteries Included”

Default Include-Bundles:

Page 32: Groovy Monkey

“Batteries Included”

Groovy Monkey Editor: Code Completion

Page 33: Groovy Monkey

“Batteries Included”

Groovy Monkey Editor: Popup commands

Page 34: Groovy Monkey

“Batteries Included” Groovy Monkey Outline View

Page 35: Groovy Monkey

“Batteries Included”

Sharing “A script that is kept to yourself is only useful

to you.” -- James E. Ervin from this presentation

Page 36: Groovy Monkey

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

Page 37: Groovy Monkey

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: Groovy Monkey

Questions?