Skip to content

Commit 14507c7

Browse files
committed
Break out IDEWithStatus conversions
The available IDE conversion will be used when checking for an update, and installed conversion might eventually be used as well (in case there is a more recent version already installed in the workspace).
1 parent 0d954e7 commit 14507c7

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

src/main/kotlin/com/coder/gateway/models/WorkspaceProjectIDE.kt

+29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.coder.gateway.models
22

33
import com.intellij.openapi.diagnostic.Logger
4+
import com.jetbrains.gateway.ssh.AvailableIde
5+
import com.jetbrains.gateway.ssh.IdeStatus
46
import com.jetbrains.gateway.ssh.IdeWithStatus
7+
import com.jetbrains.gateway.ssh.InstalledIdeUIEx
58
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
69
import com.jetbrains.gateway.ssh.deploy.ShellArgument
710
import java.net.URL
@@ -177,6 +180,32 @@ fun IdeWithStatus.withWorkspaceProject(
177180
lastOpened = null,
178181
)
179182

183+
/**
184+
* Convert an available IDE to an IDE with status.
185+
*/
186+
fun AvailableIde.toIdeWithStatus(): IdeWithStatus = IdeWithStatus(
187+
product = product,
188+
buildNumber = buildNumber,
189+
status = IdeStatus.DOWNLOAD,
190+
download = download,
191+
pathOnHost = null,
192+
presentableVersion = presentableVersion,
193+
remoteDevType = remoteDevType,
194+
)
195+
196+
/**
197+
* Convert an installed IDE to an IDE with status.
198+
*/
199+
fun InstalledIdeUIEx.toIdeWithStatus(): IdeWithStatus = IdeWithStatus(
200+
product = product,
201+
buildNumber = buildNumber,
202+
status = IdeStatus.ALREADY_INSTALLED,
203+
download = null,
204+
pathOnHost = pathToIde,
205+
presentableVersion = presentableVersion,
206+
remoteDevType = remoteDevType,
207+
)
208+
180209
val remotePathRe = Regex("^[^(]+\\((.+)\\)$")
181210

182211
fun ShellArgument.RemotePath.toRawString(): String {

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt

+3-23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.coder.gateway.CoderGatewayBundle
44
import com.coder.gateway.cli.CoderCLIManager
55
import com.coder.gateway.icons.CoderIcons
66
import com.coder.gateway.models.WorkspaceProjectIDE
7+
import com.coder.gateway.models.toIdeWithStatus
78
import com.coder.gateway.models.withWorkspaceProject
89
import com.coder.gateway.sdk.v2.models.Workspace
910
import com.coder.gateway.sdk.v2.models.WorkspaceAgent
@@ -351,35 +352,14 @@ class CoderWorkspaceProjectIDEStepView(
351352
logger.info("Resolved OS and Arch for $name is: $workspaceOS")
352353
val installedIdesJob =
353354
cs.async(Dispatchers.IO) {
354-
executor.getInstalledIDEs().map { ide ->
355-
IdeWithStatus(
356-
ide.product,
357-
ide.buildNumber,
358-
IdeStatus.ALREADY_INSTALLED,
359-
null,
360-
ide.pathToIde,
361-
ide.presentableVersion,
362-
ide.remoteDevType,
363-
)
364-
}
355+
executor.getInstalledIDEs().map { it.toIdeWithStatus() }
365356
}
366357
val idesWithStatusJob =
367358
cs.async(Dispatchers.IO) {
368359
IntelliJPlatformProduct.entries
369360
.filter { it.showInGateway }
370361
.flatMap { CachingProductsJsonWrapper.getInstance().getAvailableIdes(it, workspaceOS) }
371-
.map {
372-
ide ->
373-
IdeWithStatus(
374-
ide.product,
375-
ide.buildNumber,
376-
IdeStatus.DOWNLOAD,
377-
ide.download,
378-
null,
379-
ide.presentableVersion,
380-
ide.remoteDevType,
381-
)
382-
}
362+
.map { it.toIdeWithStatus() }
383363
}
384364

385365
val installedIdes = installedIdesJob.await().sorted()

0 commit comments

Comments
 (0)