Skip to content

Commit

Permalink
[PURIFY] update build.gradle files to ensure build completes; gradle …
Browse files Browse the repository at this point in the history
…check fails (#7)

Signed-off-by: Peter Nied <petern@amazon.com>
  • Loading branch information
nknize authored and peternied committed Mar 13, 2021
1 parent e966245 commit 3a52e9d
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 269 deletions.
16 changes: 2 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,7 @@ allprojects {
}

File licenseHeaderFile
String prefix = ':x-pack'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
prefix = prefix.replace(':', '_')
}
if (eclipse.project.name.startsWith(prefix)) {
licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/elastic-license-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/oss-license-header.txt')

String lineSeparator = Os.isFamily(Os.FAMILY_WINDOWS) ? '\\\\r\\\\n' : '\\\\n'
String licenseHeader = licenseHeaderFile.getText('UTF-8').replace(System.lineSeparator(), lineSeparator)
Expand Down Expand Up @@ -467,11 +459,7 @@ allprojects {
def checkPart1 = tasks.register('checkPart1')
def checkPart2 = tasks.register('checkPart2')
plugins.withId('lifecycle-base') {
if (project.path.startsWith(":x-pack:")) {
checkPart2.configure { dependsOn 'check' }
} else {
checkPart1.configure { dependsOn 'check' }
}
checkPart1.configure { dependsOn 'check' }
}
}

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 All @@ -76,35 +76,10 @@ class InternalDistributionArchiveCheckPluginFuncTest extends AbstractGradleFuncT
archiveType << ["zip", 'tar']
}

def "fails on unexpected license content"() {
given:
elasticLicense()
file("LICENSE.txt") << """elastic license coorp stuff line 1
unknown license content line 2
"""
buildFile << """
tasks.withType(AbstractArchiveTask).configureEach {
into("elasticsearch-${VersionProperties.getElasticsearch()}") {
from 'LICENSE.txt'
from 'SomeFile.txt'
}
}
"""

when:
def result = gradleRunner(":darwin-tar:check").buildAndFail()
then:
result.task(":darwin-tar:checkLicense").outcome == TaskOutcome.FAILED
normalizedOutput(result.output).contains("> expected line [2] in " +
"[./darwin-tar/build/tar-extracted/elasticsearch-${VersionProperties.getElasticsearch()}/LICENSE.txt] " +
"to be [elastic license coorp stuff line 2] but was [unknown license content line 2]")
}

def "fails on unexpected notice content"() {
given:
elasticLicense()
elasticLicense(file("LICENSE.txt"))
file("NOTICE.txt").text = """Elasticsearch
license(file("LICENSE.txt"))
file("NOTICE.txt").text = """OSS Search
Copyright 2009-2018 Acme Coorp"""
buildFile << """
apply plugin:'base'
Expand All @@ -126,47 +101,10 @@ Copyright 2009-2018 Acme Coorp"""
"to be [Copyright 2009-2018 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"""

file("ml/NOTICE.txt").text = "Boost Software License - Version 1.0 - August 17th, 2003"
file('darwin-tar/build.gradle') << """
distributionArchiveCheck {
expectedMlLicenses.add('foo license')
}
"""
buildFile << """
apply plugin:'base'
tasks.withType(AbstractArchiveTask).configureEach {
into("elasticsearch-${VersionProperties.getElasticsearch()}") {
from 'LICENSE.txt'
from 'SomeFile.txt'
from 'NOTICE.txt'
into('modules/x-pack-ml') {
from 'ml/NOTICE.txt'
}
}
}
"""

when:
def result = gradleRunner(":darwin-tar:check").buildAndFail()
then:
result.task(":darwin-tar:checkMlCppNotice").outcome == TaskOutcome.FAILED
normalizedOutput(result.output)
.contains("> expected [./darwin-tar/build/tar-extracted/elasticsearch-" +
"${VersionProperties.getElasticsearch()}/modules/x-pack-ml/NOTICE.txt " +
"to contain [foo license] but it did not")
}

void elasticLicense(File file = file("licenses/ELASTIC-LICENSE.txt")) {
file << """elastic license coorp stuff line 1
elastic license coorp stuff line 2
elastic license coorp stuff line 3
void license(File file = file("licenses/APACHE-LICENSE-2.0.txt")) {
file << """license coorp stuff line 1
license coorp stuff line 2
license coorp stuff line 3
"""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ public void apply(Project project) {
.getExtensions()
.getByName(TestClustersPlugin.EXTENSION_NAME);
clusters.all(c -> {
// ceremony to set up ssl
c.setting("xpack.security.transport.ssl.keystore.path", "test-node.jks");
c.setting("xpack.security.http.ssl.keystore.path", "test-node.jks");
c.keystore("xpack.security.transport.ssl.keystore.secure_password", "keypass");
c.keystore("xpack.security.http.ssl.keystore.secure_password", "keypass");

// copy keystores & certs into config/
c.extraConfigFile(nodeKeystore.getName(), nodeKeystore);
c.extraConfigFile(clientKeyStore.getName(), clientKeyStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,15 @@
public class CopyRestApiTask extends DefaultTask {
private static final String REST_API_PREFIX = "rest-api-spec/api";
final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);
String sourceSetName;
boolean skipHasRestTestCheck;
Configuration coreConfig;
Configuration xpackConfig;
Configuration additionalConfig;

private final PatternFilterable corePatternSet;
private final PatternFilterable xpackPatternSet;

public CopyRestApiTask() {
corePatternSet = getPatternSetFactory().create();
xpackPatternSet = getPatternSetFactory().create();
}

@Inject
Expand All @@ -95,11 +91,6 @@ public ListProperty<String> getIncludeCore() {
return includeCore;
}

@Input
public ListProperty<String> getIncludeXpack() {
return includeXpack;
}

@Input
String getSourceSetName() {
return sourceSetName;
Expand All @@ -114,11 +105,6 @@ public boolean isSkipHasRestTestCheck() {
@InputFiles
public FileTree getInputDir() {
FileTree coreFileTree = null;
FileTree xpackFileTree = null;
if (includeXpack.get().isEmpty() == false) {
xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
xpackFileTree = xpackConfig.getAsFileTree().matching(xpackPatternSet);
}
boolean projectHasYamlRestTests = skipHasRestTestCheck || projectHasYamlRestTests();
if (includeCore.get().isEmpty() == false || projectHasYamlRestTests) {
if (BuildParams.isInternal()) {
Expand All @@ -130,13 +116,11 @@ public FileTree getInputDir() {
}

ConfigurableFileCollection fileCollection = additionalConfig == null
? getProject().files(coreFileTree, xpackFileTree)
: getProject().files(coreFileTree, xpackFileTree, additionalConfig.getAsFileTree());
? getProject().files(coreFileTree)
: getProject().files(coreFileTree, additionalConfig.getAsFileTree());

// if project has rest tests or the includes are explicitly configured execute the task, else NO-SOURCE due to the null input
return projectHasYamlRestTests || includeCore.get().isEmpty() == false || includeXpack.get().isEmpty() == false
? fileCollection.getAsFileTree()
: null;
return projectHasYamlRestTests || includeCore.get().isEmpty() == false ? fileCollection.getAsFileTree() : null;
}

@OutputDirectory
Expand Down Expand Up @@ -179,15 +163,6 @@ void copy() {
}
});
}
// only copy x-pack specs if explicitly instructed
if (includeXpack.get().isEmpty() == false) {
getLogger().debug("X-pack rest specs for project [{}] will be copied to the test resources.", projectPath);
getFileSystemOperations().copy(c -> {
c.from(xpackConfig.getSingleFile());
c.into(getOutputDir());
c.include(xpackPatternSet.getIncludes());
});
}
// TODO: once https://github.com/elastic/elasticsearch/pull/62968 lands ensure that this uses `getFileSystemOperations()`
// copy any additional config
if (additionalConfig != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,15 @@
public class CopyRestTestsTask extends DefaultTask {
private static final String REST_TEST_PREFIX = "rest-api-spec/test";
final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);

String sourceSetName;
Configuration coreConfig;
Configuration xpackConfig;
Configuration additionalConfig;

private final PatternFilterable corePatternSet;
private final PatternFilterable xpackPatternSet;

public CopyRestTestsTask() {
corePatternSet = getPatternSetFactory().create();
xpackPatternSet = getPatternSetFactory().create();
}

@Inject
Expand All @@ -92,11 +88,6 @@ public ListProperty<String> getIncludeCore() {
return includeCore;
}

@Input
public ListProperty<String> getIncludeXpack() {
return includeXpack;
}

@Input
String getSourceSetName() {
return sourceSetName;
Expand All @@ -106,11 +97,6 @@ String getSourceSetName() {
@InputFiles
public FileTree getInputDir() {
FileTree coreFileTree = null;
FileTree xpackFileTree = null;
if (includeXpack.get().isEmpty() == false) {
xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
xpackFileTree = xpackConfig.getAsFileTree().matching(xpackPatternSet);
}
if (includeCore.get().isEmpty() == false) {
if (BuildParams.isInternal()) {
corePatternSet.setIncludes(includeCore.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
Expand All @@ -120,13 +106,11 @@ public FileTree getInputDir() {
}
}
ConfigurableFileCollection fileCollection = additionalConfig == null
? getProject().files(coreFileTree, xpackFileTree)
: getProject().files(coreFileTree, xpackFileTree, additionalConfig.getAsFileTree());
? getProject().files(coreFileTree)
: getProject().files(coreFileTree, additionalConfig.getAsFileTree());

// copy tests only if explicitly requested
return includeCore.get().isEmpty() == false || includeXpack.get().isEmpty() == false || additionalConfig != null
? fileCollection.getAsFileTree()
: null;
return includeCore.get().isEmpty() == false || additionalConfig != null ? fileCollection.getAsFileTree() : null;
}

@OutputDirectory
Expand Down Expand Up @@ -167,15 +151,6 @@ void copy() {
});
}
}
// only copy x-pack tests if explicitly instructed
if (includeXpack.get().isEmpty() == false) {
getLogger().debug("X-pack rest tests for project [{}] will be copied to the test resources.", projectPath);
getFileSystemOperations().copy(c -> {
c.from(xpackConfig.getAsFileTree());
c.into(getOutputDir());
c.include(xpackPatternSet.getIncludes());
});
}
// copy any additional config
if (additionalConfig != null) {
getFileSystemOperations().copy(c -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.elasticsearch.gradle.test.rest;

import org.elasticsearch.gradle.info.BuildParams;
import org.gradle.api.Action;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.ListProperty;
Expand Down Expand Up @@ -50,30 +49,17 @@ void restTests(Action<? super RestResourcesSpec> spec) {
static class RestResourcesSpec {

private final ListProperty<String> includeCore;
private final ListProperty<String> includeXpack;

RestResourcesSpec(ObjectFactory objects) {
includeCore = objects.listProperty(String.class);
includeXpack = objects.listProperty(String.class);
}

public void includeCore(String... include) {
this.includeCore.addAll(include);
}

public void includeXpack(String... include) {
if (BuildParams.isInternal() == false) {
throw new IllegalStateException("Can not include x-pack rest resources from an external build.");
}
this.includeXpack.addAll(include);
}

public ListProperty<String> getIncludeCore() {
return includeCore;
}

public ListProperty<String> getIncludeXpack() {
return includeXpack;
}
}
}
Loading

0 comments on commit 3a52e9d

Please sign in to comment.