Build: Allow license header check to be customized
This change allows setting which license families are approved, as well as adding matchers for additional license types.
This commit is contained in:
parent
cd596772ee
commit
0ecaa6ec3c
|
@ -23,6 +23,7 @@ import org.apache.rat.anttasks.SubstringLicenseMatcher
|
||||||
import org.apache.rat.license.SimpleLicenseFamily
|
import org.apache.rat.license.SimpleLicenseFamily
|
||||||
import org.elasticsearch.gradle.AntTask
|
import org.elasticsearch.gradle.AntTask
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
|
import org.gradle.api.tasks.Input
|
||||||
import org.gradle.api.tasks.OutputFile
|
import org.gradle.api.tasks.OutputFile
|
||||||
import org.gradle.api.tasks.SourceSet
|
import org.gradle.api.tasks.SourceSet
|
||||||
|
|
||||||
|
@ -44,6 +45,16 @@ public class LicenseHeadersTask extends AntTask {
|
||||||
*/
|
*/
|
||||||
protected List<FileCollection> javaFiles
|
protected List<FileCollection> javaFiles
|
||||||
|
|
||||||
|
/** Allowed license families for this project. */
|
||||||
|
@Input
|
||||||
|
List<String> approvedLicenses = ['Apache', 'Generated']
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional license families that may be found. The key is the license category name (5 characters),
|
||||||
|
* followed by the family name and the value list of patterns to search for.
|
||||||
|
*/
|
||||||
|
protected Map<String, String> additionalLicenses = [:]
|
||||||
|
|
||||||
LicenseHeadersTask() {
|
LicenseHeadersTask() {
|
||||||
description = "Checks sources for missing, incorrect, or unacceptable license headers"
|
description = "Checks sources for missing, incorrect, or unacceptable license headers"
|
||||||
// Delay resolving the dependencies until after evaluation so we pick up generated sources
|
// Delay resolving the dependencies until after evaluation so we pick up generated sources
|
||||||
|
@ -53,6 +64,13 @@ public class LicenseHeadersTask extends AntTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void additionalLicense(String categoryName, String familyName, String pattern) {
|
||||||
|
if (categoryName.length() != 5) {
|
||||||
|
throw new IllegalArgumentException("License category name must be exactly 5 characters, got ${categoryName}");
|
||||||
|
}
|
||||||
|
additionalLicenses.put("${categoryName}${familyName}", pattern);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void runAnt(AntBuilder ant) {
|
protected void runAnt(AntBuilder ant) {
|
||||||
ant.project.addTaskDefinition('ratReport', Report)
|
ant.project.addTaskDefinition('ratReport', Report)
|
||||||
|
@ -98,9 +116,20 @@ public class LicenseHeadersTask extends AntTask {
|
||||||
pattern(substring: "ANTLR GENERATED CODE")
|
pattern(substring: "ANTLR GENERATED CODE")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// license types added by the project
|
||||||
|
for (Map.Entry<String, String[]> additional : additionalLicenses.entrySet()) {
|
||||||
|
String category = additional.getKey().substring(0, 5)
|
||||||
|
String family = additional.getKey().substring(5)
|
||||||
|
substringMatcher(licenseFamilyCategory: category,
|
||||||
|
licenseFamilyName: family) {
|
||||||
|
pattern(substring: additional.getValue())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// approved categories
|
// approved categories
|
||||||
approvedLicense(familyName: "Apache")
|
for (String licenseFamily : approvedLicenses) {
|
||||||
approvedLicense(familyName: "Generated")
|
approvedLicense(familyName: licenseFamily)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the license file for any errors, this should be fast.
|
// check the license file for any errors, this should be fast.
|
||||||
|
|
Loading…
Reference in New Issue