Dashboard > Contrib: Sakai Groovy Shell > Home
  Contrib: Sakai Groovy Shell Log In | Signup View a printable version of the current page.  
  Home
Added by Peter A. Knoop, last edited by Thomas Amsler on Jul 08, 2008  (view change)
Labels: 

Contrib: Sakai Groovy Shell

Overview

The Sakai Groovy Shell (SGS) projects allows you to execute Groovy code within Sakai. SGS provides two ways to do this:

  1. Telnet connection to a remote Groovy shell
  2. Sakai Groovy Shell Tool, which allows you to enter and execute groovy code

Getting Started

  • SGS has the following dependencies
  • Building SGS in sakai_2-4-x
    • svn co https://source.sakaiproject.org/svn/sakai/branches/sakai_2-4-x/
      cd sakai_2-4-x
      svn co https://source.sakaiproject.org/contrib/wicket/sakai-wicket/branches/sakai_2-4-x/ sakai-wicket
      svn co https://source.sakaiproject.org/contrib/groovy/sgs/branches/sakai_2-4-x/ sgs
      maven sakai
      
  • Building SGS in sakai_2-5-x
    • svn co https://source.sakaiproject.org/svn/sakai/branches/sakai_2-5-x/
      cd sakai_2-5-x
      svn co https://source.sakaiproject.org/contrib/wicket/sakai-wicket/branches/sakai_2-5-x/ sakai-wicket
      svn co https://source.sakaiproject.org/contrib/groovy/sakai-groovy/branches/sakai_2-5-x/ sakai-groovy
      svn co https://source.sakaiproject.org/contrib/groovy/sgs/branches/sakai_2-5-x/ sgs
      edit sakai_2-5-x/pom.xml
      - adding sakai-wicket, sakai-groovy, and sgs
      mvn clean install sakai:deploy
      

Example connecting to the remote Groovy Shell via telnet

  • To access SGS, telnet to the server at the default port (6789) where Sakai and SGS are installed.
    • e.g. telnet localhost 6789
  • Note: The SGS default configuration only allows to connect from localhost. To change this, edit the SGS' component.xml file:
    • <bean id="org.sakaiproject.sgs.service.api.GroovyRemoteShellService"
      		class="org.sakaiproject.sgs.service.impl.GroovyRemoteShellServiceImpl"
      		init-method="init" destroy-method="destroy" singleton="true">
      		<property name="serviceEnabled">
      			<value>true</value>
      		</property>
      		<property name="portNumber">
      			<value>6789</value>
      		</property>
      		<property name="allowedClientIps">
      			<list>
      				<value>127.0.0.1</value>
      			</list>
      		</property>
      	</bean>
      
  • When the connection is established, you will see something like:
    • # telnet localhost 6789
      Trying 127.0.0.1...
      Connected to localhost.localdomain (127.0.0.1).
      Escape character is '^]'.
      Let's get Groovy!
      ================
      Version: 1.0 JVM: 1.5.0_13-b05
      Type 'exit' to terminate the shell
      Type 'help' for command help
      Type 'go' to execute the statements
      
  • Now you are ready to enter some Groovy code. The following is an example that lists all the users
    • groovy> import org.sakaiproject.component.cover.ComponentManager;
      groovy> userDir = ComponentManager.get('org.sakaiproject.user.api.UserDirectoryService');
      groovy> def userList = userDir.getUsers();
      groovy> userList.each { user -> out.println user.getDisplayName() }
      groovy> go
      Sakai Administrator
      Sakai Postmaster
      
      ===> null
      

Example Using the Sakai Groovy Shell Tool

  • Start Sakai
  • Add the SGS tool to the admin workspace
  • Click on the SGS tool and enter Groovy code in the text area, then click on Submit
  • All the output is written to tomcat's catalina.out file
    • First it prints the Groovy source code that you have entered and submitted
    • Then it prints any output resulting from the executed Groovy code

Development

Project Team

Lead(s): Thomas Amsler

PC-Description (Contrib: Sakai Groovy Shell)

Site running on a free Atlassian Confluence Open Source Project License granted to Sakai Foundation. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators