Skip to content

Commit

Permalink
Update build logic for license changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Feb 2, 2021
1 parent 564d757 commit b22cf2f
Show file tree
Hide file tree
Showing 49 changed files with 925 additions and 697 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ license header unless instructed otherwise:
*/

The top-level `x-pack` directory contains code covered by the [Elastic
license](licenses/ELASTIC-LICENSE.txt). Community contributions to this code are
license](licenses/ELASTIC-LICENSE-2.0.txt). Community contributions to this code are
welcome, and should have the following license header unless instructed
otherwise:

Expand Down
17 changes: 7 additions & 10 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
Source code in this repository is covered by one of three licenses: (i) the
Apache License 2.0 (ii) an Apache License 2.0 compatible license (iii) the
Elastic License. The default license throughout the repository is Apache License
2.0 unless the header specifies another license. Elastic Licensed code is found
only in the x-pack directory.

The build produces two sets of binaries - one set that falls under the Elastic
License and another set that falls under Apache License 2.0. The binaries that
contain `-oss` in the artifact name are licensed under Apache License 2.0 and
these binaries do not package any code from the x-pack directory.
Source code in this repository is covered by (i) a dual license under the Server
Side Public License, v 1 and the Elastic License 2.0 or (ii) an Apache License
2.0 compatible license or (iii) solely under the Elastic License 2.0, in each
case, as noted in the applicable header. The default throughout the repository
is a dual license under the Server Side Public License, v 1 and the Elastic
License 2.0, unless the header specifies another license. Code that is licensed
solely under the Elastic License 2.0 is found only in the x-pack folder.
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Elasticsearch
Copyright 2009-2018 Elasticsearch
Copyright 2009-2021 Elasticsearch

This product includes software developed by The Apache Software
Foundation (http://www.apache.org/).
Expand Down
27 changes: 16 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
} else {
licenseCommit = "v${version}"
}
String elasticLicenseUrl = "https://raw.githubusercontent.com/elastic/elasticsearch/${licenseCommit}/licenses/ELASTIC-LICENSE.txt"
String elasticLicenseUrl = "https://raw.githubusercontent.com/elastic/elasticsearch/${licenseCommit}/licenses/ELASTIC-LICENSE-2.0.txt"

subprojects {
// Default to the apache license
project.ext.licenseName = 'The Apache Software License, Version 2.0'
project.ext.licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
// Default to the SSPL+Elastic dual license
project.ext.projectLicenses = [
'Server Side Public License, v 1': 'https://www.mongodb.com/licensing/server-side-public-license',
'Elastic License 2.0': elasticLicenseUrl
]

// But stick the Elastic license url in project.ext so we can get it if we need to switch to it
project.ext.elasticLicenseUrl = elasticLicenseUrl
Expand All @@ -83,10 +85,13 @@ subprojects {
Node node = xml.asNode()
node.appendNode('inceptionYear', '2009')

Node license = node.appendNode('licenses').appendNode('license')
license.appendNode('name', project.licenseName)
license.appendNode('url', project.licenseUrl)
license.appendNode('distribution', 'repo')
Node licensesNode = node.appendNode('licenses')
project.ext.projectLicenses.forEach { licenseName, licenseUrl ->
Node license = licensesNode.appendNode('license')
license.appendNode('name', licenseName)
license.appendNode('url', licenseUrl)
license.appendNode('distribution', 'repo')
}

Node developer = node.appendNode('developers').appendNode('developer')
developer.appendNode('name', 'Elastic')
Expand All @@ -104,7 +109,7 @@ subprojects {
}

plugins.withType(BuildPlugin).whenPluginAdded {
project.licenseFile = project.rootProject.file('licenses/APACHE-LICENSE-2.0.txt')
project.licenseFile = project.rootProject.file('licenses/SSPL-1.0+ELASTIC-LICENSE-2.0.txt')
project.noticeFile = project.rootProject.file('NOTICE.txt')
}
}
Expand Down Expand Up @@ -371,9 +376,9 @@ allprojects {
prefix = prefix.replace(':', '_')
}
if (eclipse.project.name.startsWith(prefix)) {
licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/elastic-license-header.txt')
licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/elastic-license-2.0-header.txt')
} else {
licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/oss-license-header.txt')
licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/sspl+elastic-license-header.txt')
}

String lineSeparator = Os.isFamily(Os.FAMILY_WINDOWS) ? '\\\\r\\\\n' : '\\\\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class InternalDistributionArchiveCheckPluginFuncTest extends AbstractGradleFuncT
}"""
}
file("SomeFile.txt") << """
some dummy txt file
some dummy txt file
"""

buildFile << """
Expand All @@ -59,7 +59,7 @@ class InternalDistributionArchiveCheckPluginFuncTest extends AbstractGradleFuncT
def "plain class files in distribution #archiveType archives are detected"() {
given:
file("SomeFile.class") << """
some dummy class file
some dummy class file
"""
buildFile << """
tasks.withType(AbstractArchiveTask).configureEach {
Expand Down Expand Up @@ -123,15 +123,15 @@ Copyright 2009-2018 Acme Coorp"""
result.task(":darwin-tar:checkNotice").outcome == TaskOutcome.FAILED
normalized(result.output).contains("> expected line [2] in " +
"[./darwin-tar/build/tar-extracted/elasticsearch-${VersionProperties.getElasticsearch()}/NOTICE.txt] " +
"to be [Copyright 2009-2018 Elasticsearch] but was [Copyright 2009-2018 Acme Coorp]")
"to be [Copyright 2009-2021 Elasticsearch] but was [Copyright 2009-2018 Acme Coorp]")
}

def "fails on unexpected ml notice content"() {
given:
elasticLicense()
elasticLicense(file("LICENSE.txt"))
file("NOTICE.txt").text = """Elasticsearch
Copyright 2009-2018 Elasticsearch"""
Copyright 2009-2021 Elasticsearch"""

file("ml/NOTICE.txt").text = "Boost Software License - Version 1.0 - August 17th, 2003"
file('darwin-tar/build.gradle') << """
Expand Down Expand Up @@ -163,7 +163,7 @@ Copyright 2009-2018 Elasticsearch"""
"to contain [foo license] but it did not")
}

void elasticLicense(File file = file("licenses/ELASTIC-LICENSE.txt")) {
void elasticLicense(File file = file("licenses/ELASTIC-LICENSE-2.0.txt")) {
file << """elastic license coorp stuff line 1
elastic license coorp stuff line 2
elastic license coorp stuff line 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LicenseHeadersPrecommitPluginFuncTest extends AbstractGradleFuncTest {
id 'elasticsearch.internal-licenseheaders'
}
"""
apacheSourceFile()
dualLicensedFile()
unknownSourceFile()
unapprovedSourceFile()

Expand All @@ -41,10 +41,10 @@ class LicenseHeadersPrecommitPluginFuncTest extends AbstractGradleFuncTest {

then:
result.task(":licenseHeaders").outcome == TaskOutcome.FAILED
assertOutputContains(result.output, "> License header problems were found! Full details: ./build/reports/licenseHeaders/rat.xml")
assertOutputContains(result.output, "> Check failed. License header problems were found. Full details: ./build/reports/licenseHeaders/rat.xml")
assertOutputContains(result.output, "./src/main/java/org/acme/UnknownLicensed.java")
assertOutputContains(result.output, "./src/main/java/org/acme/UnapprovedLicensed.java")
normalized(result.output).contains("./src/main/java/org/acme/ApacheLicensed.java") == false
normalized(result.output).contains("./src/main/java/org/acme/DualLicensed.java") == false
}

def "can filter source files"() {
Expand All @@ -54,12 +54,12 @@ class LicenseHeadersPrecommitPluginFuncTest extends AbstractGradleFuncTest {
id 'java'
id 'elasticsearch.internal-licenseheaders'
}
tasks.named("licenseHeaders").configure {
excludes << 'org/acme/filtered/**/*'
}
"""
apacheSourceFile()
dualLicensedFile()
unknownSourceFile("src/main/java/org/acme/filtered/FilteredUnknownLicensed.java")
unapprovedSourceFile("src/main/java/org/acme/filtered/FilteredUnapprovedLicensed.java")

Expand Down Expand Up @@ -90,7 +90,7 @@ class LicenseHeadersPrecommitPluginFuncTest extends AbstractGradleFuncTest {
*/
package ${packageString(sourceFile)};
public class ${sourceFile.getName() - ".java"} {
}
"""
Expand All @@ -102,37 +102,26 @@ class LicenseHeadersPrecommitPluginFuncTest extends AbstractGradleFuncTest {
/*
* Blubb my custom license shrug!
*/
package ${packageString(sourceFile)};
public class ${sourceFile.getName() - ".java"} {
}
"""
}

private File apacheSourceFile() {
file("src/main/java/org/acme/ApacheLicensed.java") << """
private File dualLicensedFile() {
file("src/main/java/org/acme/DualLicensed.java") << """
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.acme;
public class ApacheLicensed {
package org.acme;
public class DualLicensed {
}
"""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -74,8 +75,11 @@ public void apply(Project project) {

String projectName = project.getName();
if (projectName.contains("oss") == false && (projectName.contains("zip") || projectName.contains("tar"))) {
project.getExtensions().add("licenseName", "Elastic License");
project.getExtensions().add("licenseUrl", project.getExtensions().getExtraProperties().get("elasticLicenseUrl"));
project.getExtensions()
.add(
"projectLicenses",
Map.of("Elastic License 2.0", project.getExtensions().getExtraProperties().get("elasticLicenseUrl"))
);
TaskProvider<Task> checkMlCppNoticeTask = registerCheckMlCppNoticeTask(
project,
checkExtraction,
Expand Down Expand Up @@ -135,7 +139,7 @@ private TaskProvider<Task> registerCheckNoticeTask(Project project, TaskProvider
task.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
final List<String> noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2018 Elasticsearch");
final List<String> noticeLines = Arrays.asList("Elasticsearch", "Copyright 2009-2021 Elasticsearch");
final Path noticePath = checkExtraction.get()
.getDestinationDir()
.toPath()
Expand All @@ -154,9 +158,9 @@ private TaskProvider<Task> registerCheckLicenseTask(Project project, TaskProvide
public void execute(Task task) {
String licenseFilename = null;
if (project.getName().contains("oss-") || project.getName().equals("integ-test-zip")) {
licenseFilename = "APACHE-LICENSE-2.0.txt";
licenseFilename = "SSPL-1.0+ELASTIC-LICENSE-2.0.txt";
} else {
licenseFilename = "ELASTIC-LICENSE.txt";
licenseFilename = "ELASTIC-LICENSE-2.0.txt";
}
final List<String> licenseLines;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void setExcludes(List<String> excludes) {
* Allowed license families for this project.
*/
@Input
private List<String> approvedLicenses = new ArrayList<String>(Arrays.asList("Apache", "Generated", "Vendored"));
private List<String> approvedLicenses = new ArrayList<String>(Arrays.asList("SSPL+Elastic License", "Generated", "Vendored"));
/**
* Files that should be excluded from the license header check. Use with extreme care, only in situations where the license on the
* source file is compatible with the codebase but we do not want to add the license to the list of approved headers (to avoid the
Expand Down Expand Up @@ -169,6 +169,8 @@ public void runRat() {
matchers.add(subStringMatcher("GEN ", "Generated", "ANTLR GENERATED CODE"));
// Vendored Code
matchers.add(subStringMatcher("VEN ", "Vendored", "@notice"));
// Dual SSPLv1 and Elastic
matchers.add(subStringMatcher("DUAL", "SSPL+Elastic License", "the Elastic License 2.0 or the Server"));

for (Map.Entry<String, String> additional : additionalLicenses.entrySet()) {
String category = additional.getKey().substring(0, 5);
Expand All @@ -187,8 +189,9 @@ public void runRat() {
boolean unknownLicenses = stats.getNumUnknown() > 0;
boolean unApprovedLicenses = stats.getNumUnApproved() > 0;
if (unknownLicenses || unApprovedLicenses) {
getLogger().error("The following files contain unapproved license headers:");
unapprovedFiles(getReportFile()).stream().forEachOrdered(unapprovedFile -> getLogger().error(unapprovedFile));
throw new GradleException("License header problems were found! Full details: " + reportFile.getAbsolutePath());
throw new GradleException("Check failed. License header problems were found. Full details: " + reportFile.getAbsolutePath());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
*/
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch;

Expand Down
3 changes: 3 additions & 0 deletions client/rest-high-level/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ apply plugin: 'elasticsearch.rest-resources'
group = 'org.elasticsearch.client'
archivesBaseName = 'elasticsearch-rest-high-level-client'

// HLRC is published under the Elastic License
ext.projectLicenses = ['Elastic License 2.0': ext.elasticLicenseUrl]

restResources {
//we need to copy the yaml spec so we can check naming (see RestHighlevelClientTests#testApiNamingConventions)
restApi {
Expand Down
3 changes: 3 additions & 0 deletions client/rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ sourceCompatibility = JavaVersion.VERSION_1_8
group = 'org.elasticsearch.client'
archivesBaseName = 'elasticsearch-rest-client'

// REST client is published under the Elastic License
ext.projectLicenses = ['Elastic License 2.0': ext.elasticLicenseUrl]

dependencies {
api "org.apache.httpcomponents:httpclient:${versions.httpclient}"
api "org.apache.httpcomponents:httpcore:${versions.httpcore}"
Expand Down
2 changes: 1 addition & 1 deletion distribution/archives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla
include 'README.asciidoc'
}
from(rootProject.file('licenses')) {
include oss ? 'APACHE-LICENSE-2.0.txt' : 'ELASTIC-LICENSE.txt'
include oss ? 'SSPL-1.0+ELASTIC-LICENSE-2.0.txt' : 'ELASTIC-LICENSE-2.0.txt'
rename { 'LICENSE.txt' }
}

Expand Down
4 changes: 2 additions & 2 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@ subprojects {

String licenseText
if (oss) {
licenseText = rootProject.file('licenses/APACHE-LICENSE-2.0.txt').getText('UTF-8')
licenseText = rootProject.file('licenses/SSPL-1.0+ELASTIC-LICENSE-2.0.txt').getText('UTF-8')
} else {
licenseText = rootProject.file('licenses/ELASTIC-LICENSE.txt').getText('UTF-8')
licenseText = rootProject.file('licenses/ELASTIC-LICENSE-2.0.txt').getText('UTF-8')
}
// license text needs to be indented with a single space
licenseText = ' ' + licenseText.replace('\n', '\n ')
Expand Down
2 changes: 1 addition & 1 deletion distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ RUN curl --retry 10 -S -L \\
'build_date' : BuildParams.buildDate,
'config_dir' : base == DockerBase.IRON_BANK ? 'scripts' : 'config',
'git_revision' : BuildParams.gitRevision,
'license' : oss ? 'Apache-2.0' : 'Elastic-License',
'license' : 'Elastic-License-2.0',
'package_manager' : base == DockerBase.UBI ? 'microdnf' : 'yum',
'source_elasticsearch': sourceElasticsearch,
'docker_base' : base.name().toLowerCase(),
Expand Down
Loading

0 comments on commit b22cf2f

Please sign in to comment.