@@ -11,14 +11,18 @@ import com.intellij.docker.connection.sshId
11
11
import com.intellij.docker.utils.createDefaultDockerServer
12
12
import com.intellij.docker.utils.getDockerServers
13
13
import com.intellij.execution.configurations.RunProfile
14
+ import com.intellij.openapi.application.ApplicationInfo
14
15
import com.intellij.openapi.project.Project
15
16
import com.intellij.openapi.project.guessProjectDir
16
17
import com.intellij.openapi.ui.DialogWrapper
17
18
import com.intellij.openapi.vfs.VirtualFile
18
19
import com.intellij.psi.PsiElement
20
+ import com.intellij.remoteDev.hostStatus.UnattendedHostStatus
19
21
import com.intellij.remoteServer.configuration.RemoteServer
20
22
import com.intellij.util.ui.JBUI
21
23
import com.intellij.util.ui.components.BorderLayoutPanel
24
+ import com.jetbrains.gateway.api.GatewayConnectionHandle
25
+ import com.jetbrains.gateway.api.GatewayConnector
22
26
import com.jetbrains.rd.util.lifetime.Lifetime
23
27
import java.io.File
24
28
import javax.swing.JComponent
@@ -47,6 +51,7 @@ class RunDevContainerService : RunService {
47
51
val context = try {
48
52
createContext(containerFile, projectDir, server)
49
53
} catch (e: Exception ) {
54
+ logger<RunDevContainerService >().warn(project, " Cannot create context: $e " )
50
55
DockerDevcontainerDeployContext ()
51
56
}
52
57
@@ -56,25 +61,32 @@ class RunDevContainerService : RunService {
56
61
val panel = contentPanel
57
62
val lifetime = Lifetime .Companion .Eternal
58
63
59
- try {
60
- val component = createDeployViewComponent(project, lifetime, context)
61
- component.setBorder( JBUI . Borders .empty())
62
-
63
- panel.add(component)
64
- panel.revalidate( )
65
- panel.repaint()
64
+ val baseLine = ApplicationInfo .getInstance().build.baselineVersion
65
+ val component = try {
66
+ if (baseLine >= 242 ) {
67
+ createDeployViewComponentFor242(project, lifetime, context)
68
+ } else {
69
+ createDeployViewComponentFor241(project, lifetime, context )
70
+ }
66
71
} catch (e: Exception ) {
67
- AutoDevNotifications .error (project, " Cannot create DockerDeployView: ${e.message} " )
68
- e.printStackTrace()
72
+ logger< RunDevContainerService >().warn (project, " Cannot create DockerDeployView: $e " )
73
+ createByLifetime(lifetime) ? : throw e
69
74
}
75
+
76
+ component.setBorder(JBUI .Borders .empty())
77
+
78
+ panel.add(component)
79
+ panel.revalidate()
80
+ panel.repaint()
81
+
70
82
}
71
83
}
72
84
73
85
wrapper.show()
74
86
return " Running devcontainer.json"
75
87
}
76
88
77
- private fun createDeployViewComponent (
89
+ private fun createDeployViewComponentFor241 (
78
90
project : Project ,
79
91
lifetime : Lifetime ,
80
92
context : DockerDevcontainerDeployContext
@@ -97,6 +109,37 @@ class RunDevContainerService : RunService {
97
109
return component
98
110
}
99
111
112
+ private fun createDeployViewComponentFor242 (
113
+ project : Project ,
114
+ lifetime : Lifetime ,
115
+ context : DockerDevcontainerDeployContext
116
+ ): JComponent {
117
+ val dockerDeployViewClass = Class .forName(" com.intellij.clouds.docker.gateway.ui.DockerDeployView" )
118
+ val constructor = dockerDeployViewClass.getDeclaredConstructor(
119
+ Project ::class .java,
120
+ Lifetime ::class .java,
121
+ DockerDevcontainerDeployContext ::class .java,
122
+ Function2 ::class .java
123
+ )
124
+
125
+ val function2 = { _: GatewayConnectionHandle , _: UnattendedHostStatus -> Unit }
126
+
127
+ val instance = constructor .newInstance(project, lifetime, context, function2)
128
+ val componentMethod = dockerDeployViewClass.getMethod(" getComponent" )
129
+ val component = componentMethod.invoke(instance) as JComponent
130
+ return component
131
+ }
132
+
133
+ fun createByLifetime (lifetime : Lifetime ): JComponent ? {
134
+ val view = GatewayConnector .getConnectors()
135
+ .firstOrNull { it.isAvailable() && it.javaClass.name == " com.intellij.clouds.docker.gateway.DockerGatewayConnector" }
136
+ ? : return null
137
+
138
+ val connectorView = view.createView(lifetime)
139
+
140
+ return connectorView.component
141
+ }
142
+
100
143
private fun dockerServers (): List <RemoteServer <DockerCloudConfiguration >> {
101
144
val filteredServers =
102
145
getDockerServers().filter {
0 commit comments