Fix for the multi-sources not being generated properly (#6430)
* Potential fix for the multi-sources not being generated properly As described here https://www.infoworld.com/article/2071275/when-runtime-exec---won-t.html under "Listing 4.2 BadExecJavac2.java" the limited buffer size of the standard input associated with the sub-process can cause problems with the Runtime exec method. Consuming what the sub-process outputs should in theory allow for the process to finish (+ if you enable log level debug we could get some nice debug information in the future). I've tested this on my local machine and it works there, please do not accept the PR with this commit before the Github checks pass successfully and I've looked further into this. * Multi-sources not being generated properly - ErrorStream redirect Now redirecting the errorStream of the sub-process to the standard output of the subprocess, so that we can consume it with the `javaProcess.inputStream` stream.
This commit is contained in:
parent
c82de4147f
commit
66c0ee00b8
|
@ -1,3 +1,6 @@
|
||||||
|
import java.io.BufferedReader
|
||||||
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.library")
|
id("com.android.library")
|
||||||
kotlin("android")
|
kotlin("android")
|
||||||
|
@ -24,22 +27,37 @@ tasks {
|
||||||
val generateExtensions by registering {
|
val generateExtensions by registering {
|
||||||
doLast {
|
doLast {
|
||||||
val isWindows = System.getProperty("os.name").toString().toLowerCase().contains("win")
|
val isWindows = System.getProperty("os.name").toString().toLowerCase().contains("win")
|
||||||
val classPath = (configurations.debugCompileOnly.get().asFileTree.toList() +
|
var classPath = (configurations.debugCompileOnly.get().asFileTree.toList() +
|
||||||
listOf(
|
listOf(
|
||||||
configurations.androidApis.get().asFileTree.first().absolutePath, // android.jar path
|
configurations.androidApis.get().asFileTree.first().absolutePath, // android.jar path
|
||||||
"$projectDir/build/intermediates/aar_main_jar/debug/classes.jar" // jar made from this module
|
"$projectDir/build/intermediates/aar_main_jar/debug/classes.jar" // jar made from this module
|
||||||
))
|
))
|
||||||
.joinToString(if (isWindows) ";" else ":")
|
.joinToString(if (isWindows) ";" else ":")
|
||||||
val javaPath = "${System.getProperty("java.home")}/bin/java"
|
|
||||||
|
var javaPath = "${System.getProperty("java.home")}/bin/java"
|
||||||
|
|
||||||
val mainClass = "generator.GeneratorMainKt" // Main class we want to execute
|
val mainClass = "generator.GeneratorMainKt" // Main class we want to execute
|
||||||
|
|
||||||
val javaCommand = if (isWindows) {
|
if (isWindows) {
|
||||||
"\"$javaPath\" -classpath $classPath $mainClass".replace("/", "\\")
|
classPath = classPath.replace("/", "\\")
|
||||||
} else {
|
javaPath = javaPath.replace("/", "\\")
|
||||||
"$javaPath -classpath $classPath $mainClass"
|
|
||||||
}
|
}
|
||||||
val javaProcess = Runtime.getRuntime().exec(javaCommand)
|
|
||||||
|
val javaProcess = ProcessBuilder()
|
||||||
|
.directory(null).command(javaPath, "-classpath", classPath, mainClass)
|
||||||
|
.redirectErrorStream(true).start()
|
||||||
|
|
||||||
|
val inputStreamReader = InputStreamReader(javaProcess.inputStream)
|
||||||
|
val bufferedReader = BufferedReader(inputStreamReader)
|
||||||
|
|
||||||
|
var s: String?
|
||||||
|
while (bufferedReader.readLine().also { s = it } != null) {
|
||||||
|
logger.info(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferedReader.close()
|
||||||
|
inputStreamReader.close()
|
||||||
|
|
||||||
val exitCode = javaProcess.waitFor()
|
val exitCode = javaProcess.waitFor()
|
||||||
if (exitCode != 0) {
|
if (exitCode != 0) {
|
||||||
throw Exception("Java process failed with exit code: $exitCode")
|
throw Exception("Java process failed with exit code: $exitCode")
|
||||||
|
|
Loading…
Reference in New Issue