summaryrefslogtreecommitdiff
path: root/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java')
-rw-r--r--platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java126
1 files changed, 61 insertions, 65 deletions
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 6288c62ab9e5..01e2f9e036d0 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
@@ -39,13 +39,14 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.*;
+import com.intellij.util.PathUtilRt;
+import com.intellij.util.SmartList;
import com.intellij.util.containers.OrderedSet;
-import com.intellij.util.io.fs.FileSystem;
-import com.intellij.util.io.fs.IFile;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.lang.annotation.Annotation;
@@ -55,23 +56,21 @@ import java.util.List;
import java.util.Set;
class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProjectStore {
- private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.components.impl.stores.ProjectStoreImpl");
+ private static final Logger LOG = Logger.getInstance(ProjectStoreImpl.class);
@NonNls private static final String OLD_PROJECT_SUFFIX = "_old.";
@NonNls static final String OPTION_WORKSPACE = "workspace";
- @NonNls static final String DEFAULT_STATE_STORAGE = StoragePathMacros.PROJECT_FILE;
-
static final Storage DEFAULT_STORAGE_ANNOTATION = new MyStorage();
private static int originalVersion = -1;
protected ProjectImpl myProject;
private StorageScheme myScheme = StorageScheme.DEFAULT;
- private String myCachedLocation;
private String myPresentableUrl;
- ProjectStoreImpl(final ProjectImpl project) {
+ ProjectStoreImpl(@NotNull ProjectImpl project) {
super(project);
+
myProject = project;
}
@@ -169,15 +168,15 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
final File dirStore = file.isDirectory() ? new File(file, Project.DIRECTORY_STORE_FOLDER)
: new File(file.getParentFile(), Project.DIRECTORY_STORE_FOLDER);
- stateStorageManager.addMacro(StoragePathMacros.getMacroName(StoragePathMacros.PROJECT_FILE), new File(dirStore, "misc.xml").getPath());
+ stateStorageManager.addMacro(StoragePathMacros.PROJECT_FILE, new File(dirStore, "misc.xml").getPath());
final File ws = new File(dirStore, "workspace.xml");
- stateStorageManager.addMacro(StoragePathMacros.getMacroName(StoragePathMacros.WORKSPACE_FILE), ws.getPath());
+ stateStorageManager.addMacro(StoragePathMacros.WORKSPACE_FILE, ws.getPath());
if (!ws.exists() && !file.isDirectory()) {
useOldWsContent(filePath, ws);
}
- stateStorageManager.addMacro(StoragePathMacros.getMacroName(StoragePathMacros.PROJECT_CONFIG_DIR), dirStore.getPath());
+ stateStorageManager.addMacro(StoragePathMacros.PROJECT_CONFIG_DIR, dirStore.getPath());
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
@@ -189,10 +188,10 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
else {
myScheme = StorageScheme.DEFAULT;
- stateStorageManager.addMacro(StoragePathMacros.getMacroName(StoragePathMacros.PROJECT_FILE), filePath);
+ stateStorageManager.addMacro(StoragePathMacros.PROJECT_FILE, filePath);
final String workspacePath = composeWsPath(filePath);
- stateStorageManager.addMacro(StoragePathMacros.getMacroName(StoragePathMacros.WORKSPACE_FILE), workspacePath);
+ stateStorageManager.addMacro(StoragePathMacros.WORKSPACE_FILE, workspacePath);
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
@@ -202,7 +201,6 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
}, ModalityState.defaultModalityState());
}
- myCachedLocation = null;
myPresentableUrl = null;
}
@@ -258,18 +256,26 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
final String path = getProjectFilePath();
if (!StringUtil.isEmptyOrSpaces(path)) {
- return myScheme == StorageScheme.DEFAULT ? new File(path).getParent() : new File(path).getParentFile().getParent();
+ return getBasePath(new File(path));
}
//we are not yet initialized completely ("open directory", etc)
- final StateStorage s = getStateStorageManager().getFileStateStorage(StoragePathMacros.PROJECT_FILE);
- if (!(s instanceof FileBasedStorage)) return null;
- final FileBasedStorage storage = (FileBasedStorage)s;
+ StateStorage storage = getStateStorageManager().getStateStorage(StoragePathMacros.PROJECT_FILE, RoamingType.PER_USER);
+ if (!(storage instanceof FileBasedStorage)) {
+ return null;
+ }
- final File file = storage.getFile();
- if (file == null) return null;
+ return getBasePath(((FileBasedStorage)storage).getFile());
+ }
- return myScheme == StorageScheme.DEFAULT ? file.getParent() : file.getParentFile().getParent();
+ private String getBasePath(@NotNull File file) {
+ if (myScheme == StorageScheme.DEFAULT) {
+ return file.getParent();
+ }
+ else {
+ File parentFile = file.getParentFile();
+ return parentFile == null ? null : parentFile.getParent();
+ }
}
@NotNull
@@ -302,7 +308,7 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
return baseDir.getName().replace(":", "");
}
else {
- String temp = getProjectFileName();
+ String temp = PathUtilRt.getFileName(((FileBasedStorage)getProjectFileStorage()).getFilePath());
FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(temp);
if (fileType instanceof ProjectFileType) {
temp = temp.substring(0, temp.length() - fileType.getDefaultExtension().length() - 1);
@@ -316,13 +322,6 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
}
@NotNull
- private String getProjectFileName() {
- final FileBasedStorage storage = (FileBasedStorage)getStateStorageManager().getFileStateStorage(StoragePathMacros.PROJECT_FILE);
- assert storage != null;
- return storage.getFileName();
- }
-
- @NotNull
@Override
public StorageScheme getStorageScheme() {
return myScheme;
@@ -349,26 +348,28 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
@Override
public VirtualFile getProjectFile() {
- if (myProject.isDefault()) return null;
- final FileBasedStorage storage = (FileBasedStorage)getStateStorageManager().getFileStateStorage(StoragePathMacros.PROJECT_FILE);
+ return myProject.isDefault() ? null : ((FileBasedStorage)getProjectFileStorage()).getVirtualFile();
+ }
+
+ @NotNull
+ private XmlElementStorage getProjectFileStorage() {
+ // XmlElementStorage if default project, otherwise FileBasedStorage
+ XmlElementStorage storage = (XmlElementStorage)getStateStorageManager().getStateStorage(StoragePathMacros.PROJECT_FILE, RoamingType.PER_USER);
assert storage != null;
- return storage.getVirtualFile();
+ return storage;
}
@Override
public VirtualFile getWorkspaceFile() {
if (myProject.isDefault()) return null;
- final FileBasedStorage storage = (FileBasedStorage)getStateStorageManager().getFileStateStorage(StoragePathMacros.WORKSPACE_FILE);
+ final FileBasedStorage storage = (FileBasedStorage)getStateStorageManager().getStateStorage(StoragePathMacros.WORKSPACE_FILE, RoamingType.DISABLED);
assert storage != null;
return storage.getVirtualFile();
}
@Override
public void loadProjectFromTemplate(@NotNull final ProjectImpl defaultProject) {
- final StateStorage stateStorage = getStateStorageManager().getFileStateStorage(DEFAULT_STATE_STORAGE);
-
- assert stateStorage instanceof XmlElementStorage;
- XmlElementStorage xmlElementStorage = (XmlElementStorage)stateStorage;
+ XmlElementStorage stateStorage = getProjectFileStorage();
defaultProject.save();
final IProjectStore projectStore = defaultProject.getStateStore();
@@ -376,24 +377,19 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
DefaultProjectStoreImpl defaultProjectStore = (DefaultProjectStoreImpl)projectStore;
final Element element = defaultProjectStore.getStateCopy();
if (element != null) {
- xmlElementStorage.setDefaultState(element);
+ stateStorage.setDefaultState(element);
}
}
@NotNull
@Override
public String getProjectFilePath() {
- if (myProject.isDefault()) return "";
- final FileBasedStorage storage = (FileBasedStorage)getStateStorageManager().getFileStateStorage(StoragePathMacros.PROJECT_FILE);
- assert storage != null;
- return storage.getFilePath();
+ return myProject.isDefault() ? "" : ((FileBasedStorage)getProjectFileStorage()).getFilePath();
}
@Override
protected XmlElementStorage getMainStorage() {
- final XmlElementStorage storage = (XmlElementStorage)getStateStorageManager().getFileStateStorage(DEFAULT_STATE_STORAGE);
- assert storage != null;
- return storage;
+ return getProjectFileStorage();
}
@NotNull
@@ -402,7 +398,6 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
return new ProjectStateStorageManager(PathMacroManager.getInstance(getComponentManager()).createTrackingSubstitutor(), myProject);
}
-
static class ProjectStorageData extends BaseStorageData {
protected final Project myProject;
@@ -447,16 +442,16 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
}
@Override
- public void load(@NotNull final Element root) throws IOException {
- final String v = root.getAttributeValue(VERSION_OPTION);
+ public void load(@NotNull Element rootElement, @Nullable PathMacroSubstitutor pathMacroSubstitutor, boolean intern) {
+ final String v = rootElement.getAttributeValue(VERSION_OPTION);
//noinspection AssignmentToStaticFieldFromInstanceMethod
originalVersion = v != null ? Integer.parseInt(v) : 0;
if (originalVersion != ProjectManagerImpl.CURRENT_FORMAT_VERSION) {
- convert(root, originalVersion);
+ convert(rootElement, originalVersion);
}
- super.load(root);
+ super.load(rootElement, pathMacroSubstitutor, intern);
}
protected void convert(final Element root, final int originalVersion) {
@@ -479,19 +474,16 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
@NotNull
@Override
- public List<IFile> getAllStorageFilesToSave(final boolean includingSubStructures) throws IOException {
- List<IFile> result = new ArrayList<IFile>();
-
+ public List<File> getAllStorageFilesToSave(final boolean includingSubStructures) throws IOException {
+ List<File> result = new SmartList<File>();
if (includingSubStructures) {
- collectSubfilesToSave(result);
+ collectSubFilesToSave(result);
}
-
result.addAll(super.getAllStorageFilesToSave(false));
-
return result;
}
- protected void collectSubfilesToSave(final List<IFile> result) throws IOException { }
+ protected void collectSubFilesToSave(final List<File> result) throws IOException { }
@NotNull
@Override
@@ -523,10 +515,10 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
return ApplicationManager.getApplication().runReadAction(new Computable<ReadonlyStatusHandler.OperationStatus>() {
@Override
public ReadonlyStatusHandler.OperationStatus compute() {
- final List<IFile> filesToSave;
+ final List<File> filesToSave;
try {
filesToSave = getAllStorageFilesToSave(true);
- final Iterator<IFile> iterator = filesToSave.iterator();
+ final Iterator<File> iterator = filesToSave.iterator();
while (iterator.hasNext()) {
if (!iterator.next().exists()) {
iterator.remove();
@@ -543,14 +535,12 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
if (myProject.isToSaveProjectName()) {
final VirtualFile baseDir = getProjectBaseDir();
if (baseDir != null && baseDir.isValid()) {
- filesToSave.add(FileSystem.FILE_SYSTEM
- .createFile(new File(new File(baseDir.getPath(), Project.DIRECTORY_STORE_FOLDER), ProjectImpl.NAME_FILE).getPath()));
+ filesToSave.add(new File(new File(baseDir.getPath(), Project.DIRECTORY_STORE_FOLDER), ProjectImpl.NAME_FILE));
}
}
- for (IFile file : filesToSave) {
+ for (File file : filesToSave) {
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
-
if (virtualFile != null) {
virtualFile.refresh(false, false);
if (virtualFile.isValid() && !virtualFile.isWritable()) {
@@ -670,7 +660,7 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
@Override
public String file() {
- return DEFAULT_STATE_STORAGE;
+ return StoragePathMacros.PROJECT_FILE;
}
@Override
@@ -679,15 +669,21 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
}
@Override
+ public RoamingType roamingType() {
+ return RoamingType.PER_USER;
+ }
+
+ @Override
public Class<? extends StateStorage> storageClass() {
- return StorageAnnotationsDefaultValues.NullStateStorage.class;
+ return StateStorage.class;
}
@Override
public Class<? extends StateSplitter> stateSplitter() {
- return StorageAnnotationsDefaultValues.NullStateSplitter.class;
+ return StateSplitter.class;
}
+ @NotNull
@Override
public Class<? extends Annotation> annotationType() {
throw new UnsupportedOperationException("Method annotationType not implemented in " + getClass());