@@ -12,62 +12,58 @@ const val DOCKER_COMPOSE_COMMAND = "docker-compose"
1212
1313private val logger = Logger .getInstance(" org.digma.intellij.plugin.docker.CmdHelper" )
1414
15- fun getCommand (program : String ): String? {
1615
17- Log .log(logger::debug, " getCommand invoked for {}" , program)
18-
19- val cmd = GeneralCommandLine (WHICH_COMMAND , program)
20- .withParentEnvironmentType(GeneralCommandLine .ParentEnvironmentType .CONSOLE )
21-
22- try {
23- val result = ExecUtil .execAndReadLine(cmd)
24- Log .log(logger::debug, " getCommand.getExecPath: {} result with: {}" , cmd.commandLineString, result)
25- return result
26- } catch (ex: Exception ) {
27- Log .warnWithException(logger, ex, " getCommand Failed to run '{}'" , cmd.commandLineString)
28- }
29- return null
30- }
3116
3217
3318fun getDockerCommand (): String? {
34-
3519 Log .log(logger::debug, " getDockerCommand invoked" )
36-
37- var dockerCmd = getCommand(DOCKER_COMMAND )
38- if (dockerCmd != null ) {
39- if (SystemInfo .isWindows && ! dockerCmd.endsWith(" exe" , true )) {
40- dockerCmd = dockerCmd.plus(" .exe" )
41- }
42- return dockerCmd
43- }
44- return null
20+ return getCommand(DOCKER_COMMAND )
4521}
4622
4723
4824fun getDockerComposeCommand (): List <String >? {
4925
5026 Log .log(logger::debug, " getDockerComposeCommand invoked" )
5127
52- var dockerComposeCmd = getCommand(DOCKER_COMPOSE_COMMAND )
28+ val dockerComposeCmd = getCommand(DOCKER_COMPOSE_COMMAND )
5329 if (dockerComposeCmd != null ) {
54- if (SystemInfo .isWindows && ! dockerComposeCmd.endsWith(" exe" , true )) {
55- dockerComposeCmd = dockerComposeCmd.plus(" .exe" )
56- }
5730 return listOf (dockerComposeCmd)
5831 }
5932
60- var dockerCmd = getCommand(DOCKER_COMMAND )
33+ val dockerCmd = getCommand(DOCKER_COMMAND )
6134 if (dockerCmd != null ) {
62- if (SystemInfo .isWindows && ! dockerCmd.endsWith(" exe" , true )) {
63- dockerCmd = dockerCmd.plus(" .exe" )
64- }
6535 return listOf (dockerCmd, " compose" )
6636 }
6737 return null
6838}
6939
7040
41+ private fun getCommand (program : String ): String? {
42+
43+ Log .log(logger::debug, " getCommand invoked for {}" , program)
44+
45+ val cmd = GeneralCommandLine (WHICH_COMMAND , program)
46+ .withParentEnvironmentType(GeneralCommandLine .ParentEnvironmentType .CONSOLE )
47+
48+ try {
49+ val result = if (SystemInfo .isWindows) {
50+ // on windows the result of 'where docker' may return two lines, ../docker and ..docker.exe
51+ val output = ExecUtil .execAndGetOutput(cmd).stdoutLines
52+ // prefer line that ends with exe or bat, or just the first one if none found
53+ output.first { it.endsWith(" .exe" , true ) || it.endsWith(" .bat" , true ) } ? : output.first()
54+ }else {
55+ ExecUtil .execAndReadLine(cmd)
56+ }
57+
58+ Log .log(logger::debug, " getCommand {} result with {}" , cmd.commandLineString, result)
59+ return result
60+ } catch (ex: Exception ) {
61+ Log .warnWithException(logger, ex, " getCommand Failed to run '{}'" , cmd.commandLineString)
62+ }
63+ return null
64+ }
65+
66+
7167fun isInstalled (program : String ): Boolean {
7268
7369 Log .log(logger::debug, " isInstalled invoked for {}" , program)
0 commit comments