1
1
package com.coder.toolbox.cli
2
2
3
+ import com.coder.toolbox.CoderToolboxContext
3
4
import com.coder.toolbox.cli.ex.MissingVersionException
4
5
import com.coder.toolbox.cli.ex.ResponseException
5
6
import com.coder.toolbox.cli.ex.SSHConfigFormatException
6
- import com.coder.toolbox.logger.CoderLoggerFactory
7
7
import com.coder.toolbox.settings.CoderSettings
8
8
import com.coder.toolbox.settings.CoderSettingsState
9
9
import com.coder.toolbox.util.CoderHostnameVerifier
@@ -17,6 +17,7 @@ import com.coder.toolbox.util.getHeaders
17
17
import com.coder.toolbox.util.getOS
18
18
import com.coder.toolbox.util.safeHost
19
19
import com.coder.toolbox.util.sha1
20
+ import com.jetbrains.toolbox.api.core.diagnostics.Logger
20
21
import com.squareup.moshi.Json
21
22
import com.squareup.moshi.JsonClass
22
23
import com.squareup.moshi.JsonDataException
@@ -55,12 +56,13 @@ internal data class Version(
55
56
* from step 2 with the data directory.
56
57
*/
57
58
fun ensureCLI (
59
+ context : CoderToolboxContext ,
58
60
deploymentURL : URL ,
59
61
buildVersion : String ,
60
62
settings : CoderSettings ,
61
63
indicator : ((t: String ) -> Unit )? = null,
62
64
): CoderCLIManager {
63
- val cli = CoderCLIManager (deploymentURL, settings)
65
+ val cli = CoderCLIManager (deploymentURL, context.logger, settings)
64
66
65
67
// Short-circuit if we already have the expected version. This
66
68
// lets us bypass the 304 which is slower and may not be
@@ -89,7 +91,7 @@ fun ensureCLI(
89
91
}
90
92
91
93
// Try falling back to the data directory.
92
- val dataCLI = CoderCLIManager (deploymentURL, settings, true )
94
+ val dataCLI = CoderCLIManager (deploymentURL, context.logger, settings, true )
93
95
val dataCLIMatches = dataCLI.matchesVersion(buildVersion)
94
96
if (dataCLIMatches == true ) {
95
97
return dataCLI
@@ -120,14 +122,13 @@ data class Features(
120
122
class CoderCLIManager (
121
123
// The URL of the deployment this CLI is for.
122
124
private val deploymentURL : URL ,
125
+ private val logger : Logger ,
123
126
// Plugin configuration.
124
- private val settings : CoderSettings = CoderSettings (CoderSettingsState ()),
127
+ private val settings : CoderSettings = CoderSettings (CoderSettingsState (), logger ),
125
128
// If the binary directory is not writable, this can be used to force the
126
129
// manager to download to the data directory instead.
127
130
forceDownloadToData : Boolean = false ,
128
131
) {
129
- private val logger = CoderLoggerFactory .getLogger(javaClass)
130
-
131
132
val remoteBinaryURL: URL = settings.binSource(deploymentURL)
132
133
val localBinaryPath: Path = settings.binPath(deploymentURL, forceDownloadToData)
133
134
val coderConfigPath: Path = settings.dataDir(deploymentURL).resolve(" config" )
@@ -196,7 +197,7 @@ class CoderCLIManager(
196
197
} catch (e: FileNotFoundException ) {
197
198
null
198
199
} catch (e: Exception ) {
199
- logger.warn(" Unable to calculate hash for $localBinaryPath " , e )
200
+ logger.warn(e, " Unable to calculate hash for $localBinaryPath " )
200
201
null
201
202
}
202
203
@@ -275,7 +276,8 @@ class CoderCLIManager(
275
276
if (settings.sshLogDirectory.isNotBlank()) escape(settings.sshLogDirectory) else null ,
276
277
if (feats.reportWorkspaceUsage) " --usage-app=jetbrains" else null ,
277
278
)
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 )
279
281
val extraConfig =
280
282
if (settings.sshConfigOptions.isNotBlank()) {
281
283
" \n " + settings.sshConfigOptions.prependIndent(" " )
@@ -417,6 +419,7 @@ class CoderCLIManager(
417
419
is InvalidVersionException -> {
418
420
logger.info(" Got invalid version from $localBinaryPath : ${e.message} " )
419
421
}
422
+
420
423
else -> {
421
424
// An error here most likely means the CLI does not exist or
422
425
// it executed successfully but output no version which
0 commit comments