ashald / EnvFile

EnvFile 3.x is a plugin for JetBrains IDEs that allows you to set environment variables for your run configurations from one or multiple files.
MIT License
533 stars 125 forks source link

Issue with variable substitution ($PROJECT_DIR$) #194

Closed LeRoiLapin closed 1 year ago

LeRoiLapin commented 1 year ago

Hi,

I just updated the EnvFile plugin to the latest version (as of today 3.4.1 but this is also valid for 3.4.0) and my whole project broke down. After a simple inspection it appears that the substitution for the $PROJECT_DIR$ variable is wrong.

For a given $PROJECT_DIR$ with the value /path/to/project and an .env file containing TEST_VALUE=$PROJECT_DIR$/path/to/data the substitution will result in: /path/to/project/$PROJECT_DIR$/path/to/data (the variable is still here but the substitution was done).

This issue occur for version 3.4.0 and 3.4.1 on intellij version 2022.2.2

ashald commented 1 year ago

Can you share more details about EnvFile settings you use to reproduce the issue? Namely, is "Substitute env vars is enabled"?

ShrykeWindgrace commented 1 year ago

I have the same issue. My settings are image

$ cat vars.env
LOCAL_TEST_VARIABLE=$PROJECT_DIR$/something

With EnvFile-3.4.1 this variable get expanded to literally $PROJECT_DIR$/something. With EnvFile-3.2.2 it is correctly expanded to /full/path/to/project/something.

LeRoiLapin commented 1 year ago

Sure.

The configuration I used is the same for each version (namely 3.2.2, 3.4.0 and 3.4.1) but I have yet to test if this issue is present for other version of intellij (I'm using the community edition, if I have enough time I will try to test with ultimate and another release).

As for the settings I have both Substitute Environment Variables and Process JetBrains path macro reference enable while Ìgnore missing filesandEnable experimental integrationsare disable. Working directory is set to the root directory of the project and in the previous example is/path/to/project(And of courseEnable EnvFile`).

Also while I'm using a gradle project the run configuration is done by intellij. I have confirmed by running some ut that the problem seems to come from the plugin (and further confirmation came from the downgrade to 3.2.2).

We encounter the problem on several different computer.

If you need anymore information feel free to ask, I will look on my side if I can find the issue and will submit a pull request if I can fix it.

Also I want to truly thank you for your works I never had any issue with it for the past 5 years

Edit: Also I'm using Temurin 11

ShrykeWindgrace commented 1 year ago

The problem boils down to the logic here: https://github.com/ashald/EnvFile/blob/6fe1c3931b735474570005bd82298e969af82161/modules/platform/src/main/java/net/ashald/envfile/platform/EnvFileEnvironmentVariables.java#L121-L136

If there is both Intellij macro substitution and regular env var substition, then the value stored in postMacro is discarded, and only env var substitution is done.

I do not have the expertise to say how the correct logic should look like, but the problem is definitely in that function. Maybe, the line 130 should read

String stage1 = new StringSubstitutor(context).replace(postMacro);

?

trduc79 commented 1 year ago

I had the same issue with version newer than 3.2.2 that $PROJECT_DIR$ is not recognized so cannot import packages from project folder.