@@ -65,95 +65,22 @@ open class CoderProtocolHandler(
65
65
if (! prepareWorkspace(workspace, restClient, workspaceName, deploymentURL)) return
66
66
if (! ensureAgentIsReady(workspace, agent)) return
67
67
68
- val cli = ensureCLI(
69
- context,
70
- deploymentURL.toURL(),
71
- restClient.buildInfo().version
72
- )
73
-
74
- // We only need to log in if we are using token-based auth.
75
- if (restClient.token != null ) {
76
- context.logger.info(" Authenticating Coder CLI..." )
77
- cli.login(restClient.token)
78
- }
79
-
80
- context.logger.info(" Configuring Coder CLI..." )
81
- cli.configSsh(restClient.workspacesByAgents())
68
+ val cli = configureCli(deploymentURL, restClient)
82
69
83
70
if (shouldWaitForAutoLogin) {
84
71
isInitialized.waitForTrue()
85
72
}
86
73
reInitialize(restClient, cli)
87
74
88
75
val environmentId = " ${workspace.name} .${agent.name} "
89
- context.popupPluginMainPage( )
90
- context.envPageManager.showEnvironmentPage(environmentId, false )
76
+ context.showEnvironmentPage(environmentId )
77
+
91
78
val productCode = params.ideProductCode()
92
79
val buildNumber = params.ideBuildNumber()
93
80
val projectFolder = params.projectFolder()
94
- if (! productCode.isNullOrBlank() && ! buildNumber.isNullOrBlank()) {
95
- var selectedIde = " $productCode -$buildNumber "
96
- context.cs.launch {
97
- val installedIdes = context.remoteIdeOrchestrator.getInstalledRemoteTools(environmentId, productCode)
98
- val alreadyInstalled = installedIdes.firstOrNull { it.contains(buildNumber) } != null
99
- if (alreadyInstalled) {
100
- context.logger.info(" $productCode -$buildNumber is already on $environmentId . Going to launch JBClient" )
101
- } else {
102
- val availableVersions =
103
- context.remoteIdeOrchestrator.getAvailableRemoteTools(environmentId, productCode)
104
- if (availableVersions.isEmpty()) {
105
- val error = IllegalArgumentException (" $productCode is not available on $environmentId " )
106
- context.logger.error(error, " Error encountered while handling Coder URI" )
107
- context.ui.showSnackbar(
108
- UUID .randomUUID().toString(),
109
- context.i18n.ptrl(" Error encountered while handling Coder URI" ),
110
- context.i18n.pnotr(" $productCode is not available on $environmentId " ),
111
- context.i18n.ptrl(" OK" )
112
- )
113
- return @launch
114
- }
115
-
116
- val matchingBuildNumber = availableVersions.firstOrNull { it.contains(buildNumber) } != null
117
- if (! matchingBuildNumber) {
118
- selectedIde = availableVersions.maxOf { it }
119
- val msg =
120
- " $productCode -$buildNumber is not available, we've selected the latest $selectedIde "
121
- context.logger.info(msg)
122
- context.ui.showSnackbar(
123
- UUID .randomUUID().toString(),
124
- context.i18n.pnotr(" $productCode -$buildNumber not available" ),
125
- context.i18n.pnotr(msg),
126
- context.i18n.ptrl(" OK" )
127
- )
128
- }
129
81
130
- // needed otherwise TBX will install it again
131
- if (! installedIdes.contains(selectedIde)) {
132
- context.logger.info(" Installing $selectedIde on $environmentId ..." )
133
- context.remoteIdeOrchestrator.installRemoteTool(environmentId, selectedIde)
134
- if (context.remoteIdeOrchestrator.waitForIdeToBeInstalled(environmentId, selectedIde)) {
135
- context.logger.info(" Successfully installed $selectedIde on $environmentId ..." )
136
- } else {
137
- context.ui.showSnackbar(
138
- UUID .randomUUID().toString(),
139
- context.i18n.pnotr(" $selectedIde could not be installed" ),
140
- context.i18n.pnotr(" $selectedIde could not be installed on time. Check the logs for more details" ),
141
- context.i18n.ptrl(" OK" )
142
- )
143
- }
144
- } else {
145
- context.logger.info(" $selectedIde is already present on $environmentId ..." )
146
- }
147
- }
148
-
149
- val job = context.cs.launch {
150
- context.logger.info(" Downloading and installing JBClient counterpart to $selectedIde locally" )
151
- context.jbClientOrchestrator.prepareClient(environmentId, selectedIde)
152
- }
153
- job.join()
154
- context.logger.info(" Launching $selectedIde on $environmentId " )
155
- context.jbClientOrchestrator.connectToIde(environmentId, selectedIde, projectFolder)
156
- }
82
+ if (! productCode.isNullOrBlank() && ! buildNumber.isNullOrBlank()) {
83
+ launchIde(productCode, buildNumber, environmentId, projectFolder)
157
84
}
158
85
}
159
86
@@ -354,6 +281,97 @@ open class CoderProtocolHandler(
354
281
return true
355
282
}
356
283
284
+ private suspend fun configureCli (
285
+ deploymentURL : String ,
286
+ restClient : CoderRestClient
287
+ ): CoderCLIManager {
288
+ val cli = ensureCLI(
289
+ context,
290
+ deploymentURL.toURL(),
291
+ restClient.buildInfo().version
292
+ )
293
+
294
+ // We only need to log in if we are using token-based auth.
295
+ if (restClient.token != null ) {
296
+ context.logger.info(" Authenticating Coder CLI..." )
297
+ cli.login(restClient.token)
298
+ }
299
+
300
+ context.logger.info(" Configuring Coder CLI..." )
301
+ cli.configSsh(restClient.workspacesByAgents())
302
+ return cli
303
+ }
304
+
305
+ private fun launchIde (
306
+ productCode : String ,
307
+ buildNumber : String ,
308
+ environmentId : String ,
309
+ projectFolder : String?
310
+ ) {
311
+ var selectedIde = " $productCode -$buildNumber "
312
+ context.cs.launch {
313
+ val installedIdes = context.remoteIdeOrchestrator.getInstalledRemoteTools(environmentId, productCode)
314
+ val alreadyInstalled = installedIdes.firstOrNull { it.contains(buildNumber) } != null
315
+ if (alreadyInstalled) {
316
+ context.logger.info(" $productCode -$buildNumber is already on $environmentId . Going to launch JBClient" )
317
+ } else {
318
+ val availableVersions =
319
+ context.remoteIdeOrchestrator.getAvailableRemoteTools(environmentId, productCode)
320
+ if (availableVersions.isEmpty()) {
321
+ val error = IllegalArgumentException (" $productCode is not available on $environmentId " )
322
+ context.logger.error(error, " Error encountered while handling Coder URI" )
323
+ context.ui.showSnackbar(
324
+ UUID .randomUUID().toString(),
325
+ context.i18n.ptrl(" Error encountered while handling Coder URI" ),
326
+ context.i18n.pnotr(" $productCode is not available on $environmentId " ),
327
+ context.i18n.ptrl(" OK" )
328
+ )
329
+ return @launch
330
+ }
331
+
332
+ val matchingBuildNumber = availableVersions.firstOrNull { it.contains(buildNumber) } != null
333
+ if (! matchingBuildNumber) {
334
+ selectedIde = availableVersions.maxOf { it }
335
+ val msg =
336
+ " $productCode -$buildNumber is not available, we've selected the latest $selectedIde "
337
+ context.logger.info(msg)
338
+ context.ui.showSnackbar(
339
+ UUID .randomUUID().toString(),
340
+ context.i18n.pnotr(" $productCode -$buildNumber not available" ),
341
+ context.i18n.pnotr(msg),
342
+ context.i18n.ptrl(" OK" )
343
+ )
344
+ }
345
+
346
+ // needed otherwise TBX will install it again
347
+ if (! installedIdes.contains(selectedIde)) {
348
+ context.logger.info(" Installing $selectedIde on $environmentId ..." )
349
+ context.remoteIdeOrchestrator.installRemoteTool(environmentId, selectedIde)
350
+ if (context.remoteIdeOrchestrator.waitForIdeToBeInstalled(environmentId, selectedIde)) {
351
+ context.logger.info(" Successfully installed $selectedIde on $environmentId ..." )
352
+ } else {
353
+ context.ui.showSnackbar(
354
+ UUID .randomUUID().toString(),
355
+ context.i18n.pnotr(" $selectedIde could not be installed" ),
356
+ context.i18n.pnotr(" $selectedIde could not be installed on time. Check the logs for more details" ),
357
+ context.i18n.ptrl(" OK" )
358
+ )
359
+ }
360
+ } else {
361
+ context.logger.info(" $selectedIde is already present on $environmentId ..." )
362
+ }
363
+ }
364
+
365
+ val job = context.cs.launch {
366
+ context.logger.info(" Downloading and installing JBClient counterpart to $selectedIde locally" )
367
+ context.jbClientOrchestrator.prepareClient(environmentId, selectedIde)
368
+ }
369
+ job.join()
370
+ context.logger.info(" Launching $selectedIde on $environmentId " )
371
+ context.jbClientOrchestrator.connectToIde(environmentId, selectedIde, projectFolder)
372
+ }
373
+ }
374
+
357
375
private suspend fun CoderRestClient.waitForReady (workspace : Workspace ): Boolean {
358
376
var status = workspace.latestBuild.status
359
377
try {
@@ -440,4 +458,9 @@ private fun CoderToolboxContext.popupPluginMainPage() {
440
458
this .envPageManager.showPluginEnvironmentsPage(true )
441
459
}
442
460
461
+ private suspend fun CoderToolboxContext.showEnvironmentPage (envId : String ) {
462
+ this .ui.showWindow()
463
+ this .envPageManager.showEnvironmentPage(envId, false )
464
+ }
465
+
443
466
class MissingArgumentException (message : String , ex : Throwable ? = null ) : IllegalArgumentException(message, ex)
0 commit comments