diff --git a/build.gradle b/build.gradle index 0c61eecd85c..c538c0cb898 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,7 @@ import org.apache.tools.ant.taskdefs.condition.Os import org.elasticsearch.gradle.BuildPlugin +import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.VersionCollection import org.elasticsearch.gradle.VersionProperties @@ -30,6 +31,7 @@ import org.gradle.api.tasks.wrapper.Wrapper.DistributionType import org.gradle.util.GradleVersion import org.gradle.util.DistributionLocator +import java.nio.file.Files import java.nio.file.Path import java.security.MessageDigest @@ -459,6 +461,59 @@ gradle.projectsEvaluated { } +static void assertLinesInFile(final Path path, final List expectedLines) { + final List actualLines = Files.readAllLines(path) + int line = 0 + for (final String expectedLine : expectedLines) { + final String actualLine = actualLines.get(line) + if (expectedLine != actualLine) { + throw new GradleException("expected line [${line + 1}] in [${path}] to be [${expectedLine}] but was [${actualLine}]") + } + line++ + } +} + +/* + * Check that all generated JARs have our NOTICE.txt and an appropriate + * LICENSE.txt in them. We configurate this in gradle but we'd like to + * be extra paranoid. + */ +subprojects { project -> + project.tasks.withType(Jar).whenTaskAdded { jarTask -> + final Task extract = project.task("extract${jarTask.name.capitalize()}", type: LoggedExec) { + dependsOn jarTask + ext.destination = project.buildDir.toPath().resolve("jar-extracted/${jarTask.name}") + commandLine "${->new File(rootProject.compilerJavaHome, 'bin/jar')}", + 'xf', "${-> jarTask.outputs.files.singleFile}", 'META-INF/LICENSE.txt', 'META-INF/NOTICE.txt' + workingDir destination + doFirst { + project.delete(destination) + Files.createDirectories(destination) + } + } + + final Task checkNotice = project.task("verify${jarTask.name.capitalize()}Notice") { + dependsOn extract + doLast { + final List noticeLines = Files.readAllLines(project.noticeFile.toPath()) + final Path noticePath = extract.destination.resolve('META-INF/NOTICE.txt') + assertLinesInFile(noticePath, noticeLines) + } + } + project.check.dependsOn checkNotice + + final Task checkLicense = project.task("verify${jarTask.name.capitalize()}License") { + dependsOn extract + doLast { + final List licenseLines = Files.readAllLines(project.licenseFile.toPath()) + final Path licensePath = extract.destination.resolve('META-INF/LICENSE.txt') + assertLinesInFile(licensePath, licenseLines) + } + } + project.check.dependsOn checkLicense + } +} + /* Remove assemble on all qa projects because we don't need to publish * artifacts for them. */ gradle.projectsEvaluated { diff --git a/distribution/archives/build.gradle b/distribution/archives/build.gradle index af9d5f36245..f2fc297a9e4 100644 --- a/distribution/archives/build.gradle +++ b/distribution/archives/build.gradle @@ -201,8 +201,7 @@ subprojects { } final List licenseLines = Files.readAllLines(rootDir.toPath().resolve("licenses/" + licenseFilename)) final Path licensePath = archiveExtractionDir.toPath().resolve("elasticsearch-${VersionProperties.elasticsearch}/LICENSE.txt") - final List actualLines = Files.readAllLines(licensePath) - assertLinesInFile(licensePath, actualLines, licenseLines) + assertLinesInFile(licensePath, licenseLines) } } check.dependsOn checkLicense @@ -213,8 +212,7 @@ subprojects { doLast { final List noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2018 Elasticsearch") final Path noticePath = archiveExtractionDir.toPath().resolve("elasticsearch-${VersionProperties.elasticsearch}/NOTICE.txt") - final List actualLines = Files.readAllLines(noticePath) - assertLinesInFile(noticePath, actualLines, noticeLines) + assertLinesInFile(noticePath, noticeLines) } } check.dependsOn checkNotice @@ -304,4 +302,3 @@ configure(subprojects.findAll { it.name.contains('zip') }) { } } } - diff --git a/distribution/build.gradle b/distribution/build.gradle index 23d1d7b66ad..c1ab5b76148 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -460,14 +460,3 @@ subprojects { return result } } - -static void assertLinesInFile(final Path path, final List actualLines, final List expectedLines) { - int line = 0 - for (final String expectedLine : expectedLines) { - final String actualLine = actualLines.get(line) - if (expectedLine != actualLine) { - throw new GradleException("expected line [${line + 1}] in [${path}] to be [${expectedLine}] but was [${actualLine}]") - } - line++ - } -} diff --git a/distribution/packages/build.gradle b/distribution/packages/build.gradle index 863f6a3613d..6e5b69a66f7 100644 --- a/distribution/packages/build.gradle +++ b/distribution/packages/build.gradle @@ -415,8 +415,7 @@ subprojects { "License: " + expectedLicense) final List licenseLines = Files.readAllLines(rootDir.toPath().resolve("licenses/" + licenseFilename)) final List expectedLines = header + licenseLines.collect { " " + it } - final List actualLines = Files.readAllLines(copyrightPath) - assertLinesInFile(copyrightPath, actualLines, expectedLines) + assertLinesInFile(copyrightPath, expectedLines) } } } else { @@ -432,8 +431,7 @@ subprojects { } final List licenseLines = Files.readAllLines(rootDir.toPath().resolve("licenses/" + licenseFilename)) final Path licensePath = packageExtractionDir.toPath().resolve("usr/share/elasticsearch/LICENSE.txt") - final List actualLines = Files.readAllLines(licensePath) - assertLinesInFile(licensePath, actualLines, licenseLines) + assertLinesInFile(licensePath, licenseLines) } } } @@ -444,8 +442,7 @@ subprojects { doLast { final List noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2018 Elasticsearch") final Path noticePath = packageExtractionDir.toPath().resolve("usr/share/elasticsearch/NOTICE.txt") - final List actualLines = Files.readAllLines(noticePath) - assertLinesInFile(noticePath, actualLines, noticeLines) + assertLinesInFile(noticePath, noticeLines) } } check.dependsOn checkNotice diff --git a/x-pack/build.gradle b/x-pack/build.gradle index aa3cc1de17f..88e09d82168 100644 --- a/x-pack/build.gradle +++ b/x-pack/build.gradle @@ -23,10 +23,8 @@ subprojects { ext.licenseName = 'Elastic License' ext.licenseUrl = "https://raw.githubusercontent.com/elastic/elasticsearch/${licenseCommit}/licenses/ELASTIC-LICENSE.txt" - plugins.withType(BuildPlugin).whenPluginAdded { - project.licenseFile = rootProject.file('licenses/ELASTIC-LICENSE.txt') - project.noticeFile = xpackRootProject.file('NOTICE.txt') - } + project.ext.licenseFile = rootProject.file('licenses/ELASTIC-LICENSE.txt') + project.ext.noticeFile = xpackRootProject.file('NOTICE.txt') plugins.withType(PluginBuildPlugin).whenPluginAdded { project.esplugin.licenseFile = rootProject.file('licenses/ELASTIC-LICENSE.txt') diff --git a/x-pack/plugin/build.gradle b/x-pack/plugin/build.gradle index a4db1185e23..110b26182ad 100644 --- a/x-pack/plugin/build.gradle +++ b/x-pack/plugin/build.gradle @@ -31,6 +31,20 @@ configurations { task testJar(type: Jar) { appendix 'test' from sourceSets.test.output + /* + * Stick the license and notice file in the jar. This isn't strictly + * needed because we don't publish it but it makes our super-paranoid + * tests happy. + */ + metaInf { + from(project.licenseFile.parent) { + include project.licenseFile.name + rename { 'LICENSE.txt' } + } + from(project.noticeFile.parent) { + include project.noticeFile.name + } + } } artifacts { testArtifacts testJar diff --git a/x-pack/plugin/sql/sql-cli/build.gradle b/x-pack/plugin/sql/sql-cli/build.gradle index 9eae21fb18a..06eb24c743a 100644 --- a/x-pack/plugin/sql/sql-cli/build.gradle +++ b/x-pack/plugin/sql/sql-cli/build.gradle @@ -45,9 +45,12 @@ dependencyLicenses { * can be easilly shipped around and used. */ jar { - from { + from({ configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } + }) { + // We don't need the META-INF from the things we bundle. For now. + exclude 'META-INF/*' } manifest { attributes 'Main-Class': 'org.elasticsearch.xpack.sql.cli.Cli'