How to disable auto expanding of $PROJECT_DIR$ etc (PathMacro) for my plugin settings ?



I have a simple settings class which stores my plugin settings, like this one below.

My settings UI stores collapsed paths in the "excludeFiles" map.
For example my dialog stores a "$PROJECT_DIR$/hello.xml" entry in this map.
This works. The persistent "my-settings.xml" file stores "$PROJECT_DIR$/hello.xml".

But when I restart IDEA and the settings are reloaded from the persistent file,
the HashMap does no longer contains $PROJECT_DIR$.
The entries are expanded. So the entry is "/path_to_project/hello.xml".

It seems that the deserializer automatically expand all strings (?).

My question is, is there are a easy way to avoid this without to bloat the code up ?

I know that it is possible to use f. e. PersistentStateComponent<org.jdom.Element>
instead of PersistentStateComponent<MySettings> and write the XML serialization/deserialization by myself
but I want to avoid this.

My settings class:

        name = "my-plugin",
        storages = @Storage(value = "my-settings.xml", roamingType = RoamingType.DEFAULT)
public class MySettings implements PersistentStateComponent<MySettings> {

    @Tag(value = "excludeBugsFiles")
            surroundWithTag = false,
            surroundValueWithTag = false,
            surroundKeyWithTag = false,
            entryTagName = "bugs",
            keyAttributeName = "file",
            valueAttributeName = "enabled"
    public Map<String, Boolean> excludeFiles = new HashMap<>();


Best Regards

Reto Merz

Comment actions Permalink


this is how serialization of project configurations works in IntelliJ IDEA, paths are automatically collapsed on save and expanded on load, so you don't need to expands them by hand in your code and user don't need to know macros to make his settings portable between different machines. Even if you use PersistentStateComponent<Element> the paths will be collapsed on save and expanded on load.

Why do you want to disable this?

Comment actions Permalink


Thank you for your help Nikolay!

I didn't notice that IDEA collapse paths on save automatically.

My fault was to use system dependent separator (in my case '\')
because collapse & expand only works with '/' but not with '\'.

I have changed it to use File#toSystemIndependentName() and now it works as expected.
There is no need to load collapsed paths anymore.



Please sign in to leave a comment.