4
4
package software.aws.toolkits.jetbrains.services.amazonqCodeTest.utils
5
5
6
6
import com.intellij.build.BuildContentManager
7
+ import com.intellij.execution.configurations.GeneralCommandLine
7
8
import com.intellij.execution.impl.ConsoleViewImpl
8
9
import com.intellij.execution.process.OSProcessHandler
9
10
import com.intellij.execution.process.ProcessAdapter
10
11
import com.intellij.execution.process.ProcessEvent
11
- import com.intellij.execution.process.ProcessHandler
12
12
import com.intellij.execution.ui.ConsoleView
13
13
import com.intellij.execution.ui.ConsoleViewContentType
14
14
import com.intellij.openapi.application.ApplicationManager
@@ -17,18 +17,13 @@ import com.intellij.openapi.util.Key
17
17
import com.intellij.openapi.vfs.VirtualFile
18
18
import com.intellij.openapi.vfs.VirtualFileManager
19
19
import com.intellij.ui.content.impl.ContentImpl
20
- import kotlinx.coroutines.currentCoroutineContext
21
- import kotlinx.coroutines.withContext
22
- import software.aws.toolkits.jetbrains.core.coroutines.EDT
23
20
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.getBuildIcon
24
21
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.getExecutionIcon
25
22
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.model.getFixingTestCasesIcon
26
23
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.BuildAndExecuteProgressStatus
27
24
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.session.BuildAndExecuteTaskContext
28
25
import java.io.File
29
26
import java.io.FileWriter
30
- import java.nio.charset.StandardCharsets
31
- import java.nio.file.Files
32
27
33
28
fun constructBuildAndExecutionSummaryText (currentStatus : BuildAndExecuteProgressStatus , iterationNum : Int ): String {
34
29
val progressMessages = mutableListOf<String >()
@@ -92,12 +87,14 @@ fun runBuildOrTestCommand(
92
87
buildAndExecuteTaskContext : BuildAndExecuteTaskContext ,
93
88
testFileRelativePathToProjectRoot : String ,
94
89
) {
90
+ val brazilPath = " ${System .getProperty(" user.home" )} /.toolbox/bin:/usr/local/bin:/usr/bin:/bin:/sbin"
95
91
if (localCommand.isEmpty()) {
96
92
buildAndExecuteTaskContext.testExitCode = 0
97
93
return
98
94
}
99
95
val projectRoot = File (project.basePath ? : return )
100
96
val testFileAbsolutePath = File (projectRoot, testFileRelativePathToProjectRoot)
97
+ val file = File (tmpFile.path)
101
98
102
99
// Find the nearest Gradle root directory
103
100
var packageRoot: File ? = testFileAbsolutePath.parentFile
@@ -107,40 +104,31 @@ fun runBuildOrTestCommand(
107
104
}
108
105
packageRoot = packageRoot.parentFile
109
106
}
110
-
111
107
// If no valid Gradle directory is found, fallback to the project root
112
- val workingDir = packageRoot ? : projectRoot
113
- println (" Running command in directory: ${workingDir.absolutePath} " )
114
- // val repositoryPath = project.basePath ?: return
115
- val commandParts = localCommand.split(" " )
116
- val command = commandParts.first()
117
- val args = commandParts.drop(1 )
118
- val file = File (tmpFile.path)
119
-
120
- // Create Console View for Build Output
108
+ val gradleWrapper = File (packageRoot, " gradlew" )
109
+ val workingDir = if (gradleWrapper.exists()) packageRoot else projectRoot
121
110
val console: ConsoleView = ConsoleViewImpl (project, true )
122
111
123
112
// Attach Console View to Build Tool Window
124
113
ApplicationManager .getApplication().invokeLater {
125
114
val tabName = if (isBuildCommand) " Q TestGen Build Output" else " Q Test Gen Test Execution Output"
126
115
val content = ContentImpl (console.component, tabName, true )
127
116
BuildContentManager .getInstance(project).addContent(content)
128
- // TODO: remove these tabs when they are not needed
129
117
BuildContentManager .getInstance(project).setSelectedContent(content, false , false , true , null )
130
118
}
131
119
132
- val processBuilder = ProcessBuilder ()
133
- .command( listOf ( " zsh " , " -c " , " source ~/.zshrc && $command ${args.joinToString( " " )} " ))
134
- .directory(packageRoot )
135
- .redirectErrorStream( true )
136
-
137
- val env = processBuilder.environment( )
138
-
139
- env[ " PATH " ] = System .getenv( " PATH " )
120
+ val commandLine = when {
121
+ System .getProperty( " os.name " ).lowercase().contains( " win " ) -> {
122
+ GeneralCommandLine ( " cmd.exe " , " /c " , " set PATH=%PATH%; $brazilPath && $localCommand " )
123
+ }
124
+ else -> {
125
+ GeneralCommandLine ( " sh " , " -c " , " export PATH= \" $brazilPath \" && $localCommand " )
126
+ }
127
+ }.withWorkDirectory(workingDir )
140
128
141
129
try {
142
- val process = processBuilder.start()
143
- val processHandler: ProcessHandler = OSProcessHandler (process, localCommand, null )
130
+ // val process = processBuilder.start()
131
+ val processHandler = OSProcessHandler (commandLine )
144
132
145
133
// Attach Process Listener for Output Handling
146
134
processHandler.addProcessListener(object : ProcessAdapter () {
@@ -200,4 +188,3 @@ private fun cleanText(input: String): String {
200
188
}
201
189
return cleaned.toString()
202
190
}
203
-
0 commit comments