@@ -54,7 +54,7 @@ fun cloneTemplate(templateName: String, contentMain: String, contentLib: String)
54
54
return tempDir
55
55
}
56
56
57
- fun build (
57
+ private fun build (
58
58
caseName : String ,
59
59
directory : File ,
60
60
failureExpected : Boolean = false,
@@ -70,29 +70,48 @@ fun build(
70
70
it.add(" --info" )
71
71
}.toTypedArray()
72
72
73
- val procBuilder = if (isWin) {
74
- ProcessBuilder (" gradlew.bat" , * arguments)
73
+ val gradlewFile = File (directory, if (isWin) " gradlew.bat" else " gradlew" )
74
+
75
+ println (" [compose-compiler-integration] Working directory: ${directory.absolutePath} " )
76
+
77
+ if (! gradlewFile.exists()) {
78
+ throw GradleException (" gradlew not found in ${directory.absolutePath} . Please ensure the Gradle wrapper is present." )
79
+ }
80
+
81
+ if (! isWin) {
82
+ if (! gradlewFile.canExecute()) {
83
+ val isExecutable = gradlewFile.setExecutable(true )
84
+ if (! isExecutable) {
85
+ throw GradleException (" Failed to make gradlew executable: ${gradlewFile.absolutePath} " )
86
+ }
87
+ }
88
+ }
89
+
90
+ val command: List <String > = if (isWin) {
91
+ listOf (" cmd" , " /c" , " gradlew.bat" ) + arguments
75
92
} else {
76
- ProcessBuilder ( " bash " , " ./gradlew" , * arguments)
93
+ listOf ( " ./gradlew" ) + arguments
77
94
}
78
- val proc = procBuilder
79
- .directory(directory)
80
- .redirectOutput(ProcessBuilder .Redirect .PIPE )
81
- .redirectError(ProcessBuilder .Redirect .PIPE )
82
- .start()
83
-
84
- proc.waitFor(5 , TimeUnit .MINUTES )
85
-
86
- " (COMPOSE_INTEGRATION_VERSION=\\ [.*\\ ])" .toRegex().find(
87
- proc.inputStream.bufferedReader().readText()
88
- )?.also {
89
- println (it.groupValues[1 ])
95
+ println (" [compose-compiler-integration] Executing: ${command.joinToString(" " )} " )
96
+
97
+ val proc = try {
98
+ ProcessBuilder (command)
99
+ .directory(directory)
100
+ .redirectOutput(ProcessBuilder .Redirect .INHERIT )
101
+ .redirectError(ProcessBuilder .Redirect .INHERIT )
102
+ .start()
103
+ } catch (e: Exception ) {
104
+ throw GradleException (" Failed to start Gradle process. Command: ${command.joinToString(" " )} " , e)
90
105
}
91
106
92
- println (proc.errorStream.bufferedReader().readText())
107
+ val finished = proc.waitFor(10 , TimeUnit .MINUTES )
108
+ if (! finished) {
109
+ proc.destroyForcibly()
110
+ throw GradleException (" Gradle process timed out for $caseName . Command: ${command.joinToString(" " )} " )
111
+ }
93
112
94
113
if (proc.exitValue() != 0 && ! failureExpected) {
95
- throw GradleException (" Error compiling $caseName " )
114
+ throw GradleException (" Error compiling $caseName (exit code ${proc.exitValue()} ) " )
96
115
}
97
116
98
117
if (failureExpected && proc.exitValue() == 0 ) {
0 commit comments