简体   繁体   中英

System.getenv() only works properly when debugging IntelliJ plugin

I'm running IntelliJ 13 (on OS X Yosemite) and trying to get the Go IDEA plugin working. When I debugged the application to try to find what the problem is, I found that for some reason the slave IDEA that's ran gets my environment just fine.

Normally when trying to run anything involving the go utility, an exception is thrown. The plugin will execute commands by executing go <args> with the environment vars:

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command, goEnv, new File(projectDir));

If I change the go command to be the full path of the go binary, all works fine. When debugging however, I don't have to change the path and it still succeeds.

The plugin has an action which prints out the environment which calls System.getenv()

GoToolWindow toolWindow = this.getGoToolWindow(project);
toolWindow.showAndCreate(project);
toolWindow.clearConsoleView();

String[] sysEnv = GoSdkUtil.convertEnvMapToArray(System.getenv());


toolWindow.printNormalMessage(String.format("%s -> %s%n", "Project dir", projectDir));
for (String env : sysEnv) {
    toolWindow.printNormalMessage(String.format("%s%n", env));
}

When running IDEA normally, this outputs:

Project dir -> /Users/lander/Development/downloader
SHELL=/bin/zsh
TMPDIR=/var/folders/6y/xxqr1vqn6q7c_ttvdgjt7p1w0000gn/T/
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PATH=/usr/bin:/bin:/usr/sbin:/sbin
XPC_FLAGS=0x0
USER=lander
HOME=/Users/lander
XPC_SERVICE_NAME=com.jetbrains.intellij.43484
LOGNAME=lander
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.tV9zH4QXK4/Render
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BCyPknIo2V/Listeners

And when debugging the plugin:

Project dir -> /Users/lander/IdeaProjects/gotest
ZSH=/Users/lander/.oh-my-zsh
com.apple.java.jvmMode=client
GREP_OPTIONS=--color=auto --exclude-dir=.cvs --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
GOROOT=/usr/local/opt/go/libexec
XPC_FLAGS=0x0
JAVA_MAIN_CLASS_14389=com.intellij.idea.Main
LOGNAME=lander
GREP_COLOR=1;32
ZSH_TMUX_TERM=screen
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BCyPknIo2V/Listeners
OLDPWD=/Applications/IntelliJ IDEA 13.app/Contents/bin
SHELL=/bin/zsh
LC_CTYPE=
TMPDIR=/var/folders/6y/xxqr1vqn6q7c_ttvdgjt7p1w0000gn/T/
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/Users/lander/go/bin
VERSIONER_PYTHON_VERSION=2.7
GOPATH=/Users/lander/go
LESS=-R
USER=lander
com.apple.java.jvmTask=CommandLine_Manual.java
ZSH_TMUX_AUTOSTARTED=true
PAGER=less
HOME=/Users/lander
XPC_SERVICE_NAME=0
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.tV9zH4QXK4/Render
LSCOLORS=Gxfxcxdxbxegedabagacad
_ZSH_TMUX_FIXED_CONFIG=/Users/lander/.oh-my-zsh/plugins/tmux/tmux.extra.conf
VERSIONER_PYTHON_PREFER_32_BIT=no

What's the reason for the difference?

According to a JetBrains employee , this is because the slave instance is launched with the environment given by an external script that's ran. Plugins in the parent process should not call System.getenv() and instead use the EnvironmentUtil .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM