Skip to content

Commit c935a50

Browse files
authored
Merge pull request #20 from coder/qodana-and-plugin-verifier-inspections
Address Qodana and plugin verifier inspections - remove usage of Gateway internal API - delete unused V1 models - used proper naming convention in serialized enum values - remove unused methods - remove unused property declarations - remove redundant calls on non-nullable types - suppress warnings about string capitalization & unstable API usage
2 parents 4c159ba + ca4bc3b commit c935a50

32 files changed

+109
-271
lines changed
-6.42 MB
Binary file not shown.

lib/webrtc-java-0.6.0.jar

-93.1 KB
Binary file not shown.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DialogTitleCapitalization")
2+
13
package com.coder.gateway
24

35
import com.coder.gateway.models.RecentWorkspaceConnection
@@ -63,7 +65,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
6365
buildNumber = ideBuildNumber
6466
)
6567

66-
clientLifetime.launchUnderBackgroundProgress("Coder Gateway Deploy", true, true, null) {
68+
clientLifetime.launchUnderBackgroundProgress("Coder Gateway Deploy", canBeCancelled = true, isIndeterminate = true, project = null) {
6769
val context = SshMultistagePanelContext().apply {
6870
deploy = true
6971
sshConfig = sshConfiguration
@@ -74,6 +76,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
7476
ide = ideConfig
7577
}
7678
launch {
79+
@Suppress("UnstableApiUsage")
7780
SshDeployFlowUtil.fullDeployCycle(
7881
clientLifetime,
7982
context,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ class CoderGatewayMainView : GatewayConnector {
2525
return CoderGatewayBundle.message("gateway.connector.action.text")
2626
}
2727

28-
override fun getDescription(): String? {
28+
override fun getDescription(): String {
2929
return CoderGatewayBundle.message("gateway.connector.description")
3030
}
3131

32-
override fun getDocumentationLink(): ActionLink? {
32+
override fun getDocumentationLink(): ActionLink {
3333
return BrowserLink(null, "Learn more about Coder Workspaces", null, "https://coder.com/docs/coder/latest/workspaces")
3434
}
3535

36-
override fun getRecentConnections(setContentCallback: (Component) -> Unit): GatewayRecentConnections? {
36+
override fun getRecentConnections(setContentCallback: (Component) -> Unit): GatewayRecentConnections {
3737
return CoderGatewayRecentWorkspaceConnectionsView()
3838
}
3939

src/main/kotlin/com/coder/gateway/sdk/CoderCLIDownloader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.nio.file.StandardCopyOption
1111
class CoderCLIDownloader(private val buildVersion: String) {
1212

1313
fun downloadCLI(url: URL, outputName: String, ext: String): Path {
14-
val filename = if (ext.isNullOrBlank()) "${outputName}-$buildVersion" else "${outputName}-${buildVersion}.${ext}"
14+
val filename = if (ext.isBlank()) "${outputName}-$buildVersion" else "${outputName}-${buildVersion}.${ext}"
1515
val cliPath = Paths.get(System.getProperty("java.io.tmpdir"), filename)
1616
if (Files.exists(cliPath)) {
1717
logger.info("${cliPath.toAbsolutePath()} already exists, skipping download")

src/main/kotlin/com/coder/gateway/sdk/CoderCLIManager.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.intellij.openapi.diagnostic.Logger
44
import java.net.URL
55
import java.nio.file.Path
66

7-
class CoderCLIManager(private val url: URL, private val buildVersion: String) {
7+
class CoderCLIManager(private val url: URL, buildVersion: String) {
88
private val coderCLIDownloader = CoderCLIDownloader(buildVersion)
99

1010
fun download(): Path? {
@@ -21,19 +21,19 @@ class CoderCLIManager(private val url: URL, private val buildVersion: String) {
2121
}
2222
return when (os) {
2323
OS.WINDOWS -> when (arch) {
24-
Arch.amd64 -> "coder-windows-amd64"
25-
Arch.arm64 -> "coder-windows-arm64"
24+
Arch.AMD64 -> "coder-windows-amd64"
25+
Arch.ARM64 -> "coder-windows-arm64"
2626
else -> "coder-windows-amd64"
2727
}
2828
OS.LINUX -> when (arch) {
29-
Arch.amd64 -> "coder-linux-amd64"
30-
Arch.arm64 -> "coder-linux-arm64"
31-
Arch.armv7 -> "coder-linux-armv7"
29+
Arch.AMD64 -> "coder-linux-amd64"
30+
Arch.ARM64 -> "coder-linux-arm64"
31+
Arch.ARMV7 -> "coder-linux-armv7"
3232
else -> "coder-linux-amd64"
3333
}
3434
OS.MAC -> when (arch) {
35-
Arch.amd64 -> "coder-darwin-amd64"
36-
Arch.arm64 -> "coder-darwin-arm64"
35+
Arch.AMD64 -> "coder-darwin-amd64"
36+
Arch.ARM64 -> "coder-darwin-arm64"
3737
else -> "coder-darwin-amd64"
3838
}
3939
}

src/main/kotlin/com/coder/gateway/sdk/CoderRestClientService.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.coder.gateway.sdk
33
import com.coder.gateway.sdk.convertors.InstantConverter
44
import com.coder.gateway.sdk.ex.AuthenticationException
55
import com.coder.gateway.sdk.v2.CoderV2RestFacade
6-
import com.coder.gateway.sdk.v2.models.AgentGitSSHKeys
76
import com.coder.gateway.sdk.v2.models.BuildInfo
87
import com.coder.gateway.sdk.v2.models.User
98
import com.coder.gateway.sdk.v2.models.Workspace
@@ -24,16 +23,16 @@ import java.time.Instant
2423
@Service(Service.Level.APP)
2524
class CoderRestClientService {
2625
private lateinit var retroRestClient: CoderV2RestFacade
26+
private lateinit var sessionToken: String
2727
lateinit var coderURL: URL
28-
lateinit var sessionToken: String
2928
lateinit var me: User
3029
lateinit var buildVersion: String
3130

3231
/**
3332
* This must be called before anything else. It will authenticate with coder and retrieve a session token
3433
* @throws [AuthenticationException] if authentication failed
3534
*/
36-
fun initClientSession(url: URL, token: String): User? {
35+
fun initClientSession(url: URL, token: String): User {
3736
val cookieUrl = url.toHttpUrlOrNull()!!
3837
val cookieJar = JavaNetCookieJar(CookieManager()).apply {
3938
saveFromResponse(
@@ -82,16 +81,7 @@ class CoderRestClientService {
8281
return workspacesResponse.body()!!
8382
}
8483

85-
fun userSSHKeys(): AgentGitSSHKeys {
86-
val sshKeysResponse = retroRestClient.sshKeys().execute()
87-
if (!sshKeysResponse.isSuccessful) {
88-
throw IllegalStateException("Could not retrieve Coder Workspaces:${sshKeysResponse.code()}, reason: ${sshKeysResponse.message()}")
89-
}
90-
91-
return sshKeysResponse.body()!!
92-
}
93-
94-
fun buildInfo(): BuildInfo {
84+
private fun buildInfo(): BuildInfo {
9585
val buildInfoResponse = retroRestClient.buildInfo().execute()
9686
if (!buildInfoResponse.isSuccessful) {
9787
throw java.lang.IllegalStateException("Could not retrieve build information for Coder instance $coderURL, reason:${buildInfoResponse.message()}")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class InstantConverter : JsonSerializer<Instant?>, JsonDeserializer<Instant?> {
3232
* @param typeOfSrc the actual type (fully genericized version) of the source object.
3333
* @return a JsonElement corresponding to the specified object.
3434
*/
35-
override fun serialize(src: Instant?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement? {
35+
override fun serialize(src: Instant?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
3636
return JsonPrimitive(FORMATTER.format(src))
3737
}
3838

src/main/kotlin/com/coder/gateway/sdk/ex/AuthenticationException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package com.coder.gateway.sdk.ex
22

33
import java.io.IOException
44

5-
class AuthenticationException(val reason: String) : IOException(reason)
5+
class AuthenticationException(reason: String) : IOException(reason)

src/main/kotlin/com/coder/gateway/sdk/os.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ fun getOS(): OS? {
1919
fun getArch(): Arch? {
2020
val arch = System.getProperty("os.arch").toLowerCase()
2121
return when {
22-
arch.contains("amd64", true) || arch.contains("x86_64", true) -> Arch.amd64
23-
arch.contains("arm64", true) || arch.contains("aarch64", true) -> Arch.arm64
24-
arch.contains("armv7", true) -> Arch.armv7
22+
arch.contains("amd64", true) || arch.contains("x86_64", true) -> Arch.AMD64
23+
arch.contains("arm64", true) || arch.contains("aarch64", true) -> Arch.ARM64
24+
arch.contains("armv7", true) -> Arch.ARMV7
2525
else -> null
2626
}
2727
}
@@ -31,5 +31,5 @@ enum class OS {
3131
}
3232

3333
enum class Arch {
34-
amd64, arm64, armv7
34+
AMD64, ARM64, ARMV7
3535
}

0 commit comments

Comments
 (0)