Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

First, there is a new metadata keyword called LANG, which as is implied, determines what scripting language you wish to use. Here is an example of an Groovy Monkey base example ported to Groovy:

Code Block
borderStylesolid
titleFindSystemPrints_groovy.gm
borderStylesolid
/*
 * Menu: Find System Prints > Groovy
 * Kudos: Bjorn Freeman-Benson & Ward Cunningham & James E. Ervin
 * LANG: Groovy
 * Job: UIJob
 * License: EPL 1.0
 */

def files = resources.filesMatching(".*\\.java")
for( file in files )
{
    file.removeMyTasks( metadata.path() )
    for( line in file.lines )
    {
        if( line.string.trim().contains( 'System.out.print' ) )
        {
            line.addMyTask( metadata.path(), line.string.trim() )
        }
    }
}
window.getActivePage().showView( 'org.eclipse.ui.views.TaskList' )

...

Here is an example of a script, copied from the examples given in Groovy-SWT, ported into Groovy Monkey. The Groovy-SWT DOM is now included by default when you have the net.sf.groovyMonkey.groovy fragment installed. The net.sf.groovyMonkey.groovy fragment contains Groovy Monkey's support for the Groovy language.

Code Block
borderStylesolid
titleSWTTest.gm
borderStylesolid
/*
 * Menu: Test SWT
 * Kudos: James E. Ervin
 * License: EPL 1.0
 * Job: UIJob
 */

def subapp = jface.shell( window.getShell() )
{
    gridLayout()
    group( text:'Groovy SWT', background:[255, 255, 255] )
    {
        gridLayout()
        label( text:"groove fun !" ,background:[255, 255, 255] )
        label( text:"Email: ckl@dacelo.nl", background:[255, 255, 255] )
    }
}
subapp.pack()
subapp.open()

Here is an example of a script that uses the Launch Configuration Manager DOM along with the JFace/SWT DOM and the Console output DOM. It prints out the list of all your available launch configurations and allows you to select which ones you wish to string together.

Code Block
borderStylesolid
titleLaunchManager.gm
borderStylesolid
/*
 * Menu: Launch Manager
 * Kudos: James E. Ervin
 * License: EPL 1.0
 * LANG: Groovy
 * Job: UIJob
 * DOM: http://groovy-monkey.sourceforge.net/update/net.sf.groovyMonkey.dom
 */
import org.eclipse.swt.SWT

def configurations = launchManager.manager().getLaunchConfigurations()
def selected = []
shell = jface.shell( text: 'Select desired configurations:', location: [ 100, 100 ] )
{
    gridLayout()
	table = table( toolTipText: "Select configurations to execute", style:'check,border,v_scroll,h_scroll,single' )
	{
        gridLayout()
        gridData( horizontalAlignment: SWT.FILL, verticalAlignment: SWT.FILL, grabExcessHorizontalSpace: true,
                  grabExcessVerticalSpace: true, heightHint: 400 )
		for( config in configurations )
		{
			tableItem().setText( "${config.name}" )
		}
	}
    composite()
    {
       	gridLayout( numColumns: 2 )
       	button( text: 'run', background: [ 0, 255, 255 ] )
       	{
       	    onEvent( type: 'Selection', closure:
       	    {
       	        for( item in table.items )
       	        {
       	            if( !item.checked )
       	                continue
       	            selected.add( item.text )
       	        }
       	        shell.close()
       	    } )
       	 }
        button( text: "cancel", background: [ 0, 255, 255 ] )
        {
            onEvent( type: 'Selection', closure:
       	    {
				selected.clear()
       	        shell.close()
       	    } )
        }
    }
}
shell.pack()
shell.open()
while( !shell.isDisposed() )
{
    if( !shell.display.readAndDispatch() )
		shell.display.sleep()
}
selected.each
{
	out.println "${it}"
}

launchManager.launch( 'launch test', selected )