Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work on IntelliJ IDEA 2020.2.3 (Ultimate Edition) #3

Closed
yarco opened this issue Nov 18, 2020 · 20 comments
Closed

Does not work on IntelliJ IDEA 2020.2.3 (Ultimate Edition) #3

yarco opened this issue Nov 18, 2020 · 20 comments
Assignees
Labels
bug Something isn't working

Comments

@yarco
Copy link

yarco commented Nov 18, 2020

Details:
Build #IU-202.7660.26, built on October 6, 2020
Runtime version: 11.0.8+10-b944.34 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

Trying to run a Java (Gradle) application using Run.. -> Application
env vars do not show up when running as well as when debugging.
Pressed the button a million times to no avail.

Would be happy to provide more info if needed. Please let me know.

Thanks for creating such a cool plugin!!!

@yarco
Copy link
Author

yarco commented Nov 18, 2020

Created a new maven project, included a sample .envrcfile in it, clicked the button, went to Run.. -> Application .. ; Env vars were not there as well

@fehnomenal
Copy link
Owner

I just did the same (maven and gradle probably also others) and could reproduce the issue.

As a workaround I direnv allowed in the terminal and reopened the project then it worked.

I will add some debug output to the plugin.

@yarco
Copy link
Author

yarco commented Nov 19, 2020

Do you mean in the terminal inside of intellij? I ran the allow command inside the of that terminal as well as inside of an external terminal, and still could not get it to work. Would be glad to provide any /all debug logs. Please let me know! ;)

@fehnomenal fehnomenal added the bug Something isn't working label Nov 20, 2020
@fehnomenal fehnomenal self-assigned this Nov 20, 2020
@fehnomenal
Copy link
Owner

fehnomenal commented Nov 23, 2020

I think it does not matter which terminal you execute direnv in as long as it does not give any error.

I am currently experiencing the same with Android Studio 4.2 Canary 16. Strange enough the plugin does work when launching AS during plugin development but not when running standalone...

Could you please

  1. Enable debug logging by Help > Diagnostic Tools > Debug Log Settings... and entering #systems.fehn.intellijdirenv:trace.
  2. Install the draft version (https://github.com/fehnomenal/intellij-direnv/releases) manually (see readme for instructions).
  3. Try to import from direnv (either by the action or the new popup on project load).
  4. Post a link to your idea.log (Help > Show Log in ...).

Thank you!

@yarco
Copy link
Author

yarco commented Nov 24, 2020

I cannot see a new release with the link provided in 2. I tried compiling it from master, but since I have OSX Big Sur, there's a problem ...
Screen Shot 2020-11-23 at 10 13 01 PM
Screen Shot 2020-11-23 at 10 13 06 PM

@fehnomenal
Copy link
Owner

Wow, it seems only I can see draft releases...
Please use this file: Direnv integration-0.1.0.zip

@yarco
Copy link
Author

yarco commented Nov 24, 2020

idea.log
It is a clean log - I used a dummy project with the most basic functionality

@fehnomenal
Copy link
Owner

fehnomenal commented Nov 24, 2020

Thank you.

2020-11-24 09:23:26,191 [   7093]  DEBUG - jdirenv.services.DirenvService - Did not find direnv executable in path 

How do you call direnv in a terminal? What does which direnv give?

I should disable the button if it is not available.

@yarco
Copy link
Author

yarco commented Nov 24, 2020

I get this /usr/local/bin/direnv if I run from a standard OSX terminal + iterm (the one I use) + Intellij "inner" terminal - I get this. Not sure why it is not available, since I could pretty much run it in every OSX terminal I could find on my machine :). Maybe try to run it using that ^ abs path, if plain direnv is not available?

@fehnomenal
Copy link
Owner

fehnomenal commented Nov 25, 2020

I want to detect if direnv is installed but this is only possible by looking for the executable in $PATH which is what I'm doing here

get() = System.getenv("PATH")
.split(':')
.asSequence()
.map { Paths.get(it, "direnv") }
.firstOrNull { Files.exists(it) && Files.isExecutable(it) }

The result is an absolute path and is used to call direnv.

Could you please post your $PATH if it does not contain sensitive values? And could you please post the output of ls -la /usr/local/bin/direnv?

Please test also this version which skips all tests whether direnv is available and just calls direnv (not the absolute path): Direnv integration-0.1.0.zip

@yarco
Copy link
Author

yarco commented Nov 25, 2020

So this is what I got from the logs:
java.security.PrivilegedActionException: java.security.PrivilegedActionException: java.io.IOException: Cannot run program "direnv" (in directory "/Users/yarco/tmp2"): error=2, No such file or directory at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:748) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:971) at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:906) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:838) at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:452) at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:744) at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:451) at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:505) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90) Caused by: java.security.PrivilegedActionException: java.io.IOException: Cannot run program "direnv" (in directory "/Users/yarco/tmp2"): error=2, No such file or directory at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:751) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:749) ... 17 more Caused by: java.io.IOException: Cannot run program "direnv" (in directory "/Users/yarco/tmp2"): error=2, No such file or directory at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071) at systems.fehn.intellijdirenv.services.DirenvProjectService.executeDirenv(DirenvProjectService.kt:142) at systems.fehn.intellijdirenv.services.DirenvProjectService.importDirenv(DirenvProjectService.kt:42) at systems.fehn.intellijdirenv.listeners.MyProjectManagerListener$projectOpened$notification$1.accept(MyProjectManagerListener.kt:33) at systems.fehn.intellijdirenv.listeners.MyProjectManagerListener$projectOpened$notification$1.accept(MyProjectManagerListener.kt:14) at com.intellij.notification.NotificationAction$Simple.actionPerformed(NotificationAction.java:82) at com.intellij.notification.NotificationAction.actionPerformed(NotificationAction.java:31) at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:282) at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAwareWithCallbacks(ActionUtil.java:276) at com.intellij.notification.Notification.fire(Notification.java:258) at com.intellij.notification.impl.NotificationsManagerImpl$14.linkSelected(NotificationsManagerImpl.java:780) at com.intellij.notification.impl.NotificationsManagerImpl$14.linkSelected(NotificationsManagerImpl.java:775) at com.intellij.ui.components.labels.LinkLabel.doClick(LinkLabel.java:138) at com.intellij.ui.components.labels.LinkLabel.doClick(LinkLabel.java:348) at com.intellij.ui.components.labels.LinkLabel$MyMouseHandler.mouseReleased(LinkLabel.java:322) at java.desktop/java.awt.Component.processMouseEvent(Component.java:6654) at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3345) at java.desktop/java.awt.Component.processEvent(Component.java:6419) at java.desktop/java.awt.Container.processEvent(Container.java:2263) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5029) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4861) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918) at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547) at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307) at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2773) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4861) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:778) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721) ... 22 more Caused by: java.io.IOException: error=2, No such file or directory at java.base/java.lang.ProcessImpl.forkAndExec(Native Method) at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340) at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107) ... 53 more
And my $PATH
/usr/local/opt/openjdk/bin:/usr/local/opt/gnu-getopt/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/sqlite/bin:/usr/local/bin:/Users/yarco/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/MacGPG2/bin:/usr/texbin:/usr/local/sbin:/Users/yarco/.local/bin

ls -la /usr/local/bin/direnv
lrwxr-xr-x 1 yarco admin 34 Nov 16 13:19 /usr/local/bin/direnv -> ../Cellar/direnv/2.24.0/bin/direnv -> I installed it with brew install direnv

@fehnomenal
Copy link
Owner

OK, will have to spin up my MacBook to test this further.

@fehnomenal
Copy link
Owner

I didn't manage to set up my MacBook but could you please test this version: Direnv integration-0.1.0.zip

This is probably due to a mismatch of environment variables between the shell and GUI programs on Mac.

@yarco
Copy link
Author

yarco commented Dec 1, 2020

Yup, I think you are right ...
I get a million of these in the logs now.
idea.log

2020-11-30 22:42:04,653 [ 38298] TRACE - jdirenv.services.DirenvService - Did not find direnv executable in path

I can still access direnv in (as installed by homebrew)
/usr/local/bin/direnv

Perhaps try to hardcode this path in case you cannot find direnv in $PATH, and check if this file exists, as a quick osx workaround ...

@fehnomenal
Copy link
Owner

So, this is something like your personal build. It does not check whether direnv is available but calls direnv (like you would in the shell) and falls back to /usr/local/bin/direnv if an error occurred.

Please, report back and post the log again.

Direnv integration-0.1.0.zip

@yarco
Copy link
Author

yarco commented Dec 1, 2020

idea.log

So seems like direnv works now, however ... my custom env var is still not showing up.

I have this in my .envrc file and I run this java code to print out the env vars
export AAAA="aa"

Map<String, String> env = System.getenv();
        for (String envName : env.keySet()) {
            System.out.format("%s=%s%n", envName, env.get(envName));
        }

@fehnomenal
Copy link
Owner

In the logs I see multiple of these lines:

TRACE - .services.DirenvProjectService - Set variable AAAA to "aa"

So the plugin does work now. Thank you very much for this debugging odyssey.

I will soon release an update that should solve this issue for everyone.


Probably you are hit by the same problem as me. The JetBrains guys wrote:

  /**
   * <p>A wrapper layer around {@link System#getenv()}.</p>
   *
   * <p>On Windows, the returned map is case-insensitive (i.e. {@code map.get("Path") == map.get("PATH")} holds).</p>
   *
   * <p>On macOS, things are complicated.<br/>
   * An app launched by a GUI launcher (Finder, Dock, Spotlight etc.) receives a pretty empty and useless environment,
   * since standard Unix ways of setting variables via e.g. ~/.profile do not work. What's more important, there are no
   * sane alternatives. This causes a lot of user complaints about tools working in a terminal not working when launched
   * from the IDE. To ease their pain, the IDE loads a shell environment (see {@link #getShellEnv()} for gory details)
   * and returns it as the result.<br/>
   * And one more thing (c): locale variables on macOS are usually set by a terminal app - meaning they are missing
   * even from a shell environment above. This again causes user complaints about tools being unable to output anything
   * outside ASCII range when launched from the IDE. Resolved by adding LC_CTYPE variable to the map if it doesn't contain
   * explicitly set locale variables (LANG/LC_ALL/LC_CTYPE). See {@link #setCharsetVar(Map)} for details.</p>
   *
   * @return unmodifiable map of the process environment.
   */

Source: https://github.com/JetBrains/intellij-community/blob/6e7398e3d37a88c8c2efec3e2466e85f8fc6576b/platform/util/src/com/intellij/util/EnvironmentUtil.java#L67-L84

See also e.g. this issue: flutter/flutter-intellij#601 (comment)

I guess when you run your code from the shell it should work (but of course, this plugin won't run then. So this can only work if you configured your shell to import from the .envrc file).

I'm closing this issue as the second problem is not related to this plugin.

@yarco
Copy link
Author

yarco commented Dec 3, 2020

Glad I could help!
So essentially, I cannot get my simple app, as executed from Run/Run.., to run with env vars from my .envrc using your plugin? This was my main intention.

@fehnomenal
Copy link
Owner

Honestly, I think it depends on which environment IntelliJ is passing to gradle/the java call.

You could compare the output of your app with the environment inside your shell (env probably works on OSX too) to see if they pass their "extended" environment (like I wrote above).

@davinkevin
Copy link

I have the same problem as @yarco, and on MacOS, it means this plugin is sadly not compatible at all?

Potentially an issue could be opened to Jetbrains to potentially find a solution, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants