Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p><table class="wysiwyg-macro" data-macro-name="excerpt" data-macro-parameters="atlassian-macro-output-type=BLOCK" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2V4Y2VycHQ6YXRsYXNzaWFuLW1hY3JvLW91dHB1dC10eXBlPUJMT0NLfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>Provides a shell-like capability for handling external processes.</p></td></tr></table></p> <h2>Module Overview</h2> <p>Groosh is a Unix like shell written in Groovy. It has also been known as the Process Module but was renamed (back) when it was updated to work with Groovy 1.0.</p> <p>The current version of Groosh is 0.3.6</p> <h3>Team Members</h3> <ul> <li>Yuri Schimke - Founder and original contributor</li> <li>Alexander Egger [alexander.egger at gmail.com] - Current maintainer</li> </ul> <h2>Download</h2> <h3>Distributions</h3> <p>Source code and binary releases are available at <a href="http://kenai.com/projects/groovy-groosh">http://kenai.com/projects/groovy-groosh</a>.</p> <p>Groosh can be used via Grapes. </p> <p>Note: If Ivy (Grapes) can not download Groosh add the file </p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>grapeConfig.xml</pre></td></tr></table> <p> to your </p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>~/.groovy</pre></td></tr></table> <p> directory with the following content:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <ivysettings> <property name="ivy.checksums" value=""/> <settings defaultResolver="downloadGrapes"/> <resolvers> <chain name="downloadGrapes"> <filesystem name="cachedGrapes"> <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/> <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/> </filesystem> <!-- todo add 'endorsed groovy extensions' resolver here --> <ibiblio name="codehaus" root="http://repository.codehaus.org/" m2compatible="true"/> <ibiblio name="ibiblio" m2compatible="true"/> <ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true"/> </chain> </resolvers> </ivysettings> </pre></td></tr></table> <p>There seams to be some problem with checksums generated by Maven 2.2.1</p> <h3>Installing</h3> <p>No installation required. Groosh can be added to Groovy using Grapes.</p> <p>Try the following script to check if it worked:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>@Grapes([ @Grab(group='org.codehaus.groovy.modules',module='groosh',version='[0.3.6,)'), @GrabConfig(systemClassLoader=true) ]) import groosh.Groosh Groosh.withGroosh(this) ls() >> stdout </pre></td></tr></table> <p>Pre-requisites</p> <p>Groosh is based on Groovy 1.7.0 or higher.</p> <h2>Documentation</h2> <p>The following example shows Groosh in action:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>//Read a text file and write it to stdout @Grapes([ @Grab(group='org.codehaus.groovy.modules',module='groosh',version='[0.3.6,)'), @GrabConfig(systemClassLoader=true) ]) import groosh.Groosh Groosh.withGroosh(this) cat('test_scripts/blah.txt') >> stdout </pre></td></tr></table> <p>Another example :</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>//Count the lines of all .java files in this directory and all its subdirectories. //Write the total number of lines to stdout. @Grapes([ @Grab(group='org.codehaus.groovy.modules',module='groosh',version='[0.3.6,)'), @GrabConfig(systemClassLoader=true) ]) import groosh.Groosh Groosh.withGroosh(this) def f = find('.', '-name', '*.java', '-ls') def total = 0 def lines = grid { values,w -> def x = values[2,4,6,10] def s = x.join(' ') w.println(s) total += Integer.parseInt(values[6]) } f | lines lines >> stdout println "Total: ${total}" </pre></td></tr></table> <p>Sometimes the name of a shell command conflicts with a Groovy method (for example ''grep''). This means that</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>gsh.grep(...) </pre></td></tr></table> <p>does not execute the shell command, but the Groovy method grep(...).</p> <p>As a workaround for that you may prefix any shell command with _ this means the example above becomes</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>gsh._grep(...) </pre></td></tr></table> <p>The following example shows a more elaborate example. It uploads photos to a flickr account using the command line tool flickcurl. A photo set of this images is created and named after the current directory.</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>import static groosh.Groosh.groosh import static org.codehaus.groovy.groosh.stream.DevNull.devnull ids = [:] shell = groosh() //get all images in this folder and upload it to flickr //remember the photo id we get from flickr shell.ls().grep(~/.*jpg/).each { println "Uploading file $it to flickr" flickcurl = shell.flickcurl("upload",it,"friend","family").useError(true) id = flickcurl.grep(~/.*Photo ID.*/)[0].split(":")[1].trim() ids[it] = id println "Photo ID is: $id" } //we need to know the first photo id firstKey = ids.keySet().toList()[0] //create a set with the name of the directory we are in right now //use the id of the first photo as set cover setName = shell.pwd().text.split("/")[-1] println "Creating set: $setName" flickcurl = shell.flickcurl("photosets.create",setName,setName,ids[firstKey]).useError(true) id = flickcurl.grep(~/.*Photoset.*/)[0].split(" ")[2].trim() println "Photoset ID is: $id" //make a backup of the ids in a file for later reference println "Writing ids to a file" file = new File(shell.pwd().text.trim() + "/.flickrset") file << "Photoset:" << id << "\n" ids.each { file << it.key << ":" << it.value << "\n" } //the first photo is already part of the photo set so lets remove it ids.remove(firstKey) //add the remaining photos to the photo set ids.each { println "Adding photo to set at flickr: $it" shell.flickcurl("photosets.addPhoto",id,it.value) | devnull() } println "DONE" </pre></td></tr></table> <h2>Developers</h2> <h3>Source Control</h3> <p>The Groosh source code is available from <a href="https://svn.kenai.com/svn/groovy-groosh~subversion">https://svn.kenai.com/svn/groovy-groosh~subversion</a>.</p> <h3>Building</h3> <h4>Building with Netbeans</h4> <p>Open the Kenai project in Netbeans and run build.</p> <h4>Building without Netbeans</h4> <p>Check out the source from<br /> <a href="https://svn.kenai.com/svn/groovy-groosh~subversion">https://svn.kenai.com/svn/groovy-groosh~subversion</a></p> <p>Groosh uses Maven 2 for building. You have to have Maven 2 installed.<br /> Just execute mvn in the groosh directory groosh gets build.</p> <h3>Contributing</h3> <p>Please contact Alexander Egger [alexander.egger at gmail.com] by e-mail.</p> <h2>Community</h2> <p>For mailing lists, issue trackers, forums etc see <a href="http://kenai.com/projects/groovy-groosh">http://kenai.com/projects/groovy-groosh</a></p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced