Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for excluding files in the build directory #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class LicenseExtension extends LicenseProperties {
*/
boolean ignoreFailures = false

/**
* Whether to include source files in the build directory (most likely
* generated code). This does not affect custom tasks.
* By default this is {@code false}.
*/
boolean includeBuild = false

/**
* The style mappings from file extension to the type of style of the
* comment header for the license header.
Expand Down
26 changes: 17 additions & 9 deletions src/main/groovy/org/cadixdev/gradle/licenser/Licenser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ class Licenser implements Plugin<Project> {
headers << prepareHeader(extension, extension)

extension.sourceSets.each {
def check = createTask(CHECK_TASK, LicenseCheck, headers, it)
def check = createTask(CHECK_TASK, LicenseCheck, headers, extension.includeBuild, it)
check.ignoreFailures = extension.ignoreFailures
globalCheck.dependsOn check
globalFormat.dependsOn createTask(FORMAT_TASK, LicenseUpdate, headers, it)
globalFormat.dependsOn createTask(FORMAT_TASK, LicenseUpdate, headers, extension.includeBuild, it)
}

extension.androidSourceSets.each {
def check = createAndroidTask(CHECK_TASK, LicenseCheck, headers, it)
def check = createAndroidTask(CHECK_TASK, LicenseCheck, headers, extension.includeBuild, it)
check.ignoreFailures = extension.ignoreFailures
globalCheck.dependsOn check
globalFormat.dependsOn createAndroidTask(FORMAT_TASK, LicenseUpdate, headers, it)
globalFormat.dependsOn createAndroidTask(FORMAT_TASK, LicenseUpdate, headers,
extension.includeBuild, it)
}

extension.tasks.each {
Expand Down Expand Up @@ -126,13 +127,20 @@ class Licenser implements Plugin<Project> {
}, (PatternSet) properties.filter, properties.newLine ?: extension.newLine,)
}

private <T extends LicenseTask> T createTask(String name, Class<T> type, List<Header> headers, SourceSet sourceSet) {
return makeTask(sourceSet.getTaskName(name, null), type, headers, sourceSet.allSource)
private <T extends LicenseTask> T createTask(String name, Class<T> type, List<Header> headers,
boolean includeBuild, SourceSet sourceSet) {
def files = sourceSet.allSource
def buildDir = project.buildDir.path
if (!includeBuild) files = files.filter { !it.path.startsWith(buildDir) }
return makeTask(sourceSet.getTaskName(name, null), type, headers, files)
}

private <T extends LicenseTask> T createAndroidTask(String name, Class<T> type, List<Header> headers, Object sourceSet) {
return makeTask(name + ANDROID_TASK + sourceSet.name.capitalize(), type, headers,
project.files(sourceSet.java.sourceFiles, sourceSet.res.sourceFiles, sourceSet.manifest.srcFile))
private <T extends LicenseTask> T createAndroidTask(String name, Class<T> type, List<Header> headers,
boolean includeBuild, Object sourceSet) {
def files = project.files(sourceSet.java.sourceFiles, sourceSet.res.sourceFiles, sourceSet.manifest.srcFile)
def buildDir = project.buildDir.path
if (!includeBuild) files = files.filter { !it.path.startsWith(buildDir) }
return makeTask(name + ANDROID_TASK + sourceSet.name.capitalize(), type, headers, files)
}

private <T extends LicenseTask> T createCustomTask(String name, Class<T> type, LicenseTaskProperties properties) {
Expand Down