Skip to content

Commit 142a587

Browse files
committed
impl: get rid of last remaining of internal logger
- JetBrains recommendation is to use its own diagnostic logger available via service locator - gets rid of slf4j api library
1 parent d75d0c7 commit 142a587

File tree

16 files changed

+333
-380
lines changed

16 files changed

+333
-380
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ dependencies {
5555
compileOnly(libs.bundles.toolbox.plugin.api)
5656
compileOnly(libs.bundles.serialization)
5757
compileOnly(libs.coroutines.core)
58-
implementation(libs.slf4j)
5958
implementation(libs.okhttp)
6059
implementation(libs.exec)
6160
implementation(libs.moshi)
6261
ksp(libs.moshi.codegen)
6362
implementation(libs.retrofit)
6463
implementation(libs.retrofit.moshi)
6564
testImplementation(kotlin("test"))
65+
testImplementation(libs.mokk)
66+
testImplementation(libs.bundles.toolbox.plugin.api)
6667
}
6768

6869
val extension = ExtensionJson(

gradle/libs.versions.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ kotlin = "2.1.0"
44
coroutines = "1.10.1"
55
serialization = "1.8.0"
66
okhttp = "4.10.0"
7-
slf4j = "2.0.3"
87
dependency-license-report = "2.5"
98
marketplace-client = "2.0.38"
109
gradle-wrapper = "0.14.0"
@@ -15,6 +14,7 @@ retrofit = "2.8.2"
1514
changelog = "2.2.1"
1615
gettext = "0.7.0"
1716
plugin-structure = "3.298"
17+
mockk = "1.13.17"
1818

1919
[libraries]
2020
toolbox-core-api = { module = "com.jetbrains.toolbox:core-api", version.ref = "toolbox-plugin-api" }
@@ -25,14 +25,13 @@ serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-cor
2525
serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
2626
serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version.ref = "serialization" }
2727
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
28-
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
2928
exec = { module = "org.zeroturnaround:zt-exec", version.ref = "exec" }
3029
moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" }
3130
moshi-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "moshi" }
3231
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
3332
retrofit-moshi = { module = "com.squareup.retrofit2:converter-moshi", version.ref = "retrofit" }
3433
plugin-structure = { module = "org.jetbrains.intellij.plugins:structure-toolbox", version.ref = "plugin-structure" }
35-
34+
mokk = { module = "io.mockk:mockk", version.ref = "mockk" }
3635
marketplace-client = { module = "org.jetbrains.intellij:plugin-repository-rest-client", version.ref = "marketplace-client" }
3736

3837
[bundles]

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CoderRemoteProvider(
4848

4949
// Create our services from the Toolbox ones.
5050
private val settingsService = CoderSettingsService(context.settingsStore)
51-
private val settings: CoderSettings = CoderSettings(settingsService)
51+
private val settings: CoderSettings = CoderSettings(settingsService, context.logger)
5252
private val secrets: CoderSecretsService = CoderSecretsService(context.secretsStore)
5353
private val settingsPage: CoderSettingsPage = CoderSettingsPage(context, settingsService)
5454
private val dialogUi = DialogUi(context, settings)

src/main/kotlin/com/coder/toolbox/CoderToolboxExtension.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.coder.toolbox
22

3-
import com.coder.toolbox.logger.CoderLoggerFactory
43
import com.jetbrains.toolbox.api.core.PluginSecretStore
54
import com.jetbrains.toolbox.api.core.PluginSettingsStore
65
import com.jetbrains.toolbox.api.core.ServiceLocator
@@ -20,9 +19,6 @@ import okhttp3.OkHttpClient
2019
class CoderToolboxExtension : RemoteDevExtension {
2120
// All services must be passed in here and threaded as necessary.
2221
override fun createRemoteProviderPluginInstance(serviceLocator: ServiceLocator): RemoteProvider {
23-
// initialize logger factory
24-
CoderLoggerFactory.tLogger = serviceLocator.getService(Logger::class.java)
25-
2622
return CoderRemoteProvider(
2723
CoderToolboxContext(
2824
serviceLocator.getService(ToolboxUi::class.java),

src/main/kotlin/com/coder/toolbox/cli/CoderCLIManager.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.coder.toolbox.cli
22

3+
import com.coder.toolbox.CoderToolboxContext
34
import com.coder.toolbox.cli.ex.MissingVersionException
45
import com.coder.toolbox.cli.ex.ResponseException
56
import com.coder.toolbox.cli.ex.SSHConfigFormatException
6-
import com.coder.toolbox.logger.CoderLoggerFactory
77
import com.coder.toolbox.settings.CoderSettings
88
import com.coder.toolbox.settings.CoderSettingsState
99
import com.coder.toolbox.util.CoderHostnameVerifier
@@ -17,6 +17,7 @@ import com.coder.toolbox.util.getHeaders
1717
import com.coder.toolbox.util.getOS
1818
import com.coder.toolbox.util.safeHost
1919
import com.coder.toolbox.util.sha1
20+
import com.jetbrains.toolbox.api.core.diagnostics.Logger
2021
import com.squareup.moshi.Json
2122
import com.squareup.moshi.JsonClass
2223
import com.squareup.moshi.JsonDataException
@@ -55,12 +56,13 @@ internal data class Version(
5556
* from step 2 with the data directory.
5657
*/
5758
fun ensureCLI(
59+
context: CoderToolboxContext,
5860
deploymentURL: URL,
5961
buildVersion: String,
6062
settings: CoderSettings,
6163
indicator: ((t: String) -> Unit)? = null,
6264
): CoderCLIManager {
63-
val cli = CoderCLIManager(deploymentURL, settings)
65+
val cli = CoderCLIManager(deploymentURL, context.logger, settings)
6466

6567
// Short-circuit if we already have the expected version. This
6668
// lets us bypass the 304 which is slower and may not be
@@ -89,7 +91,7 @@ fun ensureCLI(
8991
}
9092

9193
// Try falling back to the data directory.
92-
val dataCLI = CoderCLIManager(deploymentURL, settings, true)
94+
val dataCLI = CoderCLIManager(deploymentURL, context.logger, settings, true)
9395
val dataCLIMatches = dataCLI.matchesVersion(buildVersion)
9496
if (dataCLIMatches == true) {
9597
return dataCLI
@@ -120,14 +122,13 @@ data class Features(
120122
class CoderCLIManager(
121123
// The URL of the deployment this CLI is for.
122124
private val deploymentURL: URL,
125+
private val logger: Logger,
123126
// Plugin configuration.
124-
private val settings: CoderSettings = CoderSettings(CoderSettingsState()),
127+
private val settings: CoderSettings = CoderSettings(CoderSettingsState(), logger),
125128
// If the binary directory is not writable, this can be used to force the
126129
// manager to download to the data directory instead.
127130
forceDownloadToData: Boolean = false,
128131
) {
129-
private val logger = CoderLoggerFactory.getLogger(javaClass)
130-
131132
val remoteBinaryURL: URL = settings.binSource(deploymentURL)
132133
val localBinaryPath: Path = settings.binPath(deploymentURL, forceDownloadToData)
133134
val coderConfigPath: Path = settings.dataDir(deploymentURL).resolve("config")
@@ -196,7 +197,7 @@ class CoderCLIManager(
196197
} catch (e: FileNotFoundException) {
197198
null
198199
} catch (e: Exception) {
199-
logger.warn("Unable to calculate hash for $localBinaryPath", e)
200+
logger.warn(e, "Unable to calculate hash for $localBinaryPath")
200201
null
201202
}
202203

@@ -275,7 +276,8 @@ class CoderCLIManager(
275276
if (settings.sshLogDirectory.isNotBlank()) escape(settings.sshLogDirectory) else null,
276277
if (feats.reportWorkspaceUsage) "--usage-app=jetbrains" else null,
277278
)
278-
val backgroundProxyArgs = baseArgs + listOfNotNull(if (feats.reportWorkspaceUsage) "--usage-app=disable" else null)
279+
val backgroundProxyArgs =
280+
baseArgs + listOfNotNull(if (feats.reportWorkspaceUsage) "--usage-app=disable" else null)
279281
val extraConfig =
280282
if (settings.sshConfigOptions.isNotBlank()) {
281283
"\n" + settings.sshConfigOptions.prependIndent(" ")
@@ -417,6 +419,7 @@ class CoderCLIManager(
417419
is InvalidVersionException -> {
418420
logger.info("Got invalid version from $localBinaryPath: ${e.message}")
419421
}
422+
420423
else -> {
421424
// An error here most likely means the CLI does not exist or
422425
// it executed successfully but output no version which

src/main/kotlin/com/coder/toolbox/logger/CoderLoggerFactory.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)