|
1 | 1 | import groovy.json.JsonSlurper |
| 2 | +import groovy.transform.CompileStatic |
2 | 3 | import org.gradle.initialization.DefaultSettings |
3 | 4 | import org.apache.tools.ant.taskdefs.condition.Os |
4 | 5 |
|
@@ -389,28 +390,37 @@ class ReactNativeModules { |
389 | 390 | } |
390 | 391 |
|
391 | 392 | /** |
392 | | - * Runs a specified command using providers.exec in a specified directory. |
393 | | - * Throws when the command result is empty. |
394 | | - */ |
| 393 | + * Runs a specified command using ProcessBuilder in a specified directory. |
| 394 | + * Throws an exception if the command fails or produces an empty output. |
| 395 | + * |
| 396 | + * @param command The command to execute as an array of strings. |
| 397 | + * @param directory The directory in which to execute the command. |
| 398 | + * @return The trimmed output of the command. |
| 399 | + * @throws Exception if the command fails or produces an empty output. |
| 400 | + */ |
| 401 | + @CompileStatic |
395 | 402 | String getCommandOutput(String[] command, File directory) { |
396 | | - try { |
397 | | - def execOutput = providers.exec { |
398 | | - commandLine(command) |
399 | | - workingDir(directory) |
400 | | - } |
401 | | - def output = execOutput.standardOutput.asText.get().trim() |
402 | | - if (!output) { |
403 | | - this.logger.error("${LOG_PREFIX}Unexpected empty result of running '${command}' command.") |
404 | | - def error = execOutput.standardError.asText.get().trim() |
405 | | - throw new Exception(error) |
| 403 | + try { |
| 404 | + def process = new ProcessBuilder(command as String[]) |
| 405 | + .directory(directory) |
| 406 | + .redirectErrorStream(true) |
| 407 | + .start() |
| 408 | + int exitCode = process.waitFor() |
| 409 | + def output = process.inputStream.text.trim() |
| 410 | + if (exitCode != 0) { |
| 411 | + throw new Exception("Command '${command}' failed with exit code ${exitCode}.") |
| 412 | + } |
| 413 | + if (!output) { |
| 414 | + throw new Exception("Empty output received from command '${command}'.") |
| 415 | + } |
| 416 | + return output |
| 417 | + } catch (Exception e) { |
| 418 | + println "Error executing command '${command}': ${e.message}" |
| 419 | + throw e |
406 | 420 | } |
407 | | - return output |
408 | | - } catch (Exception exception) { |
409 | | - this.logger.error("${LOG_PREFIX}Running '${command}' command failed.") |
410 | | - throw exception |
411 | | - } |
412 | 421 | } |
413 | 422 |
|
| 423 | + |
414 | 424 | /** |
415 | 425 | * Runs a process to call the React Native CLI Config command and parses the output |
416 | 426 | */ |
|
0 commit comments