@@ -165,6 +165,14 @@ def _requiredLogstashJar(pathPrefix, jarSpec, flavorSpec = null) {
165165 }
166166}
167167
168+ static OutputStreamFunneler outputStreamFunneler (File logFile ) {
169+ logFile. parentFile. mkdirs()
170+ logFile. delete()
171+ logFile. createNewFile()
172+
173+ return new OutputStreamFunneler (new LazyFileOutputStream (logFile))
174+ }
175+
168176// https://docs.github.com/en/repositories/working-with-files/using-files/downloading-source-code-archives#source-code-archive-urls
169177String githubArchivePath (repo , treeish = " main" , archiveFormat = " zip" ) {
170178 def pathFragment = {
@@ -203,8 +211,10 @@ task downloadElasticsearchSourceZip(type: Download) {
203211task unzipDownloadedElasticsearchSourceZip (dependsOn : downloadElasticsearchSourceZip, type : Copy ) {
204212 description " extracts Elasticsearch source from a downloaded zip file"
205213
214+ ext. location = " ${ buildDir} /elasticsearch-source/"
215+
206216 from zipTree(downloadElasticsearchSourceZip. dest)
207- into " ${ buildDir } /elasticsearch-source/ "
217+ into ext . location
208218 eachFile {
209219 // strip top-level directory
210220 path = path. replaceFirst(/ ^.+?\/ / , " " )
@@ -216,15 +226,14 @@ task buildElasticsearchLocalDistro(dependsOn: unzipDownloadedElasticsearchSource
216226
217227 def logFile = project. file(" ${ buildDir} /elasticsearch-build.log" )
218228 doFirst {
219- def funneler = new OutputStreamFunneler ( new LazyFileOutputStream ( logFile) )
229+ def funneler = outputStreamFunneler( logFile)
220230 standardOutput = funneler. funnelInstance
221231 errorOutput = funneler. funnelInstance
222232 }
223233
224- def esSource = " ${ buildDir } /elasticsearch-source/ "
234+ def esSource = " ${ unzipDownloadedElasticsearchSourceZip.outputs.files.singleFile } "
225235 def esBuildDir = " ${ esSource} /build"
226236
227- inputs. dir esSource
228237 outputs. dir esBuildDir
229238
230239 ext. buildRoot = esBuildDir
@@ -238,7 +247,7 @@ task buildElasticsearchLocalDistro(dependsOn: unzipDownloadedElasticsearchSource
238247 ext. module = { moduleName -> localDistroResult. map { " ${ it} /modules/${ moduleName} " } }
239248
240249 workingDir esSource
241- commandLine " ./gradlew" , " localDistro"
250+ commandLine " ./gradlew" , " --stacktrace " , " localDistro"
242251
243252 ignoreExitValue true // handled in doLast
244253 doLast {
@@ -260,20 +269,22 @@ task buildElasticsearchLocalDistro(dependsOn: unzipDownloadedElasticsearchSource
260269task buildElasticsearchLogstashBridge (type : Exec ) {
261270 description " builds logstash-bridge lib module"
262271
263- dependsOn buildElasticsearchLocalDistro
272+ dependsOn unzipDownloadedElasticsearchSourceZip
273+ dependsOn buildElasticsearchLocalDistro // mustRunAfter?
264274
265275 def logFile = project. file(" ${ buildDir} /logstash-bridge-build.log" )
266276 doFirst {
267- def funneler = new OutputStreamFunneler ( new LazyFileOutputStream ( logFile) )
277+ def funneler = outputStreamFunneler( logFile)
268278 standardOutput = funneler. funnelInstance
269279 errorOutput = funneler. funnelInstance
270280 }
271281
272- def esSource = " ${ buildDir } /elasticsearch-source/ "
282+ def esSource = " ${ unzipDownloadedElasticsearchSourceZip.outputs.files.singleFile } "
273283 def esBuildDir = " ${ esSource} /build"
274284
275- inputs. dir esSource
276- outputs. dir " ${ esBuildDir} /libs/logstash-bridge"
285+ inputs. dir " ${ esSource} /libs/logstash-bridge"
286+
287+ outputs. dir(" ${ esSource} /libs/logstash-bridge/build/distributions" )
277288
278289 ext. buildRoot = esBuildDir
279290 workingDir esSource
@@ -295,6 +306,28 @@ task buildElasticsearchLogstashBridge(type: Exec) {
295306 }
296307}
297308
309+ def ingestGeoipPluginShadeNamespace = " org.elasticsearch.ingest.geoip.shaded"
310+
311+ /**
312+ * The StableBridge exposes GeoIP plugin internals, so it needs to relocate references to
313+ * its bundled dependencies to match the shaded locations in our import of that plugin.
314+ */
315+ task shadeElasticsearchStableBridge (type : com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
316+ description " Shades Maxmind dependencies"
317+
318+ dependsOn buildElasticsearchLogstashBridge
319+
320+ from(buildElasticsearchLogstashBridge)
321+
322+ archiveFileName = " logstash-stable-bridge-shaded.jar"
323+ destinationDirectory = file(" ${ buildDir} /shaded" )
324+
325+ relocate(' com.fasterxml.jackson' , " ${ ingestGeoipPluginShadeNamespace} .com.fasterxml.jackson" )
326+ relocate(' com.maxmind' , " ${ ingestGeoipPluginShadeNamespace} .com.maxmind" )
327+
328+ mergeServiceFiles()
329+ }
330+
298331task shadeElasticsearchIngestGeoIpModule (type : com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
299332 description " Shades embedded dependencies of the Elasticsearch Ingest GeoIP module"
300333
@@ -305,15 +338,16 @@ task shadeElasticsearchIngestGeoIpModule(type: com.github.jengelman.gradle.plugi
305338 archiveFileName = ' ingest-geoip-shaded.jar'
306339 destinationDirectory = file(" ${ buildDir} /shaded" )
307340
308- mergeServiceFiles()
341+ relocate(' com.fasterxml.jackson' , " ${ ingestGeoipPluginShadeNamespace} .com.fasterxml.jackson" )
342+ relocate(' com.maxmind' , " ${ ingestGeoipPluginShadeNamespace} .com.maxmind" )
309343
310- String shadeNamespace = " org.elasticsearch.ingest.geoip.shaded"
311- relocate(' com.fasterxml.jackson' , " ${ shadeNamespace} .com.fasterxml.jackson" )
312- relocate(' com.maxmind' , " ${ shadeNamespace} .com.maxmind" )
344+ mergeServiceFiles()
313345
314346 exclude ' **/module-info.class'
315347}
316348
349+ def ingestGrokPluginShadeNamespace = " org.elasticsearch.grok.shaded"
350+
317351task shadeElasticsearchGrokImplementation (type : com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
318352 description " Shades embedded dependencies of the Elasticsearch Grok implementation"
319353
@@ -329,13 +363,16 @@ task shadeElasticsearchGrokImplementation(type: com.github.jengelman.gradle.plug
329363 destinationDirectory = file(" ${ buildDir} /shaded" )
330364
331365 mergeServiceFiles()
332- String shadeNamespace = " org.elasticsearch.grok.shaded"
333- relocate(' org.joni' , " ${ shadeNamespace} .org.joni" )
334- relocate(' org.jcodings' , " ${ shadeNamespace} .org.jcodings" )
366+ relocate(' org.joni' , " ${ ingestGrokPluginShadeNamespace} .org.joni" )
367+ relocate(' org.jcodings' , " ${ ingestGrokPluginShadeNamespace} .org.jcodings" )
335368
336369 exclude ' **/module-info.class'
337370}
338371
372+ /**
373+ * The x-pack redact plugin reaches into the grok plugin's implementation, so
374+ * they both need to point to the same relocated shaded components.
375+ */
339376task shadeElasticsearchRedactPlugin (type : com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
340377 description " Shades Elasticsearch Redact plugin to reference Grok's shaded dependencies"
341378 dependsOn buildElasticsearchLocalDistro
@@ -347,37 +384,20 @@ task shadeElasticsearchRedactPlugin(type: com.github.jengelman.gradle.plugins.sh
347384 destinationDirectory = file(" ${ buildDir} /shaded" )
348385
349386 // relocate elasticsearch-grok's dependencies to match
350- String shadeNamespace = " org.elasticsearch.grok.shaded"
351- relocate(' org.joni' , " ${ shadeNamespace} .org.joni" )
352- relocate(' org.jcodings' , " ${ shadeNamespace} .org.jcodings" )
387+ relocate(' org.joni' , " ${ ingestGrokPluginShadeNamespace} .org.joni" )
388+ relocate(' org.jcodings' , " ${ ingestGrokPluginShadeNamespace} .org.jcodings" )
353389
354390 exclude ' **/module-info.class'
355391}
356392
357- task shadeElasticsearchLogstashBridge (type : com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
358- description " Shades the Elasticsearch logstash-bridge jar"
359-
360- dependsOn buildElasticsearchLogstashBridge
361-
362- from(" ${ buildDir} /elasticsearch-source/libs/logstash-bridge/build/distributions" ) {
363- include " elasticsearch-logstash-bridge-*.jar"
364- }
365-
366- archiveFileName = " elasticsearch-logstash-bridge-shaded.jar"
367- destinationDirectory = file(" ${ buildDir} /shaded" )
368-
369- exclude ' **/module-info.class'
370- }
371-
372393task importMinimalElasticsearch () {
373394 description " Imports minimal portions of Elasticsearch localDistro"
374395
375396 dependsOn buildElasticsearchLocalDistro
376- dependsOn buildElasticsearchLogstashBridge
397+ dependsOn shadeElasticsearchStableBridge
377398 dependsOn shadeElasticsearchIngestGeoIpModule
378399 dependsOn shadeElasticsearchGrokImplementation
379400 dependsOn shadeElasticsearchRedactPlugin
380- dependsOn shadeElasticsearchLogstashBridge
381401
382402 ext. jars = " ${ buildDir} /elasticsearch-minimal-jars"
383403
@@ -396,7 +416,7 @@ task importMinimalElasticsearch() {
396416 include jarPackageNamed(" lucene-core" )
397417 include jarPackageNamed(" lucene-analysis-common" )
398418 }
399- from(shadeElasticsearchLogstashBridge )
419+ from(shadeElasticsearchStableBridge . outputs . files . singleFile )
400420 from(shadeElasticsearchGrokImplementation)
401421 from(buildElasticsearchLocalDistro. module(" x-pack-core" ))
402422
0 commit comments