From 8659af68e0e6cdea45bee7755b49fc0d2e248b73 Mon Sep 17 00:00:00 2001 From: Alpar Torok Date: Tue, 20 Nov 2018 13:02:33 +0200 Subject: [PATCH] Auto skip license headers on no source (#35640) * Unmute BuildExamplePluginsIT * Skip licenseHeaders when there are no sources --- .../precommit/LicenseHeadersTask.groovy | 26 +++++++++---------- rest-api-spec/build.gradle | 1 - test/fixtures/krb5kdc-fixture/build.gradle | 1 - x-pack/plugin/ilm/qa/build.gradle | 2 -- x-pack/test/idp-fixture/build.gradle | 1 - x-pack/test/smb-fixture/build.gradle | 1 - 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/LicenseHeadersTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/LicenseHeadersTask.groovy index 45f60c35bf6..6bfd9551de9 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/LicenseHeadersTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/LicenseHeadersTask.groovy @@ -24,7 +24,9 @@ import org.apache.rat.license.SimpleLicenseFamily import org.elasticsearch.gradle.AntTask import org.gradle.api.file.FileCollection import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.SkipWhenEmpty import org.gradle.api.tasks.SourceSet import java.nio.file.Files @@ -39,12 +41,6 @@ public class LicenseHeadersTask extends AntTask { @OutputFile File reportFile = new File(project.buildDir, 'reports/licenseHeaders/rat.log') - /** - * The list of java files to check. protected so the afterEvaluate closure in the - * constructor can write to it. - */ - protected List javaFiles - /** Allowed license families for this project. */ @Input List approvedLicenses = ['Apache', 'Generated'] @@ -65,11 +61,16 @@ public class LicenseHeadersTask extends AntTask { LicenseHeadersTask() { description = "Checks sources for missing, incorrect, or unacceptable license headers" - // Delay resolving the dependencies until after evaluation so we pick up generated sources - project.afterEvaluate { - javaFiles = project.sourceSets.collect({it.allJava}) - inputs.files(javaFiles) - } + } + + /** + * The list of java files to check. protected so the afterEvaluate closure in the + * constructor can write to it. + */ + @InputFiles + @SkipWhenEmpty + public List getJavaFiles() { + return project.sourceSets.collect({it.allJava}) } /** @@ -97,9 +98,8 @@ public class LicenseHeadersTask extends AntTask { Files.deleteIfExists(reportFile.toPath()) // run rat, going to the file - List input = javaFiles ant.ratReport(reportFile: reportFile.absolutePath, addDefaultLicenseMatchers: true) { - for (FileCollection dirSet : input) { + for (FileCollection dirSet : javaFiles) { for (File dir: dirSet.srcDirs) { // sometimes these dirs don't exist, e.g. site-plugin has no actual java src/main... if (dir.exists()) { diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index cd49b9f1925..d95ad476682 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -4,4 +4,3 @@ apply plugin: 'nebula.maven-scm' test.enabled = false jarHell.enabled = false -licenseHeaders.enabled = false diff --git a/test/fixtures/krb5kdc-fixture/build.gradle b/test/fixtures/krb5kdc-fixture/build.gradle index 046ecc5fc04..75175da1b22 100644 --- a/test/fixtures/krb5kdc-fixture/build.gradle +++ b/test/fixtures/krb5kdc-fixture/build.gradle @@ -74,7 +74,6 @@ task destroy(type: org.elasticsearch.gradle.vagrant.VagrantCommandTask) { } thirdPartyAudit.enabled = false -licenseHeaders.enabled = false test.enabled = false // installKDC uses tabs in it for the Kerberos ACL file. diff --git a/x-pack/plugin/ilm/qa/build.gradle b/x-pack/plugin/ilm/qa/build.gradle index 9525da5f4fe..74412a094b4 100644 --- a/x-pack/plugin/ilm/qa/build.gradle +++ b/x-pack/plugin/ilm/qa/build.gradle @@ -16,5 +16,3 @@ subprojects { } } -// the qa modules does not have any source files -licenseHeaders.enabled = false diff --git a/x-pack/test/idp-fixture/build.gradle b/x-pack/test/idp-fixture/build.gradle index c62ac0409ba..305b1914a1b 100644 --- a/x-pack/test/idp-fixture/build.gradle +++ b/x-pack/test/idp-fixture/build.gradle @@ -38,6 +38,5 @@ task destroy(type: org.elasticsearch.gradle.vagrant.VagrantCommandTask) { } thirdPartyAudit.enabled = false -licenseHeaders.enabled = false test.enabled = false jarHell.enabled = false diff --git a/x-pack/test/smb-fixture/build.gradle b/x-pack/test/smb-fixture/build.gradle index 233b289b295..e2c9b85eab9 100644 --- a/x-pack/test/smb-fixture/build.gradle +++ b/x-pack/test/smb-fixture/build.gradle @@ -38,6 +38,5 @@ task destroy(type: org.elasticsearch.gradle.vagrant.VagrantCommandTask) { } thirdPartyAudit.enabled = false -licenseHeaders.enabled = false test.enabled = false jarHell.enabled = false