Questions tagged [groovyshell]

The term groovyshell refers to both: 1. A command line interactive groovy shell, usually invoked as "groovysh" 2. One of the primary classes (groovy.lang.GroovyShell) in the Groovy language API for dynamically compiling and invoking groovy scripts from their raw source state.

The term groovyshell refers to both:

  1. A command line interactive groovy shell, usually invoked as "groovysh"
  2. One of the primary classes groovy.lang.GroovyShell) in the Groovy language API for dynamically compiling and invoking groovy scripts from their raw source state.

Groovysh

A command line groovy interpreter, well documented in the official documentation.

GroovyShell (the class)

groovy.lang.GroovyShell is one of the core classes of the Groovy runtime. It provides support for interpreting, evaluating and compiling groovy scripts in their raw source state. The base support for source read targets are:

  1. Java Files
  2. Java Input Streams
  3. Java Readers
  4. Java Strings
  5. Groovy GroovyCodeSources (A special source construct that isolates the contained source and generated byte code)
247 questions
6
votes
1 answer

groovy beginner- how to remove a variable from memory in groovy shell

I could not see any method to remove a variable from memory in Groovy shell... is this possible? How do I do this? I can see methods for doings this in Beanshell and Javascript(Rhino) but not in Groovy.
Arvind
  • 6,404
  • 20
  • 94
  • 143
5
votes
3 answers

groovy + shell : Escaping characters

I am using Jenkins Pipeline using Groovy sandbox. And i am trying to run a shell script in a groovy sh function. The original shell script is sed -i 's/sometext/'"${othertext}"'/' filename I am trying to replace a particular text with other text…
Siddarth
  • 351
  • 2
  • 6
  • 20
5
votes
1 answer

GroovyShell in Java8 : memory leak / duplicated classes [src code + load test provided]

We have a memory leak caused by GroovyShell/ Groovy scripts (see GroovyEvaluator code at the end). Main problems are (copy-paste from MAT analyser): The class "java.beans.ThreadGroupContext", loaded by "", occupies…
Patrycja K
  • 731
  • 7
  • 14
5
votes
2 answers

How to add imports to groovysh on startup?

I'm working on a project where I'd like users to experiment with Java classes on Groovysh. I'd like to make it convenient for them and want to import certain packages by default, when groovysh starts up so that users would not have to re-type the…
ipolevoy
  • 5,432
  • 2
  • 31
  • 46
5
votes
2 answers

Java + Groovy Script - Inheritance

I have a problem with inheritance in Groovy script. I want my Groovy script to inherit methods from Java class that I invoke this script. For example, I have something like this: public class SimpleTest extends TestCase { public void test(){ …
mhuta
  • 49
  • 1
  • 5
5
votes
1 answer

Why groovyConsole supports `def name = "Neo"` while groovysh does not

Following is 2 lines of code: def name = "Neo" println name If I execute it in groovysh, I will get Unknown property: name error. If I execute it in groovyConsole, everything goes on well.
Neo
  • 2,196
  • 5
  • 32
  • 58
5
votes
1 answer

Use groovy category in groovy shell

I am working under some DSL using Groovy categories and I would like to find a way to use my DSL with groovy shell without explicitly writing use(MyCategory){ myObject.doSomething() } for each command. For example, suppose I have the following toy…
Stanislav Poslavsky
  • 2,398
  • 2
  • 24
  • 36
5
votes
1 answer

GroovyClassLoader and imports

I am using a GroovyClassLoader in my Java class to parse a certain (ideally complex) groovy file (to be executed in the next step): Call in MyClass.java final Class parsedClass = groovyClassLoader.parseClass(groovyFile); Knowing that: Groovy files…
Antonio Acevedo
  • 1,480
  • 3
  • 21
  • 39
5
votes
4 answers

How to check whether the input is a number or string by using isNan() in groovy

Hello i am a beginner to groovy i am cofused how to check whether the given input is a number or not i tried the following def a= ' 12.571245ERROR' if(a.isNan()==0) { println("not a number") } else { println("number") } Kindly help me how to use…
shashank
  • 379
  • 5
  • 6
  • 15
5
votes
1 answer

GroovyShell: embedded execution

I'm trying to embed groovy into a large Java application. The Java application should load some utility Groovy scripts at startup. The application should then run other scripts multiple times. There is also a need to enter some code at a GUI and…
Ayman
  • 11,265
  • 16
  • 66
  • 92
4
votes
1 answer

Stopping the execution of a Groovy script

I am embeding Groovy runtime in my code and I would like to have the ability to interrupt it. I don't have control of the scripts that are going to run. I read about groovy.transform.ThreadInterrupt to handle thread interruptions but for some reason…
Clueless
  • 81
  • 1
  • 1
  • 4
4
votes
2 answers

Solving groovy module version conflict

How to solve groovy module (groovy-xml) version conflict? The version 2.4.12 is what my currently project depends on, however, groovysh somehow preload a higher version: $ groovysh java.lang.reflect.InvocationTargetException at…
xpt
  • 20,363
  • 37
  • 127
  • 216
4
votes
1 answer

Find/Filter the lists with a specific key-value pair from a JSON ARRAY (list of maps)

I have a JSON array (list of maps) similar to: def listOfMap = [[TESTCASE:1, METHOD:'CLICK', RESULT:'PASS'], [TESTCASE:2, METHOD:'CLICK', RESULT:'FAIL'], [TESTCASE:3, METHOD:'CLICK', RESULT:'FAIL'], [TESTCASE:4,…
user1523153
  • 139
  • 3
  • 10
4
votes
1 answer

Are there any other Grash like enhanced Groovy shells?

Grash seems to be an interesting approach to taking groovy to the next step in terms of connectivity and monitoring of java applications. However, it seems to never have taken off and remained a toy. Has any done something similar, how did it work…
mP.
  • 18,002
  • 10
  • 71
  • 105
4
votes
1 answer

Interrupt processing in groovy shell

In groovy shell if you type this: $ groovysh Groovy Shell (2.3.7, JVM: 1.7.0_11) Type ':help' or ':h' for…
levant pied
  • 3,886
  • 5
  • 37
  • 56
1
2
3
16 17