groovyshell

groovy + shell : Escaping characters

天大地大妈咪最大 提交于 2019-12-11 07:58:32
问题 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 (taken dynamically). The script works fine when executed directly. But I want to use it in jenkins groovy sh function. sh(script: '<above shell script>', returnStdout:false) But there is a problem of escaping characters. I tried this way of escaping

groovy script Error

拥有回忆 提交于 2019-12-11 07:12:46
问题 I am newbie to groovy. In command prompt (I am not using any IDE), I typed following : (No Problem with environment variables settings please) groovy -n -e "println line.toLong()" data.txt Error : Caught: java.io.IOException: Invalid argument java.io.IOException: Invalid argument data.txt is there in that directory (verified using TAB key) Not sure why its throwing Error ???? [data.txt contains raw data in following format] 1 2 3 4 回答1: I tried to duplicate the problem with Groovy 2.3.6 and

Grails shell not seeing domain objects

一曲冷凌霜 提交于 2019-12-07 02:39:48
问题 I'm a grails newbie (and a groovy newbie), and I'm working through some grails tutorials. As a new user, the grails shell is a really useful little tool for me, but I can't figure out how to make it see my classes and objects. Here's what I'm trying: % grails create-app test % cd test % grails create-domain-class com.test.TestObj % grails shell groovy:000> new TestObj() ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, groovysh_evaluate: 2: unable to

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

佐手、 提交于 2019-12-03 14:41:10
问题 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 "<system class loader>", occupies 807,406,960 (33.38%) bytes. and: 16 instances of "org.codehaus.groovy.reflection.ClassInfo$ClassInfoSet$Segment", loaded by "sun.misc.Launcher$AppClassLoader @ 0x7004e9c80" occupy 1,510,256,544 (62.44%) bytes We're using Groovy 2.3.11 and Java8 (1.8.0_25 to be

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

北城以北 提交于 2019-12-03 03:45:40
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 "<system class loader>", occupies 807,406,960 (33.38%) bytes. and: 16 instances of "org.codehaus.groovy.reflection.ClassInfo$ClassInfoSet$Segment", loaded by "sun.misc.Launcher$AppClassLoader @ 0x7004e9c80" occupy 1,510,256,544 (62.44%) bytes We're using Groovy 2.3.11 and Java8 (1.8.0_25 to be exact) . Upgrading to Groovy 2.4.6 doesn't solve the problem. Just improves memory usage a little bit ,

Stopping the execution of a Groovy script

这一生的挚爱 提交于 2019-12-01 00:13:44
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 this code below isn't working as intended. It's actually waiting 10000 ms instead of the 1000 where it should get interrupted. Any ideas? Thank you. import groovy.lang.Binding; import groovy.lang.GroovyShell; import groovy.transform.ThreadInterrupt; import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control

MissingPropertyException in groovysh

↘锁芯ラ 提交于 2019-11-29 06:29:09
I run groovysh , and type the following code: groovy:000> String s = "Hello" ===> Hello groovy:000> s ERROR groovy.lang.MissingPropertyException: No such property: s for class: groovysh_evaluate at groovysh_evaluate.run (groovysh_evaluate:2) ... groovy:000> How to access the s here? (If I change String s = "Hello" to s = "Hello" , I can access it. But I want to know how to access it in the example) UPDATE I want to use String s = "Hello" to define a variable because I want to declare the type of it. For example, if I write: Date date = [] The date will be a java.util.Date . But if I write:

Strange variable scoping behavior in Jenkinsfile

帅比萌擦擦* 提交于 2019-11-29 03:07:54
问题 When I run the below Jenkins pipeline script: def some_var = "some value" def pr() { def another_var = "another " + some_var echo "${another_var}" } pipeline { agent any stages { stage ("Run") { steps { pr() } } } } I get this error: groovy.lang.MissingPropertyException: No such property: some_var for class: groovy.lang.Binding If the def is removed from some_var , it works fine. Could someone explain the scoping rules that cause this behavior? 回答1: TL;DR variables defined with def in the

MissingPropertyException in groovysh

别说谁变了你拦得住时间么 提交于 2019-11-27 23:51:29
问题 I run groovysh , and type the following code: groovy:000> String s = "Hello" ===> Hello groovy:000> s ERROR groovy.lang.MissingPropertyException: No such property: s for class: groovysh_evaluate at groovysh_evaluate.run (groovysh_evaluate:2) ... groovy:000> How to access the s here? (If I change String s = "Hello" to s = "Hello" , I can access it. But I want to know how to access it in the example) UPDATE I want to use String s = "Hello" to define a variable because I want to declare the type

Groovy Shell warning “Could not open/create prefs root node …”

﹥>﹥吖頭↗ 提交于 2019-11-26 14:55:21
I tried to open the Groovy Shell ( groovysh ) on Windows 8 and got the following output: java.util.prefs.WindowsPreferences <init> WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5. After printing the above message the shell started as expected. MKorsch Dennis answer is correct. However I would like to explain the solution in a bit more detailed way (for Windows User): Go into your Start Menu and type regedit into the search field. Navigate to path HKEY_LOCAL_MACHINE\Software\JavaSoft (Windows 10 seems