@@ -81,6 +81,15 @@ type LaunchContext struct {
81
81
shouldWaitBackendPlugin bool
82
82
}
83
83
84
+ func (c * LaunchContext ) getCommonJoinLinkResponse (appPid int , joinLink string ) * JoinLinkResponse {
85
+ return & JoinLinkResponse {
86
+ AppPid : appPid ,
87
+ JoinLink : joinLink ,
88
+ IDEVersion : fmt .Sprintf ("%s-%s" , c .info .ProductCode , c .info .BuildNumber ),
89
+ ProjectPath : c .projectContextDir ,
90
+ }
91
+ }
92
+
84
93
// JB startup entrypoint
85
94
func main () {
86
95
if len (os .Args ) == 3 && os .Args [1 ] == "env" && os .Args [2 ] != "" {
@@ -267,7 +276,7 @@ func serve(launchCtx *LaunchContext) {
267
276
if backendPort == "" {
268
277
backendPort = defaultBackendPort
269
278
}
270
- jsonResp , err := resolveJsonLink2 (backendPort )
279
+ jsonResp , err := resolveJsonLink2 (launchCtx , backendPort )
271
280
if err != nil {
272
281
log .WithError (err ).Error ("cannot resolve join link" )
273
282
http .Error (w , err .Error (), http .StatusServiceUnavailable )
@@ -385,6 +394,11 @@ type Response struct {
385
394
type JoinLinkResponse struct {
386
395
AppPid int `json:"appPid"`
387
396
JoinLink string `json:"joinLink"`
397
+
398
+ // IDEVersion is the ideVersionHint that required by Toolbox to `setAutoConnectOnEnvironmentReady`
399
+ IDEVersion string `json:"ideVersion"`
400
+ // ProjectPath is the projectPathHint that required by Toolbox to `setAutoConnectOnEnvironmentReady`
401
+ ProjectPath string `json:"projectPath"`
388
402
}
389
403
390
404
func resolveToolboxLink (wsInfo * supervisor.WorkspaceInfoResponse ) (string , error ) {
@@ -426,7 +440,7 @@ func resolveJsonLink(backendPort string) (string, error) {
426
440
return "" , err
427
441
}
428
442
defer resp .Body .Close ()
429
- bodyBytes , err := ioutil .ReadAll (resp .Body )
443
+ bodyBytes , err := io .ReadAll (resp .Body )
430
444
if err != nil {
431
445
return "" , err
432
446
}
@@ -438,13 +452,13 @@ func resolveJsonLink(backendPort string) (string, error) {
438
452
if err != nil {
439
453
return "" , err
440
454
}
441
- if len (jsonResp .Projects ) != 1 {
442
- return "" , xerrors . Errorf ( "project is not found" )
455
+ if len (jsonResp .Projects ) > 0 {
456
+ return jsonResp . Projects [ 0 ]. JoinLink , nil
443
457
}
444
- return jsonResp .Projects [ 0 ]. JoinLink , nil
458
+ return jsonResp .JoinLink , nil
445
459
}
446
460
447
- func resolveJsonLink2 (backendPort string ) (* JoinLinkResponse , error ) {
461
+ func resolveJsonLink2 (launchCtx * LaunchContext , backendPort string ) (* JoinLinkResponse , error ) {
448
462
var (
449
463
hostStatusUrl = "http://localhost:" + backendPort + "/codeWithMe/unattendedHostStatus?token=gitpod"
450
464
client = http.Client {Timeout : 1 * time .Second }
@@ -467,11 +481,10 @@ func resolveJsonLink2(backendPort string) (*JoinLinkResponse, error) {
467
481
return nil , err
468
482
}
469
483
if len (jsonResp .Projects ) > 0 {
470
- return & JoinLinkResponse {AppPid : jsonResp .AppPid , JoinLink : jsonResp .Projects [0 ].JoinLink }, nil
471
-
484
+ return launchCtx .getCommonJoinLinkResponse (jsonResp .AppPid , jsonResp .Projects [0 ].JoinLink ), nil
472
485
}
473
486
if len (jsonResp .JoinLink ) > 0 {
474
- return & JoinLinkResponse { AppPid : jsonResp .AppPid , JoinLink : jsonResp .JoinLink } , nil
487
+ return launchCtx . getCommonJoinLinkResponse ( jsonResp .AppPid , jsonResp .JoinLink ) , nil
475
488
}
476
489
log .Error ("failed to resolve JetBrains JoinLink" )
477
490
return nil , xerrors .Errorf ("failed to resolve JoinLink" )
@@ -889,6 +902,7 @@ func updateVMOptions(
889
902
}
890
903
*/
891
904
type ProductInfo struct {
905
+ BuildNumber string `json:"buildNumber"`
892
906
Version string `json:"version"`
893
907
ProductCode string `json:"productCode"`
894
908
}
@@ -1255,19 +1269,22 @@ func configureToolboxCliProperties(backendDir string) error {
1255
1269
1256
1270
toolboxCliPropertiesFilePath := fmt .Sprintf ("%s/environment.json" , toolboxCliPropertiesDir )
1257
1271
1272
+ debuggingToolbox := os .Getenv ("GITPOD_TOOLBOX_DEBUGGING" )
1273
+ allowInstallation := strconv .FormatBool (strings .Contains (debuggingToolbox , "allowInstallation" ))
1274
+
1258
1275
// TODO(hw): restrict IDE installation
1259
1276
content := fmt .Sprintf (`{
1260
1277
"tools": {
1261
- "allowInstallation": true ,
1278
+ "allowInstallation": %s ,
1262
1279
"allowUpdate": false,
1263
- "allowUninstallation": true ,
1280
+ "allowUninstallation": %s ,
1264
1281
"location": [
1265
1282
{
1266
1283
"path": "%s"
1267
1284
}
1268
1285
]
1269
1286
}
1270
- }` , backendDir )
1287
+ }` , allowInstallation , allowInstallation , backendDir )
1271
1288
1272
1289
return os .WriteFile (toolboxCliPropertiesFilePath , []byte (content ), 0o644 )
1273
1290
}
0 commit comments