Skip to content

Commit

Permalink
[8.1] Remove usages of elasticsearch.build plugin in non-production p…
Browse files Browse the repository at this point in the history
…rojects (#84961)
  • Loading branch information
mark-vieira committed Mar 14, 2022
1 parent 7486462 commit dc3d3b5
Show file tree
Hide file tree
Showing 28 changed files with 176 additions and 213 deletions.
6 changes: 5 additions & 1 deletion build-tools-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ gradlePlugin {
id = 'elasticsearch.internal-es-plugin'
implementationClass = 'org.elasticsearch.gradle.internal.InternalPluginBuildPlugin'
}
internalBasePlugin {
id = 'elasticsearch.base-internal-es-plugin'
implementationClass = 'org.elasticsearch.gradle.internal.BaseInternalPluginBuildPlugin'
}
internalTestArtifact {
id = 'elasticsearch.internal-test-artifact'
implementationClass = 'org.elasticsearch.gradle.internal.InternalTestArtifactPlugin'
Expand Down Expand Up @@ -304,4 +308,4 @@ abstract class JacksonAlignmentRule implements ComponentMetadataRule {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal;

import groovy.lang.Closure;

import org.elasticsearch.gradle.internal.conventions.util.Util;
import org.elasticsearch.gradle.internal.test.RestTestBasePlugin;
import org.elasticsearch.gradle.plugin.PluginBuildPlugin;
import org.elasticsearch.gradle.plugin.PluginPropertiesExtension;
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster;
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
import org.elasticsearch.gradle.util.GradleUtils;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.tasks.bundling.Zip;

import java.util.Optional;

/**
* Base plugin for building internal plugins or modules. This plugin should only be directly applied by internal test-only plugins or
* modules. That is, plugins not externally published and modules only included in snapshot builds. Otherwise
* {@link InternalPluginBuildPlugin} should be used.
*/
public class BaseInternalPluginBuildPlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
project.getPluginManager().apply(PluginBuildPlugin.class);
// Clear default dependencies added by public PluginBuildPlugin as we add our
// own project dependencies for internal builds
// TODO remove once we removed default dependencies from PluginBuildPlugin
project.getConfigurations().getByName("compileOnly").getDependencies().clear();
project.getConfigurations().getByName("testImplementation").getDependencies().clear();

project.getPluginManager().apply(RestTestBasePlugin.class);
var extension = project.getExtensions().getByType(PluginPropertiesExtension.class);

// We've ported this from multiple build scripts where we see this pattern into
// an extension method as a first step of consolidation.
// We might want to port this into a general pattern later on.
project.getExtensions()
.getExtraProperties()
.set("addQaCheckDependencies", new Closure<Object>(BaseInternalPluginBuildPlugin.this, BaseInternalPluginBuildPlugin.this) {
public void doCall(Object it) {
project.afterEvaluate(project1 -> {
// let check depend on check tasks of qa sub-projects
final var checkTaskProvider = project1.getTasks().named("check");
Optional<Project> qaSubproject = project1.getSubprojects()
.stream()
.filter(p -> p.getPath().equals(project1.getPath() + ":qa"))
.findFirst();
qaSubproject.ifPresent(
qa -> qa.getSubprojects()
.forEach(p -> checkTaskProvider.configure(task -> task.dependsOn(p.getPath() + ":check")))
);
});
}

public void doCall() {
doCall(null);
}
});

project.afterEvaluate(p -> {
boolean isModule = GradleUtils.isModuleProject(p.getPath());
boolean isXPackModule = isModule && p.getPath().startsWith(":x-pack");
if (isModule == false || isXPackModule) {
addNoticeGeneration(p, extension);
}

@SuppressWarnings("unchecked")
NamedDomainObjectContainer<ElasticsearchCluster> testClusters = (NamedDomainObjectContainer<ElasticsearchCluster>) project
.getExtensions()
.getByName(TestClustersPlugin.EXTENSION_NAME);
p.getExtensions().getByType(PluginPropertiesExtension.class).getExtendedPlugins().forEach(pluginName -> {
// Auto add any dependent modules
findModulePath(project, pluginName).ifPresent(
path -> testClusters.configureEach(elasticsearchCluster -> elasticsearchCluster.module(path))
);
});
});
}

Optional<String> findModulePath(Project project, String pluginName) {
return project.getRootProject()
.getAllprojects()
.stream()
.filter(p -> GradleUtils.isModuleProject(p.getPath()))
.filter(p -> p.getPlugins().hasPlugin(PluginBuildPlugin.class))
.filter(p -> p.getExtensions().getByType(PluginPropertiesExtension.class).getName().equals(pluginName))
.findFirst()
.map(Project::getPath);
}

/**
* Configure the pom for the main jar of this plugin
*/
protected static void addNoticeGeneration(final Project project, PluginPropertiesExtension extension) {
final var licenseFile = extension.getLicenseFile();
var tasks = project.getTasks();
if (licenseFile != null) {
tasks.withType(Zip.class).named("bundlePlugin").configure(zip -> zip.from(licenseFile.getParentFile(), copySpec -> {
copySpec.include(licenseFile.getName());
copySpec.rename(s -> "LICENSE.txt");
}));
}

final var noticeFile = extension.getNoticeFile();
if (noticeFile != null) {
final var generateNotice = tasks.register("generateNotice", NoticeTask.class, noticeTask -> {
noticeTask.setInputFile(noticeFile);
noticeTask.source(Util.getJavaMainSourceSet(project).get().getAllJava());
});
tasks.withType(Zip.class).named("bundlePlugin").configure(task -> task.from(generateNotice));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,14 @@

package org.elasticsearch.gradle.internal;

import groovy.lang.Closure;

import org.elasticsearch.gradle.internal.conventions.util.Util;
import org.elasticsearch.gradle.internal.precommit.TestingConventionsTasks;
import org.elasticsearch.gradle.internal.test.RestTestBasePlugin;
import org.elasticsearch.gradle.plugin.PluginBuildPlugin;
import org.elasticsearch.gradle.plugin.PluginPropertiesExtension;
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster;
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
import org.elasticsearch.gradle.util.GradleUtils;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.tasks.bundling.Zip;

import java.util.Optional;

public class InternalPluginBuildPlugin implements InternalPlugin {
@Override
public void apply(Project project) {
project.getPluginManager().apply(BuildPlugin.class);
project.getPluginManager().apply(PluginBuildPlugin.class);
// Clear default dependencies added by public PluginBuildPlugin as we add our
// own project dependencies for internal builds
// TODO remove once we removed default dependencies from PluginBuildPlugin
project.getConfigurations().getByName("compileOnly").getDependencies().clear();
project.getConfigurations().getByName("testImplementation").getDependencies().clear();

project.getPluginManager().apply(RestTestBasePlugin.class);
var extension = project.getExtensions().getByType(PluginPropertiesExtension.class);

// We've ported this from multiple build scripts where we see this pattern into
// an extension method as a first step of consolidation.
// We might want to port this into a general pattern later on.
project.getExtensions()
.getExtraProperties()
.set("addQaCheckDependencies", new Closure<Object>(InternalPluginBuildPlugin.this, InternalPluginBuildPlugin.this) {
public void doCall(Object it) {
project.afterEvaluate(project1 -> {
// let check depend on check tasks of qa sub-projects
final var checkTaskProvider = project1.getTasks().named("check");
Optional<Project> qaSubproject = project1.getSubprojects()
.stream()
.filter(p -> p.getPath().equals(project1.getPath() + ":qa"))
.findFirst();
qaSubproject.ifPresent(
qa -> qa.getSubprojects()
.forEach(p -> checkTaskProvider.configure(task -> task.dependsOn(p.getPath() + ":check")))
);
});
}

public void doCall() {
doCall(null);
}
});
project.getPluginManager().apply(BaseInternalPluginBuildPlugin.class);

project.getTasks().withType(TestingConventionsTasks.class).named("testingConventions").configure(t -> {
t.getNaming().clear();
Expand All @@ -74,58 +27,5 @@ public void doCall() {
testingConventionRule.baseClass("org.elasticsearch.test.ESSingleNodeTestCase");
});
});

project.afterEvaluate(p -> {
boolean isModule = GradleUtils.isModuleProject(p.getPath());
boolean isXPackModule = isModule && p.getPath().startsWith(":x-pack");
if (isModule == false || isXPackModule) {
addNoticeGeneration(p, extension);
}

@SuppressWarnings("unchecked")
NamedDomainObjectContainer<ElasticsearchCluster> testClusters = (NamedDomainObjectContainer<ElasticsearchCluster>) project
.getExtensions()
.getByName(TestClustersPlugin.EXTENSION_NAME);
p.getExtensions().getByType(PluginPropertiesExtension.class).getExtendedPlugins().forEach(pluginName -> {
// Auto add any dependent modules
findModulePath(project, pluginName).ifPresent(
path -> testClusters.configureEach(elasticsearchCluster -> elasticsearchCluster.module(path))
);
});
});
}

Optional<String> findModulePath(Project project, String pluginName) {
return project.getRootProject()
.getAllprojects()
.stream()
.filter(p -> GradleUtils.isModuleProject(p.getPath()))
.filter(p -> p.getPlugins().hasPlugin(PluginBuildPlugin.class))
.filter(p -> p.getExtensions().getByType(PluginPropertiesExtension.class).getName().equals(pluginName))
.findFirst()
.map(Project::getPath);
}

/**
* Configure the pom for the main jar of this plugin
*/
protected static void addNoticeGeneration(final Project project, PluginPropertiesExtension extension) {
final var licenseFile = extension.getLicenseFile();
var tasks = project.getTasks();
if (licenseFile != null) {
tasks.withType(Zip.class).named("bundlePlugin").configure(zip -> zip.from(licenseFile.getParentFile(), copySpec -> {
copySpec.include(licenseFile.getName());
copySpec.rename(s -> "LICENSE.txt");
}));
}

final var noticeFile = extension.getNoticeFile();
if (noticeFile != null) {
final var generateNotice = tasks.register("generateNotice", NoticeTask.class, noticeTask -> {
noticeTask.setInputFile(noticeFile);
noticeTask.source(Util.getJavaMainSourceSet(project).get().getAllJava());
});
tasks.withType(Zip.class).named("bundlePlugin").configure(task -> task.from(generateNotice));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void apply(Project project) {
project.getRootProject().getPluginManager().apply(DockerSupportPlugin.class);
project.getPlugins().apply(InternalDistributionDownloadPlugin.class);
project.getPlugins().apply(JdkDownloadPlugin.class);
project.getPluginManager().apply("elasticsearch.build");
project.getPluginManager().apply("elasticsearch.java");

Provider<DockerSupportService> dockerSupport = GradleUtils.getBuildService(
project.getGradle().getSharedServices(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void apply(Project project) {

project.getTasks().withType(StandaloneRestIntegTestTask.class).configureEach(t ->
// if this a module or plugin, it may have an associated zip file with it's contents, add that to the test cluster
project.getPluginManager().withPlugin("elasticsearch.internal-es-plugin", plugin -> {
project.getPluginManager().withPlugin("elasticsearch.esplugin", plugin -> {
TaskProvider<Zip> bundle = project.getTasks().withType(Zip.class).named("bundlePlugin");
t.dependsOn(bundle);
if (GradleUtils.isModuleProject(project.getPath())) {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.elasticsearch.gradle.util.GradleUtils

import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
import org.elasticsearch.gradle.internal.InternalPluginBuildPlugin
import org.elasticsearch.gradle.internal.BaseInternalPluginBuildPlugin
import org.elasticsearch.gradle.internal.ResolveAllDependencies
import java.nio.file.Files
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
Expand Down Expand Up @@ -174,7 +174,7 @@ allprojects {
// e.g. see https://github.com/elastic/elasticsearch/issues/72169
// apply plugin:'elasticsearch.internal-test-rerun'

plugins.withType(InternalPluginBuildPlugin).whenPluginAdded {
plugins.withType(BaseInternalPluginBuildPlugin).whenPluginAdded {
project.dependencies {
compileOnly project(":server")
testImplementation project(":test:framework")
Expand Down
2 changes: 1 addition & 1 deletion distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void copyModule(TaskProvider<Sync> copyTask, Project module) {
exclude 'config/log4j2.properties'

eachFile { details ->
String name = module.plugins.hasPlugin('elasticsearch.internal-es-plugin') ? module.esplugin.name : module.es_meta_plugin.name
String name = module.esplugin.name
// Copy all non config/bin files
// Note these might be unde a subdirectory in the case of a meta plugin
if ((details.relativePath.pathString ==~ /([^\/]+\/)?(config|bin)\/.*/) == false) {
Expand Down
12 changes: 0 additions & 12 deletions qa/os/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,8 @@ dependencies {
testImplementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
}

tasks.named('forbiddenApisTest').configure {
replaceSignatureFiles 'jdk-signatures'
}

// we don't have additional tests for the tests themselves
tasks.named("test").configure { enabled = false }
// Tests are destructive and meant to run in a VM, they don't adhere to general conventions
tasks.named("testingConventions").configure { enabled = false }

// this project doesn't get published
tasks.named("dependencyLicenses").configure { enabled = false }
tasks.named("dependenciesInfo").configure {enabled = false }

tasks.named("thirdPartyAudit").configure { ignoreMissingClasses() }

tasks.register('destructivePackagingTest') {
dependsOn 'destructiveDistroTest'
Expand Down
7 changes: 1 addition & 6 deletions qa/system-indices/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.base-internal-es-plugin'
apply plugin: 'elasticsearch.internal-java-rest-test'

esplugin {
Expand All @@ -17,11 +17,6 @@ esplugin {
noticeFile rootProject.file('NOTICE.txt')
}

tasks.named("test").configure { enabled = false }
tasks.named("javaRestTest").configure {
dependsOn "buildZip"
}

testClusters.configureEach {
testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'true'
Expand Down
4 changes: 2 additions & 2 deletions test/external-modules/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import org.elasticsearch.gradle.internal.info.BuildParams;
import org.elasticsearch.gradle.internal.info.BuildParams

subprojects {
apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.base-internal-es-plugin'
apply plugin: 'elasticsearch.internal-yaml-rest-test'

esplugin {
Expand Down
10 changes: 4 additions & 6 deletions x-pack/plugin/async-search/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.elasticsearch.gradle.internal.info.BuildParams

apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.base-internal-es-plugin'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'

Expand All @@ -21,9 +21,7 @@ testClusters.configureEach {
setting 'xpack.security.enabled', 'false'
}

tasks.named("test").configure { enabled = false }

if (BuildParams.inFipsJvm){
// Test clusters run with security disabled
tasks.named("yamlRestTest").configure{enabled = false }
// Test clusters run with security disabled
tasks.named("yamlRestTest") {
onlyIf { BuildParams.inFipsJvm == false }
}

0 comments on commit dc3d3b5

Please sign in to comment.