ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / aura-kotlin / src / toolchain.ts 357 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import * as vscode from 'vscode' ;
import { tr } from './l10n' ;
import * as fs from 'node:fs' ;
import * as os from 'node:os' ;
import * as path from 'node:path' ;
import { spawn } from 'node:child_process' ;
downloadFile extractTarGz
extractZip
execTool
platform process platform process platform
arch process arch
platform process platform process platform
jdk
kotlinc
gradle
sdk
context vscode ExtensionContext
path context globalStorageUri fsPath
home path
fs path home process platform home
bin path process platform
fs bin bin
bin path process platform
fs bin bin
sdk path
fs path sdk sdk
ToolchainStatus
jdk kotlinc gradle sdk
jdk
jdk process env process env jdk
sdk
sdk
process env process env sdk
process env process env sdk
pathSep process platform
prepend
jdk prepend path jdk
kotlinc
kotlinc prepend path kotlinc
gradle
gradle prepend path gradle
sdk
prepend
path sdk
path sdk
path sdk
current process env pathSep Boolean
missing prepend dir current dir fs dir
missing length process env missing current pathSep
home
home path home process platform
result vscode window
location vscode ProgressLocation Notification title cancellable
progress
message increment progress message increment
error
vscode window error error message error
result
archive path os
extractDir path
fs extractDir recursive
archive
process platform archive extractDir archive extractDir
inner fs extractDir name path extractDir name entry fs entry
inner
process platform fs path inner path inner inner path
fs archive force
fs extractDir recursive force
zip path os
extractDir path
fs extractDir recursive
zip
zip extractDir
inner path extractDir
fs inner inner extractDir path
path
fs zip force
fs extractDir recursive force
zip path os
extractDir path
fs extractDir recursive
zip
zip extractDir
inner path extractDir
fs inner inner extractDir path
path
fs zip force
fs extractDir recursive force
zip path os
extractDir path
fs extractDir recursive
zip
zip extractDir
inner path extractDir
dest path
fs inner inner extractDir dest
path dest
fs
fs zip force
fs extractDir recursive force
path process platform
args
sdkRoot path
env process env process env sdkRoot sdkRoot
resolve reject
child sdkRoot args shell process platform env
tail
capture data Buffer tail tail data
child stdout capture
child stderr capture
child reject
child code code
child stdin
child stdin
from to
fs to fs to recursive force
fs path to recursive
fs from to
binDir
process platform fs binDir
entry fs binDir
fs path binDir entry
current Toolchain
context vscode ExtensionContext Toolchain
current context
current
current
Toolchain current
configured vscode workspace
configured configured configured
current configured
configured vscode workspace
configured configured configured
current configured
current
error tool
message error error message error
looksMissing message
looksMissing path tool
install
pick vscode window
message
install
pick install vscode commands
vscode window message
panel
missing
current missing
current missing
panel missing
missing
result timeout
command
process platform command timeout
import
{
,
}
from
'./javaInstall'
;
import
{
}
from
'./lspInstall'
;
import
{
}
from
'./gradle'
;
const
JDK_MAJOR
=
21
;
const
KOTLIN_VERSION
=
'2.4.21'
;
export
const
GRADLE_VERSION
=
'8.10.2'
;
const
CMDLINE_TOOLS_BUILD
=
'13114758'
;
const
SDK_PLATFORM
=
'platforms;android-35'
;
const
SDK_BUILD_TOOLS
=
'build-tools;35.0.0'
;
const
SDK_PACKAGES
=
[
'platform-tools'
,
'emulator'
,
SDK_PLATFORM
,
SDK_BUILD_TOOLS
]
;
const
KOTLIN_URL
=
` https://github.com/JetBrains/kotlin/releases/download/v ${ KOTLIN_VERSION } /kotlin-compiler- ${ KOTLIN_VERSION } .zip `
;
const
GRADLE_URL
=
` https://services.gradle.org/distributions/gradle- ${ GRADLE_VERSION } -bin.zip `
;
function
jdkUrl
(
)
:
string
{
const
=
.
===
'win32'
?
'windows'
:
.
===
'darwin'
?
'mac'
:
'linux'
;
const
=
.
===
'arm64'
?
'aarch64'
:
'x64'
;
return
` https://api.adoptium.net/v3/binary/latest/ ${ JDK_MAJOR } /ga/ ${ platform} / ${ arch} /jdk/hotspot/normal/eclipse `
;
}
function
cmdlineToolsUrl
(
)
:
string
{
const
=
.
===
'win32'
?
'win'
:
.
===
'darwin'
?
'mac'
:
'linux'
;
return
` https://dl.google.com/android/repository/commandlinetools- ${ platform} - ${ CMDLINE_TOOLS_BUILD } _latest.zip `
;
}
export
interface
ToolchainStatus
{
:
boolean
;
:
boolean
;
:
boolean
;
:
boolean
;
}
export
class
Toolchain
{
constructor
(
private
readonly
:
.
)
{
}
root
(
)
:
string
{
return
.
join
(
this
.
.
.
,
'toolchain'
)
;
}
jdkHome
(
)
:
string
|
undefined
{
const
=
.
join
(
this
.
root
(
)
,
'jdk'
)
;
return
.
existsSync
(
.
join
(
,
'bin'
,
.
===
'win32'
?
'java.exe'
:
'java'
)
)
?
:
undefined
;
}
kotlincBin
(
)
:
string
|
undefined
{
const
=
.
join
(
this
.
root
(
)
,
'kotlinc'
,
'bin'
,
.
===
'win32'
?
'kotlinc.bat'
:
'kotlinc'
)
;
return
.
existsSync
(
)
?
:
undefined
;
}
gradleBin
(
)
:
string
|
undefined
{
const
=
.
join
(
this
.
root
(
)
,
'gradle'
,
'bin'
,
.
===
'win32'
?
'gradle.bat'
:
'gradle'
)
;
return
.
existsSync
(
)
?
:
undefined
;
}
androidSdk
(
)
:
string
|
undefined
{
const
=
.
join
(
this
.
root
(
)
,
'android-sdk'
)
;
return
.
existsSync
(
.
join
(
,
'platform-tools'
)
)
?
:
undefined
;
}
status
(
)
:
{
return
{
:
!
!
this
.
jdkHome
(
)
,
:
!
!
this
.
kotlincBin
(
)
,
:
!
!
this
.
gradleBin
(
)
,
:
!
!
this
.
androidSdk
(
)
}
;
}
activateEnv
(
)
:
void
{
const
=
this
.
jdkHome
(
)
;
if
(
&&
!
.
.
JAVA_HOME
)
{
.
.
JAVA_HOME
=
;
}
const
=
this
.
androidSdk
(
)
;
if
(
)
{
if
(
!
.
.
ANDROID_HOME
)
{
.
.
ANDROID_HOME
=
;
}
if
(
!
.
.
ANDROID_SDK_ROOT
)
{
.
.
ANDROID_SDK_ROOT
=
;
}
}
const
=
.
===
'win32'
?
';'
:
':'
;
const
:
string
[
]
=
[
]
;
if
(
)
{
.
push
(
.
join
(
,
'bin'
)
)
;
}
const
=
this
.
kotlincBin
(
)
;
if
(
)
{
.
push
(
.
dirname
(
)
)
;
}
const
=
this
.
gradleBin
(
)
;
if
(
)
{
.
push
(
.
dirname
(
)
)
;
}
if
(
)
{
.
push
(
.
join
(
,
'platform-tools'
)
,
.
join
(
,
'emulator'
)
,
.
join
(
,
'cmdline-tools'
,
'latest'
,
'bin'
)
,
)
;
}
const
=
(
.
.
PATH
??
''
)
.
split
(
)
.
filter
(
)
;
const
=
.
filter
(
=>
!
.
includes
(
)
&&
.
existsSync
(
)
)
;
if
(
.
)
{
.
.
PATH
=
[
...
,
...
]
.
join
(
)
;
}
}
javaBinary
(
)
:
string
|
undefined
{
const
=
this
.
jdkHome
(
)
;
return
?
.
join
(
,
'bin'
,
.
===
'win32'
?
'java.exe'
:
'java'
)
:
undefined
;
}
async
installAll
(
)
:
Promise
<
boolean
>
{
const
=
await
.
.
withProgress
(
{
:
.
.
,
:
tr
(
'Installing Kotlin/Android toolchain…'
)
,
:
false
}
,
async
=>
{
const
step
=
(
:
string
,
:
number
)
=>
.
report
(
{
,
}
)
;
try
{
if
(
!
this
.
jdkHome
(
)
)
{
step
(
tr
(
'JDK {0} (~190 MB)…'
,
String
(
JDK_MAJOR
)
)
,
5
)
;
await
this
.
installJdk
(
)
;
}
if
(
!
this
.
kotlincBin
(
)
)
{
step
(
tr
(
'Kotlin compiler {0} (~90 MB)…'
,
KOTLIN_VERSION
)
,
20
)
;
await
this
.
installKotlinc
(
)
;
}
if
(
!
this
.
gradleBin
(
)
)
{
step
(
tr
(
'Gradle {0} (~130 MB)…'
,
GRADLE_VERSION
)
,
20
)
;
await
this
.
installGradle
(
)
;
}
if
(
!
this
.
androidSdk
(
)
)
{
step
(
tr
(
'Android SDK command line tools (~130 MB)…'
)
,
20
)
;
await
this
.
installCmdlineTools
(
)
;
step
(
tr
(
'Android SDK packages (platform-tools, emulator, platform)…'
)
,
15
)
;
await
this
.
installSdkPackages
(
)
;
}
step
(
tr
(
'Finishing…'
)
,
20
)
;
this
.
activateEnv
(
)
;
return
true
;
}
catch
(
)
{
void
.
.
showErrorMessage
(
tr
(
'Toolchain installation failed: {0}'
,
instanceof
Error
?
.
:
String
(
)
)
)
;
return
false
;
}
}
,
)
;
return
;
}
private
async
installJdk
(
)
:
Promise
<
void
>
{
const
=
.
join
(
.
tmpdir
(
)
,
` jdk- ${ Date. now ( ) } ${ process. platform === 'win32' ? '.zip' : '.tar.gz' } `
)
;
const
=
.
join
(
this
.
root
(
)
,
` .jdk-extract- ${ Date. now ( ) } `
)
;
try
{
.
mkdirSync
(
,
{
:
true
}
)
;
await
downloadFile
(
jdkUrl
(
)
,
)
;
if
(
.
===
'win32'
)
{
await
extractZip
(
,
)
;
}
else
{
await
extractTarGz
(
,
)
;
}
const
=
.
readdirSync
(
)
.
map
(
=>
.
join
(
,
)
)
.
find
(
=>
.
statSync
(
)
.
isDirectory
(
)
)
;
if
(
!
)
{
throw
new
Error
(
tr
(
'JDK archive unpacked to nothing'
)
)
;
}
this
.
replaceDir
(
.
===
'darwin'
&&
.
existsSync
(
.
join
(
,
'Contents'
,
'Home'
)
)
?
.
join
(
,
'Contents'
,
'Home'
)
:
,
.
join
(
this
.
root
(
)
,
'jdk'
)
)
;
if
(
!
this
.
jdkHome
(
)
)
{
throw
new
Error
(
tr
(
'JDK unpacked, but bin/java not found'
)
)
;
}
}
finally
{
.
rmSync
(
,
{
:
true
}
)
;
.
rmSync
(
,
{
:
true
,
:
true
}
)
;
}
}
private
async
installKotlinc
(
)
:
Promise
<
void
>
{
const
=
.
join
(
.
tmpdir
(
)
,
` kotlin-compiler- ${ Date. now ( ) } .zip `
)
;
const
=
.
join
(
this
.
root
(
)
,
` .kotlinc-extract- ${ Date. now ( ) } `
)
;
try
{
.
mkdirSync
(
,
{
:
true
}
)
;
await
downloadFile
(
KOTLIN_URL
,
)
;
await
extractZip
(
,
)
;
const
=
.
join
(
,
'kotlinc'
)
;
this
.
replaceDir
(
.
existsSync
(
)
?
:
,
.
join
(
this
.
root
(
)
,
'kotlinc'
)
)
;
this
.
makeExecutable
(
.
join
(
this
.
root
(
)
,
'kotlinc'
,
'bin'
)
)
;
if
(
!
this
.
kotlincBin
(
)
)
{
throw
new
Error
(
tr
(
'Kotlin compiler unpacked, but bin/kotlinc not found'
)
)
;
}
}
finally
{
.
rmSync
(
,
{
:
true
}
)
;
.
rmSync
(
,
{
:
true
,
:
true
}
)
;
}
}
private
async
installGradle
(
)
:
Promise
<
void
>
{
const
=
.
join
(
.
tmpdir
(
)
,
` gradle- ${ Date. now ( ) } .zip `
)
;
const
=
.
join
(
this
.
root
(
)
,
` .gradle-extract- ${ Date. now ( ) } `
)
;
try
{
.
mkdirSync
(
,
{
:
true
}
)
;
await
downloadFile
(
GRADLE_URL
,
)
;
await
extractZip
(
,
)
;
const
=
.
join
(
,
` gradle- ${ GRADLE_VERSION } `
)
;
this
.
replaceDir
(
.
existsSync
(
)
?
:
,
.
join
(
this
.
root
(
)
,
'gradle'
)
)
;
this
.
makeExecutable
(
.
join
(
this
.
root
(
)
,
'gradle'
,
'bin'
)
)
;
if
(
!
this
.
gradleBin
(
)
)
{
throw
new
Error
(
tr
(
'Gradle unpacked, but bin/gradle not found'
)
)
;
}
}
finally
{
.
rmSync
(
,
{
:
true
}
)
;
.
rmSync
(
,
{
:
true
,
:
true
}
)
;
}
}
private
async
installCmdlineTools
(
)
:
Promise
<
void
>
{
const
=
.
join
(
.
tmpdir
(
)
,
` cmdline-tools- ${ Date. now ( ) } .zip `
)
;
const
=
.
join
(
this
.
root
(
)
,
` .ct-extract- ${ Date. now ( ) } `
)
;
try
{
.
mkdirSync
(
,
{
:
true
}
)
;
await
downloadFile
(
cmdlineToolsUrl
(
)
,
)
;
await
extractZip
(
,
)
;
const
=
.
join
(
,
'cmdline-tools'
)
;
const
=
.
join
(
this
.
root
(
)
,
'android-sdk'
,
'cmdline-tools'
,
'latest'
)
;
this
.
replaceDir
(
.
existsSync
(
)
?
:
,
)
;
this
.
makeExecutable
(
.
join
(
,
'bin'
)
)
;
if
(
!
.
existsSync
(
this
.
sdkmanager
(
)
)
)
{
throw
new
Error
(
tr
(
'cmdline-tools unpacked, but sdkmanager not found'
)
)
;
}
}
finally
{
.
rmSync
(
,
{
:
true
}
)
;
.
rmSync
(
,
{
:
true
,
:
true
}
)
;
}
}
private
sdkmanager
(
)
:
string
{
return
.
join
(
this
.
root
(
)
,
'android-sdk'
,
'cmdline-tools'
,
'latest'
,
'bin'
,
.
===
'win32'
?
'sdkmanager.bat'
:
'sdkmanager'
)
;
}
private
async
runSdkmanager
(
:
string
[
]
)
:
Promise
<
void
>
{
const
=
.
join
(
this
.
root
(
)
,
'android-sdk'
)
;
const
=
{
...
.
,
JAVA_HOME
:
this
.
jdkHome
(
)
??
.
.
JAVA_HOME
??
''
,
ANDROID_SDK_ROOT
:
,
ANDROID_HOME
:
}
;
await
new
Promise < void >
(
(
,
)
=>
{
const
=
spawn
(
this
.
sdkmanager
(
)
,
[
'--sdk_root='
+
,
...
]
,
{
:
.
===
'win32'
,
}
)
;
let
=
''
;
const
=
(
:
)
:
void
=>
{
=
(
+
.
toString
(
)
)
.
slice
(
-
4000
)
;
}
;
.
?.
on
(
'data'
,
)
;
.
?.
on
(
'data'
,
)
;
.
on
(
'error'
,
)
;
.
on
(
'exit'
,
=>
===
0
?
resolve
(
)
:
reject
(
new
Error
(
` sdkmanager exited with code ${ code} : ${ tail. trim ( ) . split ( / \r ? \n / ) . pop ( ) ?? '' } `
)
)
)
;
.
?.
write
(
'y\n'
.
repeat
(
50
)
)
;
.
?.
end
(
)
;
}
)
;
}
private
async
installSdkPackages
(
)
:
Promise
<
void
>
{
await
this
.
runSdkmanager
(
[
'--licenses'
]
)
;
await
this
.
runSdkmanager
(
SDK_PACKAGES
)
;
if
(
!
this
.
androidSdk
(
)
)
{
throw
new
Error
(
tr
(
'SDK packages installed, but platform-tools not found'
)
)
;
}
}
private
replaceDir
(
:
string
,
:
string
)
:
void
{
if
(
.
existsSync
(
)
)
{
.
rmSync
(
,
{
:
true
,
:
true
}
)
;
}
.
mkdirSync
(
.
dirname
(
)
,
{
:
true
}
)
;
.
renameSync
(
,
)
;
}
private
makeExecutable
(
:
string
)
:
void
{
if
(
.
===
'win32'
||
!
.
existsSync
(
)
)
{
return
;
}
for
(
const
of
.
readdirSync
(
)
)
{
try
{
.
chmodSync
(
.
join
(
,
)
,
0o755
)
;
}
catch
{
}
}
}
}
let
:
|
undefined
;
export
function
initToolchain
(
:
.
)
:
{
=
new
Toolchain
(
)
;
.
activateEnv
(
)
;
return
;
}
export
function
toolchain
(
)
:
|
undefined
{
return
;
}
export
function
resolveJavaBinary
(
)
:
string
{
const
=
.
.
getConfiguration
(
'auraKotlin'
)
.
get < string >
(
'javaPath'
,
'java'
)
.
trim
(
)
;
if
(
&&
!==
'java'
)
{
return
;
}
return
?.
javaBinary
(
)
??
??
'java'
;
}
export
function
resolveKotlincBinary
(
)
:
string
{
const
=
.
.
getConfiguration
(
'auraKotlin'
)
.
get < string >
(
'compilerPath'
,
'kotlinc'
)
.
trim
(
)
;
if
(
&&
!==
'kotlinc'
)
{
return
;
}
return
?.
kotlincBin
(
)
??
??
'kotlinc'
;
}
export
function
toolchainSdkRoot
(
)
:
string
|
undefined
{
return
?.
androidSdk
(
)
;
}
export
async
function
reportToolFailure
(
:
unknown
,
:
string
)
:
Promise
<
void
>
{
const
=
instanceof
Error
?
.
:
String
(
)
;
const
=
/ ENOENT| not found| is not recognized| не является / i
.
test
(
)
;
if
(
&&
!
.
isAbsolute
(
)
)
{
const
=
tr
(
'Install automatically'
)
;
const
=
await
.
.
showErrorMessage
(
tr
(
'{0} — the required tool is not installed.'
,
)
,
,
)
;
if
(
===
)
{
await
.
.
executeCommand
(
'auraKotlin.installToolchain'
)
;
}
return
;
}
.
.
showErrorMessage
(
)
;
}
export
async
function
missingToolchain
(
:
{
sdk
(
)
:
string
|
undefined
}
)
:
Promise
<
string
[
]
>
{
const
:
string
[
]
=
[
]
;
if
(
!
?.
jdkHome
(
)
&&
!
await
javaOnPath
(
)
)
{
.
push
(
'JDK'
)
;
}
if
(
!
?.
kotlincBin
(
)
&&
!
await
commandOnPath
(
'kotlinc'
)
)
{
.
push
(
'kotlinc'
)
;
}
if
(
!
.
sdk
(
)
)
{
.
push
(
'Android SDK'
)
;
}
return
;
}
async
function
javaOnPath
(
)
:
Promise
<
boolean
>
{
try
{
const
=
await
execTool
(
'java'
,
[
'-version'
]
,
{
:
10_000
}
)
;
return
/ version| openjdk / i
.
test
(
` ${ result. stdout} ${ result. stderr} `
)
;
}
catch
{
return
false
;
}
}
async
function
commandOnPath
(
:
string
)
:
Promise
<
boolean
>
{
try
{
await
execTool
(
.
===
'win32'
?
'where'
:
'which'
,
[
]
,
{
:
5_000
}
)
;
return
true
;
}
catch
{
return
false
;
}
}