Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Improve exclude rules #8

Merged
merged 6 commits into from Nov 14, 2016

Conversation

mr-archano
Copy link
Contributor

@mr-archano mr-archano commented Nov 11, 2016

Tracked in JIRA by PT-313

Scope of the PR

While integrating v0.1 of the plugin in one of our projects we realised that the exclude directive in the plugin extension is only supporting file patterns, but there is no way to specify an entire source set for instance.

Considerations/Implementation Details

Introduced SourceFilter as thin delegate holding all the exclude rules to be applied to a specific SourceTask. File patterns are supported as well as Files or collections of them, eg:

exclude project.fileTree('src/test/java')
exclude project.file('src/main/java/foo/bar/Constants.java')
exclude project.sourceSets.main.java.srcDirs
exclude '**/*Test.java'

Testing

SourceFilter is fully tested to cover all the scenarios above. A bunch of integration tests have been added for each configurator to validate the exclude functionality in both Java and Android projects.

Thanks to His Groovyness @devisnik for the help with the refactoring of the SourceFilter. It looks waaaaay better than expected ✨ .

} else if (exclude instanceof FileCollection) {
apply(task, exclude)
} else if (exclude instanceof Iterable<File>) {
apply(task, exclude.inject(null, accumulateIntoTree()) as FileTree)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is inject some kind of fold?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. why inject instead of fold or the more popular reduce is beyond me :/

}

private def accumulateIntoTree() {
return { tree, file -> tree?.plus(project.fileTree(file)) ?: project.fileTree(file) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAX so much

Copy link
Contributor

@takecare takecare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😲

@takecare takecare merged commit 3c97efc into master Nov 14, 2016
@takecare takecare deleted the feature/PT-311/PT-313_exclude_file_collections branch November 14, 2016 09:32
@mr-archano mr-archano mentioned this pull request Nov 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants