Skip to content

Commit

Permalink
Replace heavy weight build-tools integ tests with a simple unit test. (
Browse files Browse the repository at this point in the history
…#44056)

Remove heavy build-tool integ test.
Add a  unit test for the plugin builder plugin.

Closes #41256 #41256
  • Loading branch information
alpar-t committed Sep 30, 2019
1 parent 1c7dc3a commit 3648481
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 737 deletions.
49 changes: 12 additions & 37 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import org.gradle.util.GradleVersion

import java.util.regex.Matcher
import org.gradle.util.GradleVersion

plugins {
id 'java-gradle-plugin'
Expand Down Expand Up @@ -109,8 +108,9 @@ dependencies {

compile 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3'
compile 'com.netflix.nebula:nebula-publishing-plugin:4.4.4'
compile 'com.netflix.nebula:gradle-info-plugin:3.0.3'
compile 'com.netflix.nebula:gradle-info-plugin:5.1.0'
compile 'org.eclipse.jgit:org.eclipse.jgit:5.5.0.201909110433-r'
compile 'com.netflix.nebula:gradle-info-plugin:3.0.3'
compile 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE....
compile 'org.apache.rat:apache-rat:0.11'
compile "org.elasticsearch:jna:4.5.1"
Expand All @@ -120,6 +120,7 @@ dependencies {
testCompile "junit:junit:${props.getProperty('junit')}"
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"
testCompile 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
testCompile 'org.mockito:mockito-core:1.9.5'
minimumRuntimeCompile "junit:junit:${props.getProperty('junit')}"
minimumRuntimeCompile localGroovy()
minimumRuntimeCompile gradleApi()
Expand Down Expand Up @@ -194,40 +195,6 @@ if (project != rootProject) {
}
}

String localDownloads = "${rootProject.buildDir}/local-downloads"
task setupLocalDownloads(type:Copy) {
from configurations.distribution
into localDownloads
}

task integTest(type: Test) {
// integration test requires the local testing repo for example plugin builds
dependsOn project.rootProject.allprojects.collect {
it.tasks.matching { it.name == 'publishNebulaPublicationToTestRepository'}
}
dependsOn setupLocalDownloads
exclude "**/*Tests.class"
inputs.dir(file("src/testKit"))
// tell BuildExamplePluginsIT where to find the example plugins
systemProperty (
'test.build-tools.plugin.examples',
files(
project(':example-plugins').subprojects.collect { it.projectDir }
).asPath,
)
systemProperty 'test.local-test-repo-path', "${rootProject.buildDir}/local-test-repo"
systemProperty 'test.local-test-downloads-path', localDownloads
systemProperty 'test.version_under_test', version
Matcher isLuceneSnapshot = (/\w+-snapshot-([a-z0-9]+)/ =~ versions.lucene)
if (isLuceneSnapshot) {
systemProperty 'test.lucene-snapshot-revision', isLuceneSnapshot[0][1]
}
maxParallelForks System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel.toString()) as Integer
// These tests run Gradle which doesn't have FIPS support
onlyIf { project.inFipsJvm == false }
}
check.dependsOn(integTest)

// TODO: re-enable once randomizedtesting gradle code is published and removed from here
licenseHeaders.enabled = false

Expand All @@ -250,6 +217,14 @@ if (project != rootProject) {
}
}

task integTest(type: Test) {
inputs.dir(file("src/testKit")).withPropertyName("testkit dir").withPathSensitivity(PathSensitivity.RELATIVE)
systemProperty 'test.version_under_test', version
onlyIf { project.inFipsJvm == false }
maxParallelForks = System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel.toString()) as Integer
}
check.dependsOn(integTest)

/*
* We alread configure publication and we don't need or want this one that
* comes from the java-gradle-plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ class PluginBuildPlugin implements Plugin<Project> {
project.afterEvaluate {
boolean isXPackModule = project.path.startsWith(':x-pack:plugin')
boolean isModule = project.path.startsWith(':modules:') || isXPackModule
String name = extension.name
PluginPropertiesExtension extension1 = project.getExtensions().getByType(PluginPropertiesExtension.class)
String name = extension1.name
project.archivesBaseName = name

// set the project description so it will be picked up by publishing
project.description = extension.description

configurePublishing(project, extension)

project.description = extension1.description
configurePublishing(project, extension1)
if (project.plugins.hasPlugin(TestClustersPlugin.class) == false) {
project.integTestCluster.dependsOn(project.tasks.bundlePlugin)
if (isModule) {
Expand Down Expand Up @@ -99,7 +96,29 @@ class PluginBuildPlugin implements Plugin<Project> {
}
}
}

if (extension1.name == null) {
throw new InvalidUserDataException('name is a required setting for esplugin')
}
if (extension1.description == null) {
throw new InvalidUserDataException('description is a required setting for esplugin')
}
if (extension1.classname == null) {
throw new InvalidUserDataException('classname is a required setting for esplugin')
}
Copy buildProperties = project.tasks.getByName('pluginProperties')
Map<String, String> properties = [
'name' : extension1.name,
'description' : extension1.description,
'version' : extension1.version,
'elasticsearchVersion': Version.fromString(VersionProperties.elasticsearch).toString(),
'javaVersion' : project.targetCompatibility as String,
'classname' : extension1.classname,
'extendedPlugins' : extension1.extendedPlugins.join(','),
'hasNativeController' : extension1.hasNativeController,
'requiresKeystore' : extension1.requiresKeystore
]
buildProperties.expand(properties)
buildProperties.inputs.properties(properties)
project.tasks.run.dependsOn(project.tasks.bundlePlugin)
if (isModule) {
project.tasks.run.clusterConfig.distribution = System.getProperty(
Expand All @@ -108,9 +127,8 @@ class PluginBuildPlugin implements Plugin<Project> {
} else {
project.tasks.run.clusterConfig.plugin(project.path)
}

if (isModule == false || isXPackModule) {
addNoticeGeneration(project, extension)
addNoticeGeneration(project, extension1)
}
}
project.tasks.named('testingConventions').configure {
Expand Down Expand Up @@ -150,7 +168,6 @@ class PluginBuildPlugin implements Plugin<Project> {
if (project.plugins.hasPlugin(MavenPublishPlugin)) {
project.publishing.publications.nebula(MavenPublication).artifactId(extension.name)
}

}
}

Expand Down Expand Up @@ -207,36 +224,6 @@ class PluginBuildPlugin implements Plugin<Project> {
into("${project.buildDir}/generated-resources")
}

project.afterEvaluate {
// check require properties are set
if (extension.name == null) {
throw new InvalidUserDataException('name is a required setting for esplugin')
}
if (extension.description == null) {
throw new InvalidUserDataException('description is a required setting for esplugin')
}
if (extension.classname == null) {
throw new InvalidUserDataException('classname is a required setting for esplugin')
}

Map<String, String> properties = [
'name': extension.name,
'description': extension.description,
'version': extension.version,
'elasticsearchVersion': Version.fromString(VersionProperties.elasticsearch).toString(),
'javaVersion': project.targetCompatibility as String,
'classname': extension.classname,
'extendedPlugins': extension.extendedPlugins.join(','),
'hasNativeController': extension.hasNativeController,
'requiresKeystore': extension.requiresKeystore
]

buildProperties.configure {
expand(properties)
inputs.properties(properties)
}
}

// add the plugin properties and metadata to test resources, so unit tests can
// know about the plugin (used by test security code to statically initialize the plugin in unit tests)
SourceSet testSourceSet = project.sourceSets.test
Expand Down Expand Up @@ -291,7 +278,7 @@ class PluginBuildPlugin implements Plugin<Project> {

/** Configure the pom for the main jar of this plugin */

protected void addNoticeGeneration(Project project, PluginPropertiesExtension extension) {
protected static void addNoticeGeneration(Project project, PluginPropertiesExtension extension) {
File licenseFile = extension.licenseFile
if (licenseFile != null) {
project.tasks.bundlePlugin.from(licenseFile.parentFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void apply(Project project) {
// provide a task to be able to list defined clusters.
createListClustersTask(project, container);

if (project.getRootProject().getExtensions().findByType(TestClustersRegistry.class) == null) {
if (project.getRootProject().getExtensions().findByName("testClusters") == null) {
TestClustersRegistry registry = project.getRootProject().getExtensions()
.create("testClusters", TestClustersRegistry.class);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testPluginCanBeApplied() {

public void testCheckTask() {
BuildResult result = getGradleRunner("elasticsearch.build")
.withArguments("check", "assemble", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath())
.withArguments("check", "assemble", "-s")
.build();
assertTaskSuccessful(result, ":check");
}
Expand Down Expand Up @@ -103,7 +103,7 @@ private void runInsecureArtifactRepositoryTest(final String name, final String u

public void testLicenseAndNotice() throws IOException {
BuildResult result = getGradleRunner("elasticsearch.build")
.withArguments("clean", "assemble", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath())
.withArguments("clean", "assemble")
.build();

assertTaskSuccessful(result, ":assemble");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private BuildResult runBuild(String taskname, String... sysProps) throws IOExcep
assert sysProps.length % 2 == 0;
List<String> args = new ArrayList<>();
args.add(taskname);
args.add("-Dlocal.repo.path=" + getLocalTestRepoPath());
for (int i = 0; i < sysProps.length; i += 2) {
args.add("-D" + sysProps[i] + "=" + sysProps[i + 1]);
}
Expand Down
Loading

0 comments on commit 3648481

Please sign in to comment.