@@ -5,6 +5,8 @@ import org.elasticsearch.gradle.test.AntFixture
55import org.elasticsearch.gradle.test.ClusterConfiguration
66import org.elasticsearch.gradle.test.RestIntegTestTask
77
8+ import java.lang.reflect.Field
9+
810/*
911 * Licensed to Elasticsearch under one or more contributor
1012 * license agreements. See the NOTICE file distributed with
@@ -142,10 +144,11 @@ if (useFixture && minioDistribution) {
142144 fileMode 0755
143145 }
144146
145- long minioPid
146-
147147 task startMinio {
148148 dependsOn installMinio
149+
150+ ext. minioPid = 0L
151+
149152 doLast {
150153 new File (" ${ minioDataDir} /${ s3Bucket} " ). mkdirs()
151154 // we skip these tests on Windows so we do no need to worry about compatibility here
@@ -155,12 +158,26 @@ if (useFixture && minioDistribution) {
155158 " --address" ,
156159 minioAddress,
157160 minioDataDir)
158- minio. addShutdownHook { minio. destroy() }
159161 minio. environment(). put(' MINIO_ACCESS_KEY' , s3AccessKey)
160162 minio. environment(). put(' MINIO_SECRET_KEY' , s3SecretKey)
161163 minio. environment(). put(' MINIO_DOMAIN' , ' localhost' )
162164 final Process process = minio. start()
163- minioPid = process. pid()
165+ if (JavaVersion . current() <= JavaVersion . VERSION_1_8 ) {
166+ try {
167+ Class<?> cProcessImpl = process. getClass()
168+ Field fPid = cProcessImpl. getDeclaredField(" pid" )
169+ if (! fPid. isAccessible()) {
170+ fPid. setAccessible(true )
171+ }
172+ minioPid = fPid. getInt(process)
173+ } catch (Exception e) {
174+ logger. error(" failed to read pid from minio process" , e)
175+ process. destroyForcibly()
176+ throw e
177+ }
178+ } else {
179+ minioPid = process. pid()
180+ }
164181
165182 new BufferedReader (new InputStreamReader (process. getInputStream())). withReader { br ->
166183 String line
@@ -193,13 +210,13 @@ if (useFixture && minioDistribution) {
193210 }
194211
195212 task stopMinio(type : LoggedExec ) {
196- onlyIf { minioPid > 0 }
213+ onlyIf { startMinio . minioPid > 0 }
197214
198215 doFirst {
199- logger. info(" Shutting down minio with pid ${ minioPid} " )
216+ logger. info(" Shutting down minio with pid ${ startMinio. minioPid} " )
200217 }
201218
202- final Object pid = " ${ -> minioPid } "
219+ final Object pid = " ${ -> startMinio. minioPid } "
203220
204221 // we skip these tests on Windows so we do no need to worry about compatibility here
205222 executable = ' kill'
0 commit comments