summaryrefslogtreecommitdiff
path: root/platform/platform-impl/src/com/intellij/openapi/components/impl/stores
diff options
context:
space:
mode:
Diffstat (limited to 'platform/platform-impl/src/com/intellij/openapi/components/impl/stores')
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java23
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java4
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java40
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DefaultProjectStoreImpl.java4
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java2
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java2
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManager.java2
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java7
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java25
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java5
10 files changed, 60 insertions, 54 deletions
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java
index 41942960ab04..a00533d3244b 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.NamedJDOMExternalizable;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.Collection;
@@ -36,13 +37,14 @@ class ApplicationStoreImpl extends ComponentStoreImpl implements IApplicationSto
private static final String XML_EXTENSION = ".xml";
private static final String DEFAULT_STORAGE_SPEC = StoragePathMacros.APP_CONFIG + "/" + PathManager.DEFAULT_OPTIONS_FILE_NAME + XML_EXTENSION;
private static final String OPTIONS_MACRO = "OPTIONS";
- private static final String CONFIG_MACRO = "ROOT_CONFIG";
private static final String ROOT_ELEMENT_NAME = "application";
private final ApplicationImpl myApplication;
private final StateStorageManager myStateStorageManager;
private final DefaultsStateStorage myDefaultsStateStorage;
+ private String myConfigPath;
+
// created from PicoContainer
@SuppressWarnings({"UnusedDeclaration"})
public ApplicationStoreImpl(final ApplicationImpl application, PathMacroManager pathMacroManager) {
@@ -53,23 +55,24 @@ class ApplicationStoreImpl extends ComponentStoreImpl implements IApplicationSto
return new FileBasedStorage.FileStorageData(ROOT_ELEMENT_NAME);
}
+ @Nullable
@Override
protected String getOldStorageSpec(Object component, final String componentName, final StateStorageOperation operation) {
- final String fileName;
-
if (component instanceof NamedJDOMExternalizable) {
- fileName = StoragePathMacros.APP_CONFIG + "/" + ((NamedJDOMExternalizable)component).getExternalFileName() + XML_EXTENSION;
+ return StoragePathMacros.APP_CONFIG + "/" + ((NamedJDOMExternalizable)component).getExternalFileName() + XML_EXTENSION;
}
else {
- fileName = DEFAULT_STORAGE_SPEC;
+ return DEFAULT_STORAGE_SPEC;
}
-
- return fileName;
}
@Override
protected String getVersionsFilePath() {
- return PathManager.getConfigPath() + "/options/appComponentVersions.xml";
+ String configPath = myConfigPath;
+ if (configPath == null) {
+ configPath = PathManager.getConfigPath();
+ }
+ return configPath + "/options/appComponentVersions.xml";
}
@Override
@@ -97,7 +100,8 @@ class ApplicationStoreImpl extends ComponentStoreImpl implements IApplicationSto
@Override
public void setConfigPath(@NotNull final String configPath) {
- myStateStorageManager.addMacro(CONFIG_MACRO, configPath);
+ myStateStorageManager.addMacro(StoragePathMacros.getMacroName(StoragePathMacros.ROOT_CONFIG), configPath);
+ myConfigPath = configPath;
}
@Override
@@ -150,6 +154,7 @@ class ApplicationStoreImpl extends ComponentStoreImpl implements IApplicationSto
return myStateStorageManager;
}
+ @Nullable
@Override
protected StateStorage getDefaultsStorage() {
return myDefaultsStateStorage;
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java
index 01cc0fb987b9..25dd8a05cab3 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java
@@ -16,7 +16,6 @@
package com.intellij.openapi.components.impl.stores;
import com.intellij.openapi.components.*;
-import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.impl.ProjectManagerImpl;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
@@ -28,8 +27,6 @@ import java.util.ArrayList;
import java.util.Set;
abstract class BaseFileConfigurableStoreImpl extends ComponentStoreImpl {
- private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.components.impl.stores.BaseFileConfigurableStoreImpl");
-
@NonNls protected static final String VERSION_OPTION = "version";
@NonNls public static final String ATTRIBUTE_NAME = "name";
private final ComponentManager myComponentManager;
@@ -119,6 +116,7 @@ abstract class BaseFileConfigurableStoreImpl extends ComponentStoreImpl {
return (BaseStorageData) getMainStorage().getStorageData(false);
}
+ @Nullable
@Override
protected StateStorage getDefaultsStorage() {
return myDefaultsStateStorage;
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 575717f455f7..fc2017b57a4a 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
@@ -41,8 +41,7 @@ import java.util.*;
@SuppressWarnings({"deprecation"})
public abstract class ComponentStoreImpl implements IComponentStore {
-
- private static final Logger LOG = Logger.getInstance("#com.intellij.components.ComponentStoreImpl");
+ private static final Logger LOG = Logger.getInstance(ComponentStoreImpl.class);
private final Map<String, Object> myComponents = Collections.synchronizedMap(new THashMap<String, Object>());
private final List<SettingsSavingComponent> mySettingsSavingComponents = Collections.synchronizedList(new ArrayList<SettingsSavingComponent>());
@Nullable private SaveSessionImpl mySession;
@@ -53,9 +52,8 @@ public abstract class ComponentStoreImpl implements IComponentStore {
return getStateStorageManager().getStateStorage(storageSpec);
}
- protected StateStorage getDefaultsStorage() {
- throw new UnsupportedOperationException("Method getDefaultsStorage is not supported in " + getClass());
- }
+ @Nullable
+ protected abstract StateStorage getDefaultsStorage();
@Override
public void initComponent(@NotNull final Object component, final boolean service) {
@@ -143,12 +141,10 @@ public abstract class ComponentStoreImpl implements IComponentStore {
private <T> void commitPersistentComponent(@NotNull final PersistentStateComponent<T> persistentStateComponent,
@NotNull StateStorageManager.ExternalizationSession session) {
- Storage[] storageSpecs = getComponentStorageSpecs(persistentStateComponent, StateStorageOperation.WRITE);
-
T state = persistentStateComponent.getState();
if (state != null) {
- session
- .setState(storageSpecs, persistentStateComponent, getComponentName(persistentStateComponent), state);
+ Storage[] storageSpecs = getComponentStorageSpecs(persistentStateComponent, StateStorageOperation.WRITE);
+ session.setState(storageSpecs, persistentStateComponent, getComponentName(persistentStateComponent), state);
}
}
@@ -276,13 +272,12 @@ public abstract class ComponentStoreImpl implements IComponentStore {
@NotNull
private static <T> Class<T> getComponentStateClass(@NotNull final PersistentStateComponent<T> persistentStateComponent) {
final Class persistentStateComponentClass = PersistentStateComponent.class;
+
Class componentClass = persistentStateComponent.getClass();
nextSuperClass:
while (true) {
- final Class[] interfaces = componentClass.getInterfaces();
-
- for (Class anInterface : interfaces) {
+ for (Class anInterface : componentClass.getInterfaces()) {
if (anInterface.equals(persistentStateComponentClass)) {
break nextSuperClass;
}
@@ -292,7 +287,7 @@ public abstract class ComponentStoreImpl implements IComponentStore {
}
final Type type = ReflectionUtil.resolveVariable(persistentStateComponentClass.getTypeParameters()[0], componentClass);
-
+ assert type != null;
//noinspection unchecked
return (Class<T>)ReflectionUtil.getRawType(type);
}
@@ -319,14 +314,12 @@ public abstract class ComponentStoreImpl implements IComponentStore {
protected <T> Storage[] getComponentStorageSpecs(@NotNull final PersistentStateComponent<T> persistentStateComponent,
final StateStorageOperation operation) throws StateStorageException {
final State stateSpec = getStateSpec(persistentStateComponent);
-
final Storage[] storages = stateSpec.storages();
-
- if (storages.length == 1) return storages;
-
+ if (storages.length == 1) {
+ return storages;
+ }
assert storages.length > 0;
-
final Class<StorageAnnotationsDefaultValues.NullStateStorageChooser> defaultClass =
StorageAnnotationsDefaultValues.NullStateStorageChooser.class;
@@ -340,14 +333,11 @@ public abstract class ComponentStoreImpl implements IComponentStore {
}
else {
try {
- //noinspection unchecked
- final StateStorageChooser<PersistentStateComponent<T>> storageChooser = storageChooserClass.newInstance();
+ @SuppressWarnings("unchecked")
+ StateStorageChooser<PersistentStateComponent<T>> storageChooser = ReflectionUtil.newInstance(storageChooserClass);
return storageChooser.selectStorages(storages, persistentStateComponent, operation);
}
- catch (InstantiationException e) {
- throw new StateStorageException(e);
- }
- catch (IllegalAccessException e) {
+ catch (RuntimeException e) {
throw new StateStorageException(e);
}
}
@@ -404,7 +394,7 @@ public abstract class ComponentStoreImpl implements IComponentStore {
}
catch (StateStorageException e) {
LOG.info(e);
- throw new IOException(e.getMessage());
+ throw new IOException(e.getMessage(), e);
}
return this;
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DefaultProjectStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DefaultProjectStoreImpl.java
index 48247b2de866..6f0c3b8122cf 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DefaultProjectStoreImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DefaultProjectStoreImpl.java
@@ -159,8 +159,8 @@ public class DefaultProjectStoreImpl extends ProjectStoreImpl {
}
@Override
- public String expandMacros(final String file) {
- throw new UnsupportedOperationException("Method expandMacroses not implemented in " + getClass());
+ public String expandMacros(@NotNull String file) {
+ throw new UnsupportedOperationException("Method expandMacros not implemented in " + getClass());
}
@Override
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java
index 574823767d9b..2120030db2c1 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java
@@ -55,7 +55,7 @@ final class OldStreamProviderAdapter extends StreamProvider implements CurrentUs
}
@Override
- public void deleteFile(@NotNull String fileSpec, @NotNull RoamingType roamingType) {
+ public void delete(@NotNull String fileSpec, @NotNull RoamingType roamingType) {
if (myRoamingType == roamingType) {
myProvider.deleteFile(fileSpec, roamingType);
}
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java
index f6a4e11e5aa5..0eed50a65131 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java
@@ -20,6 +20,7 @@ import com.intellij.openapi.components.*;
import com.intellij.openapi.project.impl.ProjectImpl;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.Nullable;
import java.util.Map;
@@ -47,6 +48,7 @@ class ProjectStateStorageManager extends StateStorageManagerImpl {
return new ProjectStoreImpl.IprStorageData(ROOT_TAG_NAME, myProject);
}
+ @Nullable
@Override
protected String getOldStorageSpec(Object component, final String componentName, final StateStorageOperation operation) throws
StateStorageException {
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManager.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManager.java
index 0e2828e988a3..68d882d2b204 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManager.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManager.java
@@ -58,7 +58,7 @@ public interface StateStorageManager {
StateStorage getOldStorage(Object component, String componentName, StateStorageOperation operation) throws StateStorageException;
@Nullable
- String expandMacros(String file);
+ String expandMacros(@NotNull String file);
@Deprecated
void registerStreamProvider(@SuppressWarnings("deprecation") StreamProvider streamProvider, final RoamingType type);
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java
index 1b7da8fc2144..431c9a97820c 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java
@@ -331,7 +331,7 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
@Override
@Nullable
- public synchronized String expandMacros(final String file) {
+ public synchronized String expandMacros(@NotNull String file) {
final Matcher matcher = MACRO_PATTERN.matcher(file);
while (matcher.find()) {
String m = matcher.group(1);
@@ -427,6 +427,7 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
return getFileStateStorage(getOldStorageSpec(component, componentName, operation));
}
+ @Nullable
protected abstract String getOldStorageSpec(Object component, final String componentName, final StateStorageOperation operation)
throws StateStorageException;
@@ -615,11 +616,11 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
}
@Override
- public void deleteFile(@NotNull String fileSpec, @NotNull RoamingType roamingType) {
+ public void delete(@NotNull String fileSpec, @NotNull RoamingType roamingType) {
for (StreamProvider streamProvider : myStreamProviders) {
try {
if (streamProvider.isEnabled() && streamProvider.isApplicable(fileSpec, roamingType)) {
- streamProvider.deleteFile(fileSpec, roamingType);
+ streamProvider.delete(fileSpec, roamingType);
}
}
catch (Exception e) {
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java
index 73aea37d6444..bd732705446a 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java
@@ -113,19 +113,25 @@ public class StorageUtil {
@Nullable
static VirtualFile save(@NotNull IFile file, Parent element, Object requestor) throws StateStorageException {
try {
- VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
- Couple<String> pair = loadFile(vFile);
- String text = JDOMUtil.writeParent(element, pair.second);
-
+ String lineSeparator;
+ String oldText;
if (file.exists()) {
- if (text.equals(pair.first)) {
- return null;
- }
+ VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
+ Couple<String> pair = loadFile(vFile);
+ lineSeparator = pair.second;
+ oldText = pair.first;
}
else {
+ oldText = null;
+ lineSeparator = SystemProperties.getLineSeparator();
file.createParentDirs();
}
+ String text = JDOMUtil.writeParent(element, lineSeparator);
+ if (text.equals(oldText)) {
+ return null;
+ }
+
// mark this action as modifying the file which daemon analyzer should ignore
AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(DocumentRunnable.IgnoreDocumentRunnable.class);
try {
@@ -245,6 +251,7 @@ public class StorageUtil {
}
}
+ @NotNull
public static BufferExposingByteArrayOutputStream documentToBytes(@NotNull Document document, boolean useSystemLineSeparator) throws IOException {
BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream(512);
OutputStreamWriter writer = new OutputStreamWriter(out, CharsetToolkit.UTF8_CHARSET);
@@ -271,9 +278,9 @@ public class StorageUtil {
}
}
- public static void deleteContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull RoamingType type) {
+ public static void delete(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull RoamingType type) {
if (provider.isApplicable(fileSpec, type)) {
- provider.deleteFile(fileSpec, type);
+ provider.delete(fileSpec, type);
}
}
diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java
index cf77ee377cf1..ec57d8c63601 100644
--- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java
+++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java
@@ -47,5 +47,8 @@ public abstract class StreamProvider {
return Collections.emptyList();
}
- public abstract void deleteFile(@NotNull String fileSpec, @NotNull RoamingType roamingType);
+ /**
+ * Delete file or directory
+ */
+ public abstract void delete(@NotNull String fileSpec, @NotNull RoamingType roamingType);
} \ No newline at end of file