Search code examples
javaxmlintellij-ideaintellij-plugin

IDEA Plugin: PersistentStateComponent not persisting xml


I can not get my plugin to persist its state. The file configProvider.xml never gets created, nor does the @State annotation has any effect (apparently).

This is the relevant part in the plugin.xml

<extensions defaultExtensionNs="com.intellij">
    <applicationService serviceImplementation="my.plugins.idea.vcs.ConfigProvider" serviceInterface="my.plugins.idea.vcs.ConfigProvider"/>
</extensions>

This is the Class providing the object that should get persisted:

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import java.util.LinkedHashMap;

@State(
  name = "ConfigProvider",
  storages = {
@Storage(id = "main", file = "$APP_CONFIG$/configProvider.xml") 
  }
)
public class ConfigProvider  implements PersistentStateComponent<ConfigProvider.State> {

  private State state = new State();

  class State {
    public State() {}
    public LinkedHashMap<String, String> commitTypes = null;
    public Integer selectedDefaultCommitTypeIndex = null;
    public String jiraApiUrl;
    public String jiraAuthorization;
    public String jiraFilterId;
  } 

  public static ConfigProvider getInstance() {
return ServiceManager.getService(ConfigProvider.class);
  }

  @Override
  @org.jetbrains.annotations.Nullable
  public ConfigProvider.State getState() {
return state; // gets called regulary
  } 

  @Override
  public void loadState(ConfigProvider.State state) {
this.state = state; // not called at all
  }

}

What am I missing?

Thanks, Christopher


Solution

  • Does this help, making the State class public and static?

    public static class State {
        //...
    }