Can I combine all Groovy sources to one script? - groovy

I have a project on Groovy, which is built with Maven. Can I somehow on build step to merge all files with a source code into a single Groovy script for delivery to the end user?

That is impossible. Another way is use evaluate:
evaluate(new File("../tools/Tools.groovy"))

Related

How to convert picocli groovy-grape script to native standalone app?

I have a made my first groovy CLI app with picocli. Now, I want it to be available for use without any JVM installed on the client machine, maybe with the use of GraalVM.
This is for an opensource project:
https://github.com/kchaitanya863/db2csv
Another easy option is to dockerize your script (read this blog about how to do it https://groovy-lang.gitlab.io/101-scripts/docker/basico-en.html)
If you want to build a linux executable you need to change your project:
convert to a gradle project (maven is also an option but gradle has a lot of plugins)
change your script to a class with a tipical main (and move it to the standard directory src/main/groovy/mypackage)
add some tasks into you build.gradle similar to these https://gitlab.com/snippets/1797638
You will need to:
statically compile your groovy script
make the args variable available after static compilation with
final String[] args = getProperty("args") as String[]
specify a reflection configuration file for the classes dynamically loaded/invoked using reflection by Groovy (this may be useful)
specify a reflection configuration file for the classes loaded/invoked using reflection by picocli. The picocli-codegen module provides a picocli.codegen.aot.graalvm.ReflectionConfigGenerator tool to generate the configuration file.
If your script has any #Grape dependencies, you may need to turn off the Grape dependency manager with -Dgroovy.grape.enabled=false and add all dependencies to the classpath manually instead
Credit: I got most of these tips from this article by Szymon Stepniak
If you want to use Graal with Groovy, check out this article:
https://e.printstacktrace.blog/graalvm-and-groovy-how-to-start/

Can I create 'shared library' in Jenkins Pipeline in other language than Groovy?

I have python script which does a REST command and processes the result. I want this script to be used by different Jenkins Pipelines, one way I found through Jenkins official documentation is to use 'Shared library' and that examples(also others example which I found online) they use the Groovy.
My question is, is it possible to create a shared lib in other language than Groovy? For ex. python?
Short answer is no. All Jenkins Pipeline execution (right now) is specialized Groovy that is executed with the Pipeline: Groovy plugin that uses the Groovy CPS library to perform the compilation and runtime transformations. The Jenkins Pipeline ecosystem is very heavily tied to Groovy. That may change in the future, but is not what worth the effort right now.
What you can do, if you really want to use Python code in a Shared Library, is to put it in the resources/ folder of the library and then load and execute it with pipeline steps. Your use case for why you want to use Python is not stated (or what problem you are trying to solve), so below is a contrived example:
In your Shared Library: resources/com/mkobit/sharedlib/my_file.py
#!/usr/bin/env python
print("Hello")
Shared Library Groovy global variable: vars/mkobitVar.groovy
def runMyPython() {
final pythonContent = libraryResource('com/mkobit/sharedlib/my_file.py')
// There are definitely better ways to do this without having to write to the consumer's workspace
writeFile(file: 'my_file.py', text: pythonContent)
sh('chmod +x my_file.py && ./my_file.py')
}
In a consumer
#Library('mkobitLib') _
node('python') {
mkobitVar.runMyPython()
}

Reusing the groovy code in multiple Groovy Script test steps of SoapUI

I created functions(methods)in step1 using groovy in soapUI(open source) and calling in step2, it is not getting called, It is getting called only to that step1. I want to make those functions as global. can any one suggest me how to do that?
In order to achieve, what you are looking for is, to do the following:
Create classes (either in groovy or java of your preferred language)
Add the reusable methods into those classes
Compile the classes and create jar file
Copy the jar under SOAPUI_HOME/bin/ext directory
Restart the soapui tool
Now you should be able to call the reusable method from any of your project /test suite / test case/ test step.
Hope this is useful.

How reuse groovy scripts in soapui project?

Suppose I write a groovy function. Is it possible to store it to some teststep or another place in soapui project and include it with import in other groovy test steps?
SoapUI offers three options:
You can use the script library, where you store all your scripts in a separate directory and just call the classes.
You can use the run testcase step, where you store your script as a test which you can call from any other test.
You can compile your script into a jar, place it in $SOAPUI_HOME/bin/ext, and then call the classes inside your jar.
Note that the first two options are -Pro only features!

StringUtils for ant build files?

I am looking for some util methods for strings manipulation. Eg. split a version into its major.minor.bugfix parts:
1.0.2
major=1
minor=0
bugfix=2
I have looked at:
http://www.docjar.com/docs/api/org/apache/tools/ant/util/StringUtils.html
which is located in my C:\apache-ant-1.8.2\lib\ant.jar
but how do I use eg. the plit method in my build.xml file?
Here its done using groovy:
http://www.coderanch.com/t/431213/tools/Ant-Split-string-assign-property
But is there no "official" ant jar/extensions that contain this basic kind of string manipulation tasks that can be called in my build.xml file?
See Ant Addon Flaka, it provides some functions for string manipulation,
some examples here.
The answer to your problem is the example :
Question : Given is an ant property which has value of the type 1.0.0.123
How to extract the value after the last dot, in this case that would be '123' ?
Solution : use the split function with index
Alternatively use Groovy's Ant task or script task with groovy/jruby/beanshell..

Resources