diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ProjectWithModulesStoreImpl.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ProjectWithModulesStoreImpl.java index 39b8acade246..e8a9c6d12fff 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ProjectWithModulesStoreImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ProjectWithModulesStoreImpl.java @@ -25,13 +25,13 @@ import com.intellij.openapi.module.impl.ModuleImpl; import com.intellij.openapi.project.impl.ProjectImpl; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.SmartList; import com.intellij.util.containers.SmartHashSet; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -90,7 +90,7 @@ public class ProjectWithModulesStoreImpl extends ProjectStoreImpl { } private class ProjectWithModulesSaveSession extends ProjectSaveSession { - List myModuleSaveSessions = new ArrayList(); + List myModuleSaveSessions = new SmartList(); public ProjectWithModulesSaveSession() { for (Module module : getPersistentModules()) { @@ -169,7 +169,7 @@ public class ProjectWithModulesStoreImpl extends ProjectStoreImpl { } @Override - protected void beforeSave() throws IOException { + protected void beforeSave() { super.beforeSave(); for (SaveSession moduleSaveSession : myModuleSaveSessions) { moduleSaveSession.save(); @@ -177,7 +177,7 @@ public class ProjectWithModulesStoreImpl extends ProjectStoreImpl { } @Override - protected void collectSubFilesToSave(final List result) throws IOException { + protected void collectSubFilesToSave(@NotNull List result) { for (SaveSession moduleSaveSession : myModuleSaveSessions) { result.addAll(moduleSaveSession.getAllStorageFilesToSave(true)); } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 4158139a4f0b..dc3075ef54c4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -1390,18 +1390,18 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App try { StoreUtil.doSave(getStateStore()); } - catch (final Throwable ex) { + catch (final Throwable e) { if (isUnitTestMode()) { System.out.println("Saving application settings failed"); - ex.printStackTrace(); + e.printStackTrace(); } else { - LOG.info("Saving application settings failed", ex); + LOG.info("Saving application settings failed", e); invokeLater(new Runnable() { @Override public void run() { - if (ex instanceof PluginException) { - final PluginException pluginException = (PluginException)ex; + if (e instanceof PluginException) { + final PluginException pluginException = (PluginException)e; PluginManagerCore.disablePlugin(pluginException.getPluginId().getIdString()); Messages.showMessageDialog("The plugin " + pluginException.getPluginId() + @@ -1410,7 +1410,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App Messages.getErrorIcon()); } else { - Messages.showMessageDialog(ApplicationBundle.message("application.save.settings.error", ex.getLocalizedMessage()), + Messages.showMessageDialog(ApplicationBundle.message("application.save.settings.error", e.getLocalizedMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java index 8d7d480155b1..616515c8daf2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java @@ -36,7 +36,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.io.IOException; import java.lang.reflect.Type; import java.util.*; @@ -346,42 +345,25 @@ public abstract class ComponentStoreImpl implements IComponentStore { @NotNull @Override - public List getAllStorageFilesToSave(final boolean includingSubStructures) throws IOException { - try { - return myStorageManagerSaveSession.getAllStorageFilesToSave(); - } - catch (StateStorageException e) { - throw new IOException(e.getMessage()); - } + public List getAllStorageFilesToSave(final boolean includingSubStructures) { + return myStorageManagerSaveSession.getAllStorageFilesToSave(); } @NotNull @Override - public SaveSession save() throws IOException { - try { - final SettingsSavingComponent[] settingsComponents = - mySettingsSavingComponents.toArray(new SettingsSavingComponent[mySettingsSavingComponents.size()]); - - for (SettingsSavingComponent settingsSavingComponent : settingsComponents) { - try { - settingsSavingComponent.save(); - } - catch (StateStorageException e) { - LOG.info(e); - throw new IOException(e.getMessage()); - } - catch (Exception e) { - LOG.error(e); - } + public SaveSession save() { + SettingsSavingComponent[] settingsComponents = + mySettingsSavingComponents.toArray(new SettingsSavingComponent[mySettingsSavingComponents.size()]); + for (SettingsSavingComponent settingsSavingComponent : settingsComponents) { + try { + settingsSavingComponent.save(); + } + catch (Throwable e) { + LOG.error(e); } - - myStorageManagerSaveSession.save(); - } - catch (StateStorageException e) { - LOG.info(e); - throw new IOException(e.getMessage(), e); } + myStorageManagerSaveSession.save(); return this; } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.java index efcc813b9a15..b0e3b0520b14 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.java @@ -45,8 +45,7 @@ public interface IComponentStore { @NotNull StateStorageManager getStateStorageManager(); - - class SaveCancelledException extends IOException { + class SaveCancelledException extends RuntimeException { public SaveCancelledException() { } @@ -60,10 +59,10 @@ public interface IComponentStore { interface SaveSession { @NotNull - List getAllStorageFilesToSave(final boolean includingSubStructures) throws IOException; + List getAllStorageFilesToSave(boolean includingSubStructures); @NotNull - SaveSession save() throws IOException; + SaveSession save(); void finishSave(); diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java index b8b162884595..83877f76aaab 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java @@ -474,27 +474,36 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject @NotNull @Override - public List getAllStorageFilesToSave(final boolean includingSubStructures) throws IOException { - List result = new SmartList(); + public List getAllStorageFilesToSave(boolean includingSubStructures) { + List result = null; if (includingSubStructures) { + result = new SmartList(); collectSubFilesToSave(result); } - result.addAll(super.getAllStorageFilesToSave(false)); + + List filesToSave = super.getAllStorageFilesToSave(false); + if (result == null) { + return filesToSave; + } + result.addAll(filesToSave); return result; } - protected void collectSubFilesToSave(final List result) throws IOException { } + protected void collectSubFilesToSave(@NotNull List result) { + } @NotNull @Override - public SaveSession save() throws IOException { - final ProjectImpl.UnableToSaveProjectNotification[] notifications = + public SaveSession save() { + ProjectImpl.UnableToSaveProjectNotification[] notifications = NotificationsManager.getNotificationsManager().getNotificationsOfType(ProjectImpl.UnableToSaveProjectNotification.class, myProject); - if (notifications.length > 0) throw new SaveCancelledException(); + if (notifications.length > 0) { + throw new SaveCancelledException(); + } - final ReadonlyStatusHandler.OperationStatus operationStatus = ensureConfigFilesWritable(); + ReadonlyStatusHandler.OperationStatus operationStatus = ensureConfigFilesWritable(); if (operationStatus == null) { - throw new IOException(); + throw new StateStorageException(); } else if (operationStatus.hasReadonlyFiles()) { ProjectImpl.dropUnableToSaveProjectNotification(myProject, operationStatus.getReadonlyFiles()); @@ -502,30 +511,28 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject } beforeSave(); - super.save(); - return this; } - protected void beforeSave() throws IOException { + protected void beforeSave() { } private ReadonlyStatusHandler.OperationStatus ensureConfigFilesWritable() { return ApplicationManager.getApplication().runReadAction(new Computable() { @Override public ReadonlyStatusHandler.OperationStatus compute() { - final List filesToSave; + List filesToSave; try { filesToSave = getAllStorageFilesToSave(true); - final Iterator iterator = filesToSave.iterator(); + Iterator iterator = filesToSave.iterator(); while (iterator.hasNext()) { if (!iterator.next().exists()) { iterator.remove(); } } } - catch (IOException e) { + catch (Exception e) { LOG.error(e); return null; } @@ -549,7 +556,7 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject } } - if (readonlyFiles.size() == 0) { + if (readonlyFiles.isEmpty()) { final VirtualFile projectBaseDir = getProjectBaseDir(); if (projectBaseDir != null && projectBaseDir.isValid()) { if (!projectBaseDir.isWritable()) { @@ -581,7 +588,6 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject } } - private final StateStorageChooser> myStateStorageChooser = new StateStorageChooser>() { @Override public Storage[] selectStorages(final Storage[] storages, final PersistentStateComponent component, final StateStorageOperation operation) { diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StoreUtil.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StoreUtil.java index ead067cc9747..97d449c9acaa 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StoreUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StoreUtil.java @@ -17,8 +17,6 @@ package com.intellij.openapi.components.impl.stores; import org.jetbrains.annotations.NotNull; -import java.io.IOException; - /** * @author yole */ @@ -26,7 +24,7 @@ public class StoreUtil { private StoreUtil() { } - public static void doSave(@NotNull IComponentStore stateStore) throws IOException { + public static void doSave(@NotNull IComponentStore stateStore) { IComponentStore.SaveSession session = null; try { session = stateStore.startSave(); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java index 8725dc003da5..90d40d9235d5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java @@ -327,19 +327,21 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project @Override public void save() { - if (ApplicationManagerEx.getApplicationEx().isDoNotSave()) return; //no need to save + if (ApplicationManagerEx.getApplicationEx().isDoNotSave()) { + return; //no need to save + } if (!mySavingInProgress.compareAndSet(false, true)) { return; } + try { if (isToSaveProjectName()) { - final IProjectStore stateStore = getStateStore(); - final VirtualFile baseDir = stateStore.getProjectBaseDir(); + VirtualFile baseDir = getStateStore().getProjectBaseDir(); if (baseDir != null && baseDir.isValid()) { - final VirtualFile ideaDir = baseDir.findChild(DIRECTORY_STORE_FOLDER); + VirtualFile ideaDir = baseDir.findChild(DIRECTORY_STORE_FOLDER); if (ideaDir != null && ideaDir.isValid() && ideaDir.isDirectory()) { - final File nameFile = new File(ideaDir.getPath(), NAME_FILE); + File nameFile = new File(ideaDir.getPath(), NAME_FILE); try { FileUtil.writeToFile(nameFile, getName().getBytes("UTF-8"), false); myOldName = null; @@ -367,12 +369,13 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project (ApplicationManagerEx.getApplicationEx().isInternal() ? "

" + StringUtil.getThrowableText(e) + "

" : ""), NotificationType.ERROR); Notifications.Bus.notify(notification, this); - LOG.info("Unable to save plugin settings",e); + LOG.info("Unable to save plugin settings", e); } - catch (IOException e) { - MessagesEx.error(this, ProjectBundle.message("project.save.error", e.getMessage())).showLater(); + catch (Throwable e) { LOG.info("Error saving project", e); - } finally { + MessagesEx.error(this, ProjectBundle.message("project.save.error", e.getMessage())).showLater(); + } + finally { mySavingInProgress.set(false); ApplicationManager.getApplication().getMessageBus().syncPublisher(ProjectSaved.TOPIC).saved(this); }