-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
RFC: Test that example plugins build stand-alone #32235
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5cb970a
RFC: Test that example plugins build stand-alone
alpar-t fa25aee
Fix task up-to-date annotations
alpar-t b0213f4
Add lang-painless-spi, luceene snapshot repo
alpar-t bca30ef
Merge remote-tracking branch 'origin/master' into test-example-plugin…
alpar-t 1356199
Create a `publishNebulaPublicationToLocalTestRepository` task
alpar-t db988ef
Connect tests to the local repo
alpar-t 34d73bc
pr review
alpar-t cdb057b
useold syntax to apply plugin
alpar-t 4ef6a43
PR review
alpar-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
buildSrc/src/test/java/org/elasticsearch/gradle/BuildExamplePluginsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* 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.Path; | ||
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 | ||
Files.write( | ||
getTempPath("settings.gradle"), | ||
"enableFeaturePreview('STABLE_PUBLISHING')\n".getBytes(StandardCharsets.UTF_8) | ||
); | ||
|
||
adaptBuildScriptForTest(); | ||
|
||
Files.write( | ||
tmpDir.newFile("NOTICE.txt").toPath(), | ||
"dummy test notice".getBytes(StandardCharsets.UTF_8) | ||
); | ||
|
||
GradleRunner.create() | ||
.withProjectDir(tmpDir.getRoot()) | ||
.withArguments("clean", "check", "-s", "-i", "--warning-mode=all", "--scan") | ||
.withPluginClasspath() | ||
.build(); | ||
} | ||
|
||
private void adaptBuildScriptForTest() throws IOException { | ||
// Add the local repo as a build script URL so we can pull in build-tools and apply the plugin under test | ||
// + is ok because we have no other repo and just want to pick up latest | ||
writeBuildScript( | ||
"buildscript {\n" + | ||
" repositories {\n" + | ||
" maven {\n" + | ||
" url = '" + getLocalTestRepoPath() + "'\n" + | ||
" }\n" + | ||
" }\n" + | ||
" dependencies {\n" + | ||
" classpath \"org.elasticsearch.gradle:build-tools:+\"\n" + | ||
" }\n" + | ||
"}\n" | ||
); | ||
// get the original file | ||
Files.readAllLines(getTempPath("build.gradle"), StandardCharsets.UTF_8) | ||
.stream() | ||
.map(line -> line + "\n") | ||
.forEach(this::writeBuildScript); | ||
// Add a repositories section to be able to resolve dependencies | ||
String luceneSnapshotRepo = ""; | ||
String luceneSnapshotRevision = System.getProperty("test.lucene-snapshot-revision"); | ||
if (luceneSnapshotRepo != null) { | ||
luceneSnapshotRepo = " maven {\n" + | ||
" url \"http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/" + luceneSnapshotRevision + "\"\n" + | ||
" }\n"; | ||
} | ||
writeBuildScript("\n" + | ||
"repositories {\n" + | ||
" maven {\n" + | ||
" url \"" + getLocalTestRepoPath() + "\"\n" + | ||
" }\n" + | ||
luceneSnapshotRepo + | ||
"}\n" | ||
); | ||
Files.delete(getTempPath("build.gradle")); | ||
Files.move(getTempPath("build.gradle.new"), getTempPath("build.gradle")); | ||
System.err.print("Generated build script is:"); | ||
Files.readAllLines(getTempPath("build.gradle")).forEach(System.err::println); | ||
} | ||
|
||
private Path getTempPath(String fileName) { | ||
return new File(tmpDir.getRoot(), fileName).toPath(); | ||
} | ||
|
||
private Path writeBuildScript(String script) { | ||
try { | ||
Path path = getTempPath("build.gradle.new"); | ||
return Files.write( | ||
path, | ||
script.getBytes(StandardCharsets.UTF_8), | ||
Files.exists(path) ? StandardOpenOption.APPEND : StandardOpenOption.CREATE_NEW | ||
); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wonder I this test would make more sense inside
plugins/examples
, so one could just runcheck
under there and be confident the examples are setup correctly?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.
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
qa
- which I think would be in-line with how we handle this in general.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.
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 comment
The 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.