Add setIncludes(String ... ) to match the setInclude(String...)

On PatternFilterable there is a convenience method for setInclude() that takes a var args String.

For consistency it would seem logical to have the same for setIncludes().

In a normal use case most people would use:

include ‘fred.java’, ‘bob.java’

but when you want to use includes, you need to write:

setIncludes(new HashSet([‘fred.java’, ‘bob.java’]))

This is something we want for every multi-valued property in the DSL, so you can add values using varargs or an Iterable, and you can set values using varargs or an Iterable. Probably remove too.

We will probably just mix these in dynamically, so they’ll be usable from Groovy, but not Java.

but when you want to use includes, you need to write: setIncludes(new HashSet([‘fred.java’, ‘bob.java’]))

Why not simply:

includes = [‘fred.java’, ‘bob.java’]

Adding a setIncludes(String…) would only be an improvement for Java callers.

I had tried to use “includes” the same way “include” is used in the documentation ie:

includes [a,b]

But without the ‘=’ gradle fails saying it can not find the method includes(), so I reverted to my tried and tested Java way of doing things :slight_smile:

This is a bit of a tangent for this post, but why does “include ‘a’, ‘b’” work but not “includes ‘a’, ‘b’”?

I am guessing this a groovy thing that I am not familiar with…?

Thanks,

-MIke

I had tried to use “includes” the same way “include” is used in the documentation ie: includes [a,b]

Which documentation are you referring to? “include [a, b]” would never work here because it would be considered a subscript operation by Groovy.

This is a bit of a tangent for this post, but why does “include ‘a’, ‘b’” work but not “includes ‘a’, ‘b’”?

Because PatternFilterable has an include() method but no includes() method.

To sum up, PatternFilterable has a getIncludes() method, a setIncludes() method, and several include() convenience methods. I don’t see how adding an includes() method would help.

Which documentation are you referring to? “include [a, b]” would never work here because it would be considered a subscript operation by Groovy.

Ah, sorry Pater, that was my mistake when I typed it in. I meant to type “include ‘a’, ‘b’” which was taken from the samples that came with the gradle milestone 3 zip.

Because PatternFilterable has an include() method but no includes() method.

Again, my mistake, I was thinking bean accessors and I did not read the source code well enough.

My original premise was that by having the convenience methods for includes, was based on the fact that I ended up using new HashSet to make use of the setIncludes method.

However, as you pointed out there is a shorter form:

includes = [‘fred.java’, ‘bob.java’]

But by having the convenience method for includes you could shorten this to:

includes ‘fred.java’, ‘bob.java’

It makes the resulting build file a little more consistent when mixed along side code that uses exclude in same PatternFilterable definition.

But by having the convenience method for includes you could shorten this to: includes ‘fred.java’, ‘bob.java’

That’s exactly what include(String…) is for. Why add another method with the same behavior?

If you read them out aloud, the current methods make a lot of sense:

includes = [“foo”, “bar”] // The includes are …

include “foo”, “bar” // include “foo” and “bar” (i.e.: add the includes …)

Hmm, after looking at the documentation and the source code for the TestTask I noticed this:

if (patterns.getIncludes().isEmpty()) {

patterns.include("/*Tests.class", "/*Test.class"); } if (patterns.getExcludes().isEmpty()) {

patterns.exclude("**/Abstract*.class"); }

This means that there is a default pattern ONLY if no other include or excludes are added manually.

I originally looked at this and thought that by default there were ALREADY the two patterns included. So my assumption was that you would need to use setIncludes to clear those default patterns when they were not suitable.

Thanks for the tips Peter.

-Mike