diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 1b86475dd6f..dcd38af0dc4 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -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' @@ -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" @@ -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() @@ -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 @@ -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. diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index b832f53b342..c816ab518a8 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -62,14 +62,11 @@ class PluginBuildPlugin implements Plugin { 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) { @@ -99,7 +96,29 @@ class PluginBuildPlugin implements Plugin { } } } - + 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 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( @@ -108,9 +127,8 @@ class PluginBuildPlugin implements Plugin { } else { project.tasks.run.clusterConfig.plugin(project.path) } - if (isModule == false || isXPackModule) { - addNoticeGeneration(project, extension) + addNoticeGeneration(project, extension1) } } project.tasks.named('testingConventions').configure { @@ -150,7 +168,6 @@ class PluginBuildPlugin implements Plugin { if (project.plugins.hasPlugin(MavenPublishPlugin)) { project.publishing.publications.nebula(MavenPublication).artifactId(extension.name) } - } } @@ -207,36 +224,6 @@ class PluginBuildPlugin implements Plugin { 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 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 @@ -291,7 +278,7 @@ class PluginBuildPlugin implements Plugin { /** 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) { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersPlugin.java index b6c8c39e2ed..a76de72e82a 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersPlugin.java @@ -57,7 +57,7 @@ public class TestClustersPlugin implements Plugin { // 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); diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/BuildExamplePluginsIT.java b/buildSrc/src/test/java/org/elasticsearch/gradle/BuildExamplePluginsIT.java deleted file mode 100644 index 7b4b315fd00..00000000000 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/BuildExamplePluginsIT.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.Ignore; -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; - -@Ignore("https://github.com/elastic/elasticsearch/issues/42453") -public class BuildExamplePluginsIT extends GradleIntegrationTestCase { - - private static final List EXAMPLE_PLUGINS = Collections.unmodifiableList( - Arrays.stream( - Objects.requireNonNull(System.getProperty("test.build-tools.plugin.examples")) - .split(File.pathSeparator) - ).map(File::new).collect(Collectors.toList()) - ); - - private static final String BUILD_TOOLS_VERSION = Objects.requireNonNull(System.getProperty("test.version_under_test")); - - @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 parameters() { - return EXAMPLE_PLUGINS - .stream() - .map(each -> new Object[] {each}) - .collect(Collectors.toList()); - } - - public void testCurrentExamplePlugin() throws IOException { - FileUtils.copyDirectory(examplePlugin, tmpDir.getRoot(), pathname -> pathname.getPath().contains("/build/") == false); - - 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 - // we need to specify the exact version of build-tools because gradle automatically adds its plugin portal - // which appears to mirror jcenter, opening us up to pulling a "later" version of build-tools - writeBuildScript( - "buildscript {\n" + - " repositories {\n" + - " maven {\n" + - " name = \"test\"\n" + - " url = '" + getLocalTestRepoPath() + "'\n" + - " }\n" + - " }\n" + - " dependencies {\n" + - " classpath \"org.elasticsearch.gradle:build-tools:" + BUILD_TOOLS_VERSION + "\"\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" + - " name \"lucene-snapshots\"\n" + - " url \"https://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/" + luceneSnapshotRevision + "\"\n" + - " }\n"; - } - writeBuildScript("\n" + - "repositories {\n" + - " maven {\n" + - " name \"test\"\n" + - " url \"" + getLocalTestRepoPath() + "\"\n" + - " }\n" + - " flatDir {\n" + - " dir '" + getLocalTestDownloadsPath() + "'\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); - } - } -} diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/BuildPluginIT.java b/buildSrc/src/test/java/org/elasticsearch/gradle/BuildPluginIT.java index 2e0e594b0f5..c1c8a8b5e52 100644 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/BuildPluginIT.java +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/BuildPluginIT.java @@ -51,7 +51,7 @@ public class BuildPluginIT extends GradleIntegrationTestCase { public void testCheckTask() { BuildResult result = getGradleRunner("elasticsearch.build") - .withArguments("check", "assemble", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath()) + .withArguments("check", "assemble", "-s") .build(); assertTaskSuccessful(result, ":check"); } @@ -103,7 +103,7 @@ public class BuildPluginIT extends GradleIntegrationTestCase { 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"); diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginIT.java b/buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginIT.java index 5f728392313..d4769bba573 100644 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginIT.java +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginIT.java @@ -99,7 +99,6 @@ public class DistributionDownloadPluginIT extends GradleIntegrationTestCase { assert sysProps.length % 2 == 0; List 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]); } diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/JdkDownloadPluginIT.java b/buildSrc/src/test/java/org/elasticsearch/gradle/JdkDownloadPluginIT.java index e31ce72d89a..4e760502e2c 100644 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/JdkDownloadPluginIT.java +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/JdkDownloadPluginIT.java @@ -109,7 +109,6 @@ public abstract class JdkDownloadPluginIT extends GradleIntegrationTestCase { GradleRunner runner = GradleRunner.create().withProjectDir(getProjectDir("jdk-download")) .withArguments(taskname, - "-Dlocal.repo.path=" + getLocalTestRepoPath(), "-Dtests.jdk_vendor=" + vendor, "-Dtests.jdk_version=" + version, "-Dtests.jdk_repo=" + wireMock.baseUrl(), diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginBuildPluginTests.java b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginBuildPluginTests.java new file mode 100644 index 00000000000..b3dccfbcbc8 --- /dev/null +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginBuildPluginTests.java @@ -0,0 +1,69 @@ +package org.elasticsearch.gradle.plugin; + +import org.elasticsearch.gradle.BwcVersions; +import org.elasticsearch.gradle.test.GradleUnitTestCase; +import org.gradle.api.Project; +import org.gradle.api.Task; +import org.gradle.api.internal.project.ProjectInternal; +import org.gradle.testfixtures.ProjectBuilder; +import org.junit.Before; +import org.junit.Ignore; +import org.mockito.Mockito; + +import java.util.stream.Collectors; + +public class PluginBuildPluginTests extends GradleUnitTestCase { + + private Project project; + + @Before + public void setUp() throws Exception { + project = ProjectBuilder.builder() + .withName(getClass().getName()) + .build(); + } + + public void testApply() { + // FIXME: distribution download plugin doesn't support running externally + project.getExtensions().getExtraProperties().set( + "bwcVersions", Mockito.mock(BwcVersions.class) + ); + project.getPlugins().apply(PluginBuildPlugin.class); + + assertNotNull( + "plugin extension created with the right name", + project.getExtensions().findByName(PluginBuildPlugin.PLUGIN_EXTENSION_NAME) + ); + assertNotNull( + "plugin extensions has the right type", + project.getExtensions().findByType(PluginPropertiesExtension.class) + ); + + assertNotNull( + "plugin created an integTest class", + project.getTasks().findByName("integTest") + ); + } + + @Ignore("https://github.com/elastic/elasticsearch/issues/47123") + public void testApplyWithAfterEvaluate() { + project.getExtensions().getExtraProperties().set( + "bwcVersions", Mockito.mock(BwcVersions.class) + ); + project.getPlugins().apply(PluginBuildPlugin.class); + PluginPropertiesExtension extension = project.getExtensions().getByType(PluginPropertiesExtension.class); + extension.setNoticeFile(project.file("test.notice")); + extension.setLicenseFile(project.file("test.license")); + extension.setDescription("just a test"); + extension.setClassname(getClass().getName()); + + ((ProjectInternal) project).evaluate(); + + assertNotNull( + "Task to generate notice not created: " + project.getTasks().stream() + .map(Task::getPath) + .collect(Collectors.joining(", ")), + project.getTasks().findByName("generateNotice") + ); + } +} diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/precommit/JarHellTaskIT.java b/buildSrc/src/test/java/org/elasticsearch/gradle/precommit/JarHellTaskIT.java deleted file mode 100644 index d45028d8445..00000000000 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/precommit/JarHellTaskIT.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.elasticsearch.gradle.precommit; - -import org.elasticsearch.gradle.test.GradleIntegrationTestCase; -import org.gradle.testkit.runner.BuildResult; - -/* - * 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. - */ -public class JarHellTaskIT extends GradleIntegrationTestCase { - - public void testJarHellDetected() { - BuildResult result = getGradleRunner("jarHell") - .withArguments("clean", "precommit", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath()) - .buildAndFail(); - - assertTaskFailed(result, ":jarHell"); - assertOutputContains( - result.getOutput(), - "java.lang.IllegalStateException: jar hell!", - "class: org.apache.logging.log4j.Logger" - ); - } - -} diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java b/buildSrc/src/test/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java index 46a9194780c..6c8795cbdab 100644 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java @@ -157,10 +157,6 @@ public abstract class GradleIntegrationTestCase extends GradleUnitTestCase { ); } - protected String getLocalTestRepoPath() { - return getLocalTestPath("test.local-test-repo-path"); - } - protected String getLocalTestDownloadsPath() { return getLocalTestPath("test.local-test-downloads-path"); } diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/testclusters/TestClustersPluginIT.java b/buildSrc/src/test/java/org/elasticsearch/gradle/testclusters/TestClustersPluginIT.java deleted file mode 100644 index 6859d9ee858..00000000000 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/testclusters/TestClustersPluginIT.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * 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.testclusters; - -import org.elasticsearch.gradle.test.GradleIntegrationTestCase; -import org.gradle.testkit.runner.BuildResult; -import org.gradle.testkit.runner.GradleRunner; -import org.junit.Before; -import org.junit.Ignore; - - -import java.util.Arrays; - -@Ignore("https://github.com/elastic/elasticsearch/issues/42453") -public class TestClustersPluginIT extends GradleIntegrationTestCase { - - private GradleRunner runner; - - @Before - public void setUp() throws Exception { - runner = getGradleRunner("testclusters"); - } - - public void testListClusters() { - BuildResult result = getTestClustersRunner("listTestClusters").build(); - - assertTaskSuccessful(result, ":listTestClusters"); - assertOutputContains( - result.getOutput(), - " * myTestCluster:" - ); - } - - public void testUseClusterByOne() { - BuildResult result = getTestClustersRunner(":user1").build(); - assertTaskSuccessful(result, ":user1"); - assertStartedAndStoppedOnce(result); - } - - public void testUseClusterByOneWithDryRun() { - BuildResult result = getTestClustersRunner("--dry-run", ":user1").build(); - assertNull(result.task(":user1")); - assertNotStarted(result); - } - - public void testUseClusterByTwo() { - BuildResult result = getTestClustersRunner(":user1", ":user2").build(); - assertTaskSuccessful(result, ":user1", ":user2"); - assertStartedAndStoppedOnce(result); - } - - public void testUseClusterByUpToDateTask() { - // Run it once, ignoring the result and again to make sure it's considered up to date. - // Gradle randomly considers tasks without inputs and outputs as as up-to-date or success on the first run - getTestClustersRunner(":upToDate1").build(); - BuildResult result = getTestClustersRunner(":upToDate1").build(); - assertTaskUpToDate(result, ":upToDate1"); - assertNotStarted(result); - } - - public void testUseClusterBySkippedTask() { - BuildResult result = getTestClustersRunner(":skipped1", ":skipped2").build(); - assertTaskSkipped(result, ":skipped1", ":skipped2"); - assertNotStarted(result); - } - - public void testUseClusterBySkippedAndWorkingTask() { - BuildResult result = getTestClustersRunner("skipped1", "user1").build(); - assertTaskSkipped(result, ":skipped1"); - assertTaskSuccessful(result, ":user1"); - assertOutputContains( - result.getOutput(), - "> Task :user1", - "Starting `node{::myTestCluster-0}`", - "Stopping `node{::myTestCluster-0}`" - ); - } - - @Ignore // https://github.com/elastic/elasticsearch/issues/41256 - public void testMultiProject() { - BuildResult result = getTestClustersRunner( - "user1", "user2", "-s", "-i", "--parallel", "-Dlocal.repo.path=" + getLocalTestRepoPath() - ).build(); - - assertTaskSuccessful( - result, - ":user1", ":user2", ":alpha:user1", ":alpha:user2", ":bravo:user1", ":bravo:user2" - ); - assertStartedAndStoppedOnce(result); - assertOutputOnlyOnce( - result.getOutput(), - "Starting `node{:alpha:myTestCluster-0}`", - "Stopping `node{::myTestCluster-0}`" - ); - assertOutputOnlyOnce( - result.getOutput(), - "Starting `node{::myTestCluster-0}`", - "Stopping `node{:bravo:myTestCluster-0}`" - ); - } - - public void testReleased() { - BuildResult result = getTestClustersRunner("testReleased").build(); - assertTaskSuccessful(result, ":testReleased"); - assertStartedAndStoppedOnce(result, "releasedVersionDefault-0"); - assertStartedAndStoppedOnce(result, "releasedVersionOSS-0"); - assertStartedAndStoppedOnce(result, "releasedVersionIntegTest-0"); - } - - public void testIncremental() { - BuildResult result = getTestClustersRunner("clean", ":user1").build(); - assertTaskSuccessful(result, ":user1"); - assertStartedAndStoppedOnce(result); - - result = getTestClustersRunner(":user1").build(); - assertTaskSuccessful(result, ":user1"); - assertStartedAndStoppedOnce(result); - - result = getTestClustersRunner("clean", ":user1").build(); - assertTaskSuccessful(result, ":user1"); - assertStartedAndStoppedOnce(result); - assertStartedAndStoppedOnce(result); - } - - public void testUseClusterByFailingOne() { - BuildResult result = getTestClustersRunner(":itAlwaysFails").buildAndFail(); - assertTaskFailed(result, ":itAlwaysFails"); - assertStartedAndStoppedOnce(result); - assertOutputContains( - result.getOutput(), - "Stopping `node{::myTestCluster-0}`, tailLogs: true", - "Execution failed for task ':itAlwaysFails'." - ); - } - - public void testUseClusterByFailingDependency() { - BuildResult result = getTestClustersRunner(":dependsOnFailed").buildAndFail(); - assertTaskFailed(result, ":itAlwaysFails"); - assertNull(result.task(":dependsOnFailed")); - assertStartedAndStoppedOnce(result); - assertOutputContains( - result.getOutput(), - "Stopping `node{::myTestCluster-0}`, tailLogs: true", - "Execution failed for task ':itAlwaysFails'." - ); - } - - public void testConfigurationLocked() { - BuildResult result = getTestClustersRunner(":illegalConfigAlter").buildAndFail(); - assertTaskFailed(result, ":illegalConfigAlter"); - assertOutputContains( - result.getOutput(), - "Configuration for node{::myTestCluster-0} can not be altered, already locked" - ); - } - - @Ignore // https://github.com/elastic/elasticsearch/issues/41256 - public void testMultiNode() { - BuildResult result = getTestClustersRunner(":multiNode").build(); - assertTaskSuccessful(result, ":multiNode"); - assertStartedAndStoppedOnce(result, "multiNode-0"); - assertStartedAndStoppedOnce(result, "multiNode-1"); - assertStartedAndStoppedOnce(result, "multiNode-2"); - } - - public void testPluginInstalled() { - BuildResult result = getTestClustersRunner(":printLog").build(); - assertTaskSuccessful(result, ":printLog"); - assertStartedAndStoppedOnce(result); - assertOutputContains(result.getOutput(), "-> Installed dummy"); - assertOutputContains(result.getOutput(), "loaded plugin [dummy]"); - } - - private void assertNotStarted(BuildResult result) { - assertOutputDoesNotContain( - result.getOutput(), - "Starting ", - "Stopping " - ); - } - - private GradleRunner getTestClustersRunner(String... tasks) { - String[] arguments = Arrays.copyOf(tasks, tasks.length + 3); - arguments[tasks.length] = "-s"; - arguments[tasks.length + 1] = "-i"; - arguments[tasks.length + 2] = "-Dlocal.repo.path=" + getLocalTestRepoPath(); - return runner.withArguments(arguments); - } - - private void assertStartedAndStoppedOnce(BuildResult result, String nodeName) { - assertOutputOnlyOnce( - result.getOutput(), - "Starting `node{::" + nodeName + "}`", - "Stopping `node{::" + nodeName + "}`" - ); - } - - private void assertStartedAndStoppedOnce(BuildResult result) { - assertStartedAndStoppedOnce(result, "myTestCluster-0"); - } - - -} diff --git a/buildSrc/src/testKit/elasticsearch.build/build.gradle b/buildSrc/src/testKit/elasticsearch.build/build.gradle index daac5bfe33e..03ff3f90275 100644 --- a/buildSrc/src/testKit/elasticsearch.build/build.gradle +++ b/buildSrc/src/testKit/elasticsearch.build/build.gradle @@ -14,12 +14,6 @@ dependencies { repositories { jcenter() - repositories { - maven { - name "local-repo" - url System.getProperty("local.repo.path") - } - } } // todo remove offending rules @@ -30,6 +24,8 @@ jarHell.enabled = false // we don't have tests for now test.enabled = false thirdPartyAudit.enabled = false +// This requires an additional Jar not part of build-tools +loggerUsageCheck.enabled = false task hello { doFirst { diff --git a/buildSrc/src/testKit/jarHell/build.gradle b/buildSrc/src/testKit/jarHell/build.gradle deleted file mode 100644 index cb12ce03f51..00000000000 --- a/buildSrc/src/testKit/jarHell/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id 'java' - id 'elasticsearch.build' -} - -dependencyLicenses.enabled = false -dependenciesInfo.enabled = false -forbiddenApisMain.enabled = false -forbiddenApisTest.enabled = false -thirdPartyAudit.enabled = false -ext.licenseFile = file("$buildDir/dummy/license") -ext.noticeFile = file("$buildDir/dummy/notice") - -repositories { - jcenter() - repositories { - maven { - name "local" - url System.getProperty("local.repo.path") - } - } -} - -dependencies { - // Needed for the JarHell task - testCompile ("org.elasticsearch.test:framework:${versions.elasticsearch}") - // causes jar hell with local sources - compile "org.apache.logging.log4j:log4j-api:${versions.log4j}" -} diff --git a/buildSrc/src/testKit/jarHell/settings.gradle b/buildSrc/src/testKit/jarHell/settings.gradle deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/buildSrc/src/testKit/jarHell/src/main/java/org/apache/logging/log4j/Logger.java b/buildSrc/src/testKit/jarHell/src/main/java/org/apache/logging/log4j/Logger.java deleted file mode 100644 index a4332c664fa..00000000000 --- a/buildSrc/src/testKit/jarHell/src/main/java/org/apache/logging/log4j/Logger.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.apache.logging.log4j; - -// Jar Hell ! -public class Logger { - -} - diff --git a/buildSrc/src/testKit/testclusters/build.gradle b/buildSrc/src/testKit/testclusters/build.gradle deleted file mode 100644 index 4296965a73f..00000000000 --- a/buildSrc/src/testKit/testclusters/build.gradle +++ /dev/null @@ -1,142 +0,0 @@ -plugins { - id 'elasticsearch.testclusters' - id 'base' -} - -allprojects { all -> - repositories { - flatDir { - dir System.getProperty("test.local-test-downloads-path") - } - maven { - name "local" - url System.getProperty("local.repo.path") - } - String luceneSnapshotRevision = System.getProperty("test.lucene-snapshot-revision") - if (luceneSnapshotRevision != null) { - maven { - name "lucene-snapshots" - url "https://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/" + luceneSnapshotRevision - } - } - } - - if (project == rootProject || project.name == "alpha" || project.name == "bravo") { - apply plugin: 'elasticsearch.testclusters' - - all.testClusters { - myTestCluster { - testDistribution = 'DEFAULT' - version = System.getProperty("test.version_under_test") - javaHome = file(System.getProperty('java.home')) - plugin file("${project(":dummyPlugin").buildDir}/distributions/dummy-${System.getProperty("test.version_under_test")}.zip") - } - } - - task user1 { - useCluster testClusters.myTestCluster - doFirst { - println "$path: Cluster running @ ${testClusters.myTestCluster.httpSocketURI}" - } - } - task user2 { - useCluster testClusters.myTestCluster - doFirst { - println "$path: Cluster running @ ${testClusters.myTestCluster.httpSocketURI}" - } - } - syncTestClustersArtifacts { - dependsOn ":dummyPlugin:bundlePlugin" - } - } -} - -testClusters { - multiNode { - version = System.getProperty("test.version_under_test") - testDistribution = 'DEFAULT' - javaHome = file(System.getProperty('java.home')) - numberOfNodes = 3 - } - releasedVersionDefault { - version = "7.0.0" - testDistribution = 'DEFAULT' - javaHome = file(System.getProperty('java.home')) - } - releasedVersionOSS { - version = "7.0.0" - testDistribution = 'OSS' - javaHome = file(System.getProperty('java.home')) - } - releasedVersionIntegTest { - version = "7.0.0" - testDistribution = 'INTEG_TEST' - javaHome = file(System.getProperty('java.home')) - } -} - -task multiNode { - useCluster testClusters.multiNode - doFirst { - println "$path: Cluster running @ ${testClusters.multiNode.httpSocketURI}" - } -} - -task testReleased { - useCluster testClusters.releasedVersionDefault - useCluster testClusters.releasedVersionOSS - useCluster testClusters.releasedVersionIntegTest - doFirst { - println "$path: Cluster running @ ${testClusters.releasedVersionDefault.httpSocketURI}" - println "$path: Cluster running @ ${testClusters.releasedVersionOSS.httpSocketURI}" - println "$path: Cluster running @ ${testClusters.releasedVersionIntegTest.httpSocketURI}" - } -} - -task printLog { - useCluster testClusters.myTestCluster - doFirst { - println "$path: Cluster running @ ${testClusters.myTestCluster.httpSocketURI}" - testClusters.myTestCluster.singleNode().logLines().each { - println it - } - } -} - -task upToDate1 { - useCluster testClusters.myTestCluster - outputs.upToDateWhen { true } - doLast { - println "Some task action" - } -} - -task skipped1 { - enabled = false - useCluster testClusters.myTestCluster -} - -task skipped2 { - enabled = false - useCluster testClusters.myTestCluster -} - -task itAlwaysFails { - doLast { - throw new GradleException("Task 1 failed!") - } - useCluster testClusters.myTestCluster -} - -task dependsOnFailed { - dependsOn itAlwaysFails - useCluster testClusters.myTestCluster -} - -task illegalConfigAlter { - useCluster testClusters.myTestCluster - doFirst { - println "Going to alter configuration after use" - testClusters.myTestCluster.testDistribution = 'OSS' - } -} diff --git a/buildSrc/src/testKit/testclusters/dummyPlugin/build.gradle b/buildSrc/src/testKit/testclusters/dummyPlugin/build.gradle deleted file mode 100644 index 73833fc80cc..00000000000 --- a/buildSrc/src/testKit/testclusters/dummyPlugin/build.gradle +++ /dev/null @@ -1,11 +0,0 @@ -apply plugin: 'elasticsearch.esplugin' - -version = System.getProperty("test.version_under_test") - -esplugin { - name 'dummy' - description 'A dummy plugin used for testing' - classname 'DummyPlugin' - licenseFile rootProject.file('empty.txt') - noticeFile rootProject.file('empty.txt') -} \ No newline at end of file diff --git a/buildSrc/src/testKit/testclusters/dummyPlugin/src/main/java/DummyPlugin.java b/buildSrc/src/testKit/testclusters/dummyPlugin/src/main/java/DummyPlugin.java deleted file mode 100644 index fff45b7365e..00000000000 --- a/buildSrc/src/testKit/testclusters/dummyPlugin/src/main/java/DummyPlugin.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - */ - -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.common.settings.Settings; - -import java.nio.file.Path; - -public class DummyPlugin extends Plugin { - - public DummyPlugin(final Settings settings, final Path configPath) { - } - -} diff --git a/buildSrc/src/testKit/testclusters/empty.txt b/buildSrc/src/testKit/testclusters/empty.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/buildSrc/src/testKit/testclusters/settings.gradle b/buildSrc/src/testKit/testclusters/settings.gradle deleted file mode 100644 index 0b90220482d..00000000000 --- a/buildSrc/src/testKit/testclusters/settings.gradle +++ /dev/null @@ -1,5 +0,0 @@ -include 'dummyPlugin' -include ':alpha' -include ':bravo' -include ':charlie' -include 'dummyPlugin' \ No newline at end of file