groovy - Error in script to count the number of occurrences

I am entirely new to Groovy scripting and need help.I tried the following script to count the number of lines that has a specific text occurrence. Error observed: groovy.lang.MissingMethodException: No signature of method: is applicable for argument types: (Hemanth_v1$_run_closure2) values: [Hemanth_v1$_run_closure2@10f39d0]Possible solutions: eachLine(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(java.lang.String, int, g...Read more

How to extract string between two delimiters in groovy?

Currently I have string line feature/USRSTORY-447-testing-rest-apiI want to extract only USRSTORY-447.Currently I have a line written which works and I get the output below:str.substring(str.indexOf("/") + 1, str.indexOf("-") + 4);USRSTORY-447But in future when the number count after USRSTORY - has more than 3 digits then it will only fetch the first 3 of those after ´-` Can anyone help how to resolve this so that there is no need to change the above line of code every time?...Read more

Run X number of test case per batch on groovy scipt SoapUI

I have this code which runs all test case inside the test suite concurrently:import testRunner.testCase.testSuite.getRunType()testRunner.testCase.testSuite.setRunType(TestSuiteRunType.PARALLEL)assert testRunner.testCase.testSuite.getRunType() == TestSuiteRunType.PARALLELbut it seems that the application can't handle too much test case, question is: Is it possible to run test case per batch? like for example I have 300 test cases and it will get only 10 test cases to run concu...Read more

Is groovy native to JVM or ported to JVM?

I know Jython and JRuby is ported to JVM, and scala/Clojure is native to JVM, what about Groovy? Groovy looks like a dynamic language, I guess it is ported, but it seems it could also be compiled. For those language native to JVM such as Scala, is that some tool to decompile the code to the source code?...Read more

Understanding the groovy syntax in a gradle task definition

I am new to Gradle and Groovy and trying to understand what is happening at the level of groovy when a gradle task is defined. task hello { println "configuring task hello" doLast { println "hello there" }}From reading the "Gradle In Action" book I know that the task hello {} is a really a call to the task() method of the groovy Project interface. On page 77 it shows that there are 4 methods called task on the Project interfacetask(args: Map<String,?>, name:String)task(args: Map<String,?>, name:String, c:Closure)task(n...Read more

Creating a Jenkins environment variable using Groovy

I think this is another simple question but I couldn't get any of the web solutions to work. My project takes in a version number. Each number can be separated by a '.' or a '_'. I want a variable that only displays the first two numbers. I tried writing a groovy script that creates a Jenkins environment variable.I want to take the first two digits instead of the entire string. //Get the version parameterdef env = System.getenv()def version = env['currentversion']def m = version =~/\d{1,2}/env = ['miniVersion':m[0].m[1]]Am I doing this cor...Read more

Groovy: what's the purpose of "def" in "def x = 0"?

In the following piece of code (taken from the Groovy Semantics Manual page), why prefix the assignment with the keyword def?def x = 0def y = 5while ( y-- > 0 ) { println "" + x + " " + y x++}assert x == 5The def keyword can be removed, and this snippet would produce the same results. So what's the effect of the keyword def ?...Read more

Groovy executing shell commands

Groovy adds the execute method to String to make executing shells fairly easy;println "ls".execute().textbut if an error happens, then there is no resulting output. Is there an easy way to get both the standard error and standard out? (other than creating a bunch of code to; create two threads to read both inputstreams, then using a parent stream to wait for them to complete then convert the strings back to text?)It would be nice to have something like; def x = shellDo("ls /tmp/NoFile") println "out: ${x.out} err:${x.err}"...Read more

nsxmlparser - Groovy xmlSlurper to remove empty fields

I have a code that is removing empty fields using XMLParser, I wonder if could you help me to have a version of the same using xmlSlurper instead. The code is below:File doc = new File("C:/Temp/input.xml")def text = new String(doc.bytes, "UTF-8")def xml = new XmlParser().parseText( text )xml.depthFirst().each { if( it.children().size() == 0 ) { it.parent().remove( it ) }}def file = new File("C:/Temp/out/test.xml") def xmltext = XmlUtil.serialize(xml)file.write(xmltext,'UTF-8')So far, my best guess using the XMLSlurper is, but it isn't w...Read more

groovy.lang.MissingMethodException: No signature of method (How to use relative path with DOS commands in Groovy?)

I'm trying to run a simple DOS command (pushed with relative path) in Groovy. "pfxFileFolde" is defined at test suite level as "${projector}/testfolder". def pfxFileFolder = context.expand('${#TestCase#pfxFileFolder}')String command = "cmd /c pushd "pfxFileFolder"";Process child = Runtime.getRuntime().exec(command);I got error: groovy.lang.MissingMethodException: No signature of method: Script70.cmd /c pushd () is applicable for argument types: (java.lang.String) values: [/my/relative/path/testfolder] error at line: 37I'm pretty new to JAVA, G...Read more