use of com.intellij.openapi.components.PersistentStateComponent in project intellij-community by JetBrains.
the class FacetUtil method saveFacetConfiguration.
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;
}
}
use of com.intellij.openapi.components.PersistentStateComponent in project intellij-community by JetBrains.
the class AbstractExternalProjectImportBuilder method executeAndRestoreDefaultProjectSettings.
@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();
Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
projects.add(getCurrentExternalProjectSettings());
systemSettings.setLinkedProjectsSettings(projects);
try {
task.run();
} finally {
if (systemStateToRestore != null) {
((PersistentStateComponent) systemSettings).loadState(systemStateToRestore);
} else {
systemSettings.setLinkedProjectsSettings(projectSettingsToRestore);
}
}
}
use of com.intellij.openapi.components.PersistentStateComponent in project intellij-community by JetBrains.
the class SystemFileProcessor method encodeFileText.
@Nullable
@Override
protected String encodeFileText(String content, VirtualFile file, Project project) throws IOException {
final String fileName = file.getName();
if (file.getParent().getName().equals(Project.DIRECTORY_STORE_FOLDER) && fileName.equals("workspace.xml")) {
List<Object> componentList = new ArrayList<>();
for (String componentName : COMPONENT_NAMES) {
Object component = project.getComponent(componentName);
if (component == null) {
try {
Class<?> aClass = Class.forName(componentName);
component = project.getComponent(aClass);
if (component == null) {
component = ServiceManager.getService(project, aClass);
}
} catch (ClassNotFoundException ignore) {
}
}
ContainerUtil.addIfNotNull(componentList, component);
}
if (!componentList.isEmpty()) {
final Element root = new Element("project");
for (final Object component : componentList) {
final Element element = new Element("component");
element.setAttribute("name", ComponentManagerImpl.getComponentName(component));
root.addContent(element);
ApplicationManager.getApplication().invokeAndWait(() -> {
if (component instanceof JDOMExternalizable) {
try {
((JDOMExternalizable) component).writeExternal(element);
} catch (WriteExternalException ignore) {
LOG.error(ignore);
}
} else if (component instanceof PersistentStateComponent) {
Object state = WriteAction.compute(() -> ((PersistentStateComponent) component).getState());
if (state == null) {
return;
}
Element element1 = state instanceof Element ? (Element) state : XmlSerializer.serialize(state);
element.addContent(element1.cloneContent());
element.setAttribute("name", StoreUtil.getStateSpec((PersistentStateComponent) component).name());
}
}, ModalityState.defaultModalityState());
}
PathMacroManager.getInstance(project).collapsePaths(root);
return JDOMUtil.writeElement(root);
}
}
return null;
}
use of com.intellij.openapi.components.PersistentStateComponent in project intellij-community by JetBrains.
the class RootModelImpl method writeExternal.
public void writeExternal(@NotNull Element element) {
for (ModuleExtension extension : myExtensions) {
if (extension instanceof PersistentStateComponent) {
//noinspection ConstantConditions
XmlSerializer.serializeInto(((PersistentStateComponent) extension).getState(), element);
} else {
//noinspection deprecation
extension.writeExternal(element);
}
}
for (ContentEntry contentEntry : getContent()) {
if (contentEntry instanceof ContentEntryImpl) {
final Element subElement = new Element(ContentEntryImpl.ELEMENT_NAME);
((ContentEntryImpl) contentEntry).writeExternal(subElement);
element.addContent(subElement);
}
}
for (OrderEntry orderEntry : getOrderEntries()) {
if (orderEntry instanceof WritableOrderEntry) {
((WritableOrderEntry) orderEntry).writeExternal(element);
}
}
}
Aggregations