@@ -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,11 +338,16 @@ task shadeElasticsearchIngestGeoIpModule(type: com.github.jengelman.gradle.plugi
305338 archiveFileName = ' ingest-geoip-shaded.jar'
306339 destinationDirectory = file(" ${ buildDir} /shaded" )
307340
341+ relocate(' com.fasterxml.jackson' , " ${ ingestGeoipPluginShadeNamespace} .com.fasterxml.jackson" )
342+ relocate(' com.maxmind' , " ${ ingestGeoipPluginShadeNamespace} .com.maxmind" )
343+
308344 mergeServiceFiles()
309345
310346 exclude ' **/module-info.class'
311347}
312348
349+ def ingestGrokPluginShadeNamespace = " org.elasticsearch.grok.shaded"
350+
313351task shadeElasticsearchGrokImplementation (type : com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
314352 description " Shades embedded dependencies of the Elasticsearch Grok implementation"
315353
@@ -325,13 +363,16 @@ task shadeElasticsearchGrokImplementation(type: com.github.jengelman.gradle.plug
325363 destinationDirectory = file(" ${ buildDir} /shaded" )
326364
327365 mergeServiceFiles()
328- String shadeNamespace = " org.elasticsearch.grok.shaded"
329- relocate(' org.joni' , " ${ shadeNamespace} .org.joni" )
330- relocate(' org.jcodings' , " ${ shadeNamespace} .org.jcodings" )
366+ relocate(' org.joni' , " ${ ingestGrokPluginShadeNamespace} .org.joni" )
367+ relocate(' org.jcodings' , " ${ ingestGrokPluginShadeNamespace} .org.jcodings" )
331368
332369 exclude ' **/module-info.class'
333370}
334371
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+ */
335376task shadeElasticsearchRedactPlugin (type : com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
336377 description " Shades Elasticsearch Redact plugin to reference Grok's shaded dependencies"
337378 dependsOn buildElasticsearchLocalDistro
@@ -343,24 +384,8 @@ task shadeElasticsearchRedactPlugin(type: com.github.jengelman.gradle.plugins.sh
343384 destinationDirectory = file(" ${ buildDir} /shaded" )
344385
345386 // relocate elasticsearch-grok's dependencies to match
346- String shadeNamespace = " org.elasticsearch.grok.shaded"
347- relocate(' org.joni' , " ${ shadeNamespace} .org.joni" )
348- relocate(' org.jcodings' , " ${ shadeNamespace} .org.jcodings" )
349-
350- exclude ' **/module-info.class'
351- }
352-
353- task shadeElasticsearchLogstashBridge (type : com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
354- description " Shades the Elasticsearch logstash-bridge jar"
355-
356- dependsOn buildElasticsearchLogstashBridge
357-
358- from(" ${ buildDir} /elasticsearch-source/libs/logstash-bridge/build/distributions" ) {
359- include " elasticsearch-logstash-bridge-*.jar"
360- }
361-
362- archiveFileName = " elasticsearch-logstash-bridge-shaded.jar"
363- destinationDirectory = file(" ${ buildDir} /shaded" )
387+ relocate(' org.joni' , " ${ ingestGrokPluginShadeNamespace} .org.joni" )
388+ relocate(' org.jcodings' , " ${ ingestGrokPluginShadeNamespace} .org.jcodings" )
364389
365390 exclude ' **/module-info.class'
366391}
@@ -369,11 +394,10 @@ task importMinimalElasticsearch() {
369394 description " Imports minimal portions of Elasticsearch localDistro"
370395
371396 dependsOn buildElasticsearchLocalDistro
372- dependsOn buildElasticsearchLogstashBridge
397+ dependsOn shadeElasticsearchStableBridge
373398 dependsOn shadeElasticsearchIngestGeoIpModule
374399 dependsOn shadeElasticsearchGrokImplementation
375400 dependsOn shadeElasticsearchRedactPlugin
376- dependsOn shadeElasticsearchLogstashBridge
377401
378402 ext. jars = " ${ buildDir} /elasticsearch-minimal-jars"
379403
@@ -392,7 +416,7 @@ task importMinimalElasticsearch() {
392416 include jarPackageNamed(" lucene-core" )
393417 include jarPackageNamed(" lucene-analysis-common" )
394418 }
395- from(shadeElasticsearchLogstashBridge )
419+ from(shadeElasticsearchStableBridge . outputs . files . singleFile )
396420 from(shadeElasticsearchGrokImplementation)
397421 from(buildElasticsearchLocalDistro. module(" x-pack-core" ))
398422
0 commit comments