@@ -65,13 +65,13 @@ type LaunchContext struct {
6565 backendVersion * version.Version
6666 wsInfo * supervisor.WorkspaceInfoResponse
6767
68- vmOptionsFile string
69- projectDir string
70- configDir string
71- systemDir string
72- projectConfigDir string
73- projectContextDir string
74- riderSolutionFile string
68+ vmOptionsFile string
69+ platformPropertiesFile string
70+ projectDir string
71+ configDir string
72+ systemDir string
73+ projectContextDir string
74+ riderSolutionFile string
7575
7676 env []string
7777}
@@ -462,34 +462,36 @@ func launch(launchCtx *LaunchContext) {
462462 }
463463
464464 launchCtx .projectDir = projectDir
465- launchCtx .configDir = fmt .Sprintf ("/workspace/.config/JetBrains%s" , launchCtx .qualifier )
466- launchCtx .systemDir = fmt .Sprintf ("/workspace/.cache/JetBrains%s" , launchCtx .qualifier )
465+ launchCtx .configDir = fmt .Sprintf ("/workspace/.config/JetBrains%s/RemoteDev-%s " , launchCtx .qualifier , launchCtx . info . ProductCode )
466+ launchCtx .systemDir = fmt .Sprintf ("/workspace/.cache/JetBrains%s/RemoteDev-%s " , launchCtx .qualifier , launchCtx . info . ProductCode )
467467 launchCtx .riderSolutionFile = riderSolutionFile
468468 launchCtx .projectContextDir = resolveProjectContextDir (launchCtx )
469- launchCtx .projectConfigDir = fmt .Sprintf ("%s/RemoteDev-%s/%s" , launchCtx .configDir , launchCtx .info .ProductCode , strings .ReplaceAll (launchCtx .projectContextDir , "/" , "_" ))
470469
471- alreadySync , err := syncInitialContent (launchCtx , Options )
470+ launchCtx .platformPropertiesFile = launchCtx .backendDir + "/bin/idea.properties"
471+ _ , err = configurePlatformProperties (launchCtx .platformPropertiesFile , launchCtx .configDir , launchCtx .systemDir )
472+ if err != nil {
473+ log .WithError (err ).Error ("failed to update platform properties file" )
474+ }
475+
476+ _ , err = syncInitialContent (launchCtx , Options )
472477 if err != nil {
473478 log .WithError (err ).Error ("failed to sync initial options" )
474479 }
475480
476- launchCtx .env = resolveLaunchContextEnv (launchCtx . configDir , launchCtx . systemDir , ! alreadySync )
481+ launchCtx .env = resolveLaunchContextEnv ()
477482
478483 _ , err = syncInitialContent (launchCtx , Plugins )
479484 if err != nil {
480485 log .WithError (err ).Error ("failed to sync initial plugins" )
481486 }
482487
483488 // install project plugins
484- version_2022_1 , _ := version .NewVersion ("2022.1" )
485- if version_2022_1 .LessThanOrEqual (launchCtx .backendVersion ) {
486- err = installPlugins (gitpodConfig , launchCtx )
487- installPluginsCost := time .Now ().Local ().Sub (launchCtx .startTime ).Milliseconds ()
488- if err != nil {
489- log .WithError (err ).WithField ("cost" , installPluginsCost ).Error ("installing repo plugins: done" )
490- } else {
491- log .WithField ("cost" , installPluginsCost ).Info ("installing repo plugins: done" )
492- }
489+ err = installPlugins (gitpodConfig , launchCtx )
490+ installPluginsCost := time .Now ().Local ().Sub (launchCtx .startTime ).Milliseconds ()
491+ if err != nil {
492+ log .WithError (err ).WithField ("cost" , installPluginsCost ).Error ("installing repo plugins: done" )
493+ } else {
494+ log .WithField ("cost" , installPluginsCost ).Info ("installing repo plugins: done" )
493495 }
494496
495497 // install gitpod plugin
@@ -586,7 +588,7 @@ func resolveUserEnvs() (userEnvs []string, err error) {
586588 return
587589}
588590
589- func resolveLaunchContextEnv (configDir string , systemDir string , enableNewUI bool ) []string {
591+ func resolveLaunchContextEnv () []string {
590592 var launchCtxEnv []string
591593 userEnvs , err := resolveUserEnvs ()
592594 if err == nil {
@@ -596,21 +598,14 @@ func resolveLaunchContextEnv(configDir string, systemDir string, enableNewUI boo
596598 launchCtxEnv = os .Environ ()
597599 }
598600
599- // Set default config and system directories under /workspace to preserve between restarts
600- launchCtxEnv = append (launchCtxEnv ,
601- // Set default config and system directories under /workspace to preserve between restarts
602- fmt .Sprintf ("IJ_HOST_CONFIG_BASE_DIR=%s" , configDir ),
603- fmt .Sprintf ("IJ_HOST_SYSTEM_BASE_DIR=%s" , systemDir ),
604- )
605-
606601 // instead put them into /ide-desktop/${alias}${qualifier}/backend/bin/idea64.vmoptions
607602 // otherwise JB will complain to a user on each startup
608603 // by default remote dev already set -Xmx2048m, see /ide-desktop/${alias}${qualifier}/backend/plugins/remote-dev-server/bin/launcher.sh
609604 launchCtxEnv = append (launchCtxEnv , "JAVA_TOOL_OPTIONS=" )
610605
611- if enableNewUI {
612- launchCtxEnv = append ( launchCtxEnv , "REMOTE_DEV_NEW_UI_ENABLED=1" )
613- }
606+ // Force it to be disabled as we update platform properties file already
607+ // TODO: Some ides have it enabled by default still, check pycharm and remove next release
608+ launchCtxEnv = append ( launchCtxEnv , "REMOTE_DEV_LEGACY_PER_PROJECT_CONFIGS=0" )
614609
615610 log .WithField ("env" , strings .Join (launchCtxEnv , "\n " )).Info ("resolved launch env" )
616611
@@ -637,6 +632,52 @@ func handleSignal() {
637632 log .Info ("asked IDE to terminate" )
638633}
639634
635+ func configurePlatformProperties (platformOptionsPath string , configDir string , systemDir string ) (bool , error ) {
636+ buffer , err := os .ReadFile (platformOptionsPath )
637+ if err != nil {
638+ return false , err
639+ }
640+
641+ content := string (buffer )
642+
643+ updated , content := updatePlatformProperties (content , configDir , systemDir )
644+
645+ if updated {
646+ return true , os .WriteFile (platformOptionsPath , []byte (content ), 0 )
647+ }
648+
649+ return false , nil
650+ }
651+
652+ func updatePlatformProperties (content string , configDir string , systemDir string ) (bool , string ) {
653+ lines := strings .Split (content , "\n " )
654+ configMap := make (map [string ]bool )
655+ for _ , v := range lines {
656+ v = strings .TrimSpace (v )
657+ if v != "" && ! strings .HasPrefix (v , "#" ) {
658+ key , _ , found := strings .Cut (v , "=" )
659+ if found {
660+ configMap [key ] = true
661+ }
662+ }
663+ }
664+
665+ updated := false
666+
667+ if _ , found := configMap ["idea.config.path" ]; ! found {
668+ updated = true
669+ content = strings .Join ([]string {
670+ content ,
671+ fmt .Sprintf ("idea.config.path=%s" , configDir ),
672+ fmt .Sprintf ("idea.plugins.path=%s" , configDir + "/plugins" ),
673+ fmt .Sprintf ("idea.system.path=%s" , systemDir ),
674+ fmt .Sprintf ("idea.log.path=%s" , systemDir + "/log" ),
675+ }, "\n " )
676+ }
677+
678+ return updated , content
679+ }
680+
640681func configureVMOptions (config * gitpod.GitpodConfig , alias string , vmOptionsPath string ) error {
641682 options , err := readVMOptions (vmOptionsPath )
642683 if err != nil {
@@ -647,7 +688,7 @@ func configureVMOptions(config *gitpod.GitpodConfig, alias string, vmOptionsPath
647688}
648689
649690func readVMOptions (vmOptionsPath string ) ([]string , error ) {
650- content , err := ioutil .ReadFile (vmOptionsPath )
691+ content , err := os .ReadFile (vmOptionsPath )
651692 if err != nil {
652693 return nil , err
653694 }
@@ -657,7 +698,7 @@ func readVMOptions(vmOptionsPath string) ([]string, error) {
657698func writeVMOptions (vmOptionsPath string , vmoptions []string ) error {
658699 // vmoptions file should end with a newline
659700 content := strings .Join (vmoptions , "\n " ) + "\n "
660- return ioutil .WriteFile (vmOptionsPath , []byte (content ), 0 )
701+ return os .WriteFile (vmOptionsPath , []byte (content ), 0 )
661702}
662703
663704// deduplicateVMOption append new VMOptions onto old VMOptions and remove any duplicated leftmost options
@@ -844,7 +885,7 @@ func syncPlugin(file fs.FileInfo, srcDir, destDir string) error {
844885}
845886
846887func ensureInitialSyncDest (launchCtx * LaunchContext , target SyncTarget ) (string , error , bool ) {
847- targetDestDir := launchCtx .projectConfigDir
888+ targetDestDir := launchCtx .configDir
848889 if target == Plugins {
849890 targetDestDir = launchCtx .backendDir
850891 }
@@ -964,7 +1005,7 @@ func installPlugins(config *gitpod.GitpodConfig, launchCtx *LaunchContext) error
9641005 installErr := cmd .Run ()
9651006
9661007 // delete alien_plugins.txt to suppress 3rd-party plugins consent on startup to workaround backend startup freeze
967- err = os .Remove (launchCtx .projectConfigDir + "/alien_plugins.txt" )
1008+ err = os .Remove (launchCtx .configDir + "/alien_plugins.txt" )
9681009 if err != nil && ! os .IsNotExist (err ) && ! strings .Contains (err .Error (), "no such file or directory" ) {
9691010 log .WithError (err ).Error ("failed to suppress 3rd-party plugins consent" )
9701011 }
0 commit comments