@SuppressWarnings("unchecked") private void executeAndRestoreDefaultProjectSettings(@NotNull Project project, @NotNull Runnable task) { AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId); Object systemStateToRestore = null; if (systemSettings instanceof PersistentStateComponent) { systemStateToRestore = ((PersistentStateComponent)systemSettings).getState(); } systemSettings.copyFrom(myControl.getSystemSettings()); Collection projectSettingsToRestore = systemSettings.getLinkedProjectsSettings(); systemSettings.setLinkedProjectsSettings(Collections.singleton(getCurrentExternalProjectSettings())); try { task.run(); } finally { if (systemStateToRestore != null) { ((PersistentStateComponent)systemSettings).loadState(systemStateToRestore); } else { systemSettings.setLinkedProjectsSettings(projectSettingsToRestore); } } }
@NotNull public static State getStateSpecOrError(@NotNull Class<? extends PersistentStateComponent> componentClass) { State spec = getStateSpec(componentClass); if (spec != null) { return spec; } PluginId pluginId = PluginManagerCore.getPluginByClassName(componentClass.getName()); if (pluginId == null) { throw new RuntimeException("No @State annotation found in " + componentClass); } else { throw new PluginException("No @State annotation found in " + componentClass, pluginId); } }
@Nullable private static Object getProviderInstance(Object componentInstance) { if (componentInstance instanceof PersistentStateComponent) { return ((PersistentStateComponent)componentInstance).getState(); } return componentInstance; }
public static void loadFacetConfiguration(final @NotNull FacetConfiguration configuration, final @Nullable Element config) throws InvalidDataException { if (config != null) { if (configuration instanceof PersistentStateComponent) { ComponentSerializationUtil.loadComponentState((PersistentStateComponent)configuration, config); } else { configuration.readExternal(config); } } }
public static Element saveFacetConfiguration(final FacetConfiguration configuration) throws WriteExternalException { if (configuration instanceof PersistentStateComponent) { Object state = ((PersistentStateComponent)configuration).getState(); if (state instanceof Element) return ((Element)state); return XmlSerializer.serialize(state, new SkipDefaultValuesSerializationFilters()); } else { final Element config = new Element(JpsFacetSerializer.CONFIGURATION_TAG); configuration.writeExternal(config); return config; } }
@SuppressWarnings("unchecked") private void executeAndRestoreDefaultProjectSettings(@NotNull Project project, @NotNull Runnable task) { if (!project.isDefault()) { task.run(); return; } AbstractExternalSystemSettings systemSettings = mySettingsManager.getSettings(project, myExternalSystemId); Object systemStateToRestore = null; if (systemSettings instanceof PersistentStateComponent) { systemStateToRestore = ((PersistentStateComponent)systemSettings).getState(); } systemSettings.copyFrom(myControl.getSystemSettings()); Collection projectSettingsToRestore = systemSettings.getLinkedProjectsSettings(); systemSettings.setLinkedProjectsSettings(Collections.singleton(getCurrentExternalProjectSettings())); try { task.run(); } finally { if (systemStateToRestore != null) { ((PersistentStateComponent)systemSettings).loadState(systemStateToRestore); } else { systemSettings.setLinkedProjectsSettings(projectSettingsToRestore); } } }
@SuppressWarnings("unchecked") private void executeAndRestoreDefaultProjectSettings(@Nonnull Project project, @Nonnull Runnable task) { if (!project.isDefault()) { task.run(); return; } AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId); Object systemStateToRestore = null; if (systemSettings instanceof PersistentStateComponent) { systemStateToRestore = ((PersistentStateComponent)systemSettings).getState(); } systemSettings.copyFrom(myControl.getSystemSettings()); Collection projectSettingsToRestore = systemSettings.getLinkedProjectsSettings(); systemSettings.setLinkedProjectsSettings(Collections.singleton(getCurrentExternalProjectSettings())); try { task.run(); } finally { if (systemStateToRestore != null) { ((PersistentStateComponent)systemSettings).loadState(systemStateToRestore); } else { systemSettings.setLinkedProjectsSettings(projectSettingsToRestore); } } }
@Override public PersistentStateComponent<?> getSerializer() { return this; }
@NotNull public static <T> State getStateSpec(@NotNull PersistentStateComponent<T> persistentStateComponent) { return getStateSpecOrError(persistentStateComponent.getClass()); }
@Override public Object getComponentInstance(@NotNull PicoContainer container) throws PicoInitializationException, PicoIntrospectionException { Object instance = myInitializedComponentInstance; if (instance != null) { return instance; } // we must take read action before adapter lock - if service requested from EDT (2) and pooled (1), will be a deadlock, because EDT waits adapter lock and Pooled waits read lock boolean useReadActionToInitService = isUseReadActionToInitService(); AccessToken readToken = useReadActionToInitService ? ReadAction.start() : null; try { synchronized (this) { instance = myInitializedComponentInstance; if (instance != null) { // DCL is fine, field is volatile return instance; } ComponentAdapter delegate = getDelegate(); // useReadActionToInitService is enabled currently only in internal or test mode or explicitly (registry) - we have enough feedback to fix, so, don't disturb all users if (!useReadActionToInitService && LOG.isDebugEnabled() && ApplicationManager.getApplication().isWriteAccessAllowed() && PersistentStateComponent.class.isAssignableFrom(delegate.getComponentImplementation())) { LOG.warn(new Throwable("Getting service from write-action leads to possible deadlock. Service implementation " + myDescriptor.getImplementation())); } // prevent storages from flushing and blocking FS AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Creating component '" + myDescriptor.getImplementation() + "'"); try { instance = delegate.getComponentInstance(container); if (instance instanceof Disposable) { Disposer.register(myComponentManager, (Disposable)instance); } myComponentManager.initializeComponent(instance, true); myInitializedComponentInstance = instance; return instance; } finally { token.finish(); } } } finally { if (readToken != null) { readToken.finish(); } } }
public void loadContext(Element fromElement) throws InvalidDataException { //noinspection unchecked ((PersistentStateComponent<Element>)myDebuggerManager).loadState(fromElement); }
public abstract PersistentStateComponent<?> getSerializer();
void reloadState(@NotNull Class<? extends PersistentStateComponent<?>> componentClass);