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

$PROJECT_DIR$ in checkstyle-idea.xml replaced with absolute paths #430

Open
theotherp opened this issue Feb 19, 2019 · 11 comments
Open

$PROJECT_DIR$ in checkstyle-idea.xml replaced with absolute paths #430

theotherp opened this issue Feb 19, 2019 · 11 comments

Comments

@theotherp
Copy link

Since one of the last updates (sorry, can't say for sure which one) the variable $PROJECT_DIR$ in the file checkstyle-idea.xml is replaced with absolute paths which changes the file and requires me to manually revert it.

@jshiell
Copy link
Owner

jshiell commented Feb 19, 2019

Hi - this was last changed in #404, when we started using $PROJECT_DIR$ - which is managed by IDEA, rather than the plugin. At some point IDEA started to become grabby about anything in $ signs, which is what led to the change.

Hence if there's a change in the behaviour it's most likely a change in the IDEA version. Has this changed recently? And if so, do you recall what versions were involved?

@andrewryno
Copy link

andrewryno commented Dec 3, 2019

I'm seeing this behavior as well. I can't say if the behavior changed since this is my first time viewing the exported configuration, however my versions are:

IntelliJ IDEA 2019.3 (#IU-193.5233.102)
CheckStyle-IDEA 5.34.0

Edit: also one thing that might be relevant is my path to the .xml file is not located within the project root but up one directory. Example:

<entry key="active-configuration" value="LOCAL_FILE:$PROJECT_DIR$/../checkstyle-shared/checkstyle.xml:Custom" />

which is turned to:

<entry key="active-configuration" value="LOCAL_FILE:/Users/andrewryno/checkstyle-shared/checkstyle.xml:Custom" />

@jshiell
Copy link
Owner

jshiell commented Dec 27, 2019

Thanks for the report. Is that a normal configuration layout, or something custom? I haven't encountered it before.

@andrewryno
Copy link

Sorry, somehow missed your last reply. Not sure what you mean by normal/custom. By default it saves with /Users/andrewryno/... and I want to manually update it to be relative to the current project. The ultimate goal is to commit this configuration file so it can be shared with others working on the same project without any changes needing to be done on their end.

@jshiell
Copy link
Owner

jshiell commented Mar 11, 2020

No worries. By "custom" I meant "edited directly", rather than saved through the configuration UI. By your clarification I guess that you have manually edited it to try and accomplish your goal?

From memory (it's been a while since I played with this), IDEA itself resolves $PROJECT_DIR - the code we have to do the same is a leftover from supported versions of IDEA that didn't do this. Certainly our code is a direct replace, so I wouldn't have thought it'd mangle ... But as said, it's been a while, so it may have changed.

The downside is that if it's IDEA doing it then we're probably scuppered. But I'll have a look in any case.

jshiell added a commit that referenced this issue Mar 11, 2020
@javanna
Copy link

javanna commented Jan 11, 2022

Hello, I just stumbled upon the same problem with IntelliJ 2021.3.1 . Never seen this before, which is also weird. Some colleagues see the same behaviour, some others don't. I get this with every change hence I need to remember not to commit the change to the checkstyle configuration file. Would you know of work-around or how this has been solved for others?

@jshiell
Copy link
Owner

jshiell commented Jan 15, 2022

Unfortunately the above is an accurate representation of the progress, or lack of. Given IDEA is also involved in the resolution of this, is a bit messier than we'd hope. We also do manual checks in the plugin to try and tokenise the value where it starts with the IDEA project path, but this obviously isn't helping in this case.

Without a reproducible case, I don't expect much progress to be made here. Indeed, it may be unfixable, as the concept of a "project path" has become very ambiguous in newer versions of IDEA - even the API call is now called guessProjectDir, with this delightful explanation:

There is no strict definition of what is a project directory, since a project can contain multiple modules located in different places, and the .idea directory can be located elsewhere (making the popular Project.getBaseDir method not applicable to get the "project directory"). This method should be preferred, although it can't provide perfect accuracy either.

So it's possible, given the above, that it could be dependent on the local project setup, and hence may differ from workstation to workstation. Which is madness.

One thought - are you using Windows? I only use MacOS and hence all my testing is with Unix paths, and we've certainly run into problems before with some of the delights of Windows FS paths.

@javanna
Copy link

javanna commented Jan 17, 2022

Thanks @jshiell for the help. I am on Linux, no Windows.

@Master-Code-Programmer
Copy link

It seems whenever someone edits something, and saves the settings in the Checkstyle-Dialog with "OK", IntelliJ resolves the $PROJECT_DIR$, replaces it with the resolved path, and saves that back into the XML file. Which is wrong, it should save back the original path - not the resolved path.

@jshiell
Copy link
Owner

jshiell commented May 13, 2022

#569 appears to be a reoccurrence of this. As stated there, it's messy, because it's IDEA that does this transformation rather than the plugin. Presumably we're doing something to trigger this behaviour, but finding it is proving difficult - in a large part because I still can't reproduce it.

@javanna
Copy link

javanna commented May 20, 2022

I have noticed that in my case, this happens when I commit changes through IntelliJ. As soon I commit a change, I will find the modified file. If I stick to committing from command line, this never happens. Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants