synchronized void clearPointerCaches(String url, VirtualFilePointerListener listener) { TreeMap<String, VirtualFilePointerImpl> urlToPointer = myUrlToPointerMaps.get(listener); if (urlToPointer == null && ApplicationManager.getApplication().isUnitTestMode()) return; assert urlToPointer != null; urlToPointer.remove(VfsUtil.urlToPath(url)); if (urlToPointer.isEmpty()) { myUrlToPointerMaps.remove(listener); } }
@Override public void after(@NotNull final List<? extends VFileEvent> events) { cleanContainerCaches(); if (myUrlsToUpdate == null) { return; } for (String url : myUrlsToUpdate) { synchronized (VirtualFilePointerManagerImpl.this) { for (TreeMap<String, VirtualFilePointerImpl> urlToPointer : myUrlToPointerMaps.values()) { VirtualFilePointerImpl pointer = urlToPointer.remove(url); if (pointer != null) { String path = VfsUtil.urlToPath(pointer.getUrl()); urlToPointer.put(path, pointer); } } } } for (VirtualFilePointer pointer : myPointersToUpdate) { ((VirtualFilePointerImpl) pointer).update(); } for (EventDescriptor event : myEvents) { event.fireAfter(); } if (!myPointersToUpdate.isEmpty()) { VirtualFilePointer[] arr = myPointersToUpdate.toArray(new VirtualFilePointer[myPointersToUpdate.size()]); myBus.syncPublisher(VirtualFilePointerListener.TOPIC).validityChanged(arr); } myUrlsToUpdate = null; myEvents = null; myPointersToUpdate = null; }
@Nullable public static String findResourcesCacheDirectory( @NotNull Module module, boolean createIfNotFound, @Nullable CompileContext context) { final Project project = module.getProject(); final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(project); if (extension == null) { if (context != null) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot get compiler settings for project " + project.getName(), null, -1, -1); } return null; } final String projectOutputDirUrl = extension.getCompilerOutputUrl(); if (projectOutputDirUrl == null) { if (context != null) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot find output directory for project " + project.getName(), null, -1, -1); } return null; } final String pngCacheDirPath = VfsUtil.urlToPath(projectOutputDirUrl) + '/' + RESOURCES_CACHE_DIR_NAME + '/' + module.getName(); final String pngCacheDirOsPath = FileUtil.toSystemDependentName(pngCacheDirPath); final File pngCacheDir = new File(pngCacheDirOsPath); if (pngCacheDir.exists()) { if (pngCacheDir.isDirectory()) { return pngCacheDirOsPath; } else { if (context != null) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot create directory " + pngCacheDirOsPath + " because file already exists", null, -1, -1); } return null; } } if (!createIfNotFound) { return null; } if (!pngCacheDir.mkdirs()) { if (context != null) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot create directory " + pngCacheDirOsPath, null, -1, -1); } return null; } return pngCacheDirOsPath; }