move getFile to StorageUtil to avoid dependency on DirectoryBasedStorage

This commit is contained in:
Vladimir Krivosheev
2015-07-24 10:35:09 +02:00
parent 67ab863e37
commit eea091a388
3 changed files with 19 additions and 19 deletions
@@ -545,7 +545,7 @@ public class SchemeManagerImpl<T : Scheme, E : ExternalizableScheme>(private val
}
if (file == null) {
file = DirectoryBasedStorage.getFile(fileName, dir, this)
file = StorageUtil.getFile(fileName, dir, this)
}
runWriteAction {
@@ -142,23 +142,7 @@ public class DirectoryBasedStorage extends StateStorageBase<DirectoryStorageData
if (parentVirtualFile == null) {
throw new StateStorageException(ProjectBundle.message("project.configuration.save.file.not.found", parentFile));
}
return getFile(ioDir.getName(), parentVirtualFile, requestor);
}
@NotNull
public static VirtualFile getFile(@NotNull String fileName, @NotNull VirtualFile parent, @NotNull Object requestor) throws IOException {
VirtualFile file = parent.findChild(fileName);
if (file != null) {
return file;
}
AccessToken token = WriteAction.start();
try {
return parent.createChildData(requestor, fileName);
}
finally {
token.finish();
}
return StorageUtil.getFile(ioDir.getName(), parentVirtualFile, requestor);
}
private static class MySaveSession extends SaveSessionBase {
@@ -258,7 +242,7 @@ public class DirectoryBasedStorage extends StateStorageBase<DirectoryStorageData
storeElement.setAttribute(StorageData.NAME, componentName);
storeElement.addContent(element);
VirtualFile file = getFile(fileName, dir, MySaveSession.this);
VirtualFile file = StorageUtil.getFile(fileName, dir, MySaveSession.this);
StorageUtil.writeFile(null, MySaveSession.this, file, storeElement, LineSeparator.fromString(file.exists() ? StorageUtil.loadFile(file).second : SystemProperties.getLineSeparator()));
}
catch (IOException e) {
@@ -356,4 +356,20 @@ public class StorageUtil {
public static boolean isProjectOrModuleFile(@NotNull String fileSpec) {
return StoragePathMacros.PROJECT_FILE.equals(fileSpec) || fileSpec.startsWith(StoragePathMacros.PROJECT_CONFIG_DIR) || fileSpec.equals(StoragePathMacros.MODULE_FILE);
}
@NotNull
public static VirtualFile getFile(@NotNull String fileName, @NotNull VirtualFile parent, @NotNull Object requestor) throws IOException {
VirtualFile file = parent.findChild(fileName);
if (file != null) {
return file;
}
AccessToken token = WriteAction.start();
try {
return parent.createChildData(requestor, fileName);
}
finally {
token.finish();
}
}
}