@@ -22,13 +22,18 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
22
22
import nebula.plugin.publishing.maven.MavenScmPlugin
23
23
import org.elasticsearch.gradle.BuildPlugin
24
24
import org.elasticsearch.gradle.NoticeTask
25
+ import org.elasticsearch.gradle.Version
26
+ import org.elasticsearch.gradle.VersionProperties
25
27
import org.elasticsearch.gradle.test.RestIntegTestTask
26
28
import org.elasticsearch.gradle.test.RunTask
27
29
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
30
+ import org.gradle.api.InvalidUserDataException
28
31
import org.gradle.api.Project
32
+ import org.gradle.api.Task
29
33
import org.gradle.api.publish.maven.MavenPublication
30
34
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
31
35
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
36
+ import org.gradle.api.tasks.Copy
32
37
import org.gradle.api.tasks.SourceSet
33
38
import org.gradle.api.tasks.bundling.Zip
34
39
import org.gradle.jvm.tasks.Jar
@@ -38,25 +43,29 @@ import java.util.regex.Pattern
38
43
/**
39
44
* Encapsulates build configuration for an Elasticsearch plugin.
40
45
*/
41
- public class PluginBuildPlugin extends BuildPlugin {
46
+ class PluginBuildPlugin extends BuildPlugin {
47
+
48
+ public static final String PLUGIN_EXTENSION_NAME = ' esplugin'
42
49
43
50
@Override
44
- public void apply (Project project ) {
51
+ void apply (Project project ) {
45
52
super . apply(project)
53
+
54
+ PluginPropertiesExtension extension = project. extensions. create(PLUGIN_EXTENSION_NAME , PluginPropertiesExtension , project)
46
55
configureDependencies(project)
47
56
48
57
// this afterEvaluate must happen before the afterEvaluate added by integTest creation,
49
58
// so that the file name resolution for installing the plugin will be setup
50
59
project. afterEvaluate {
51
60
boolean isXPackModule = project. path. startsWith(' :x-pack:plugin' )
52
61
boolean isModule = project. path. startsWith(' :modules:' ) || isXPackModule
53
- String name = project . pluginProperties . extension. name
62
+ String name = extension. name
54
63
project. archivesBaseName = name
55
64
56
65
// set the project description so it will be picked up by publishing
57
- project. description = project . pluginProperties . extension. description
66
+ project. description = extension. description
58
67
59
- configurePublishing(project)
68
+ configurePublishing(project, extension )
60
69
61
70
if (project. plugins. hasPlugin(TestClustersPlugin . class) == false ) {
62
71
project. integTestCluster. dependsOn(project. tasks. bundlePlugin)
@@ -68,12 +77,23 @@ public class PluginBuildPlugin extends BuildPlugin {
68
77
} else {
69
78
project. tasks. integTest. dependsOn(project. tasks. bundlePlugin)
70
79
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
+ )
72
83
} else {
73
84
project. testClusters. integTest. plugin(
74
85
project. file(project. tasks. bundlePlugin. archiveFile)
75
86
)
76
87
}
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
+ }
77
97
}
78
98
79
99
project. tasks. run. dependsOn(project. tasks. bundlePlugin)
@@ -87,7 +107,7 @@ public class PluginBuildPlugin extends BuildPlugin {
87
107
}
88
108
89
109
if (isModule == false || isXPackModule) {
90
- addNoticeGeneration(project)
110
+ addNoticeGeneration(project, extension )
91
111
}
92
112
}
93
113
project. testingConventions {
@@ -104,32 +124,28 @@ public class PluginBuildPlugin extends BuildPlugin {
104
124
}
105
125
}
106
126
createIntegTestTask(project)
107
- createBundleTask (project)
127
+ createBundleTasks (project, extension )
108
128
project. configurations. getByName(' default' ). extendsFrom(project. configurations. getByName(' runtime' ))
109
129
project. tasks. create(' run' , RunTask ) // allow running ES with this plugin in the foreground of a build
110
130
}
111
131
112
- private void configurePublishing (Project project ) {
132
+ private void configurePublishing (Project project , PluginPropertiesExtension extension ) {
113
133
// Only configure publishing if applied externally
114
- if (project . pluginProperties . extension. hasClientJar) {
134
+ if (extension. hasClientJar) {
115
135
project. plugins. apply(MavenScmPlugin . class)
116
136
// Only change Jar tasks, we don't want a -client zip so we can't change archivesBaseName
117
137
project. tasks. withType(Jar ) {
118
138
baseName = baseName + " -client"
119
139
}
120
140
// always configure publishing for client jars
121
141
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" )
125
143
project. tasks. withType(GenerateMavenPom . class) { GenerateMavenPom generatePOMTask ->
126
144
generatePOMTask. ext. pomFileName = " ${ project.archivesBaseName} -client-${ project.versions.elasticsearch} .pom"
127
145
}
128
146
} else {
129
147
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)
133
149
}
134
150
135
151
}
@@ -164,24 +180,64 @@ public class PluginBuildPlugin extends BuildPlugin {
164
180
* Adds a bundlePlugin task which builds the zip containing the plugin jars,
165
181
* metadata, properties, and packaging files
166
182
*/
167
- private static void createBundleTask (Project project ) {
183
+ private static void createBundleTasks (Project project , PluginPropertiesExtension extension ) {
168
184
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
+ }
169
195
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
+ }
172
231
173
232
// add the plugin properties and metadata to test resources, so unit tests can
174
233
// know about the plugin (used by test security code to statically initialize the plugin in unit tests)
175
234
SourceSet testSourceSet = project. sourceSets. test
176
- testSourceSet. output. dir(buildProperties. descriptorOutput . parentFile , builtBy : ' pluginProperties ' )
235
+ testSourceSet. output. dir(buildProperties. destinationDir , builtBy : buildProperties )
177
236
testSourceSet. resources. srcDir(pluginMetadata)
178
237
179
238
// 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
185
241
from pluginMetadata // metadata (eg custom security policy)
186
242
/*
187
243
* If the plugin is using the shadow plugin then we need to bundle
@@ -223,23 +279,17 @@ public class PluginBuildPlugin extends BuildPlugin {
223
279
}
224
280
}
225
281
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
-
232
282
/* * Configure the pom for the main jar of this plugin */
233
283
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
236
286
if (licenseFile != null ) {
237
287
project. tasks. bundlePlugin. from(licenseFile. parentFile) {
238
288
include(licenseFile. name)
239
289
rename { ' LICENSE.txt' }
240
290
}
241
291
}
242
- File noticeFile = project . pluginProperties . extension. noticeFile
292
+ File noticeFile = extension. noticeFile
243
293
if (noticeFile != null ) {
244
294
NoticeTask generateNotice = project. tasks. create(' generateNotice' , NoticeTask . class)
245
295
generateNotice. inputFile = noticeFile
0 commit comments