private void registerProjectToReload(@Nullable final Project project, final VirtualFile cause, @Nullable final StateStorage storage) { if (LOG.isDebugEnabled()) { LOG.debug("[RELOAD] Registering project to reload: " + cause, new Exception()); } if (project != null) { synchronized (myChangedProjectFiles) { List<Pair<VirtualFile, StateStorage>> changedProjectFiles = myChangedProjectFiles.get(project); if (changedProjectFiles == null) { changedProjectFiles = new ArrayList<Pair<VirtualFile, StateStorage>>(); myChangedProjectFiles.put(project, changedProjectFiles); } changedProjectFiles.add(new Pair<VirtualFile, StateStorage>(cause, storage)); } } else { myChangedApplicationFiles.add(new Pair<VirtualFile, StateStorage>(cause, storage)); } myChangedFilesAlarm.cancelAllRequests(); myChangedFilesAlarm.addRequest(new Runnable() { @Override public void run() { LOG.debug("[RELOAD] Scheduling reload application & project, myReloadBlockCount = " + myReloadBlockCount); if (myReloadBlockCount.get() == 0) { scheduleReloadApplicationAndProject(); } } }, 444); }
public CompoundSaveSession(final CompoundExternalizationSession compoundExternalizationSession) { final Collection<StateStorage> stateStorages = compoundExternalizationSession.getStateStorages(); for (StateStorage stateStorage : stateStorages) { mySaveSessions.put(stateStorage, stateStorage.startSave(compoundExternalizationSession.getExternalizationSession(stateStorage))); } }
public List<IFile> getAllStorageFilesToSave() throws StateStorageException { List<IFile> result = new ArrayList<IFile>(); for (StateStorage stateStorage : mySaveSessions.keySet()) { final StateStorage.SaveSession saveSession = mySaveSessions.get(stateStorage); result.addAll(saveSession.getStorageFilesToSave()); } return result; }
public void finishSave() { RuntimeException re = null; for (StateStorage stateStorage : mySaveSessions.keySet()) { final StateStorage.SaveSession saveSession = mySaveSessions.get(stateStorage); try { stateStorage.finishSave(saveSession); } catch(RuntimeException t) { re = t; } } if (re != null) { throw re; } }
public List<IFile> getAllStorageFiles() { List<IFile> result = new ArrayList<IFile>(); for (StateStorage.SaveSession saveSession : mySaveSessions.values()) { result.addAll(saveSession.getAllStorageFiles()); } return result; }
@NotNull public StateStorage.ExternalizationSession getExternalizationSession(@NotNull StateStorage stateStore) { StateStorage.ExternalizationSession session = mySessions.get(stateStore); if (session == null) { mySessions.put(stateStore, session = stateStore.startExternalization()); } return session; }
public void testSetStateOverridesOldState() throws Exception { MyXmlElementStorage storage = new MyXmlElementStorage(document(tag("root", tag("component", attr("name", "test"), tag("foo")))), myParentDisposable); Element newState = tag("component", attr("name", "test"), tag("bar")); StateStorage.ExternalizationSession externalizationSession = storage.startExternalization(); externalizationSession.setState(this, "test", newState, null); storage.startSave(externalizationSession).save(); assertNotNull(storage.mySavedDocument); assertNotNull(storage.mySavedDocument.getRootElement().getChild("component").getChild("bar")); assertNull(storage.mySavedDocument.getRootElement().getChild("component").getChild("foo")); }
@Override @Nullable public Set<String> analyzeExternalChanges(@NotNull final Set<Pair<VirtualFile,StateStorage>> changedFiles) { final Set<String> result = super.analyzeExternalChanges(changedFiles); if (result == null) return null; for (SaveSession moduleSaveSession : myModuleSaveSessions) { final Set<String> s = moduleSaveSession.analyzeExternalChanges(changedFiles); if (s == null) return null; result.addAll(s); } return result; }
public void testSetStateOverridesOldState() throws Exception { MyXmlElementStorage storage = new MyXmlElementStorage(tag("root", tag("component", attr("name", "test"), tag("foo")))); Element newState = tag("component", attr("name", "test"), tag("bar")); StateStorage.ExternalizationSession externalizationSession = storage.startExternalization(); externalizationSession.setState(this, "test", newState, null); externalizationSession.createSaveSession().save(); assertNotNull(storage.mySavedElement); assertNotNull(storage.mySavedElement.getChild("component").getChild("bar")); assertNull(storage.mySavedElement.getChild("component").getChild("foo")); }
public ReadOnlyModificationException(@NotNull VirtualFile file, @Nullable Throwable cause, StateStorage.SaveSession session) { super(cause); myFile = file; mySession = session; }
@Nullable public StateStorage.SaveSession getSession() { return mySession; }
@NotNull StateStorage.ExternalizationSession startExternalization();
@Nullable @Override public StateStorage.SaveSession createSaveSession() { return modifiedContent.isEmpty() && deletedContent.isEmpty() ? null : this; }
@Override public boolean reload(@NotNull final Set<Pair<VirtualFile,StateStorage>> changedFiles) { throw new UnsupportedOperationException("Method reload not implemented in " + getClass()); }
private void saveChangedProjectFile(final VirtualFile file, @Nullable final Project project, final StateStorage storage) { if (file.exists()) { copyToTemp(file); } registerProjectToReload(project, file, storage); }
public void save() throws StateStorageException { for (StateStorage.SaveSession saveSession : mySaveSessions.values()) { saveSession.save(); } }
public StateStorage.SaveSession getSaveSession(final StateStorage storage) { return mySaveSessions.get(storage); }
@NotNull public Collection<StateStorage> getStateStorages() { return mySessions.keySet(); }
boolean reload(@NotNull Set<Pair<VirtualFile, StateStorage>> changedFiles, @NotNull Collection<String> notReloadableComponents) throws StateStorageException, IOException;
@Nullable Set<String> analyzeExternalChanges(@NotNull Set<Pair<VirtualFile,StateStorage>> changedFiles);
public void testCreateFileStateStorageMacroSubstituted() { StateStorage data = myStateStorageManager.getFileStateStorage("$MACRO1$/test.xml"); assertThat(data, is(notNullValue())); }
public void testCreateFileStateStorageMacroSubstitutedWhenExpansionHas$() { myStateStorageManager.addMacro("DOLLAR_MACRO", "/temp/d$"); StateStorage data = myStateStorageManager.getFileStateStorage("$DOLLAR_MACRO$/test.xml"); assertThat(data, is(notNullValue())); }
@Override @Nullable public Set<String> analyzeExternalChanges(@NotNull final Set<Pair<VirtualFile, StateStorage>> changedFiles) { return null; }
@Override public void save(@Nonnull List<Pair<StateStorage.SaveSession, VirtualFile>> readonlyFiles) { throw new UnsupportedOperationException(); }
@Nullable @Override public Collection<String> reload(@Nonnull Collection<? extends StateStorage> changedStorages) { return null; }
public void testCreateFileStateStorageMacroSubstituted() { StateStorage data = myStateStorageManager.getStateStorage("$MACRO1$/test.xml", RoamingType.PER_USER); assertThat(data, is(notNullValue())); }
public void testCreateFileStateStorageMacroSubstitutedWhenExpansionHas$() { myStateStorageManager.addMacro("$DOLLAR_MACRO$", "/temp/d$"); StateStorage data = myStateStorageManager.getStateStorage("$DOLLAR_MACRO$/test.xml", RoamingType.PER_USER); assertThat(data, is(notNullValue())); }
public static boolean isChangedByStorageOrSaveSession(@Nonnull VirtualFileEvent event) { return event.getRequestor() instanceof StateStorage.SaveSession || event.getRequestor() instanceof StateStorage; }
@Nonnull @Override protected StateStorage.Listener createStorageTopicListener() { return myProject.getMessageBus().syncPublisher(StateStorage.PROJECT_STORAGE_TOPIC); }
@Nonnull ComponentSaveSession save(@Nonnull List<Pair<StateStorage.SaveSession, VirtualFile>> readonlyFiles);
/** * null if reloaded * empty list if nothing to reload * list of not reloadable components (reload is not performed) */ @Nullable Collection<String> reload(@Nonnull Collection<? extends StateStorage> changedStorages);
void save(@NotNull List<Pair<StateStorage.SaveSession, VirtualFile>> readonlyFiles);
boolean reload(@NotNull Set<Pair<VirtualFile,StateStorage>> changedFiles) throws StateStorageException, IOException;
void save(@Nonnull List<Pair<StateStorage.SaveSession, VirtualFile>> readonlyFiles);