Skip to content

Commit 0d954e7

Browse files
committedJul 15, 2024
Run ktlint
1 parent 388d47e commit 0d954e7

29 files changed

+367
-485
lines changed
 

‎src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
2929
return null
3030
}
3131

32-
override fun isApplicable(parameters: Map<String, String>): Boolean {
33-
return parameters.isCoder()
34-
}
32+
override fun isApplicable(parameters: Map<String, String>): Boolean = parameters.isCoder()
3533

3634
companion object {
3735
val logger = Logger.getInstance(CoderGatewayConnectionProvider::class.java.simpleName)

‎src/main/kotlin/com/coder/gateway/CoderGatewayMainView.kt

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,19 @@ class CoderGatewayMainView : GatewayConnector {
1919
override val icon: Icon
2020
get() = CoderIcons.LOGO
2121

22-
override fun createView(lifetime: Lifetime): GatewayConnectorView {
23-
return CoderGatewayConnectorWizardWrapperView()
24-
}
22+
override fun createView(lifetime: Lifetime): GatewayConnectorView = CoderGatewayConnectorWizardWrapperView()
2523

26-
override fun getActionText(): String {
27-
return CoderGatewayBundle.message("gateway.connector.action.text")
28-
}
24+
override fun getActionText(): String = CoderGatewayBundle.message("gateway.connector.action.text")
2925

30-
override fun getDescription(): String {
31-
return CoderGatewayBundle.message("gateway.connector.description")
32-
}
26+
override fun getDescription(): String = CoderGatewayBundle.message("gateway.connector.description")
3327

34-
override fun getDocumentationAction(): GatewayConnectorDocumentation {
35-
return GatewayConnectorDocumentation(true) {
36-
HelpManager.getInstance().invokeHelp(ABOUT_HELP_TOPIC)
37-
}
28+
override fun getDocumentationAction(): GatewayConnectorDocumentation = GatewayConnectorDocumentation(true) {
29+
HelpManager.getInstance().invokeHelp(ABOUT_HELP_TOPIC)
3830
}
3931

40-
override fun getRecentConnections(setContentCallback: (Component) -> Unit): GatewayRecentConnections {
41-
return CoderGatewayRecentWorkspaceConnectionsView(setContentCallback)
42-
}
32+
override fun getRecentConnections(setContentCallback: (Component) -> Unit): GatewayRecentConnections = CoderGatewayRecentWorkspaceConnectionsView(setContentCallback)
4333

44-
override fun getTitle(): String {
45-
return CoderGatewayBundle.message("gateway.connector.title")
46-
}
34+
override fun getTitle(): String = CoderGatewayBundle.message("gateway.connector.title")
4735

48-
override fun isAvailable(): Boolean {
49-
return true
50-
}
36+
override fun isAvailable(): Boolean = true
5137
}

‎src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ class CoderRemoteConnectionHandle {
7777
)
7878
},
7979
retryIf = {
80-
it is ConnectionException || it is TimeoutException ||
81-
it is SSHException || it is DeployException
80+
it is ConnectionException ||
81+
it is TimeoutException ||
82+
it is SSHException ||
83+
it is DeployException
8284
},
8385
onException = { attempt, nextMs, e ->
8486
logger.error("Failed to connect (attempt $attempt; will retry in $nextMs ms)")

‎src/main/kotlin/com/coder/gateway/cli/CoderCLIManager.kt

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,13 @@ class CoderCLIManager(
189189
/**
190190
* Return the entity tag for the binary on disk, if any.
191191
*/
192-
private fun getBinaryETag(): String? {
193-
return try {
194-
sha1(FileInputStream(localBinaryPath.toFile()))
195-
} catch (e: FileNotFoundException) {
196-
null
197-
} catch (e: Exception) {
198-
logger.warn("Unable to calculate hash for $localBinaryPath", e)
199-
null
200-
}
192+
private fun getBinaryETag(): String? = try {
193+
sha1(FileInputStream(localBinaryPath.toFile()))
194+
} catch (e: FileNotFoundException) {
195+
null
196+
} catch (e: Exception) {
197+
logger.warn("Unable to calculate hash for $localBinaryPath", e)
198+
null
201199
}
202200

203201
/**
@@ -230,12 +228,10 @@ class CoderCLIManager(
230228
/**
231229
* Return the contents of the SSH config or null if it does not exist.
232230
*/
233-
private fun readSSHConfig(): String? {
234-
return try {
235-
settings.sshConfigPath.toFile().readText()
236-
} catch (e: FileNotFoundException) {
237-
null
238-
}
231+
private fun readSSHConfig(): String? = try {
232+
settings.sshConfigPath.toFile().readText()
233+
} catch (e: FileNotFoundException) {
234+
null
239235
}
240236

241237
/**
@@ -301,7 +297,7 @@ class CoderCLIManager(
301297
LogLevel ERROR
302298
SetEnv CODER_SSH_SESSION_TYPE=JetBrains
303299
""".trimIndent()
304-
.plus(extraConfig)
300+
.plus(extraConfig),
305301
).replace("\n", System.lineSeparator())
306302
},
307303
)
@@ -398,23 +394,21 @@ class CoderCLIManager(
398394
/**
399395
* Like version(), but logs errors instead of throwing them.
400396
*/
401-
private fun tryVersion(): SemVer? {
402-
return try {
403-
version()
404-
} catch (e: Exception) {
405-
when (e) {
406-
is InvalidVersionException -> {
407-
logger.info("Got invalid version from $localBinaryPath: ${e.message}")
408-
}
409-
else -> {
410-
// An error here most likely means the CLI does not exist or
411-
// it executed successfully but output no version which
412-
// suggests it is not the right binary.
413-
logger.info("Unable to determine $localBinaryPath version: ${e.message}")
414-
}
397+
private fun tryVersion(): SemVer? = try {
398+
version()
399+
} catch (e: Exception) {
400+
when (e) {
401+
is InvalidVersionException -> {
402+
logger.info("Got invalid version from $localBinaryPath: ${e.message}")
403+
}
404+
else -> {
405+
// An error here most likely means the CLI does not exist or
406+
// it executed successfully but output no version which
407+
// suggests it is not the right binary.
408+
logger.info("Unable to determine $localBinaryPath version: ${e.message}")
415409
}
416-
null
417410
}
411+
null
418412
}
419413

420414
/**
@@ -475,23 +469,17 @@ class CoderCLIManager(
475469
fun getHostName(
476470
url: URL,
477471
workspaceName: String,
478-
): String {
479-
return "coder-jetbrains--$workspaceName--${url.safeHost()}"
480-
}
472+
): String = "coder-jetbrains--$workspaceName--${url.safeHost()}"
481473

482474
@JvmStatic
483475
fun getBackgroundHostName(
484476
url: URL,
485477
workspaceName: String,
486-
): String {
487-
return getHostName(url, workspaceName) + "--bg"
488-
}
478+
): String = getHostName(url, workspaceName) + "--bg"
489479

490480
@JvmStatic
491481
fun getBackgroundHostName(
492482
hostname: String,
493-
): String {
494-
return hostname + "--bg"
495-
}
483+
): String = hostname + "--bg"
496484
}
497485
}

‎src/main/kotlin/com/coder/gateway/help/CoderWebHelp.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import com.intellij.openapi.help.WebHelpProvider
55
const val ABOUT_HELP_TOPIC = "com.coder.gateway.about"
66

77
class CoderWebHelp : WebHelpProvider() {
8-
override fun getHelpPageUrl(helpTopicId: String): String {
9-
return when (helpTopicId) {
10-
ABOUT_HELP_TOPIC -> "https://coder.com/docs/coder-oss/latest"
11-
else -> "https://coder.com/docs/coder-oss/latest"
12-
}
8+
override fun getHelpPageUrl(helpTopicId: String): String = when (helpTopicId) {
9+
ABOUT_HELP_TOPIC -> "https://coder.com/docs/coder-oss/latest"
10+
else -> "https://coder.com/docs/coder-oss/latest"
1311
}
1412
}

‎src/main/kotlin/com/coder/gateway/icons/CoderIcons.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ fun toRetinaAwareIcon(image: BufferedImage): Icon {
150150
private val isJreHiDPI: Boolean
151151
get() = JreHiDpiUtil.isJreHiDPI(sysScale)
152152

153-
override fun toString(): String {
154-
return "TemplateIconDownloader.toRetinaAwareIcon for $image"
155-
}
153+
override fun toString(): String = "TemplateIconDownloader.toRetinaAwareIcon for $image"
156154
}
157155
}

‎src/main/kotlin/com/coder/gateway/models/RecentWorkspaceConnection.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class RecentWorkspaceConnection(
2222
configDirectory: String? = null,
2323
name: String? = null,
2424
deploymentURL: String? = null,
25-
) : BaseState(), Comparable<RecentWorkspaceConnection> {
25+
) : BaseState(),
26+
Comparable<RecentWorkspaceConnection> {
2627
@get:Attribute
2728
var coderWorkspaceHostname by string()
2829

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,17 @@ class WorkspaceProjectIDE(
4848
/**
4949
* Convert parameters into a recent workspace connection (for storage).
5050
*/
51-
fun toRecentWorkspaceConnection(): RecentWorkspaceConnection {
52-
return RecentWorkspaceConnection(
53-
name = name,
54-
coderWorkspaceHostname = hostname,
55-
projectPath = projectPath,
56-
ideProductCode = ideProduct.productCode,
57-
ideBuildNumber = ideBuildNumber,
58-
downloadSource = downloadSource,
59-
idePathOnHost = idePathOnHost,
60-
deploymentURL = deploymentURL.toString(),
61-
lastOpened = lastOpened,
62-
)
63-
}
51+
fun toRecentWorkspaceConnection(): RecentWorkspaceConnection = RecentWorkspaceConnection(
52+
name = name,
53+
coderWorkspaceHostname = hostname,
54+
projectPath = projectPath,
55+
ideProductCode = ideProduct.productCode,
56+
ideBuildNumber = ideBuildNumber,
57+
downloadSource = downloadSource,
58+
idePathOnHost = idePathOnHost,
59+
deploymentURL = deploymentURL.toString(),
60+
lastOpened = lastOpened,
61+
)
6462

6563
companion object {
6664
val logger = Logger.getInstance(WorkspaceProjectIDE::class.java.simpleName)
@@ -167,19 +165,17 @@ fun IdeWithStatus.withWorkspaceProject(
167165
hostname: String,
168166
projectPath: String,
169167
deploymentURL: URL,
170-
): WorkspaceProjectIDE {
171-
return WorkspaceProjectIDE(
172-
name = name,
173-
hostname = hostname,
174-
projectPath = projectPath,
175-
ideProduct = this.product,
176-
ideBuildNumber = this.buildNumber,
177-
downloadSource = this.download?.link,
178-
idePathOnHost = this.pathOnHost,
179-
deploymentURL = deploymentURL,
180-
lastOpened = null,
181-
)
182-
}
168+
): WorkspaceProjectIDE = WorkspaceProjectIDE(
169+
name = name,
170+
hostname = hostname,
171+
projectPath = projectPath,
172+
ideProduct = this.product,
173+
ideBuildNumber = this.buildNumber,
174+
downloadSource = this.download?.link,
175+
idePathOnHost = this.pathOnHost,
176+
deploymentURL = deploymentURL,
177+
lastOpened = null,
178+
)
183179

184180
val remotePathRe = Regex("^[^(]+\\((.+)\\)$")
185181

‎src/main/kotlin/com/coder/gateway/sdk/convertors/InstantConverter.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class InstantConverter {
1313
@ToJson fun toJson(src: Instant?): String = FORMATTER.format(src)
1414

1515
@FromJson fun fromJson(src: String): Instant? =
16-
FORMATTER.parse(src) {
17-
temporal: TemporalAccessor? ->
16+
FORMATTER.parse(src) { temporal: TemporalAccessor? ->
1817
Instant.from(temporal)
1918
}
2019

‎src/main/kotlin/com/coder/gateway/sdk/v2/models/Workspace.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ data class Workspace(
2525
* Return a list of agents combined with this workspace to display in the list.
2626
* If the workspace has no agents, return just itself with a null agent.
2727
*/
28-
fun Workspace.toAgentList(resources: List<WorkspaceResource> = this.latestBuild.resources): List<WorkspaceAgentListModel> {
29-
return resources.filter { it.agents != null }.flatMap { it.agents!! }.map { agent ->
30-
WorkspaceAgentListModel(this, agent)
31-
}.ifEmpty {
32-
listOf(WorkspaceAgentListModel(this))
33-
}
28+
fun Workspace.toAgentList(resources: List<WorkspaceResource> = this.latestBuild.resources): List<WorkspaceAgentListModel> = resources.filter { it.agents != null }.flatMap { it.agents!! }.map { agent ->
29+
WorkspaceAgentListModel(this, agent)
30+
}.ifEmpty {
31+
listOf(WorkspaceAgentListModel(this))
3432
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.coder.gateway.sdk.v2.models
2-
3-
import com.squareup.moshi.Json
4-
import com.squareup.moshi.JsonClass
5-
6-
@JsonClass(generateAdapter = true)
7-
data class WorkspacesResponse(
8-
@Json(name = "workspaces") val workspaces: List<Workspace>,
9-
)
1+
package com.coder.gateway.sdk.v2.models
2+
3+
import com.squareup.moshi.Json
4+
import com.squareup.moshi.JsonClass
5+
6+
@JsonClass(generateAdapter = true)
7+
data class WorkspacesResponse(
8+
@Json(name = "workspaces") val workspaces: List<Workspace>,
9+
)

‎src/main/kotlin/com/coder/gateway/services/CoderRestClientService.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ import java.net.URL
1313
* A client instance that hooks into global JetBrains services for default
1414
* settings.
1515
*/
16-
class CoderRestClientService(url: URL, token: String?, httpClient: OkHttpClient? = null) : CoderRestClient(
17-
url,
18-
token,
19-
service<CoderSettingsService>(),
20-
ProxyValues(
21-
HttpConfigurable.getInstance().proxyLogin,
22-
HttpConfigurable.getInstance().plainProxyPassword,
23-
HttpConfigurable.getInstance().PROXY_AUTHENTICATION,
24-
HttpConfigurable.getInstance().onlyBySettingsSelector,
25-
),
26-
PluginManagerCore.getPlugin(PluginId.getId("com.coder.gateway"))!!.version,
27-
httpClient,
28-
)
16+
class CoderRestClientService(url: URL, token: String?, httpClient: OkHttpClient? = null) :
17+
CoderRestClient(
18+
url,
19+
token,
20+
service<CoderSettingsService>(),
21+
ProxyValues(
22+
HttpConfigurable.getInstance().proxyLogin,
23+
HttpConfigurable.getInstance().plainProxyPassword,
24+
HttpConfigurable.getInstance().PROXY_AUTHENTICATION,
25+
HttpConfigurable.getInstance().onlyBySettingsSelector,
26+
),
27+
PluginManagerCore.getPlugin(PluginId.getId("com.coder.gateway"))!!.version,
28+
httpClient,
29+
)

‎src/main/kotlin/com/coder/gateway/services/CoderSettingsService.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class CoderSettingsService : CoderSettings(service<CoderSettingsStateService>())
3333
name = "CoderSettingsState",
3434
storages = [Storage("coder-settings.xml", roamingType = RoamingType.DISABLED, exportable = true)],
3535
)
36-
class CoderSettingsStateService : CoderSettingsState(), PersistentStateComponent<CoderSettingsStateService> {
37-
override fun getState(): CoderSettingsStateService {
38-
return this
39-
}
36+
class CoderSettingsStateService :
37+
CoderSettingsState(),
38+
PersistentStateComponent<CoderSettingsStateService> {
39+
override fun getState(): CoderSettingsStateService = this
4040

4141
override fun loadState(state: CoderSettingsStateService) {
4242
XmlSerializerUtil.copyBean(state, this)

‎src/main/kotlin/com/coder/gateway/settings/Environment.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ package com.coder.gateway.settings
55
* Exists only so we can override the environment in tests.
66
*/
77
class Environment(private val env: Map<String, String> = emptyMap()) {
8-
fun get(name: String): String {
9-
return env[name] ?: System.getenv(name) ?: ""
10-
}
8+
fun get(name: String): String = env[name] ?: System.getenv(name) ?: ""
119
}

‎src/main/kotlin/com/coder/gateway/util/Dialogs.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ private class CoderWorkspaceStepDialog(
5757
return null
5858
}
5959

60-
override fun createContentPaneBorder(): Border {
61-
return JBUI.Borders.empty()
62-
}
60+
override fun createContentPaneBorder(): Border = JBUI.Borders.empty()
6361

64-
override fun createCenterPanel(): JComponent {
65-
return view
66-
}
62+
override fun createCenterPanel(): JComponent = view
6763

6864
override fun createSouthPanel(): JComponent {
6965
// The plugin provides its own buttons.

‎src/main/kotlin/com/coder/gateway/util/OS.kt

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ package com.coder.gateway.util
22

33
import java.util.Locale
44

5-
fun getOS(): OS? {
6-
return OS.from(System.getProperty("os.name"))
7-
}
5+
fun getOS(): OS? = OS.from(System.getProperty("os.name"))
86

9-
fun getArch(): Arch? {
10-
return Arch.from(System.getProperty("os.arch").lowercase(Locale.getDefault()))
11-
}
7+
fun getArch(): Arch? = Arch.from(System.getProperty("os.arch").lowercase(Locale.getDefault()))
128

139
enum class OS {
1410
WINDOWS,
@@ -17,22 +13,20 @@ enum class OS {
1713
;
1814

1915
companion object {
20-
fun from(os: String): OS? {
21-
return when {
22-
os.contains("win", true) -> {
23-
WINDOWS
24-
}
25-
26-
os.contains("nix", true) || os.contains("nux", true) || os.contains("aix", true) -> {
27-
LINUX
28-
}
16+
fun from(os: String): OS? = when {
17+
os.contains("win", true) -> {
18+
WINDOWS
19+
}
2920

30-
os.contains("mac", true) || os.contains("darwin", true) -> {
31-
MAC
32-
}
21+
os.contains("nix", true) || os.contains("nux", true) || os.contains("aix", true) -> {
22+
LINUX
23+
}
3324

34-
else -> null
25+
os.contains("mac", true) || os.contains("darwin", true) -> {
26+
MAC
3527
}
28+
29+
else -> null
3630
}
3731
}
3832
}
@@ -44,13 +38,11 @@ enum class Arch {
4438
;
4539

4640
companion object {
47-
fun from(arch: String): Arch? {
48-
return when {
49-
arch.contains("amd64", true) || arch.contains("x86_64", true) -> AMD64
50-
arch.contains("arm64", true) || arch.contains("aarch64", true) -> ARM64
51-
arch.contains("armv7", true) -> ARMV7
52-
else -> null
53-
}
41+
fun from(arch: String): Arch? = when {
42+
arch.contains("amd64", true) || arch.contains("x86_64", true) -> AMD64
43+
arch.contains("arm64", true) || arch.contains("aarch64", true) -> ARM64
44+
arch.contains("armv7", true) -> ARMV7
45+
else -> null
5446
}
5547
}
5648
}

‎src/main/kotlin/com/coder/gateway/util/Retry.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,11 @@ fun humanizeDuration(durationMs: Long): String {
9090
* cause (IllegalStateException) is useless. The error also includes a very
9191
* long useless tmp path. Return true if the error looks like this timeout.
9292
*/
93-
fun isWorkerTimeout(e: Throwable): Boolean {
94-
return e is DeployException && e.message.contains("Worker binary deploy failed")
95-
}
93+
fun isWorkerTimeout(e: Throwable): Boolean = e is DeployException && e.message.contains("Worker binary deploy failed")
9694

9795
/**
9896
* Return true if the exception is some kind of cancellation.
9997
*/
100-
fun isCancellation(e: Throwable): Boolean {
101-
return e is InterruptedException ||
102-
e is CancellationException ||
103-
e is ProcessCanceledException
104-
}
98+
fun isCancellation(e: Throwable): Boolean = e is InterruptedException ||
99+
e is CancellationException ||
100+
e is ProcessCanceledException

‎src/main/kotlin/com/coder/gateway/util/SemVer.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ class SemVer(private val major: Long = 0, private val minor: Long = 0, private v
77
require(patch >= 0) { "Coder minor version must be a positive number" }
88
}
99

10-
override fun toString(): String {
11-
return "CoderSemVer(major=$major, minor=$minor, patch=$patch)"
12-
}
10+
override fun toString(): String = "CoderSemVer(major=$major, minor=$minor, patch=$patch)"
1311

1412
override fun equals(other: Any?): Boolean {
1513
if (this === other) return true

‎src/main/kotlin/com/coder/gateway/util/TLS.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,9 @@ fun coderTrustManagers(tlsCAPath: String): Array<TrustManager> {
113113
}
114114

115115
class AlternateNameSSLSocketFactory(private val delegate: SSLSocketFactory, private val alternateName: String) : SSLSocketFactory() {
116-
override fun getDefaultCipherSuites(): Array<String> {
117-
return delegate.defaultCipherSuites
118-
}
116+
override fun getDefaultCipherSuites(): Array<String> = delegate.defaultCipherSuites
119117

120-
override fun getSupportedCipherSuites(): Array<String> {
121-
return delegate.supportedCipherSuites
122-
}
118+
override fun getSupportedCipherSuites(): Array<String> = delegate.supportedCipherSuites
123119

124120
override fun createSocket(): Socket {
125121
val socket = delegate.createSocket() as SSLSocket
@@ -248,7 +244,5 @@ class MergedSystemTrustManger(private val otherTrustManager: X509TrustManager) :
248244
}
249245
}
250246

251-
override fun getAcceptedIssuers(): Array<X509Certificate> {
252-
return otherTrustManager.acceptedIssuers + systemTrustManager.acceptedIssuers
253-
}
247+
override fun getAcceptedIssuers(): Array<X509Certificate> = otherTrustManager.acceptedIssuers + systemTrustManager.acceptedIssuers
254248
}

‎src/main/kotlin/com/coder/gateway/util/URLExtensions.kt

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,29 @@ import java.net.IDN
44
import java.net.URI
55
import java.net.URL
66

7-
fun String.toURL(): URL {
8-
return URL(this)
9-
}
7+
fun String.toURL(): URL = URL(this)
108

11-
fun URL.withPath(path: String): URL {
12-
return URL(
13-
this.protocol,
14-
this.host,
15-
this.port,
16-
if (path.startsWith("/")) path else "/$path",
17-
)
18-
}
9+
fun URL.withPath(path: String): URL = URL(
10+
this.protocol,
11+
this.host,
12+
this.port,
13+
if (path.startsWith("/")) path else "/$path",
14+
)
1915

2016
/**
2117
* Return the host, converting IDN to ASCII in case the file system cannot
2218
* support the necessary character set.
2319
*/
24-
fun URL.safeHost(): String {
25-
return IDN.toASCII(this.host, IDN.ALLOW_UNASSIGNED)
26-
}
20+
fun URL.safeHost(): String = IDN.toASCII(this.host, IDN.ALLOW_UNASSIGNED)
2721

28-
fun URI.toQueryParameters(): Map<String, String> {
29-
return (this.query ?: "")
30-
.split("&").filter {
31-
it.isNotEmpty()
32-
}.associate {
33-
val parts = it.split("=", limit = 2)
34-
if (parts.size == 2) {
35-
parts[0] to parts[1]
36-
} else {
37-
parts[0] to ""
38-
}
22+
fun URI.toQueryParameters(): Map<String, String> = (this.query ?: "")
23+
.split("&").filter {
24+
it.isNotEmpty()
25+
}.associate {
26+
val parts = it.split("=", limit = 2)
27+
if (parts.size == 2) {
28+
parts[0] to parts[1]
29+
} else {
30+
parts[0] to ""
3931
}
40-
}
32+
}

‎src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

Lines changed: 62 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ data class DeploymentInfo(
7676
var error: String? = null,
7777
)
7878

79-
class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback: (Component) -> Unit) : GatewayRecentConnections, Disposable {
79+
class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback: (Component) -> Unit) :
80+
GatewayRecentConnections,
81+
Disposable {
8082
private val settings = service<CoderSettingsService>()
8183
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
8284
private val cs = CoroutineScope(Dispatchers.Main)
@@ -98,48 +100,46 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
98100
private var deployments: MutableMap<String, DeploymentInfo> = mutableMapOf()
99101
private var poller: Job? = null
100102

101-
override fun createRecentsView(lifetime: Lifetime): JComponent {
102-
return panel {
103-
indent {
104-
row {
105-
label(CoderGatewayBundle.message("gateway.connector.recent-connections.title")).applyToComponent {
106-
font = JBFont.h3().asBold()
107-
}
108-
searchBar =
109-
cell(SearchTextField(false)).resizableColumn().align(AlignX.FILL).applyToComponent {
110-
minimumSize = Dimension(350, -1)
111-
textEditor.border = JBUI.Borders.empty(2, 5, 2, 0)
112-
addDocumentListener(
113-
object : DocumentAdapter() {
114-
override fun textChanged(e: DocumentEvent) {
115-
filterString = this@applyToComponent.text.trim()
116-
updateContentView()
117-
}
118-
},
119-
)
120-
}.component
121-
actionButton(
122-
object : DumbAwareAction(
123-
CoderGatewayBundle.message("gateway.connector.recent-connections.new.wizard.button.tooltip"),
124-
null,
125-
AllIcons.General.Add,
126-
) {
127-
override fun actionPerformed(e: AnActionEvent) {
128-
setContentCallback(CoderGatewayConnectorWizardWrapperView().component)
129-
}
130-
},
131-
).gap(RightGap.SMALL)
132-
}.bottomGap(BottomGap.SMALL)
133-
separator(background = WelcomeScreenUIManager.getSeparatorColor())
134-
row {
135-
resizableRow()
136-
cell(recentWorkspacesContentPanel).resizableColumn().align(AlignX.FILL).align(AlignY.FILL).component
103+
override fun createRecentsView(lifetime: Lifetime): JComponent = panel {
104+
indent {
105+
row {
106+
label(CoderGatewayBundle.message("gateway.connector.recent-connections.title")).applyToComponent {
107+
font = JBFont.h3().asBold()
137108
}
109+
searchBar =
110+
cell(SearchTextField(false)).resizableColumn().align(AlignX.FILL).applyToComponent {
111+
minimumSize = Dimension(350, -1)
112+
textEditor.border = JBUI.Borders.empty(2, 5, 2, 0)
113+
addDocumentListener(
114+
object : DocumentAdapter() {
115+
override fun textChanged(e: DocumentEvent) {
116+
filterString = this@applyToComponent.text.trim()
117+
updateContentView()
118+
}
119+
},
120+
)
121+
}.component
122+
actionButton(
123+
object : DumbAwareAction(
124+
CoderGatewayBundle.message("gateway.connector.recent-connections.new.wizard.button.tooltip"),
125+
null,
126+
AllIcons.General.Add,
127+
) {
128+
override fun actionPerformed(e: AnActionEvent) {
129+
setContentCallback(CoderGatewayConnectorWizardWrapperView().component)
130+
}
131+
},
132+
).gap(RightGap.SMALL)
133+
}.bottomGap(BottomGap.SMALL)
134+
separator(background = WelcomeScreenUIManager.getSeparatorColor())
135+
row {
136+
resizableRow()
137+
cell(recentWorkspacesContentPanel).resizableColumn().align(AlignX.FILL).align(AlignY.FILL).component
138138
}
139-
}.apply {
140-
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
141-
border = JBUI.Borders.empty(12, 0, 0, 12)
142139
}
140+
}.apply {
141+
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
142+
border = JBUI.Borders.empty(12, 0, 0, 12)
143143
}
144144

145145
override fun getRecentsTitle() = CoderGatewayBundle.message("gateway.connector.title")
@@ -328,37 +328,33 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
328328
/**
329329
* Get valid connections grouped by deployment and workspace.
330330
*/
331-
private fun getConnectionsByDeployment(filter: Boolean): Map<String, Map<String, List<WorkspaceProjectIDE>>> {
332-
return recentConnectionsService.getAllRecentConnections()
333-
// Validate and parse connections.
334-
.mapNotNull {
335-
try {
336-
it.toWorkspaceProjectIDE()
337-
} catch (e: Exception) {
338-
logger.warn("Removing invalid recent connection $it", e)
339-
recentConnectionsService.removeConnection(it)
340-
null
341-
}
342-
}
343-
.filter { !filter || matchesFilter(it) }
344-
// Group by the deployment.
345-
.groupBy { it.deploymentURL.toString() }
346-
// Group the connections in each deployment by workspace.
347-
.mapValues { (_, connections) ->
348-
connections
349-
.groupBy { it.name.split(".", limit = 2).first() }
331+
private fun getConnectionsByDeployment(filter: Boolean): Map<String, Map<String, List<WorkspaceProjectIDE>>> = recentConnectionsService.getAllRecentConnections()
332+
// Validate and parse connections.
333+
.mapNotNull {
334+
try {
335+
it.toWorkspaceProjectIDE()
336+
} catch (e: Exception) {
337+
logger.warn("Removing invalid recent connection $it", e)
338+
recentConnectionsService.removeConnection(it)
339+
null
350340
}
351-
}
341+
}
342+
.filter { !filter || matchesFilter(it) }
343+
// Group by the deployment.
344+
.groupBy { it.deploymentURL.toString() }
345+
// Group the connections in each deployment by workspace.
346+
.mapValues { (_, connections) ->
347+
connections
348+
.groupBy { it.name.split(".", limit = 2).first() }
349+
}
352350

353351
/**
354352
* Return true if the connection matches the current filter.
355353
*/
356-
private fun matchesFilter(connection: WorkspaceProjectIDE): Boolean {
357-
return filterString.let {
358-
it.isNullOrBlank() ||
359-
connection.hostname.lowercase(Locale.getDefault()).contains(it) ||
360-
connection.projectPath.lowercase(Locale.getDefault()).contains(it)
361-
}
354+
private fun matchesFilter(connection: WorkspaceProjectIDE): Boolean = filterString.let {
355+
it.isNullOrBlank() ||
356+
connection.hostname.lowercase(Locale.getDefault()).contains(it) ||
357+
connection.projectPath.lowercase(Locale.getDefault()).contains(it)
362358
}
363359

364360
/**

‎src/main/kotlin/com/coder/gateway/views/LazyBrowserLink.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,21 @@ class LazyBrowserLink(
5656
}
5757
}
5858

59-
private class CopyLinkAction(val url: String) : DumbAwareAction(
60-
IdeBundle.messagePointer("action.text.copy.link.address"),
61-
AllIcons.Actions.Copy,
62-
) {
59+
private class CopyLinkAction(val url: String) :
60+
DumbAwareAction(
61+
IdeBundle.messagePointer("action.text.copy.link.address"),
62+
AllIcons.Actions.Copy,
63+
) {
6364
override fun actionPerformed(event: AnActionEvent) {
6465
CopyPasteManager.getInstance().setContents(StringSelection(url))
6566
}
6667
}
6768

68-
private class OpenLinkInBrowser(val url: String) : DumbAwareAction(
69-
IdeBundle.messagePointer("action.text.open.link.in.browser"),
70-
AllIcons.Nodes.PpWeb,
71-
) {
69+
private class OpenLinkInBrowser(val url: String) :
70+
DumbAwareAction(
71+
IdeBundle.messagePointer("action.text.open.link.in.browser"),
72+
AllIcons.Nodes.PpWeb,
73+
) {
7274
override fun actionPerformed(event: AnActionEvent) {
7375
BrowserUtil.browse(url)
7476
}

‎src/main/kotlin/com/coder/gateway/views/steps/CoderWizardStep.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import javax.swing.JButton
1414

1515
sealed class CoderWizardStep<T>(
1616
nextActionText: String,
17-
) : BorderLayoutPanel(), Disposable {
17+
) : BorderLayoutPanel(),
18+
Disposable {
1819
var onPrevious: (() -> Unit)? = null
1920
var onNext: ((data: T) -> Unit)? = null
2021

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

Lines changed: 60 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,10 @@ class CoderWorkspaceProjectIDEStepView(
233233
retrieveIDEs(executor, data.workspace, data.agent)
234234
},
235235
retryIf = {
236-
it is ConnectionException || it is TimeoutException ||
237-
it is SSHException || it is DeployException
236+
it is ConnectionException ||
237+
it is TimeoutException ||
238+
it is SSHException ||
239+
it is DeployException
238240
},
239241
onException = { attempt, nextMs, e ->
240242
logger.error("Failed to retrieve IDEs (attempt $attempt; will retry in $nextMs ms)")
@@ -317,17 +319,15 @@ class CoderWorkspaceProjectIDEStepView(
317319
/**
318320
* Connect to the remote worker via SSH.
319321
*/
320-
private suspend fun createRemoteExecutor(host: String): HighLevelHostAccessor {
321-
return HighLevelHostAccessor.create(
322-
RemoteCredentialsHolder().apply {
323-
setHost(host)
324-
userName = "coder"
325-
port = 22
326-
authType = AuthType.OPEN_SSH
327-
},
328-
true,
329-
)
330-
}
322+
private suspend fun createRemoteExecutor(host: String): HighLevelHostAccessor = HighLevelHostAccessor.create(
323+
RemoteCredentialsHolder().apply {
324+
setHost(host)
325+
userName = "coder"
326+
port = 22
327+
authType = AuthType.OPEN_SSH
328+
},
329+
true,
330+
)
331331

332332
/**
333333
* Get a list of available IDEs.
@@ -351,8 +351,7 @@ class CoderWorkspaceProjectIDEStepView(
351351
logger.info("Resolved OS and Arch for $name is: $workspaceOS")
352352
val installedIdesJob =
353353
cs.async(Dispatchers.IO) {
354-
executor.getInstalledIDEs().map {
355-
ide ->
354+
executor.getInstalledIDEs().map { ide ->
356355
IdeWithStatus(
357356
ide.product,
358357
ide.buildNumber,
@@ -397,44 +396,40 @@ class CoderWorkspaceProjectIDEStepView(
397396
private fun toDeployedOS(
398397
os: OS,
399398
arch: Arch,
400-
): DeployTargetOS {
401-
return when (os) {
402-
OS.LINUX ->
403-
when (arch) {
404-
Arch.AMD64 -> DeployTargetOS(OSKind.Linux, OSArch.X86_64)
405-
Arch.ARM64 -> DeployTargetOS(OSKind.Linux, OSArch.ARM_64)
406-
Arch.ARMV7 -> DeployTargetOS(OSKind.Linux, OSArch.UNKNOWN)
407-
}
399+
): DeployTargetOS = when (os) {
400+
OS.LINUX ->
401+
when (arch) {
402+
Arch.AMD64 -> DeployTargetOS(OSKind.Linux, OSArch.X86_64)
403+
Arch.ARM64 -> DeployTargetOS(OSKind.Linux, OSArch.ARM_64)
404+
Arch.ARMV7 -> DeployTargetOS(OSKind.Linux, OSArch.UNKNOWN)
405+
}
408406

409-
OS.WINDOWS ->
410-
when (arch) {
411-
Arch.AMD64 -> DeployTargetOS(OSKind.Windows, OSArch.X86_64)
412-
Arch.ARM64 -> DeployTargetOS(OSKind.Windows, OSArch.ARM_64)
413-
Arch.ARMV7 -> DeployTargetOS(OSKind.Windows, OSArch.UNKNOWN)
414-
}
407+
OS.WINDOWS ->
408+
when (arch) {
409+
Arch.AMD64 -> DeployTargetOS(OSKind.Windows, OSArch.X86_64)
410+
Arch.ARM64 -> DeployTargetOS(OSKind.Windows, OSArch.ARM_64)
411+
Arch.ARMV7 -> DeployTargetOS(OSKind.Windows, OSArch.UNKNOWN)
412+
}
415413

416-
OS.MAC ->
417-
when (arch) {
418-
Arch.AMD64 -> DeployTargetOS(OSKind.MacOs, OSArch.X86_64)
419-
Arch.ARM64 -> DeployTargetOS(OSKind.MacOs, OSArch.ARM_64)
420-
Arch.ARMV7 -> DeployTargetOS(OSKind.MacOs, OSArch.UNKNOWN)
421-
}
422-
}
414+
OS.MAC ->
415+
when (arch) {
416+
Arch.AMD64 -> DeployTargetOS(OSKind.MacOs, OSArch.X86_64)
417+
Arch.ARM64 -> DeployTargetOS(OSKind.MacOs, OSArch.ARM_64)
418+
Arch.ARMV7 -> DeployTargetOS(OSKind.MacOs, OSArch.UNKNOWN)
419+
}
423420
}
424421

425422
/**
426423
* Return the selected parameters. Throw if not configured.
427424
*/
428-
override fun data(): WorkspaceProjectIDE {
429-
return withoutNull(cbIDE.selectedItem, state) { selectedIDE, state ->
430-
val name = "${state.workspace.name}.${state.agent.name}"
431-
selectedIDE.withWorkspaceProject(
432-
name = name,
433-
hostname = CoderCLIManager.getHostName(state.client.url, name),
434-
projectPath = tfProject.text,
435-
deploymentURL = state.client.url,
436-
)
437-
}
425+
override fun data(): WorkspaceProjectIDE = withoutNull(cbIDE.selectedItem, state) { selectedIDE, state ->
426+
val name = "${state.workspace.name}.${state.agent.name}"
427+
selectedIDE.withWorkspaceProject(
428+
name = name,
429+
hostname = CoderCLIManager.getHostName(state.client.url, name),
430+
projectPath = tfProject.text,
431+
deploymentURL = state.client.url,
432+
)
438433
}
439434

440435
override fun stop() {
@@ -451,9 +446,7 @@ class CoderWorkspaceProjectIDEStepView(
451446
putClientProperty(AnimatedIcon.ANIMATION_IN_RENDERER_ALLOWED, true)
452447
}
453448

454-
override fun getSelectedItem(): IdeWithStatus? {
455-
return super.getSelectedItem() as IdeWithStatus?
456-
}
449+
override fun getSelectedItem(): IdeWithStatus? = super.getSelectedItem() as IdeWithStatus?
457450
}
458451

459452
private class IDECellRenderer(message: String, cellIcon: Icon = AnimatedIcon.Default.INSTANCE) : ListCellRenderer<IdeWithStatus> {
@@ -478,27 +471,25 @@ class CoderWorkspaceProjectIDEStepView(
478471
index: Int,
479472
isSelected: Boolean,
480473
cellHasFocus: Boolean,
481-
): Component {
482-
return if (ideWithStatus == null && index == -1) {
483-
loadingComponentRenderer.getListCellRendererComponent(list, null, -1, isSelected, cellHasFocus)
484-
} else if (ideWithStatus != null) {
485-
JPanel().apply {
486-
layout = FlowLayout(FlowLayout.LEFT)
487-
add(JLabel(ideWithStatus.product.ideName, ideWithStatus.product.icon, SwingConstants.LEFT))
488-
add(
489-
JLabel(
490-
"${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase(
491-
Locale.getDefault(),
492-
)}",
493-
).apply {
494-
foreground = UIUtil.getLabelDisabledForeground()
495-
},
496-
)
497-
background = UIUtil.getListBackground(isSelected, cellHasFocus)
498-
}
499-
} else {
500-
panel { }
474+
): Component = if (ideWithStatus == null && index == -1) {
475+
loadingComponentRenderer.getListCellRendererComponent(list, null, -1, isSelected, cellHasFocus)
476+
} else if (ideWithStatus != null) {
477+
JPanel().apply {
478+
layout = FlowLayout(FlowLayout.LEFT)
479+
add(JLabel(ideWithStatus.product.ideName, ideWithStatus.product.icon, SwingConstants.LEFT))
480+
add(
481+
JLabel(
482+
"${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase(
483+
Locale.getDefault(),
484+
)}",
485+
).apply {
486+
foreground = UIUtil.getLabelDisabledForeground()
487+
},
488+
)
489+
background = UIUtil.getListBackground(isSelected, cellHasFocus)
501490
}
491+
} else {
492+
panel { }
502493
}
503494
}
504495

‎src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ data class CoderWorkspacesStepSelection(
111111
* A list of agents/workspaces belonging to a deployment. Has inputs for
112112
* connecting and authorizing to different deployments.
113113
*/
114-
class CoderWorkspacesStepView : CoderWizardStep<CoderWorkspacesStepSelection>(
115-
CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.next.text"),
116-
) {
114+
class CoderWorkspacesStepView :
115+
CoderWizardStep<CoderWorkspacesStepSelection>(
116+
CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.next.text"),
117+
) {
117118
private val settings: CoderSettingsService = service<CoderSettingsService>()
118119
private val cs = CoroutineScope(Dispatchers.Main)
119120
private val jobs: MutableMap<UUID, Job> = mutableMapOf()
@@ -778,31 +779,26 @@ class CoderWorkspacesStepView : CoderWizardStep<CoderWorkspacesStepSelection>(
778779
}
779780
}
780781

781-
class WorkspacesTableModel : ListTableModel<WorkspaceAgentListModel>(
782-
WorkspaceIconColumnInfo(""),
783-
WorkspaceNameColumnInfo("Name"),
784-
WorkspaceTemplateNameColumnInfo("Template"),
785-
WorkspaceVersionColumnInfo("Version"),
786-
WorkspaceStatusColumnInfo("Status"),
787-
) {
782+
class WorkspacesTableModel :
783+
ListTableModel<WorkspaceAgentListModel>(
784+
WorkspaceIconColumnInfo(""),
785+
WorkspaceNameColumnInfo("Name"),
786+
WorkspaceTemplateNameColumnInfo("Template"),
787+
WorkspaceVersionColumnInfo("Version"),
788+
WorkspaceStatusColumnInfo("Status"),
789+
) {
788790
private class WorkspaceIconColumnInfo(columnName: String) : ColumnInfo<WorkspaceAgentListModel, String>(columnName) {
789-
override fun valueOf(item: WorkspaceAgentListModel?): String? {
790-
return item?.workspace?.templateName
791-
}
791+
override fun valueOf(item: WorkspaceAgentListModel?): String? = item?.workspace?.templateName
792792

793793
override fun getRenderer(item: WorkspaceAgentListModel?): TableCellRenderer {
794794
return object : IconTableCellRenderer<String>() {
795-
override fun getText(): String {
796-
return ""
797-
}
795+
override fun getText(): String = ""
798796

799797
override fun getIcon(
800798
value: String,
801799
table: JTable?,
802800
row: Int,
803-
): Icon {
804-
return item?.icon ?: CoderIcons.UNKNOWN
805-
}
801+
): Icon = item?.icon ?: CoderIcons.UNKNOWN
806802

807803
override fun isCenterAlignment() = true
808804

@@ -824,14 +820,10 @@ class WorkspacesTableModel : ListTableModel<WorkspaceAgentListModel>(
824820
}
825821

826822
private class WorkspaceNameColumnInfo(columnName: String) : ColumnInfo<WorkspaceAgentListModel, String>(columnName) {
827-
override fun valueOf(item: WorkspaceAgentListModel?): String? {
828-
return item?.name
829-
}
823+
override fun valueOf(item: WorkspaceAgentListModel?): String? = item?.name
830824

831-
override fun getComparator(): Comparator<WorkspaceAgentListModel> {
832-
return Comparator { a, b ->
833-
a.name.compareTo(b.name, ignoreCase = true)
834-
}
825+
override fun getComparator(): Comparator<WorkspaceAgentListModel> = Comparator { a, b ->
826+
a.name.compareTo(b.name, ignoreCase = true)
835827
}
836828

837829
override fun getRenderer(item: WorkspaceAgentListModel?): TableCellRenderer {
@@ -857,16 +849,11 @@ class WorkspacesTableModel : ListTableModel<WorkspaceAgentListModel>(
857849
}
858850
}
859851

860-
private class WorkspaceTemplateNameColumnInfo(columnName: String) :
861-
ColumnInfo<WorkspaceAgentListModel, String>(columnName) {
862-
override fun valueOf(item: WorkspaceAgentListModel?): String? {
863-
return item?.workspace?.templateName
864-
}
852+
private class WorkspaceTemplateNameColumnInfo(columnName: String) : ColumnInfo<WorkspaceAgentListModel, String>(columnName) {
853+
override fun valueOf(item: WorkspaceAgentListModel?): String? = item?.workspace?.templateName
865854

866-
override fun getComparator(): java.util.Comparator<WorkspaceAgentListModel> {
867-
return Comparator { a, b ->
868-
a.workspace.templateName.compareTo(b.workspace.templateName, ignoreCase = true)
869-
}
855+
override fun getComparator(): java.util.Comparator<WorkspaceAgentListModel> = Comparator { a, b ->
856+
a.workspace.templateName.compareTo(b.workspace.templateName, ignoreCase = true)
870857
}
871858

872859
override fun getRenderer(item: WorkspaceAgentListModel?): TableCellRenderer {
@@ -892,14 +879,12 @@ class WorkspacesTableModel : ListTableModel<WorkspaceAgentListModel>(
892879
}
893880

894881
private class WorkspaceVersionColumnInfo(columnName: String) : ColumnInfo<WorkspaceAgentListModel, String>(columnName) {
895-
override fun valueOf(workspace: WorkspaceAgentListModel?): String? {
896-
return if (workspace == null) {
897-
"Unknown"
898-
} else if (workspace.workspace.outdated) {
899-
"Outdated"
900-
} else {
901-
"Up to date"
902-
}
882+
override fun valueOf(workspace: WorkspaceAgentListModel?): String? = if (workspace == null) {
883+
"Unknown"
884+
} else if (workspace.workspace.outdated) {
885+
"Outdated"
886+
} else {
887+
"Up to date"
903888
}
904889

905890
override fun getRenderer(item: WorkspaceAgentListModel?): TableCellRenderer {
@@ -925,14 +910,10 @@ class WorkspacesTableModel : ListTableModel<WorkspaceAgentListModel>(
925910
}
926911

927912
private class WorkspaceStatusColumnInfo(columnName: String) : ColumnInfo<WorkspaceAgentListModel, String>(columnName) {
928-
override fun valueOf(item: WorkspaceAgentListModel?): String? {
929-
return item?.status?.label
930-
}
913+
override fun valueOf(item: WorkspaceAgentListModel?): String? = item?.status?.label
931914

932-
override fun getComparator(): java.util.Comparator<WorkspaceAgentListModel> {
933-
return Comparator { a, b ->
934-
a.status.label.compareTo(b.status.label, ignoreCase = true)
935-
}
915+
override fun getComparator(): java.util.Comparator<WorkspaceAgentListModel> = Comparator { a, b ->
916+
a.status.label.compareTo(b.status.label, ignoreCase = true)
936917
}
937918

938919
override fun getRenderer(item: WorkspaceAgentListModel?): TableCellRenderer {

‎src/test/kotlin/com/coder/gateway/cli/CoderCLIManagerTest.kt

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,17 @@ internal class CoderCLIManagerTest {
3737
/**
3838
* Return the contents of a script that contains the string.
3939
*/
40-
private fun mkbin(str: String): String {
41-
return if (getOS() == OS.WINDOWS) {
42-
// Must use a .bat extension for this to work.
43-
listOf("@echo off", str)
44-
} else {
45-
listOf("#!/bin/sh", str)
46-
}.joinToString(System.lineSeparator())
47-
}
40+
private fun mkbin(str: String): String = if (getOS() == OS.WINDOWS) {
41+
// Must use a .bat extension for this to work.
42+
listOf("@echo off", str)
43+
} else {
44+
listOf("#!/bin/sh", str)
45+
}.joinToString(System.lineSeparator())
4846

4947
/**
5048
* Return the contents of a script that outputs JSON containing the version.
5149
*/
52-
private fun mkbinVersion(version: String): String {
53-
return mkbin(echo("""{"version": "$version"}"""))
54-
}
50+
private fun mkbinVersion(version: String): String = mkbin(echo("""{"version": "$version"}"""))
5551

5652
private fun mockServer(
5753
errorCode: Int = 0,
@@ -333,7 +329,7 @@ internal class CoderCLIManagerTest {
333329
"header-command-windows",
334330
"blank",
335331
""""C:\Program Files\My Header Command\HeaderCommand.exe" --url="%CODER_URL%" --test="foo bar"""",
336-
features = Features(false, true)
332+
features = Features(false, true),
337333
)
338334
} else {
339335
SSHTest(
@@ -342,7 +338,7 @@ internal class CoderCLIManagerTest {
342338
"header-command",
343339
"blank",
344340
"my-header-command --url=\"\$CODER_URL\" --test=\"foo bar\" --literal='\$CODER_URL'",
345-
features = Features(false, true)
341+
features = Features(false, true),
346342
)
347343
},
348344
SSHTest(listOf("foo"), null, "disable-autostart", "blank", "", true, Features(true, true)),
@@ -354,15 +350,15 @@ internal class CoderCLIManagerTest {
354350
"extra-config",
355351
"blank",
356352
extraConfig = extraConfig,
357-
features = Features(false, true)
353+
features = Features(false, true),
358354
),
359355
SSHTest(
360356
listOf("extra"),
361357
null,
362358
"extra-config",
363359
"blank",
364360
env = Environment(mapOf(CODER_SSH_CONFIG_OPTIONS to extraConfig)),
365-
features = Features(false, true)
361+
features = Features(false, true),
366362
),
367363
)
368364

@@ -476,23 +472,19 @@ internal class CoderCLIManagerTest {
476472
/**
477473
* Return an echo command for the OS.
478474
*/
479-
private fun echo(str: String): String {
480-
return if (getOS() == OS.WINDOWS) {
481-
"echo $str"
482-
} else {
483-
"echo '$str'"
484-
}
475+
private fun echo(str: String): String = if (getOS() == OS.WINDOWS) {
476+
"echo $str"
477+
} else {
478+
"echo '$str'"
485479
}
486480

487481
/**
488482
* Return an exit command for the OS.
489483
*/
490-
private fun exit(code: Number): String {
491-
return if (getOS() == OS.WINDOWS) {
492-
"exit /b $code"
493-
} else {
494-
"exit $code"
495-
}
484+
private fun exit(code: Number): String = if (getOS() == OS.WINDOWS) {
485+
"exit /b $code"
486+
} else {
487+
"exit $code"
496488
}
497489

498490
@Test

‎src/test/kotlin/com/coder/gateway/sdk/CoderRestClientTest.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,7 @@ class CoderRestClientTest {
505505
"bar",
506506
true,
507507
object : ProxySelector() {
508-
override fun select(uri: URI): List<Proxy> {
509-
return listOf(Proxy(Proxy.Type.HTTP, InetSocketAddress("localhost", srv2.address.port)))
510-
}
508+
override fun select(uri: URI): List<Proxy> = listOf(Proxy(Proxy.Type.HTTP, InetSocketAddress("localhost", srv2.address.port)))
511509

512510
override fun connectFailed(
513511
uri: URI,

‎src/test/kotlin/com/coder/gateway/sdk/DataGen.kt

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,22 @@ class DataGen {
2929
fun resource(
3030
agentName: String,
3131
agentId: String,
32-
): WorkspaceResource {
33-
return WorkspaceResource(
34-
agents =
35-
listOf(
36-
WorkspaceAgent(
37-
id = UUID.fromString(agentId),
38-
status = WorkspaceAgentStatus.CONNECTED,
39-
name = agentName,
40-
architecture = Arch.from("amd64"),
41-
operatingSystem = OS.from("linux"),
42-
directory = null,
43-
expandedDirectory = null,
44-
lifecycleState = WorkspaceAgentLifecycleState.READY,
45-
loginBeforeReady = false,
46-
),
32+
): WorkspaceResource = WorkspaceResource(
33+
agents =
34+
listOf(
35+
WorkspaceAgent(
36+
id = UUID.fromString(agentId),
37+
status = WorkspaceAgentStatus.CONNECTED,
38+
name = agentName,
39+
architecture = Arch.from("amd64"),
40+
operatingSystem = OS.from("linux"),
41+
directory = null,
42+
expandedDirectory = null,
43+
lifecycleState = WorkspaceAgentLifecycleState.READY,
44+
loginBeforeReady = false,
4745
),
48-
)
49-
}
46+
),
47+
)
5048

5149
fun workspace(
5250
name: String,
@@ -72,25 +70,19 @@ class DataGen {
7270
fun build(
7371
templateVersionID: UUID = UUID.randomUUID(),
7472
resources: List<WorkspaceResource> = emptyList(),
75-
): WorkspaceBuild {
76-
return WorkspaceBuild(
77-
templateVersionID = templateVersionID,
78-
resources = resources,
79-
status = WorkspaceStatus.RUNNING,
80-
)
81-
}
73+
): WorkspaceBuild = WorkspaceBuild(
74+
templateVersionID = templateVersionID,
75+
resources = resources,
76+
status = WorkspaceStatus.RUNNING,
77+
)
8278

83-
fun template(): Template {
84-
return Template(
85-
id = UUID.randomUUID(),
86-
activeVersionID = UUID.randomUUID(),
87-
)
88-
}
79+
fun template(): Template = Template(
80+
id = UUID.randomUUID(),
81+
activeVersionID = UUID.randomUUID(),
82+
)
8983

90-
fun user(): User {
91-
return User(
92-
"tester",
93-
)
94-
}
84+
fun user(): User = User(
85+
"tester",
86+
)
9587
}
9688
}

‎src/test/kotlin/com/coder/gateway/util/LinkHandlerTest.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ internal class LinkHandlerTest {
2828
private fun mockRedirectServer(
2929
location: String,
3030
temp: Boolean,
31-
): Pair<HttpServer, String> {
32-
return mockServer { exchange ->
33-
exchange.responseHeaders.set("Location", location)
34-
exchange.sendResponseHeaders(
35-
if (temp) HttpURLConnection.HTTP_MOVED_TEMP else HttpURLConnection.HTTP_MOVED_PERM,
36-
-1,
37-
)
38-
exchange.close()
39-
}
31+
): Pair<HttpServer, String> = mockServer { exchange ->
32+
exchange.responseHeaders.set("Location", location)
33+
exchange.sendResponseHeaders(
34+
if (temp) HttpURLConnection.HTTP_MOVED_TEMP else HttpURLConnection.HTTP_MOVED_PERM,
35+
-1,
36+
)
37+
exchange.close()
4038
}
4139

4240
private val agents =

0 commit comments

Comments
 (0)
Please sign in to comment.