Skip to content

Commit 0d954e7

Browse files
committed
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
}

0 commit comments

Comments
 (0)