From 47b8294236685a4f3190bf04ea09532e711bc43d Mon Sep 17 00:00:00 2001 From: Simon Dierl Date: Tue, 9 Feb 2021 20:33:41 +0100 Subject: [PATCH] Add support for excluding files in the build directory. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most likely, these files are generated or downloaded external code. In the former case, licensing information should be generated by the code generator; in the latter, the license should remain untouched. This is controlled by the extension property “includeBuild”, defaulting to true. --- .../gradle/licenser/LicenseExtension.groovy | 7 +++++ .../cadixdev/gradle/licenser/Licenser.groovy | 26 ++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/groovy/org/cadixdev/gradle/licenser/LicenseExtension.groovy b/src/main/groovy/org/cadixdev/gradle/licenser/LicenseExtension.groovy index 83a70bc..a421e83 100644 --- a/src/main/groovy/org/cadixdev/gradle/licenser/LicenseExtension.groovy +++ b/src/main/groovy/org/cadixdev/gradle/licenser/LicenseExtension.groovy @@ -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. diff --git a/src/main/groovy/org/cadixdev/gradle/licenser/Licenser.groovy b/src/main/groovy/org/cadixdev/gradle/licenser/Licenser.groovy index 64425ca..8d10347 100644 --- a/src/main/groovy/org/cadixdev/gradle/licenser/Licenser.groovy +++ b/src/main/groovy/org/cadixdev/gradle/licenser/Licenser.groovy @@ -83,17 +83,18 @@ class Licenser implements Plugin { 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 { @@ -126,13 +127,20 @@ class Licenser implements Plugin { }, (PatternSet) properties.filter, properties.newLine ?: extension.newLine,) } - private T createTask(String name, Class type, List
headers, SourceSet sourceSet) { - return makeTask(sourceSet.getTaskName(name, null), type, headers, sourceSet.allSource) + private T createTask(String name, Class type, List
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 createAndroidTask(String name, Class type, List
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 createAndroidTask(String name, Class type, List
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 createCustomTask(String name, Class type, LicenseTaskProperties properties) {