[ 
https://issues.apache.org/jira/browse/KARAF-5202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16046729#comment-16046729
 ] 

Denis Jouvin commented on KARAF-5202:
-------------------------------------

Exemple session 3, to illustrate how to pass variables from Karaf console 
session to Groovy session, and vice versa.

Enter Groovy interactive session, passing the current bundle list as a variable 
(implicitly then explicitly).
Then get the number of bundles who's name start with {{org.apache}} and access 
it back from the Karaf session.

{noformat}
ServiceMix-5.0.0:7412003A@root> bundles = ($.context bundles)
(...)
ServiceMix-5.0.0:7412003A@root> groovy
ggroovy:000> karafContext*.key
===> [TERM, karaf.lastException, APPLICATION, LINES, _GROOVYSH_LOADER, SCOPE, 
PROMPT, bundles, ARGUMENTS_LIST, COLUMNS, USER, cluster]
groovy:000> karafContext.bundles.length
===> 282
groovy:000> :x
0
ServiceMix-5.0.0:7412003A@root> groovy -v bundles
groovy:000> bundles.length
===> 282
groovy:000> n = bundles.count { it.symbolicName.startsWith 'org.apache' }
===> 182
groovy:000> :x
0
ServiceMix-5.0.0:7412003A@root> $groovyContext get n
182
{noformat}


> Groovy and groovysh integration into Karaf console
> --------------------------------------------------
>
>                 Key: KARAF-5202
>                 URL: https://issues.apache.org/jira/browse/KARAF-5202
>             Project: Karaf
>          Issue Type: New Feature
>          Components: karaf-shell
>            Reporter: Denis Jouvin
>            Assignee: Jean-Baptiste Onofré
>            Priority: Minor
>              Labels: Groovy, Groovysh, Karaf, ShellCommands
>
> The idea is to integrate Groovy into Karaf as an alternative scripting and/or 
> interactive shell language. Since Groovysh also uses JLine, integration is 
> quite easy (pass the current Jline console/session instance to Groovysh at 
> construction time). There are some class loading issues though since Groovy 
> uses sometimes the TCCL even when we instruct it to use a given class loader 
> (I opened a Groovy JIRA issue about that).
> The Groovysh shell then would allow to get OSGi service reference or 
> Blueprint/Spring context references, or execute Karaf commands. Groovysh has 
> a very nice command completion feature that enable to discover any objet 
> (including OSGi service instance) API at runtime, which makes it very easy to 
> play with in a dynamic environment like Karaf. In addition, its native 
> closures and set operations, and very concise syntaxe, facilitates its use as 
> a shell replacement.
> This open nice possibilites like exploratory programming on a live running 
> Karaf instance, scripting, tests or analysis, etc.
> Another common use case is to modify a not yet parameterized value in a 
> Blueprint or Spring context at runtime (you can browse or access the 
> Blueprint context components, and reinstaciate them or inject properties).



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to