-
Notifications
You must be signed in to change notification settings - Fork 25.2k
RFC: Test that example plugins build stand-alone #32235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
5cb970a
fa25aee
b0213f4
bca30ef
1356199
db988ef
34d73bc
cdb057b
4ef6a43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,8 +87,23 @@ subprojects { | |
} | ||
} | ||
} | ||
repositories { | ||
maven { | ||
name = 'localTest' | ||
url = "$rootProject.buildDir/local-test-repo" | ||
} | ||
} | ||
} | ||
} | ||
// Make nebula and shadow play nice together, Gradle doesn't like it how one jar task replaces the output of another | ||
// if both are part of published artifacts | ||
project.afterEvaluate { | ||
if (plugins.hasPlugin(MavenPublishPlugin) && plugins.hasPlugin(ShadowPlugin)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this something that should be in BuildPlugin? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a strong preference. I'm thinking build plugin will be implemented in Java and perhaps the bulk of it split into smaller focused classes. In this respect small scripts and glue could live and would be easier to write in the groovy script. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems wrong to me to have the shadow plugin and publishing be something we support via BuildPlugin, yet require additional hacks within our build files. |
||
project.publishing.publications.nebula.artifacts = [project.tasks.shadowJar] | ||
} | ||
} | ||
|
||
|
||
plugins.withType(BuildPlugin).whenPluginAdded { | ||
project.licenseFile = project.rootProject.file('licenses/APACHE-LICENSE-2.0.txt') | ||
project.noticeFile = project.rootProject.file('NOTICE.txt') | ||
|
@@ -228,6 +243,7 @@ subprojects { | |
"org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}": ':client:rest-high-level', | ||
"org.elasticsearch.client:test:${version}": ':client:test', | ||
"org.elasticsearch.client:transport:${version}": ':client:transport', | ||
"org.elasticsearch.plugin:elasticsearch-scripting-painless-spi:${version}": ':modules:lang-painless:spi', | ||
"org.elasticsearch.test:framework:${version}": ':test:framework', | ||
"org.elasticsearch.distribution.integ-test-zip:elasticsearch:${version}": ':distribution:archives:integ-test-zip', | ||
"org.elasticsearch.distribution.zip:elasticsearch:${version}": ':distribution:archives:zip', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,11 +162,24 @@ if (project != rootProject) { | |
// it's fine as we run them as part of :buildSrc | ||
test.enabled = false | ||
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 == 'publishNebulaPublicationToLocalTestRepository'} | ||
} | ||
exclude "**/*Tests.class" | ||
include "**/*IT.class" | ||
testClassesDirs = sourceSets.test.output.classesDirs | ||
classpath = sourceSets.test.runtimeClasspath | ||
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 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder I this test would make more sense inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think one is better than the other. It's an integration between the too, and right now chances are greater that build-tools will break the test as the plugins barely change. I taught about it too because it's odd to a new example ad have a distant projects tests break. We could always move them around or create a project in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this as an integration between the two. The examples are on their own. They use the build-tools, like any other project within the repo. This test is about ensuring those projects build files are correct. Ensuring build-tools is not itself broken is a place other tests here, IMO. Actually, I think it would be even nicer if each example plugin had an additional integration test task in place to check that specific plugin. This would make reproducing failures a lot easier (since it is a task on the project that fails). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with a task on the example plugins, but not entirely convinced it's worth the effort now . I started writing these tests to make sure build-tools can run for other builds too, something that the example plugins helped with. We build these during the regular build so making sure build script and all is correct is already done there to some extent. I propose we do this in a subsequent PR after seeing where this approach takes us, so we can get some tests running and feedback before we invest more effort into it. |
||
).asPath, | ||
) | ||
systemProperty 'test.local-test-repo-path', "$rootProject.buildDir/local-test-repo" | ||
systemProperty 'test.luceene-snapshot-revision', (versions.lucene =~ /\w+-snapshot-([a-z0-9]+)/)[0][1] | ||
} | ||
check.dependsOn(integTest) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.elasticsearch.gradle; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
import org.apache.commons.io.FileUtils; | ||
import org.elasticsearch.gradle.test.GradleIntegrationTestCase; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class BuildExamplePluginsIT extends GradleIntegrationTestCase { | ||
|
||
private static List<File> EXAMPLE_PLUGINS = Collections.unmodifiableList( | ||
Arrays.stream( | ||
Objects.requireNonNull(System.getProperty("test.build-tools.plugin.examples")) | ||
.split(File.pathSeparator) | ||
).map(File::new).collect(Collectors.toList()) | ||
); | ||
|
||
@Rule | ||
public TemporaryFolder tmpDir = new TemporaryFolder(); | ||
|
||
public final File examplePlugin; | ||
|
||
public BuildExamplePluginsIT(File examplePlugin) { | ||
this.examplePlugin = examplePlugin; | ||
} | ||
|
||
@BeforeClass | ||
public static void assertProjectsExist() { | ||
assertEquals( | ||
EXAMPLE_PLUGINS, | ||
EXAMPLE_PLUGINS.stream().filter(File::exists).collect(Collectors.toList()) | ||
); | ||
} | ||
|
||
@ParametersFactory | ||
public static Iterable<Object[]> parameters() { | ||
return EXAMPLE_PLUGINS | ||
.stream() | ||
.map(each -> new Object[] {each}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public void testCurrentExamplePlugin() throws IOException { | ||
FileUtils.copyDirectory(examplePlugin, tmpDir.getRoot()); | ||
// just get rid of deprecation warnings from now | ||
Files.write( | ||
tmpDir.newFile("settings.gradle").toPath(), "enableFeaturePreview('STABLE_PUBLISHING')\n".getBytes(StandardCharsets.UTF_8) | ||
); | ||
// Add a repositories section to be able to resolve dependencies | ||
Files.write( | ||
new File(tmpDir.getRoot(), "build.gradle").toPath(), | ||
("\n" + | ||
"repositories {\n" + | ||
" maven {\n" + | ||
" url \"" + getLocalTestRepoPath() + "\"\n" + | ||
" }\n" + | ||
" maven {\n" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we conditionally add this only if the build is using a lucene snapshot? |
||
" url \"http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/" + getLuceneSnapshotRevision() + "\"\n" + | ||
" }\n" + | ||
"}\n").getBytes(StandardCharsets.UTF_8), | ||
StandardOpenOption.APPEND | ||
); | ||
Files.write( | ||
tmpDir.newFile("NOTICE.txt").toPath(), | ||
"dummy test nottice".getBytes(StandardCharsets.UTF_8) | ||
); | ||
|
||
GradleRunner.create() | ||
// Todo make a copy, write a settings file enabling stable publishing | ||
.withProjectDir(tmpDir.getRoot()) | ||
.withArguments("clean", "check", "-s", "-i", "--warning-mode=all", "--scan") | ||
.withPluginClasspath() | ||
.build(); | ||
} | ||
|
||
private String getLuceneSnapshotRevision() { | ||
return System.getProperty("test.luceene-snapshot-revision", "not-a-snapshot"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: luceene -> lucene |
||
} | ||
|
||
private String getLocalTestRepoPath() { | ||
String property = System.getProperty("test.local-test-repo-path"); | ||
Objects.requireNonNull(property, "test.local-test-repo-path not passed to tests"); | ||
File file = new File(property); | ||
assertTrue("Expected " + property + " to exist, but it did not!", file.exists()); | ||
return file.getAbsolutePath(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,21 @@ | |
* under the License. | ||
*/ | ||
|
||
apply plugin: 'elasticsearch.esplugin' | ||
plugins { | ||
id 'elasticsearch.esplugin' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't like having this using the plugins dsl until we actually have build-tools published to the gradle plugin portal. While these examples currently are missing the buildtools section to make apply work outside the build, if they are copied with the plugins block they will never work, and the purpose of these is to make the examples copyable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely happy about it either, but it handles the injection of the plugin that was just built, a lot of boilerplate that this DSL and testKit helps us avoid. That being said, I think with what we have now, we could inject the local repo into the build script classpath and easily avoid that boilerplate. I will take a look. |
||
} | ||
|
||
esplugin { | ||
name 'custom-settings' | ||
description 'An example plugin showing how to register custom settings' | ||
classname 'org.elasticsearch.example.customsettings.ExampleCustomSettingsPlugin' | ||
licenseFile rootProject.file('licenses/APACHE-LICENSE-2.0.txt') | ||
noticeFile rootProject.file('NOTICE.txt') | ||
} | ||
|
||
integTestCluster { | ||
// Adds a setting in the Elasticsearch keystore before running the integration tests | ||
keystoreSetting 'custom.secured', 'password' | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extra newlines |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
${rootProject.buildDir}
as it is more clear where the substitution ends.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still seems outstanding?