@Override public void saveChangedProjectFile(@Nonnull VirtualFile file, @Nonnull Project project) { StateStorageManager storageManager = ((ProjectEx)project).getStateStore().getStateStorageManager(); String fileSpec = storageManager.collapseMacros(file.getPath()); Couple<Collection<FileBasedStorage>> storages = storageManager.getCachedFileStateStorages(Collections.singletonList(fileSpec), Collections.<String>emptyList()); FileBasedStorage storage = ContainerUtil.getFirstItem(storages.first); // if empty, so, storage is not yet loaded, so, we don't have to reload if (storage != null) { registerProjectToReload(project, file, storage); } }
public ClasspathStorage(@NotNull final Module module, @NotNull StateStorageManager storageManager) { String storageType = module.getOptionValue(JpsProjectLoader.CLASSPATH_ATTRIBUTE); if (storageType == null) { throw new IllegalStateException("Classpath storage requires non-default storage type"); } ClasspathStorageProvider provider = getProvider(storageType); if (provider == null) { throw new IllegalStateException("Classpath storage provider not found, please ensure that Eclipse plugin is installed"); } myConverter = provider.createConverter(module); myPathMacroSubstitutor = storageManager.getMacroSubstitutor(); final List<String> paths = myConverter.getFilePaths(); MessageBusConnection busConnection = module.getMessageBus().connect(); busConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { if (!event.isFromRefresh() || !(event instanceof VFileContentChangeEvent)) { continue; } for (String path : paths) { if (path.equals(event.getPath())) { module.getMessageBus().syncPublisher(StateStorageManager.STORAGE_TOPIC).storageFileChanged(event, ClasspathStorage.this, module); return; } } } } }); busConnection.subscribe(StateStorageManager.STORAGE_TOPIC, new StorageManagerListener() { private String fileNameToModuleName(@NotNull String fileName) { return fileName.substring(0, fileName.length() - ModuleFileType.DOT_DEFAULT_EXTENSION.length()); } @Override public void storageFileChanged(@NotNull VFileEvent event, @NotNull StateStorage storage, @NotNull ComponentManager componentManager) { assert componentManager == module; if (!(event instanceof VFilePropertyChangeEvent)) { return; } VFilePropertyChangeEvent propertyEvent = (VFilePropertyChangeEvent)event; if (propertyEvent.getPropertyName().equals(VirtualFile.PROP_NAME)) { String oldFileName = (String)propertyEvent.getOldValue(); if (oldFileName.endsWith(ModuleFileType.DOT_DEFAULT_EXTENSION)) { ClasspathStorageProvider provider = getProvider(ClassPathStorageUtil.getStorageType(module)); if (provider != null) { provider.moduleRenamed(module, fileNameToModuleName(oldFileName), fileNameToModuleName((String)propertyEvent.getNewValue())); } } } } }); }
@NotNull @Override public StateStorageManager getStateStorageManager() { throw new UnsupportedOperationException("Method getStateStorageManager not implemented in " + getClass()); }
@Nonnull @Override public StateStorageManager getStateStorageManager() { throw new UnsupportedOperationException("Method getStateStorageManager not implemented in " + getClass()); }
public ExternalStorageStreamProvider(ExternalStorage storage, StateStorageManager stateStorageManager) { myStorage = storage; myStateStorageManager = stateStorageManager; }
LoadItem(String fileSpec, RoamingType roamingType, int modCount, StateStorageManager stateStorageManager) { myFileSpec = fileSpec; myRoamingType = roamingType; myModCount = modCount; myStateStorageManager = stateStorageManager; }
@Nonnull public static MultiMap<File, ExportableItem> getExportableComponentsMap(final boolean onlyExisting) { final MultiMap<File, ExportableItem> result = MultiMap.createLinkedSet(); ApplicationImpl application = (ApplicationImpl)ApplicationManager.getApplication(); final StateStorageManager storageManager = application.getStateStore().getStateStorageManager(); ServiceManagerImpl.processAllImplementationClasses(application, (aClass, pluginDescriptor) -> { State stateAnnotation = aClass.getAnnotation(State.class); if (stateAnnotation != null && !StringUtil.isEmpty(stateAnnotation.name())) { int storageIndex; Storage[] storages = stateAnnotation.storages(); if (storages.length == 1) { storageIndex = 0; } else if (storages.length > 1) { storageIndex = storages.length - 1; } else { return true; } Storage storage = storages[storageIndex]; if (storage.roamingType() != RoamingType.DISABLED) { String fileSpec = storageManager.buildFileSpec(storage); if (!fileSpec.startsWith(StoragePathMacros.APP_CONFIG)) { return true; } File file = new File(storageManager.expandMacros(fileSpec)); File additionalExportFile = null; if (!StringUtil.isEmpty(stateAnnotation.additionalExportFile())) { additionalExportFile = new File(storageManager.expandMacros(stateAnnotation.additionalExportFile())); if (onlyExisting && !additionalExportFile.exists()) { additionalExportFile = null; } } boolean fileExists = !onlyExisting || file.exists(); if (fileExists || additionalExportFile != null) { File[] files; if (additionalExportFile == null) { files = new File[]{file}; } else { files = fileExists ? new File[]{file, additionalExportFile} : new File[]{additionalExportFile}; } ExportableItem item = new ExportableItem(files, getComponentPresentableName(stateAnnotation, aClass, pluginDescriptor)); result.putValue(file, item); if (additionalExportFile != null) { result.putValue(additionalExportFile, item); } } } } return true; }); return result; }
@Override public void beforeApplicationLoaded(Application application) { ApplicationEx2 applicationEx = (ApplicationEx2)application; IApplicationStore stateStore = applicationEx.getStateStore(); StateStorageManager stateStorageManager = stateStore.getStateStorageManager(); ExternalStorage storage = new ExternalStorage(); stateStorageManager.setStreamProvider(new ExternalStorageStreamProvider(storage, stateStorageManager)); }
void wantLoad(@Nonnull String fileSpec, @Nonnull RoamingType roamingType, int mod, @Nonnull StateStorageManager stateStorageManager) { myLoadTask.cancel(false); myLoadItems.add(new LoadItem(fileSpec, roamingType, mod, stateStorageManager)); myLoadTask = AppExecutorUtil.getAppScheduledExecutorService().schedule(this::executeLoad, 1, TimeUnit.MINUTES); }