Hi all!
since we update Jenkins to V2.319 some pipelines Broke
I'm trying to run a job with eachFileRecurse()instead of traverse
I get this error:
Something went wrong: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachFileRecurse() is applicable for argument types: (java.util.LinkedHashMap, groovy.io.FileType, WorkflowScript$_find_versions_closure1) values: [[nameFilter:app_ver.*.json$, excludeNameFilter:], ...]
Possible solutions: eachFileRecurse(groovy.io.FileType, groovy.lang.Closure), eachFileRecurse(groovy.lang.Closure)
This is my code
def find_versions(dirFile, fileNamefilter, excludeFileNameFiles) {
list = []
dirFile.traverse(type: FileType.FILES, nameFilter: fileNamefilter, excludeNameFilter: excludeFileNameFiles) {
//println it.name
def data= it.eachLine { line ->
// check if the line contains version
if(line.contains('"app_ver":')){
version = line.split(':')[1].split('-')[0].substring(1)
version = version.replace('"','')
version = version.replace(' ','')
println it.name+ " -> use " + version
if(version.startsWith("v")){
list.add(version)
}
}
}
}
return list.unique()
}
Can anyone help?
Related
I need to generate FlatBuffers files from *.fbs file before the build.
So i'm using gradle.plugin.io.netifi:gradle-flatbuffers-plugin:1.0.7 to do it for me.
It works as expected for 1 task:
def generatedSourcePathJava = "$buildDir/generated/source/flatbuffers/java"
def generatedSourcePathCpp = "$buildDir/generated/source/flatbuffers/cpp"
...
task createFlatBuffersJava(type: io.netifi.flatbuffers.plugin.tasks.FlatBuffers) {
outputDir = file(generatedSourcePathJava)
language = "kotlin"
}
build.dependsOn createFlatBuffersJava
But if i add the 2nd one (to generate C++ files for JNI):
task createFlatBuffersJava(type: io.netifi.flatbuffers.plugin.tasks.FlatBuffers) {
outputDir = file(generatedSourcePathJava)
language = "kotlin"
}
task createFlatBuffersCpp(type: io.netifi.flatbuffers.plugin.tasks.FlatBuffers) {
outputDir = file(generatedSourcePathCpp)
language = "cpp"
}
assemble.dependsOn createFlatBuffersJava, createFlatBuffersCpp
Gradle build (../gradlew :engine-flatbuffers:clean :engine-flatbuffers:build) fails with the following:
What went wrong:
A problem occurred configuring project ':engine-flatbuffers'.
java.util.ConcurrentModificationException (no error message)
I think the question can be generalized to "How to add multiple tasks of the same type in Gradle?".
PS. "gradle-5.6-all"
That's a known plugin bug/feature reported at https://github.com/gregwhitaker/gradle-flatbuffers-plugin/issues/7.
It works in 1.0.5 but kotlin [argument] is sadly not supported there at that point. java works and it's compatible.
For example, if I wanted a shell script to be able to get the value of rootProject.name, how could I do this? Ideally, I'd like to invoke ./gradlew with some set of arguments and have it print the property value (and nothing else) to stdout.
For clarity, here is my Gradle wrapper version:
$ ./gradlew --version
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9-LTS)
OS: Mac OS X 10.14.4 x86_64
This is an existing task to give you an idea of the properties available:
$ ./gradlew properties
> Task :properties
------------------------------------------------------------
Root project
------------------------------------------------------------
allprojects: [root project 'myProject', project ':otherProject', ...]
...
rootDir: /path/to/rootDir
rootProject: root project 'myProject'
...
version: 2.3.0
...
Here is a custom task I've built to print out a project property
class ResolveProperties extends DefaultTask {
#Input
String prop
ResolveProperties() {
// if no --prop=<property> is provided, default to spitting out all properties
prop = "properties"
}
#Option(option = 'prop', description = 'Set the property to be evaluated for the project.')
void setProp(final String prop) {
this.prop = prop
}
#TaskAction
void resolveProp() {
List<String> propPath = this.prop.tokenize('.')
int n = propPath.size()
def currentProp = project
propPath.eachWithIndex { p, i ->
if(currentProp.hasProperty(p)) {
currentProp = currentProp.property(p)
}
else {
throw new GradleException("failed to resolve property: ${this.prop}")
}
}
println "${this.prop} -> ${currentProp}"
}
}
task resolveProperties(type: ResolveProperties)
And this is how I use my custom task with a --prop parameter (indicated by #Option(option = 'prop'. I'm using the -q (quiet) Gradle option to suppress some of the extra output.
$ ./gradlew -q resolveProperties --prop=rootProject.name
rootProject.name -> onestop
resolveProperties took 0 seconds
$ ./gradlew -q resolveProperties --prop=rootProject.version
rootProject.version -> 2.3.0
resolveProperties took 0 seconds
$ ./gradlew -q resolveProperties --prop=rootProject.group
rootProject.group -> org.cedar.onestop
resolveProperties took 0 seconds
Because we are throwing a GradleException when we can't find the property, in Bash you can check the return code of the command to know when to parse out the value. The formatting of a successful output is up to you and you could make it easily parsed.
$ ./gradlew -q resolveProperties --prop=does.not.exist
resolveProperties took 0 seconds
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/elliott/Documents/GitHub/onestop/build.gradle' line: 259
* What went wrong:
Execution failed for task ':resolveProperties'.
> failed to resolve property: does.not.exist
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
In case of a failure like the one above, we get a non-zero return code in Bash, and we know we don't need to try and parse out the value:
$ echo $?
1
Unfortunately, I don't know a simple way in Gradle to only give the value you are concerned with to stdout (prevent some parsing), but this gets you most of the way there with some flexibility.
If it is still relevant ...
Possible Solution A: print value of "rootProject.name" on cmd line
Add task in build.gradle:
/**
* Prints value of property "rootProject.name" to stdout.
*
* Usage: ./gradlew -q printRootProjectName
*/
task printRootProjectName {
doLast {
println(project.findProperty('rootProject').name)
}
}
Possible Solution B: print a property value as provided on cmd line
Add task in build.gradle:
/**
* Print value of property provided in "-Pprop" on command line to stdout.
*
* Usage Example: ./gradlew -q printProperty -Pprop=rootProject.name
*/
task printProperty {
doLast {
// get the "property name" in question from commandline:
String prop = project.findProperty('prop')
if (prop == null) {
return // or use println ...
}
// treat as property name:
Object theProperty = project.findProperty(prop)
if (null == theProperty) {
// try to handle provided information as "nested property"
List < String > thePropPath = prop.split('\\.').toList()
theProperty = project.findProperty(thePropPath.head())
// aux. closure to travel "property path"
def pp = {
s,
t - >
if (s != null && s.hasProperty(t).is(true)) {
return s.property(t)
}
return null
}
thePropPath.tail().each {
item - >
theProperty = pp(theProperty, item)
}
}
println(theProperty ? : "") // or print "null" ...
}
}
I have a below task
task showLog1 <<{
def grgit = org.ajoberstar.grgit.Grgit.open(dir: '')
def log = grgit.log {
range '$tag1','$tag2'
}
}
Now I was using my tag names after the range but I want to pass this through Command Line. I have gone through few links like http://mrhaki.blogspot.in/2010/10/gradle-goodness-pass-command-line.html and I am passing from cli using -p like below:
gradlew showLog1 -ptag1=tag_one -ptag2=tag_two
But this doesn't give me the log. Anything that I am missing
Try a capital "P".
Like so: -Ptag1=tag_one -Ptag2=tag_two
Its working, I need to write my task like below:
build.gradle
def grgit = org.ajoberstar.grgit.Grgit.open(dir: "")
def log = grgit.log {
range "$tag1","$tag2"
}
Then I need to execute it like this :
Command Line
gradlew showLog1 -Ptag1=tag_one -project-prop tag2=tag_two
If you pass your vars via -P option as format -PvarName=xxx. varName became a property of you project object in buildScript
if (project.hasProperty('varName')) { //check varName is set or not
println "varName set to:" + varName; //use the varName directly.
}
I have written the following validation Rule:
#Check
def checkDeclarationIsNotReferenceToItself(Declaration dec) {
if(dec.decCon.singleContent.reference == null && !dec.decCon.nextCon.isEmpty) {
//only proceed if it is a reference
return
}
var name = dec.name
if(dec.decCon.singleContent.reference.name == name) {
//only if the declaration is a self-reference without further actions
var warningMsg = "The declaration '" + name + "' is a reference to itself"
warning(warningMsg,
SQFPackage.eINSTANCE.declaration_DecCon,
SELFREFERENCE)
}
}
And then I have written an test case for it looking as following:
#Test
def void checkDeclarationIsNotReferenceToItselfTest() {
'''
test = 3;
test = test;
'''.parse.assertWarning(SQFPackage.eINSTANCE.decContent,
SQFValidator.SELFREFERENCE,
"The declaration 'test' is a reference to itself")
}
But when I run JUnit it reports an error:
Expected WARNING 'raven.sqf.SelfReference' on DecContent at [-1:-1] but got
WARNING (raven.sqf.SelfReference) 'The declaration 'test' is a reference to itself' on Declaration, offset 18, length 4
I don't understand this because it actually expects exactly that error message (As far as I see it)
Anyone has an idea why it doesn't work?
Greetings Krzmbrzl
looks like the way you create the warning and test the validation do not match together
warning(warningMsg,
SQFPackage.eINSTANCE.declaration_DecCon,
SELFREFERENCE)
creates the warning on a Declaration
.assertWarning(SQFPackage.eINSTANCE.decContent,
SQFValidator.SELFREFERENCE,
"The declaration 'test' is a reference to itself")
tests for a DecContent
I am on page 78 of the gradle userguide: Example 14.5. Configuring arbitrary objects using a script.
I have copied all of the code in the example:
build.gradle
task configure << {
pos = java.text.FieldPosition( ) new 10
// Apply the script
apply from: 'other.gradle', to: pos
println pos.beginIndex
println pos.endIndex
}
other.gradle
beginIndex = 1;
endIndex = 5;
Output of gradle -q configure
D:\Gradle\ThisAndThat>gradle -q configure
FAILURE: Build failed with an exception.
Where: Build file 'D:\Gradle\ThisAndThat\build.gradle' line: 1
What went wrong: Could not compile build file 'D:\Gradle\ThisAndThat\build.gradle'.
> startup failed:
build file 'D:\Gradle\ThisAndThat\build.gradle': 1: expecting EOF, found 'configure' # line 1, column 6.
task configure << { ^
1 error
I cannot figure out why I am getting this error. Any help would be appreciated. Thanks!
When I literally copy the code from Chapter 14.5 of the userguide it works. Your mistake is in the build.gradle script:
task configure << {
pos = java.text.FieldPosition( ) new 10
should be
task configure << {
pos = new java.text.FieldPosition(10)