Pass along environment variables to existing Idea process

Answered

Hey all!

 

I have a plugin we are using internally that automates our build process. To kick it off, I pass in environment variables to the IntelliJ launch script and listen for those in the plugin. This works fine if there are no existing IntelliJ processes, but issues arise when there is an existing process (because the new process instead calls the existing process to open the project in the existing process).

 

I am curious if anyone has any thoughts on how I can pass along the environment variables from new process to the existing process show how (I know it cant be a native system property).

 

My only other thought is to instead use the file system to pass this flag along, but that feels a bit more messy. Anyone recommendations welcome!

7 comments
Comment actions Permalink

Just an idea: https://github.com/JetBrains/intellij-community/compare/master...brian-mcnamara:env (pardon the mess, threw it together to see how it would work)

Pass through the environment from the second process to the first so it is able to use it as part of the project that was opened. 

0
Comment actions Permalink

I do believe that changing the environment in a running process would cause hard-to-debug problems, but passing the new environment as a parameter of `ApplicationStarter#processExternalCommandLine` and letting a plugin handle it may make sense.

Using files looks cleaner to me, though - changes are more visible, and one can subscribe to FS events to react immediately.

0
Comment actions Permalink

Oh for sure, changing the environment on the existing process would be a real bad idea. But passing along the environment and having a project level component hold onto that would be safer. That being said, it would be hard to provide a contract to that component. The environment values would match the process unless a user kicks off a new project from invoking a new process. TBH, I could see use for something like that, but not too sure others would either.

 

I was also thinking last night that another option would be to have EPs that could listen into the command line parameters. There currently is a EP that allows changing the startup behavior, but thats not really what I am after. If I could instead listen to the command line parameters and set a project level flag, I could also accomplish what I am after. (the plugin kicks off a full rebuild of the project on application start if the environment variables are set to true, followed by kicking off post compile tasks).

 

Let me play around with the file idea. The thing I don't really like about it is Ill have to add a bunch of logic to verify that the "trigger" was created within the past few minutes to prevent rouge compiles from getting kicked off. The environment variables were convenient because the tooling devs use invoke idea.sh and can control the environment variables to trigger a compile once the project is opened. 

0
Comment actions Permalink

But that `ApplicationStarter#processExternalCommandLine` EP kind of allows listening to command-line parameters - the only requirement is that one has to prepend the command line with a special command.

0
Comment actions Permalink

Yes, I was thinking about that too, but if the plugin is not installed, IntelliJ treats the command as a project which eventually errors out later on. 

0
Comment actions Permalink

That's right, but if I got it right you need the plugin anyway - for managing build processes.

I guess we can improve the diagnostic on our side when the first parameter looks like a command.

0
Comment actions Permalink

That is fair, currently its an optional plugin, but maybe I should just install it when the tooling downloads and installs intellij and assume its available.

 

I have though about ways to distribute the plugin, if I were to use the command approach, I would want the plugin to be bundled in with the install to make sure its not uninstalled by the user. That may be the best option... Let me try coding that up into the plugin and see how it works.

 

Thanks for the help!

0

Please sign in to leave a comment.