File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -187,10 +187,15 @@ struct JExtractSwiftBuildToolPlugin: SwiftJavaPluginProtocol, BuildToolPlugin {
187187 var gradlewEnvironment = ProcessInfo . processInfo. environment
188188 gradlewEnvironment [ GradleUserHome] = gradleUserHomePath
189189 log ( " Forward environment: \( gradlewEnvironment) " )
190+
191+ let gradleExecutable = findExecutable ( name: " gradle " ) ?? // try using installed 'gradle' if available in PATH
192+ swiftJavaDirectory. appending ( path: " gradlew " ) // fallback to calling ./gradlew if gradle is not installed
193+ log ( " Detected 'gradle' executable (or gradlew fallback): \( gradleExecutable) " )
194+
190195 commands += [
191196 . buildCommand(
192197 displayName: " Build SwiftKitCore using Gradle (Java) " ,
193- executable: swiftJavaDirectory . appending ( path : " gradlew " ) ,
198+ executable: gradleExecutable ,
194199 arguments: [
195200 " :SwiftKitCore:build " ,
196201 " -p " , swiftJavaDirectory. path ( percentEncoded: false ) ,
@@ -349,3 +354,19 @@ struct JExtractSwiftBuildToolPlugin: SwiftJavaPluginProtocol, BuildToolPlugin {
349354 }
350355}
351356
357+ func findExecutable( name: String ) -> URL ? {
358+ let fileManager = FileManager . default
359+
360+ guard let path = ProcessInfo . processInfo. environment [ " PATH " ] else {
361+ return nil
362+ }
363+
364+ for path in path. split ( separator: " : " ) {
365+ let fullURL = URL ( fileURLWithPath: String ( path) ) . appendingPathComponent ( name)
366+ if fileManager. isExecutableFile ( atPath: fullURL. path) {
367+ return fullURL
368+ }
369+ }
370+
371+ return nil
372+ }
You can’t perform that action at this time.
0 commit comments