Skip to content

Commit a3bc293

Browse files
committed
Merge remote-tracking branch 'elastic/master' into jdk-13-ci
* elastic/master: (25 commits) Rollup ignores time_zone on date histogram (elastic#40844) HLRC: fix uri encode bug when url path starts with '/' (elastic#34436) Mutes GatewayIndexStateIT.testRecoverBrokenIndexMetadata Docs: Pin two IDs in the rest client (elastic#40785) Adds version 6.7.2 [DOCS] Remind users to include @ symbol when applying license file (elastic#40688) HLRC: Convert xpack methods to client side objects (elastic#40705) Allow ILM to stop if indices have nonexistent policies (elastic#40820) Add an OpenID Connect authentication realm (elastic#40674) [DOCS] Rewrite query def (elastic#40746) [ML] Changes default destination index field mapping and adds scripted_metric agg (elastic#40750) Docs: Drop inline callouts from painless book (elastic#40805) [ML] refactoring start task a bit, removing unused code (elastic#40798) [DOCS] Document index.load_fixed_bitset_filters_eagerly (elastic#40780) Make remote cluster resolution stricter (elastic#40419) [ML] Add created_by info to usage stats (elastic#40518) SQL: [Docs] Small fixes for CURRENT_TIMESTAMP docs (elastic#40792) convert modules to use testclusters (elastic#40804) Replace javax activation with jakarta activation (elastic#40247) Document restrictions on fuzzy matching when using synonyms (elastic#40783) ...
2 parents fca71ee + fa82df0 commit a3bc293

File tree

172 files changed

+130456
-1757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+130456
-1757
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
2222
import nebula.plugin.publishing.maven.MavenScmPlugin
2323
import org.elasticsearch.gradle.BuildPlugin
2424
import org.elasticsearch.gradle.NoticeTask
25+
import org.elasticsearch.gradle.Version
26+
import org.elasticsearch.gradle.VersionProperties
2527
import org.elasticsearch.gradle.test.RestIntegTestTask
2628
import org.elasticsearch.gradle.test.RunTask
2729
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
30+
import org.gradle.api.InvalidUserDataException
2831
import org.gradle.api.Project
32+
import org.gradle.api.Task
2933
import org.gradle.api.publish.maven.MavenPublication
3034
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
3135
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
36+
import org.gradle.api.tasks.Copy
3237
import org.gradle.api.tasks.SourceSet
3338
import org.gradle.api.tasks.bundling.Zip
3439
import org.gradle.jvm.tasks.Jar
@@ -38,25 +43,29 @@ import java.util.regex.Pattern
3843
/**
3944
* Encapsulates build configuration for an Elasticsearch plugin.
4045
*/
41-
public class PluginBuildPlugin extends BuildPlugin {
46+
class PluginBuildPlugin extends BuildPlugin {
47+
48+
public static final String PLUGIN_EXTENSION_NAME = 'esplugin'
4249

4350
@Override
44-
public void apply(Project project) {
51+
void apply(Project project) {
4552
super.apply(project)
53+
54+
PluginPropertiesExtension extension = project.extensions.create(PLUGIN_EXTENSION_NAME, PluginPropertiesExtension, project)
4655
configureDependencies(project)
4756

4857
// this afterEvaluate must happen before the afterEvaluate added by integTest creation,
4958
// so that the file name resolution for installing the plugin will be setup
5059
project.afterEvaluate {
5160
boolean isXPackModule = project.path.startsWith(':x-pack:plugin')
5261
boolean isModule = project.path.startsWith(':modules:') || isXPackModule
53-
String name = project.pluginProperties.extension.name
62+
String name = extension.name
5463
project.archivesBaseName = name
5564

5665
// set the project description so it will be picked up by publishing
57-
project.description = project.pluginProperties.extension.description
66+
project.description = extension.description
5867

59-
configurePublishing(project)
68+
configurePublishing(project, extension)
6069

6170
if (project.plugins.hasPlugin(TestClustersPlugin.class) == false) {
6271
project.integTestCluster.dependsOn(project.tasks.bundlePlugin)
@@ -68,12 +77,23 @@ public class PluginBuildPlugin extends BuildPlugin {
6877
} else {
6978
project.tasks.integTest.dependsOn(project.tasks.bundlePlugin)
7079
if (isModule) {
71-
throw new RuntimeException("Testclusters does not support modules yet");
80+
project.testClusters.integTest.module(
81+
project.file(project.tasks.bundlePlugin.archiveFile)
82+
)
7283
} else {
7384
project.testClusters.integTest.plugin(
7485
project.file(project.tasks.bundlePlugin.archiveFile)
7586
)
7687
}
88+
89+
project.extensions.getByType(PluginPropertiesExtension).extendedPlugins.each { pluginName ->
90+
// Auto add dependent modules to the test cluster
91+
if (project.findProject(":modules:${pluginName}") != null) {
92+
project.testClusters.integTest.module(
93+
project.file(project.project(":modules:${pluginName}").tasks.bundlePlugin.archiveFile)
94+
)
95+
}
96+
}
7797
}
7898

7999
project.tasks.run.dependsOn(project.tasks.bundlePlugin)
@@ -87,7 +107,7 @@ public class PluginBuildPlugin extends BuildPlugin {
87107
}
88108

89109
if (isModule == false || isXPackModule) {
90-
addNoticeGeneration(project)
110+
addNoticeGeneration(project, extension)
91111
}
92112
}
93113
project.testingConventions {
@@ -104,32 +124,28 @@ public class PluginBuildPlugin extends BuildPlugin {
104124
}
105125
}
106126
createIntegTestTask(project)
107-
createBundleTask(project)
127+
createBundleTasks(project, extension)
108128
project.configurations.getByName('default').extendsFrom(project.configurations.getByName('runtime'))
109129
project.tasks.create('run', RunTask) // allow running ES with this plugin in the foreground of a build
110130
}
111131

112-
private void configurePublishing(Project project) {
132+
private void configurePublishing(Project project, PluginPropertiesExtension extension) {
113133
// Only configure publishing if applied externally
114-
if (project.pluginProperties.extension.hasClientJar) {
134+
if (extension.hasClientJar) {
115135
project.plugins.apply(MavenScmPlugin.class)
116136
// Only change Jar tasks, we don't want a -client zip so we can't change archivesBaseName
117137
project.tasks.withType(Jar) {
118138
baseName = baseName + "-client"
119139
}
120140
// always configure publishing for client jars
121141
project.plugins.apply(MavenScmPlugin.class)
122-
project.publishing.publications.nebula(MavenPublication).artifactId(
123-
project.pluginProperties.extension.name + "-client"
124-
)
142+
project.publishing.publications.nebula(MavenPublication).artifactId(extension.name + "-client")
125143
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom generatePOMTask ->
126144
generatePOMTask.ext.pomFileName = "${project.archivesBaseName}-client-${project.versions.elasticsearch}.pom"
127145
}
128146
} else {
129147
if (project.plugins.hasPlugin(MavenPublishPlugin)) {
130-
project.publishing.publications.nebula(MavenPublication).artifactId(
131-
project.pluginProperties.extension.name
132-
)
148+
project.publishing.publications.nebula(MavenPublication).artifactId(extension.name)
133149
}
134150

135151
}
@@ -164,24 +180,64 @@ public class PluginBuildPlugin extends BuildPlugin {
164180
* Adds a bundlePlugin task which builds the zip containing the plugin jars,
165181
* metadata, properties, and packaging files
166182
*/
167-
private static void createBundleTask(Project project) {
183+
private static void createBundleTasks(Project project, PluginPropertiesExtension extension) {
168184
File pluginMetadata = project.file('src/main/plugin-metadata')
185+
File templateFile = new File(project.buildDir, "templates/plugin-descriptor.properties")
186+
187+
// create tasks to build the properties file for this plugin
188+
Task copyPluginPropertiesTemplate = project.tasks.create('copyPluginPropertiesTemplate') {
189+
outputs.file(templateFile)
190+
doLast {
191+
InputStream resourceTemplate = PluginBuildPlugin.getResourceAsStream("/${templateFile.name}")
192+
templateFile.setText(resourceTemplate.getText('UTF-8'), 'UTF-8')
193+
}
194+
}
169195

170-
// create a task to build the properties file for this plugin
171-
PluginPropertiesTask buildProperties = project.tasks.create('pluginProperties', PluginPropertiesTask.class)
196+
Copy buildProperties = project.tasks.create('pluginProperties', Copy) {
197+
dependsOn(copyPluginPropertiesTemplate)
198+
from(templateFile)
199+
into("${project.buildDir}/generated-resources")
200+
}
201+
202+
project.afterEvaluate {
203+
// check require properties are set
204+
if (extension.name == null) {
205+
throw new InvalidUserDataException('name is a required setting for esplugin')
206+
}
207+
if (extension.description == null) {
208+
throw new InvalidUserDataException('description is a required setting for esplugin')
209+
}
210+
if (extension.classname == null) {
211+
throw new InvalidUserDataException('classname is a required setting for esplugin')
212+
}
213+
214+
Map<String, String> properties = [
215+
'name': extension.name,
216+
'description': extension.description,
217+
'version': extension.version,
218+
'elasticsearchVersion': Version.fromString(VersionProperties.elasticsearch).toString(),
219+
'javaVersion': project.targetCompatibility as String,
220+
'classname': extension.classname,
221+
'extendedPlugins': extension.extendedPlugins.join(','),
222+
'hasNativeController': extension.hasNativeController,
223+
'requiresKeystore': extension.requiresKeystore
224+
]
225+
226+
buildProperties.configure {
227+
expand(properties)
228+
inputs.properties(properties)
229+
}
230+
}
172231

173232
// add the plugin properties and metadata to test resources, so unit tests can
174233
// know about the plugin (used by test security code to statically initialize the plugin in unit tests)
175234
SourceSet testSourceSet = project.sourceSets.test
176-
testSourceSet.output.dir(buildProperties.descriptorOutput.parentFile, builtBy: 'pluginProperties')
235+
testSourceSet.output.dir(buildProperties.destinationDir, builtBy: buildProperties)
177236
testSourceSet.resources.srcDir(pluginMetadata)
178237

179238
// create the actual bundle task, which zips up all the files for the plugin
180-
Zip bundle = project.tasks.create(name: 'bundlePlugin', type: Zip, dependsOn: [project.jar, buildProperties]) {
181-
from(buildProperties.descriptorOutput.parentFile) {
182-
// plugin properties file
183-
include(buildProperties.descriptorOutput.name)
184-
}
239+
Zip bundle = project.tasks.create(name: 'bundlePlugin', type: Zip) {
240+
from buildProperties
185241
from pluginMetadata // metadata (eg custom security policy)
186242
/*
187243
* If the plugin is using the shadow plugin then we need to bundle
@@ -223,23 +279,17 @@ public class PluginBuildPlugin extends BuildPlugin {
223279
}
224280
}
225281

226-
/** Adds nebula publishing task to generate a pom file for the plugin. */
227-
protected static void addClientJarPomGeneration(Project project) {
228-
project.plugins.apply(MavenScmPlugin.class)
229-
project.description = project.pluginProperties.extension.description
230-
}
231-
232282
/** Configure the pom for the main jar of this plugin */
233283

234-
protected void addNoticeGeneration(Project project) {
235-
File licenseFile = project.pluginProperties.extension.licenseFile
284+
protected void addNoticeGeneration(Project project, PluginPropertiesExtension extension) {
285+
File licenseFile = extension.licenseFile
236286
if (licenseFile != null) {
237287
project.tasks.bundlePlugin.from(licenseFile.parentFile) {
238288
include(licenseFile.name)
239289
rename { 'LICENSE.txt' }
240290
}
241291
}
242-
File noticeFile = project.pluginProperties.extension.noticeFile
292+
File noticeFile = extension.noticeFile
243293
if (noticeFile != null) {
244294
NoticeTask generateNotice = project.tasks.create('generateNotice', NoticeTask.class)
245295
generateNotice.inputFile = noticeFile

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesTask.groovy

Lines changed: 0 additions & 82 deletions
This file was deleted.

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public void plugin(File plugin) {
128128
nodes.all(each -> each.plugin(plugin));
129129
}
130130

131+
@Override
132+
public void module(File module) {
133+
nodes.all(each -> each.module(module));
134+
}
135+
131136
@Override
132137
public void keystore(String key, String value) {
133138
nodes.all(each -> each.keystore(key, value));
@@ -198,6 +203,11 @@ public void start() {
198203
}
199204
}
200205

206+
@Override
207+
public void extraConfigFile(String destination, File from) {
208+
nodes.all(node -> node.extraConfigFile(destination, from));
209+
}
210+
201211
private void writeUnicastHostsFiles() {
202212
String unicastUris = nodes.stream().flatMap(node -> node.getAllTransportPortURI().stream()).collect(Collectors.joining("\n"));
203213
nodes.forEach(node -> {

0 commit comments

Comments
 (0)