0

i have this gradle task to get zip content and put it into another zip. From src zip, i want to take all in directory 'r' and copy it into the target zip directory 'x/y/z'.
The code works, but I wonder if it can be more elegant.

    from( zipTree("a.zip") ) {
        include "r/**"
        includeEmptyDirs = false
        into "x/y/z"
        eachFile { fcd ->
            def segs1 = [fcd.relativePath.segments].flatten().findAll { it2 -> it2 != null };
            segs1.removeAt(3)
            fcd.relativePath = new RelativePath(true, segs1.toArray(new String[0]))
        }
    }

The problem I had is that fcd.relativePath.segments is String[], where i want to remove element with index 3.
Here i convert to list and back to array, brrr.

Ideas?

Frank

0

1 Answer 1

1

groovy based on java

and in java:

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

so, you could convert it to List, modify size, and then convert back to array

or create a new array with new size and copy required elements into it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.