Jenkins Groovy with Java Stream API

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jenkins Groovy with Java Stream API

Sverre Moe-2

The following piece of code works fine in Groovy, but Jenkins complains about unexpected token: ->

    final def files = findFiles(glob: filePattern)
    final def rootNode = files.stream()
        .map(file -> findByContent(file.getPath()))
        .filter(node -> node != null)
        .findFirst()

To get this working in a local Groovy script the findFile is switched with a simple List of strings.

So why is it not working in Jenkins?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e6adc124-fb97-4f72-87d5-d9f9ada90ef8n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Jenkins Groovy with Java Stream API

Sverre Moe-2
Here is a solution that does work in both Groovy and Jenkins

    def foundRootNode = null
    for(file in files) {
        final def rootNode = findByContent(file.getPath());
        if (rootNode != null) {
            foundRootNode = rootNode
            break;
        }
    }

However it is not as elegant as using Java Stream API.
søndag 7. februar 2021 kl. 19:00:39 UTC+1 skrev Sverre Moe:

The following piece of code works fine in Groovy, but Jenkins complains about unexpected token: ->

    final def files = findFiles(glob: filePattern)
    final def rootNode = files.stream()
        .map(file -> findByContent(file.getPath()))
        .filter(node -> node != null)
        .findFirst()

To get this working in a local Groovy script the findFile is switched with a simple List of strings.

So why is it not working in Jenkins?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5b921dcf-2f8d-45ff-86c6-5640925c7c04n%40googlegroups.com.