private Collection<String> readDeletedSchemeNames() { Collection<String> result = new HashSet<String>(); 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); } } } } catch (Exception e) { LOG.debug(e); } } return result; }
public void exportScheme(final E scheme, final String name, final String description) throws WriteExternalException, IOException { final StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager() .getStreamProviders(RoamingType.GLOBAL); if (providers != null) { Document document = myProcessor.writeScheme(scheme); if (document != null) { Document wrapped = wrap(document, name, description); for (StreamProvider provider : providers) { if (provider instanceof CurrentUserHolder) { wrapped = (Document)wrapped.clone(); String userName = ((CurrentUserHolder)provider).getCurrentUserName(); if (userName != null) { wrapped.getRootElement().setAttribute(USER, userName); } } StorageUtil.sendContent(provider, getFileFullPath(UniqueFileNamesProvider.convertName(scheme.getName())) + mySchemeExtension, wrapped, RoamingType.GLOBAL, false); } } } }
public FileTemplateManagerImpl(@Nonnull FileTypeManagerEx typeManager, FileTemplateSettings projectSettings, ExportableFileTemplateSettings defaultSettings, /*need this to ensure disposal of the service _after_ project manager*/ @SuppressWarnings("UnusedParameters") ProjectManager pm, final Project project) { myTypeManager = typeManager; myProjectSettings = projectSettings; myDefaultSettings = defaultSettings; myProject = project; myProjectScheme = project.isDefault() ? null : new FileTemplatesScheme("Project") { @Nonnull @Override public String getTemplatesDir() { return FileUtilRt.toSystemDependentName(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR); } @Nonnull @Override public Project getProject() { return project; } }; }
protected FileTemplatesLoader(@Nonnull FileTypeManagerEx typeManager, @Nullable Project project) { myTypeManager = typeManager; File configDir = project == null || project.isDefault() ? new File(PathManager.getConfigPath(), TEMPLATES_DIR) : new File(UriUtil.trimTrailingSlashes(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR)); myDefaultTemplatesManager = new FTManager(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, configDir); myInternalTemplatesManager = new FTManager(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, new File(configDir, INTERNAL_DIR), true); myPatternsManager = new FTManager(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, new File(configDir, INCLUDES_DIR)); myCodeTemplatesManager = new FTManager(FileTemplateManager.CODE_TEMPLATES_CATEGORY, new File(configDir, CODE_TEMPLATES_DIR)); myJ2eeTemplatesManager = new FTManager(FileTemplateManager.J2EE_TEMPLATES_CATEGORY, new File(configDir, J2EE_TEMPLATES_DIR)); myAllManagers = new FTManager[]{myDefaultTemplatesManager, myInternalTemplatesManager, myPatternsManager, myCodeTemplatesManager, myJ2eeTemplatesManager}; myDirToManagerMap.put("", myDefaultTemplatesManager); myDirToManagerMap.put(INTERNAL_DIR + "/", myInternalTemplatesManager); myDirToManagerMap.put(INCLUDES_DIR + "/", myPatternsManager); myDirToManagerMap.put(CODE_TEMPLATES_DIR + "/", myCodeTemplatesManager); myDirToManagerMap.put(J2EE_TEMPLATES_DIR + "/", myJ2eeTemplatesManager); loadDefaultTemplates(); for (FTManager manager : myAllManagers) { manager.loadCustomizedContent(); } }
@Override public void apply() throws ConfigurationException { myEditor.commit(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { StorageUtil.checkUnknownMacros(project, false); } }
@Override public void save() throws IOException { CachedXmlDocumentSet fileSet = EclipseClasspathStorageProvider.getFileCache(module); AccessToken token = WriteAction.start(); try { for (String key : modifiedContent.keySet()) { Element content = modifiedContent.get(key); String path = fileSet.getParent(key) + '/' + key; Writer writer = new OutputStreamWriter(StorageUtil.getOrCreateVirtualFile(this, new File(path)).getOutputStream(this), CharsetToolkit.UTF8_CHARSET); try { EclipseJDOMUtil.output(content, writer, module.getProject()); } finally { writer.close(); } } if (deletedContent.isEmpty()) { return; } for (String deleted : deletedContent) { VirtualFile file = fileSet.getFile(deleted, false); if (file != null) { try { file.delete(this); } catch (IOException ignore) { } } } deletedContent.clear(); } finally { token.finish(); } }
@Nullable private static Document loadGlobalScheme(final String schemePath) throws IOException { final StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager() .getStreamProviders(RoamingType.GLOBAL); for (StreamProvider provider : providers) { if (provider.isEnabled()) { Document document = StorageUtil.loadDocument(provider.loadContent(schemePath, RoamingType.GLOBAL)); if (document != null) return document; } } return null; }
private void saveIfNeeded(E schemeKey, String fileName, Document document, long newHash, Long oldHash) throws IOException { if (oldHash == null || newHash != oldHash.longValue() || myVFSBaseDir.findChild(fileName) == null) { byte[] text = StorageUtil.printDocument(document); ensureFileText(fileName, text); schemeKey.getExternalInfo().setHash(newHash); saveFileName(fileName, schemeKey); saveOnServer(fileName, document); } }
private void saveOnServer(final String fileName, final Document document) { for (StreamProvider provider : getEnabledProviders()) { try { StorageUtil.sendContent(provider, getFileFullPath(fileName), document, myRoamingType, true); } catch (IOException e) { LOG.debug(e); } } }
@Override public boolean openProject(@NotNull final Project project) { if (isLight(project)) { ((ProjectImpl)project).setTemporarilyDisposed(false); boolean isInitialized = StartupManagerEx.getInstanceEx(project).startupActivityPassed(); if (isInitialized) { addToOpened(project); // events already fired return true; } } if (!addToOpened(project)) { return false; } fireProjectOpened(project); DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() { @Override public void run() { DumbService.getInstance(project).queueTask(new DumbModeTask() { @Override public void performInDumbMode(@NotNull ProgressIndicator indicator) { waitForFileWatcher(indicator); } @Override public String toString() { return "wait for file watcher"; } }); } }); final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project); boolean ok = myProgressManager.runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { startupManager.runStartupActivities(); // dumb mode should start before post-startup activities // only when startCacheUpdate is called from UI thread, we can guarantee that // when the method returns, the application has entered dumb mode UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { startupManager.startCacheUpdate(); } }); startupManager.runPostStartupActivitiesFromExtensions(); UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (!project.isDisposed()) { startupManager.runPostStartupActivities(); Application application = ApplicationManager.getApplication(); if (!(application.isHeadlessEnvironment() || application.isUnitTestMode())) { StorageUtil.checkUnknownMacros(project, true); } } } }); } }, ProjectBundle.message("project.load.progress"), canCancelProjectLoading(), project); if (!ok) { closeProject(project, false, false, true); notifyProjectOpenFailed(); return false; } return true; }
@Override public boolean openProject(final Project project) { if (isLight(project)) { throw new AssertionError("must not open light project"); } final Application application = ApplicationManager.getApplication(); if (!application.isUnitTestMode() && !((ProjectEx)project).getStateStore().checkVersion()) { return false; } synchronized (myOpenProjects) { if (myOpenProjects.contains(project)) { return false; } myOpenProjects.add(project); cacheOpenProjects(); } fireProjectOpened(project); final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project); waitForFileWatcher(project); boolean ok = myProgressManager.runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { startupManager.runStartupActivities(); // dumb mode should start before post-startup activities // only when startCacheUpdate is called from UI thread, we can guarantee that // when the method returns, the application has entered dumb mode UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { startupManager.startCacheUpdate(); } }); startupManager.runPostStartupActivitiesFromExtensions(); UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { startupManager.runPostStartupActivities(); } }); } }, ProjectBundle.message("project.load.progress"), true, project); if (!ok) { closeProject(project, false, false, true); notifyProjectOpenFailed(); return false; } if (!application.isHeadlessEnvironment() && !application.isUnitTestMode()) { // should be invoked last startupManager.runWhenProjectIsInitialized(new Runnable() { @Override public void run() { final TrackingPathMacroSubstitutor macroSubstitutor = ((ProjectEx)project).getStateStore().getStateStorageManager().getMacroSubstitutor(); if (macroSubstitutor != null) { StorageUtil.notifyUnknownMacros(macroSubstitutor, project, null); } } }); } return true; }
private Collection<E> readSchemesFromProviders() { Collection<E> result = new ArrayList<E>(); for (StreamProvider provider : getEnabledProviders()) { String[] paths = provider.listSubFiles(myFileSpec); for (String subpath : paths) { 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; } } String fileName = checkFileNameIsFree(subpath, scheme.getName()); 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()); } } } } return result; }
@NotNull public Collection<SharedScheme<E>> loadSharedSchemes(Collection<T> currentSchemeList) { Collection<String> names = new HashSet<String>(getAllSchemeNames(currentSchemeList)); final StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager() .getStreamProviders(RoamingType.GLOBAL); final HashMap<String, SharedScheme<E>> result = new HashMap<String, SharedScheme<E>>(); if (providers != null) { for (StreamProvider provider : providers) { if (provider.isEnabled()) { String[] paths = provider.listSubFiles(myFileSpec); for (String subpath : paths) { 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<E>(original.user == null ? "unknown" : original.user, original.description, scheme)); } } } catch (Exception e) { LOG.debug("Cannot load data from IDEAServer: " + e.getLocalizedMessage()); } } } } } for (SharedScheme<E> t : result.values()) { myProcessor.initScheme(t.getScheme()); } return result.values(); }
private void projectStorageFileChanged(@Nonnull VirtualFileEvent event, @Nonnull StateStorage storage, @Nullable Project project) { VirtualFile file = event.getFile(); if (!StorageUtil.isChangedByStorageOrSaveSession(event) && !(event.getRequestor() instanceof ProjectManagerImpl)) { registerProjectToReload(project, file, storage); } }
@Override public boolean openProject(@Nonnull final Project project, @Nonnull UIAccess uiAccess) { if (isLight(project)) { ((ProjectImpl)project).setTemporarilyDisposed(false); boolean isInitialized = StartupManagerEx.getInstanceEx(project).startupActivityPassed(); if (isInitialized) { addToOpened(project); // events already fired return true; } } for (Project p : getOpenProjects()) { if (ProjectUtil.isSameProject(project.getProjectFilePath(), p)) { GuiUtils.invokeLaterIfNeeded(() -> ProjectUtil.focusProjectWindow(p, false), ModalityState.NON_MODAL); return false; } } if (!addToOpened(project)) { return false; } Runnable process = () -> { TransactionGuard.getInstance().submitTransactionAndWait(() -> fireProjectOpened(project)); final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project); startupManager.runStartupActivities(); // Startup activities (e.g. the one in FileBasedIndexProjectHandler) have scheduled dumb mode to begin "later" // Now we schedule-and-wait to the same event queue to guarantee that the dumb mode really begins now: // Post-startup activities should not ever see unindexed and at the same time non-dumb state TransactionGuard.getInstance().submitTransactionAndWait(startupManager::startCacheUpdate); startupManager.runPostStartupActivitiesFromExtensions(uiAccess); GuiUtils.invokeLaterIfNeeded(() -> { if (!project.isDisposed()) { startupManager.runPostStartupActivities(); Application application = ApplicationManager.getApplication(); if (!application.isHeadlessEnvironment() && !application.isUnitTestMode()) { final TrackingPathMacroSubstitutor macroSubstitutor = ((ProjectEx)project).getStateStore().getStateStorageManager().getMacroSubstitutor(); if (macroSubstitutor != null) { StorageUtil.notifyUnknownMacros(macroSubstitutor, project, null); } } if (ApplicationManager.getApplication().isActive()) { JFrame projectFrame = WindowManager.getInstance().getFrame(project); if (projectFrame != null) { IdeFocusManager.getInstance(project).requestFocus(projectFrame, true); } } } }, ModalityState.NON_MODAL); }; ProgressIndicator indicator = myProgressManager.getProgressIndicator(); if (indicator != null) { indicator.setText("Preparing workspace..."); process.run(); return true; } boolean ok = myProgressManager.runProcessWithProgressSynchronously(process, ProjectBundle.message("project.load.progress"), canCancelProjectLoading(), project); if (!ok) { closeProject(project, false, false, true); notifyProjectOpenFailed(); return false; } return true; }
private void deleteServerFile(@Nonnull String path) { if (myProvider != null && myProvider.isEnabled()) { StorageUtil.delete(myProvider, getFileFullPath(path), myRoamingType); } }