diff --git a/platform/platform-impl/src/com/intellij/application/options/ExportSchemeAction.java b/platform/platform-impl/src/com/intellij/application/options/ExportSchemeAction.java index c0e672634096..cee9580bafc9 100644 --- a/platform/platform-impl/src/com/intellij/application/options/ExportSchemeAction.java +++ b/platform/platform-impl/src/com/intellij/application/options/ExportSchemeAction.java @@ -35,6 +35,7 @@ public abstract class ExportSchemeAction myStreamProviders = new SmartList(); + private StreamProvider myStreamProvider; - private final StreamProvider myCompoundStreamProvider = new StreamProvider() { - @Override - public boolean isEnabled() { - synchronized (myStreamProviders) { - for (StreamProvider provider : myStreamProviders) { - if (provider.isEnabled()) { - return true; - } - } - } - return false; - } - - @Override - public boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException { - boolean result = false; - for (StreamProvider streamProvider : getStreamProviders()) { - try { - if (streamProvider.isEnabled()) { - if (streamProvider.saveContent(fileSpec, content, size, roamingType, async)) { - result = true; - } - } - } - catch (ConnectException e) { - LOG.debug("Cannot send user profile to server: " + e.getLocalizedMessage()); - } - catch (Exception e) { - LOG.debug(e); - } - } - return result; - } - - @Override - public InputStream loadContent(@NotNull final String fileSpec, @NotNull final RoamingType roamingType) throws IOException { - for (StreamProvider streamProvider : getStreamProviders()) { - try { - if (streamProvider.isEnabled()) { - InputStream content = streamProvider.loadContent(fileSpec, roamingType); - if (content != null) { - return content; - } - } - } - catch (ConnectException e) { - LOG.debug("Cannot send user profile o server: " + e.getLocalizedMessage()); - } - catch (Exception e) { - LOG.debug(e); - } - } - - return null; - } - - @Override - public void deleteFile(@NotNull String fileSpec, @NotNull RoamingType roamingType) { - for (StreamProvider streamProvider : getStreamProviders()) { - try { - if (streamProvider.isEnabled()) { - streamProvider.deleteFile(fileSpec, roamingType); - } - } - catch (Exception e) { - LOG.debug(e); - } - } - } - }; + private final OldStreamProviderManager myOldStreamProvider = new OldStreamProviderManager(); public StateStorageManagerImpl(@Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor, String rootTagName, @@ -306,7 +239,7 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di throw new IllegalArgumentException("Extension is missing for storage file: " + expandedFile); } - return new FileBasedStorage(getMacroSubstitutor(fileSpec), myCompoundStreamProvider, expandedFile, fileSpec, myRootTagName, this, + return new FileBasedStorage(getMacroSubstitutor(fileSpec), getStreamProvider(), expandedFile, fileSpec, myRootTagName, this, myPicoContainer, ComponentRoamingManager.getInstance(), this) { @Override @NotNull @@ -379,13 +312,10 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di isDirty = true; } - @NotNull + @Nullable @Override - public StreamProvider[] getStreamProviders() { - synchronized (myStreamProviders) { - Collection providers = myStreamProviders; - return providers.isEmpty() ? StreamProvider.EMPTY_ARRAY : providers.toArray(new StreamProvider[providers.size()]); - } + public StreamProvider getStreamProvider() { + return ObjectUtils.chooseNotNull(myStreamProvider, myOldStreamProvider); } protected TrackingPathMacroSubstitutor getMacroSubstitutor(@NotNull final String fileSpec) { @@ -559,23 +489,14 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di @Override public void registerStreamProvider(com.intellij.openapi.options.StreamProvider streamProvider, final RoamingType type) { - synchronized (myStreamProviders) { - myStreamProviders.add(new OldStreamProviderAdapter(streamProvider, type)); + synchronized (myOldStreamProvider) { + myOldStreamProvider.myStreamProviders.add(new OldStreamProviderAdapter(streamProvider, type)); } } @Override - public void registerStreamProvider(@NotNull StreamProvider streamProvider) { - synchronized (myStreamProviders) { - myStreamProviders.add(streamProvider); - } - } - - @Override - public void unregisterStreamProvider(@NotNull StreamProvider streamProvider) { - synchronized (myStreamProviders) { - myStreamProviders.remove(streamProvider); - } + public void setStreamProvider(@Nullable StreamProvider streamProvider) { + myStreamProvider = streamProvider; } public void save() { @@ -621,4 +542,86 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di } return root; } + + private static class OldStreamProviderManager extends StreamProvider implements CurrentUserHolder { + private final List myStreamProviders = new SmartList(); + + @Override + public boolean isEnabled() { + for (StreamProvider provider : myStreamProviders) { + if (provider.isEnabled()) { + return true; + } + } + return false; + } + + @Override + public boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException { + boolean result = false; + for (StreamProvider streamProvider : myStreamProviders) { + try { + if (streamProvider.isEnabled()) { + if (streamProvider.saveContent(fileSpec, content, size, roamingType, async)) { + result = true; + } + } + } + catch (ConnectException e) { + LOG.debug("Cannot send user profile to server: " + e.getLocalizedMessage()); + } + catch (Exception e) { + LOG.debug(e); + } + } + return result; + } + + @Override + public InputStream loadContent(@NotNull final String fileSpec, @NotNull final RoamingType roamingType) throws IOException { + for (StreamProvider streamProvider : myStreamProviders) { + try { + if (streamProvider.isEnabled()) { + InputStream content = streamProvider.loadContent(fileSpec, roamingType); + if (content != null) { + return content; + } + } + } + catch (ConnectException e) { + LOG.debug("Cannot send user profile o server: " + e.getLocalizedMessage()); + } + catch (Exception e) { + LOG.debug(e); + } + } + + return null; + } + + @Override + public void deleteFile(@NotNull String fileSpec, @NotNull RoamingType roamingType) { + for (StreamProvider streamProvider : myStreamProviders) { + try { + if (streamProvider.isEnabled()) { + streamProvider.deleteFile(fileSpec, roamingType); + } + } + catch (Exception e) { + LOG.debug(e); + } + } + } + + @Override + public String getCurrentUserName() { + for (OldStreamProviderAdapter provider : myStreamProviders) { + String userName = provider.getCurrentUserName(); + if (userName != null) { + return userName; + } + } + return null; + } + } } 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 c8300b6f30b1..d75c56a9753c 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 @@ -256,17 +256,23 @@ public class StorageUtil { } } - public static boolean sendContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull Document copy, @NotNull RoamingType type, boolean async) throws IOException { - if (!provider.isEnabled()) { + public static boolean sendContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull Document copy, @NotNull RoamingType type, boolean async) { + try { + return doSendContent(provider, fileSpec, copy, type, async); + } + catch (IOException e) { + LOG.warn(e); return false; } + } + public static boolean doSendContent(StreamProvider provider, String fileSpec, Document copy, RoamingType type, boolean async) throws IOException { // we should use standard line-separator (\n) - stream provider can share file content on any OS BufferExposingByteArrayOutputStream content = documentToBytes(copy, false); return provider.saveContent(fileSpec, content.getInternalBuffer(), content.size(), type, async); } - public static void logStateDiffInfo(Set> changedFiles, Set componentNames) throws IOException { + public static void logStateDiffInfo(Set> changedFiles, Set componentNames) { if (componentNames.isEmpty() || !(DUMP_COMPONENT_STATES || ApplicationManager.getApplication().isInternal())) { return; } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java index f82655297659..4f9ca8c8da6f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java @@ -468,7 +468,7 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { } try { - boolean result = StorageUtil.sendContent(streamProvider, myFileSpec, actualDocument, roamingType, true); + boolean result = StorageUtil.doSendContent(streamProvider, myFileSpec, actualDocument, roamingType, true); TObjectLongHashMap versions = loadVersions(actualDocument.getRootElement().getChildren(StorageData.COMPONENT)); if (!versions.isEmpty()) { Document versionDoc = new Document(StateStorageManagerImpl.createComponentVersionsXml(versions)); diff --git a/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerFactoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerFactoryImpl.java index 6473ed2b1fca..12e36f2363f7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerFactoryImpl.java @@ -47,8 +47,8 @@ public class SchemesManagerFactoryImpl extends SchemesManagerFactory implements if (baseDirPath != null) { - StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager().getStreamProviders(); - SchemesManagerImpl manager = new SchemesManagerImpl(fileSpec, processor, roamingType, providers, new File(baseDirPath)); + StreamProvider provider = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager().getStreamProvider(); + SchemesManagerImpl manager = new SchemesManagerImpl(fileSpec, processor, roamingType, provider, new File(baseDirPath)); myRegisteredManagers.add(manager); return manager; } diff --git a/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java index 3359920e5696..f02daffda795 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java @@ -69,7 +69,7 @@ public class SchemesManagerImpl processor, @NotNull RoamingType roamingType, - @NotNull StreamProvider[] providers, + @Nullable StreamProvider provider, @NotNull File baseDir) { myFileSpec = fileSpec; myProcessor = processor; myRoamingType = roamingType; - myProviders = providers; + myProvider = provider; myBaseDir = baseDir; if (processor instanceof SchemeExtensionProvider) { mySchemeExtension = ((SchemeExtensionProvider)processor).getSchemeExtension(); @@ -267,26 +267,27 @@ public class SchemesManagerImpl readDeletedSchemeNames() { - Collection result = new HashSet(); - for (StreamProvider provider : getEnabledProviders()) { - try { - Document deletedNameDoc = StorageUtil.loadDocument(provider.loadContent(getFileFullPath(DELETED_XML), myRoamingType)); - if (deletedNameDoc != null) { - for (Object child : deletedNameDoc.getRootElement().getChildren()) { - String deletedSchemeName = ((Element)child).getAttributeValue("name"); - if (deletedSchemeName != null) { - result.add(deletedSchemeName); - } + Collection result = new THashSet(); + if (myProvider == null || !myProvider.isEnabled()) { + return result; + } + + try { + Document deletedNameDoc = StorageUtil.loadDocument(myProvider.loadContent(getFileFullPath(DELETED_XML), myRoamingType)); + if (deletedNameDoc != null) { + for (Element child : deletedNameDoc.getRootElement().getChildren()) { + String deletedSchemeName = child.getAttributeValue("name"); + if (deletedSchemeName != null) { + result.add(deletedSchemeName); } } } - catch (Exception e) { - LOG.debug(e); - } + } + catch (Exception e) { + LOG.debug(e); } return result; - } private void initLoadedSchemes(final Collection read) { @@ -298,43 +299,44 @@ public class SchemesManagerImpl readSchemesFromProviders() { Collection result = new ArrayList(); - for (StreamProvider provider : getEnabledProviders()) { - for (String subPath : provider.listSubFiles(myFileSpec, myRoamingType)) { - if (!subPath.equals(DELETED_XML)) { - try { - final Document subDocument = StorageUtil.loadDocument(provider.loadContent(getFileFullPath(subPath), myRoamingType)); - if (subDocument != null) { - E scheme = readScheme(subDocument); - boolean fileRenamed = false; - T existing = findSchemeByName(scheme.getName()); - if (existing != null && existing instanceof ExternalizableScheme) { - String currentFileName = ((ExternalizableScheme)existing).getExternalInfo().getCurrentFileName(); - if (currentFileName != null && !currentFileName.equals(subPath)) { - deleteServerFiles(subPath); - subPath = currentFileName; - fileRenamed = true; - } + if (myProvider == null || !myProvider.isEnabled()) { + return result; + } - } - String fileName = checkFileNameIsFree(subPath, scheme.getName()); - - if (!fileRenamed && !fileName.equals(subPath)) { + for (String subPath : myProvider.listSubFiles(myFileSpec, myRoamingType)) { + if (!subPath.equals(DELETED_XML)) { + try { + final Document subDocument = StorageUtil.loadDocument(myProvider.loadContent(getFileFullPath(subPath), myRoamingType)); + if (subDocument != null) { + E scheme = readScheme(subDocument); + boolean fileRenamed = false; + T existing = findSchemeByName(scheme.getName()); + if (existing != null && existing instanceof ExternalizableScheme) { + String currentFileName = ((ExternalizableScheme)existing).getExternalInfo().getCurrentFileName(); + if (currentFileName != null && !currentFileName.equals(subPath)) { deleteServerFiles(subPath); + subPath = currentFileName; + fileRenamed = true; } + } + String fileName = checkFileNameIsFree(subPath, scheme.getName()); - if (scheme != null) { - loadScheme(scheme, false, fileName); - result.add(scheme); - } + if (!fileRenamed && !fileName.equals(subPath)) { + deleteServerFiles(subPath); + } + if (scheme != null) { + loadScheme(scheme, false, fileName); + result.add(scheme); } } - catch (Exception e) { - LOG.info("Cannot load data from IDEAServer: " + e.getLocalizedMessage()); - } + } + catch (Exception e) { + LOG.info("Cannot load data from IDEAServer: " + e.getLocalizedMessage()); } } } + return result; } @@ -556,15 +558,8 @@ public class SchemesManagerImpl> loadSharedSchemes(Collection currentSchemeList) { - StreamProvider[] providers = getProvidersForGlobal(); - if (providers.length == 0) { + StreamProvider provider = getProvider(); + if (provider == null || !provider.isEnabled()) { return Collections.emptyList(); } Collection names = new THashSet(getAllSchemeNames(currentSchemeList)); Map> result = new THashMap>(); - for (StreamProvider provider : providers) { - if (!provider.isEnabled()) { - continue; - } - - for (String subPath : provider.listSubFiles(myFileSpec, RoamingType.GLOBAL)) { - try { - final Document subDocument = StorageUtil.loadDocument(provider.loadContent(getFileFullPath(subPath), RoamingType.GLOBAL)); - if (subDocument != null) { - SharedSchemeData original = unwrap(subDocument); - final E scheme = myProcessor.readScheme(original.original); - if (!alreadyShared(subPath, currentSchemeList)) { - String schemeName = original.name; - String uniqueName = UniqueNameGenerator.generateUniqueName("[shared] " + schemeName, names); - renameScheme(scheme, uniqueName); - schemeName = uniqueName; - scheme.getExternalInfo().setOriginalPath(getFileFullPath(subPath)); - scheme.getExternalInfo().setIsImported(true); - result.put(schemeName, new SharedScheme(original.user == null ? "unknown" : original.user, original.description, scheme)); - } + for (String subPath : provider.listSubFiles(myFileSpec, RoamingType.GLOBAL)) { + try { + final Document subDocument = StorageUtil.loadDocument(provider.loadContent(getFileFullPath(subPath), RoamingType.GLOBAL)); + if (subDocument != null) { + SharedSchemeData original = unwrap(subDocument); + final E scheme = myProcessor.readScheme(original.original); + if (!alreadyShared(subPath, currentSchemeList)) { + String schemeName = original.name; + String uniqueName = UniqueNameGenerator.generateUniqueName("[shared] " + schemeName, names); + renameScheme(scheme, uniqueName); + schemeName = uniqueName; + scheme.getExternalInfo().setOriginalPath(getFileFullPath(subPath)); + scheme.getExternalInfo().setIsImported(true); + result.put(schemeName, new SharedScheme(original.user == null ? "unknown" : original.user, original.description, scheme)); } } - catch (Exception e) { - LOG.debug("Cannot load data from IDEAServer: " + e.getLocalizedMessage()); - } + } + catch (Exception e) { + LOG.debug("Cannot load data from IDEAServer: " + e.getLocalizedMessage()); } } @@ -699,25 +688,23 @@ public class SchemesManagerImpl schemes, final UniqueFileNamesProvider fileNameProvider) throws WriteExternalException { @@ -941,26 +914,11 @@ public class SchemesManagerImpl getEnabledProviders() { - ArrayList result = new ArrayList(); - for (StreamProvider provider : myProviders) { - if (provider.isEnabled()) { - result.add(provider); - } - } - return result; - } - private void reserveUsingFileNames(final Collection schemes, final UniqueFileNamesProvider fileNameProvider) { fileNameProvider.reserveFileName(DELETED_XML); diff --git a/platform/util/src/com/intellij/util/ObjectUtils.java b/platform/util/src/com/intellij/util/ObjectUtils.java index 8e5e52d94bd4..df1cb1c2e5c6 100644 --- a/platform/util/src/com/intellij/util/ObjectUtils.java +++ b/platform/util/src/com/intellij/util/ObjectUtils.java @@ -16,6 +16,7 @@ package com.intellij.util; import com.intellij.openapi.util.Condition; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,7 +39,7 @@ public class ObjectUtils { return t; } - @Nullable + @Contract("null, null -> null") public static T chooseNotNull(@Nullable T t1, @Nullable T t2) { return t1 == null? t2 : t1; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java index 388c68beab7b..f01922ce8577 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java @@ -25,18 +25,18 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.vcs.changes.CommitContext; import com.intellij.openapi.vfs.CharsetToolkit; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.*; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashSet; +import java.util.Collections; import java.util.List; public class CompoundShelfFileProcessor { private final String mySubdirName; - private final StreamProvider[] myServerStreamProviders; + private final StreamProvider myServerStreamProvider; private final String FILE_SPEC; private final String myShelfPath; @@ -44,20 +44,19 @@ public class CompoundShelfFileProcessor { public CompoundShelfFileProcessor(final String subdirName) { mySubdirName = subdirName; - myServerStreamProviders = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager().getStreamProviders(); + myServerStreamProvider = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager().getStreamProvider(); FILE_SPEC = "$ROOT_CONFIG$/" + subdirName + "/"; myShelfPath = PathManager.getConfigPath() + File.separator + mySubdirName; } - public CompoundShelfFileProcessor(final StreamProvider[] serverStreamProviders, final String shelfPath) { - myServerStreamProviders = serverStreamProviders; + public CompoundShelfFileProcessor(@Nullable StreamProvider serverStreamProvider, String shelfPath) { + myServerStreamProvider = serverStreamProvider; myShelfPath = shelfPath; mySubdirName = new File(myShelfPath).getName(); FILE_SPEC = "$ROOT_CONFIG$/" + mySubdirName + "/"; } - /* public void onWriteExternal() { if (myShelfPath != null) { @@ -98,39 +97,33 @@ public class CompoundShelfFileProcessor { } public Collection getServerFiles() { - Collection result = new LinkedHashSet(); - for (StreamProvider serverStreamProvider : myServerStreamProviders) { - if (serverStreamProvider.isEnabled()) { - ContainerUtil.addAll(result, serverStreamProvider.listSubFiles(FILE_SPEC, RoamingType.PER_USER)); - } + if (myServerStreamProvider == null || !myServerStreamProvider.isEnabled()) { + return Collections.emptyList(); } - return result; + return myServerStreamProvider.listSubFiles(FILE_SPEC, RoamingType.PER_USER); } public String copyFileFromServer(final String serverFileName, final List localFileNames) { - for (StreamProvider serverStreamProvider : myServerStreamProviders) { - if (serverStreamProvider.isEnabled()) { - try { - File file = new File(new File(myShelfPath), serverFileName); - if (!file.exists()) { - InputStream stream = serverStreamProvider.loadContent(FILE_SPEC + serverFileName, RoamingType.PER_USER); - if (stream != null) { - //noinspection ResultOfMethodCallIgnored - file.getParentFile().mkdirs(); - FileOutputStream out = new FileOutputStream(file); - try { - FileUtil.copy(stream, out); - } - finally { - out.close(); - stream.close(); - } + if (myServerStreamProvider != null && myServerStreamProvider.isEnabled()) { + try { + File file = new File(new File(myShelfPath), serverFileName); + if (!file.exists()) { + InputStream stream = myServerStreamProvider.loadContent(FILE_SPEC + serverFileName, RoamingType.PER_USER); + if (stream != null) { + //noinspection ResultOfMethodCallIgnored + file.getParentFile().mkdirs(); + FileOutputStream out = new FileOutputStream(file); + try { + FileUtil.copy(stream, out); + } + finally { + out.close(); + stream.close(); } } } - catch (IOException e) { - //ignore - } + } + catch (IOException ignored) { } } localFileNames.add(serverFileName); @@ -139,12 +132,9 @@ public class CompoundShelfFileProcessor { public String renameFileOnServer(final String serverFileName, final Collection serverFileNames, final Collection localFileNames) { String newName = getNewFileName(serverFileName, serverFileNames, localFileNames); - String oldFilePath = FILE_SPEC + serverFileName; - String newFilePath = FILE_SPEC + newName; - for (StreamProvider serverStreamProvider : myServerStreamProviders) { - renameFileOnProvider(newName, oldFilePath, newFilePath, serverStreamProvider); + if (myServerStreamProvider != null && myServerStreamProvider.isEnabled()) { + renameFileOnProvider(newName, FILE_SPEC + serverFileName, FILE_SPEC + newName, myServerStreamProvider); } - return newName; } @@ -205,7 +195,6 @@ public class CompoundShelfFileProcessor { } public void savePathFile(ContentProvider contentProvider, final File patchPath, CommitContext commitContext) throws IOException { - OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(patchPath), CharsetToolkit.UTF8_CHARSET); try { contentProvider.writeContentTo(writer, commitContext); @@ -214,13 +203,9 @@ public class CompoundShelfFileProcessor { writer.close(); } - - - for (StreamProvider serverStreamProvider : myServerStreamProviders) { - copyFileContentToProviders(FILE_SPEC + patchPath.getName(), serverStreamProvider, patchPath); + if (myServerStreamProvider != null && myServerStreamProvider.isEnabled()) { + copyFileContentToProviders(FILE_SPEC + patchPath.getName(), myServerStreamProvider, patchPath); } - - } public File getBaseIODir() { @@ -228,23 +213,16 @@ public class CompoundShelfFileProcessor { } public void saveFile(final File from, final File to) throws IOException { - for (StreamProvider serverStreamProvider : myServerStreamProviders) { - copyFileContentToProviders(FILE_SPEC + to.getName(), serverStreamProvider, from); + if (myServerStreamProvider != null && myServerStreamProvider.isEnabled()) { + copyFileContentToProviders(FILE_SPEC + to.getName(), myServerStreamProvider, from); } - - FileUtil.copy(from, to); - - } public void delete(final String name) { FileUtil.delete(new File(getBaseIODir(), name)); - for (StreamProvider serverStreamProvider : myServerStreamProviders) { - if (serverStreamProvider.isEnabled()) { - serverStreamProvider.deleteFile(FILE_SPEC + name, RoamingType.PER_USER); - } + if (myServerStreamProvider != null && myServerStreamProvider.isEnabled()) { + myServerStreamProvider.deleteFile(FILE_SPEC + name, RoamingType.PER_USER); } - } -} +} \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelfManagerConfigurationMerger.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelfManagerConfigurationMerger.java index dcf780288c3e..bfaead47ab3a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelfManagerConfigurationMerger.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelfManagerConfigurationMerger.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.WriteExternalException; import org.jdom.Attribute; import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import java.io.File; @@ -38,9 +39,9 @@ public class ShelfManagerConfigurationMerger implements XmlConfigurationMerger { } @TestOnly - public ShelfManagerConfigurationMerger(final String configPath, final StreamProvider[] streamProviders) { + public ShelfManagerConfigurationMerger(final String configPath, @Nullable StreamProvider streamProvider) { myConfigPath = configPath; - myFileProcessor = new CompoundShelfFileProcessor(streamProviders, configPath); + myFileProcessor = new CompoundShelfFileProcessor(streamProvider, configPath); } @Override diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java index 84d3428eb0e1..c213feb38c40 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java @@ -26,7 +26,6 @@ import com.intellij.lifecycle.PeriodicalTasksCloser; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.components.AbstractProjectComponent; -import com.intellij.openapi.components.impl.stores.StreamProvider; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.impl.patch.*; import com.intellij.openapi.diff.impl.patch.apply.ApplyFilePatchBase; @@ -87,7 +86,7 @@ public class ShelveChangesManager extends AbstractProjectComponent implements JD super(project); myBus = bus; if (project.isDefault()) { - myFileProcessor = new CompoundShelfFileProcessor(StreamProvider.EMPTY_ARRAY, PathManager.getConfigPath() + File.separator + "shelf"); + myFileProcessor = new CompoundShelfFileProcessor(null, PathManager.getConfigPath() + File.separator + "shelf"); } else { myFileProcessor = new CompoundShelfFileProcessor("shelf");