com.intellij.openapi.vfs.newvfs.RefreshQueue Java Examples

The following examples show how to use com.intellij.openapi.vfs.newvfs.RefreshQueue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DesktopSaveAndSyncHandlerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void refreshOpenFiles() {
  List<VirtualFile> files = ContainerUtil.newArrayList();

  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    for (VirtualFile file : FileEditorManager.getInstance(project).getSelectedFiles()) {
      if (file instanceof NewVirtualFile) {
        files.add(file);
      }
    }
  }

  if (!files.isEmpty()) {
    // refresh open files synchronously so it doesn't wait for potentially longish refresh request in the queue to finish
    RefreshQueue.getInstance().refresh(false, false, null, files);
  }
}
 
Example #2
Source File: BlazeIntegrationTestCase.java    From intellij with Apache License 2.0 6 votes vote down vote up
@After
public final void tearDown() throws Exception {
  if (!isLightTestCase()) {
    // Workaround to avoid a platform race condition that occurs when we delete a VirtualDirectory
    // whose children were affected by external file system events that RefreshQueue is still
    // processing. We only need this for heavy test cases, since light test cases perform all file
    // operations synchronously through an in-memory file system.
    // See https://youtrack.jetbrains.com/issue/IDEA-218773
    RefreshSession refreshSession = RefreshQueue.getInstance().createSession(false, true, null);
    refreshSession.addFile(fileSystem.findFile(workspaceRoot.directory().getPath()));
    refreshSession.launch();
  }
  SyncCache.getInstance(getProject()).clear();
  runWriteAction(
      () -> {
        ProjectJdkTable table = ProjectJdkTable.getInstance();
        for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
          table.removeJdk(sdk);
        }
      });
  testFixture.tearDown();
  testFixture = null;
}
 
Example #3
Source File: DesktopSaveAndSyncHandlerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void maybeRefresh(@Nonnull ModalityState modalityState) {
  if (myBlockSyncOnFrameActivationCount.get() == 0 && mySettings.isSyncOnFrameActivation()) {
    RefreshQueue queue = RefreshQueue.getInstance();
    queue.cancelSession(myRefreshSessionId);

    RefreshSession session = queue.createSession(true, true, null, modalityState);
    session.addAllFiles(ManagingFS.getInstance().getLocalRoots());
    myRefreshSessionId = session.getId();
    session.launch();
    LOG.debug("vfs refreshed");
  }
  else if (LOG.isDebugEnabled()) {
    LOG.debug("vfs refresh rejected, blocked: " + (myBlockSyncOnFrameActivationCount.get() != 0)
              + ", isSyncOnFrameActivation: " + mySettings.isSyncOnFrameActivation());
  }
}
 
Example #4
Source File: UnindexedFilesUpdater.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void scheduleInitialVfsRefresh() {
  ProjectRootManagerEx.getInstanceEx(myProject).markRootsForRefresh();

  Application app = ApplicationManager.getApplication();
  if (!app.isCommandLine()) {
    long sessionId = VirtualFileManager.getInstance().asyncRefresh(null);
    MessageBusConnection connection = app.getMessageBus().connect();
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
      @Override
      public void projectClosed(@Nonnull Project project, @Nonnull UIAccess uiAccess) {
        if (project == myProject) {
          RefreshQueue.getInstance().cancelSession(sessionId);
          connection.disconnect();
        }
      }
    });
  }
  else {
    VirtualFileManager.getInstance().syncRefresh();
  }
}
 
Example #5
Source File: VirtualDirectoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private VirtualFileSystemEntry findChild(@Nonnull String name, boolean doRefresh, boolean ensureCanonicalName, @Nonnull NewVirtualFileSystem delegate) {
  boolean caseSensitive = delegate.isCaseSensitive();
  VirtualFileSystemEntry result = doFindChild(name, ensureCanonicalName, delegate, caseSensitive);

  //noinspection UseVirtualFileEquals
  if (result == NULL_VIRTUAL_FILE) {
    result = doRefresh ? createAndFindChildWithEventFire(name, delegate) : null;
  }
  else if (result != null && doRefresh && delegate.isDirectory(result) != result.isDirectory()) {
    RefreshQueue.getInstance().refresh(false, false, null, result);
    result = findChild(name, false, ensureCanonicalName, delegate);
  }

  return result;
}
 
Example #6
Source File: FileRefresher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void dispose() {
  LOG.debug("dispose");
  if (!disposed.getAndSet(true)) {
    synchronized (watchers) {
      watchers.forEach(this::unwatch);
      watchers.clear();
    }
    RefreshSession session;
    synchronized (files) {
      files.clear();
      session = this.session;
      this.session = null;
    }
    if (session != null) RefreshQueue.getInstance().cancelSession(session.getId());
  }
}
 
Example #7
Source File: LocalFileSystemImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void refreshWithoutFileWatcher(final boolean asynchronous) {
  Runnable heavyRefresh = () -> {
    for (VirtualFile root : myManagingFS.getRoots(this)) {
      ((NewVirtualFile)root).markDirtyRecursively();
    }
    refresh(asynchronous);
  };

  if (asynchronous && myWatcher.isOperational()) {
    RefreshQueue.getInstance().refresh(true, true, heavyRefresh, myManagingFS.getRoots(this));
  }
  else {
    heavyRefresh.run();
  }
}
 
Example #8
Source File: LocalFileSystemBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void refreshIoFiles(@Nonnull Iterable<? extends File> files, boolean async, boolean recursive, @Nullable Runnable onFinish) {
  VirtualFileManagerEx manager = (VirtualFileManagerEx)VirtualFileManager.getInstance();

  Application app = ApplicationManager.getApplication();
  boolean fireCommonRefreshSession = app.isDispatchThread() || app.isWriteAccessAllowed();
  if (fireCommonRefreshSession) manager.fireBeforeRefreshStart(false);

  try {
    List<VirtualFile> filesToRefresh = new ArrayList<>();

    for (File file : files) {
      VirtualFile virtualFile = refreshAndFindFileByIoFile(file);
      if (virtualFile != null) {
        filesToRefresh.add(virtualFile);
      }
    }

    RefreshQueue.getInstance().refresh(async, recursive, onFinish, filesToRefresh);
  }
  finally {
    if (fireCommonRefreshSession) manager.fireAfterRefreshFinish(false);
  }
}
 
Example #9
Source File: FileRefresher.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void launch() {
  LOG.debug("launch");
  if (disposed.get() || launched.getAndSet(true)) return;
  RefreshSession session;
  synchronized (files) {
    if (this.session != null || files.isEmpty()) return;
    ModalityState state = producer.produce();
    LOG.debug("modality state ", state);
    session = RefreshQueue.getInstance().createSession(true, recursive, this::finish, state);
    session.addAllFiles(files);
    this.session = session;
  }
  scheduled.set(false);
  launched.set(false);
  LOG.debug("launched at ", System.currentTimeMillis());
  session.launch();
}
 
Example #10
Source File: ProjectDownloader.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
public void download(final ProgressIndicator indicator) throws IOException {
    indicator.setText("Downloading files ...");
    final URL url = new URL(Configuration.getStarterHost() + request.getAction());
    final HttpURLConnection urlConnection = HttpURLConnection.class.cast(url.openConnection());
    urlConnection.setRequestMethod(request.getRequestMethod());
    urlConnection.setRequestProperty("Accept", "application/zip");
    urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    urlConnection.setRequestProperty("User-Agent", userAgent());
    urlConnection.setDoOutput(true);
    try (final BufferedOutputStream outputStream = new BufferedOutputStream(urlConnection.getOutputStream())) {
        outputStream
                .write(("project=" + URLEncoder.encode(request.getProject(), StandardCharsets.UTF_8.name()))
                        .getBytes(StandardCharsets.UTF_8));
        outputStream.flush();
    }
    final int responseCode = urlConnection.getResponseCode();
    if (responseCode == HttpURLConnection.HTTP_OK) {
        final String contentType = urlConnection.getHeaderField("content-type");
        if (!"application/zip".equals(contentType)) {
            throw new IOException("Invalid project format from starter server, content-type='" + contentType + "'");
        }
        try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            copy(urlConnection.getInputStream(), out);
            final File targetExtractionDir = new File(requireNonNull(builder.getContentEntryPath()));
            unzip(new ByteArrayInputStream(out.toByteArray()), targetExtractionDir, true, indicator);
            indicator.setText("Please wait ...");
            markAsExecutable(targetExtractionDir, "gradlew");
            markAsExecutable(targetExtractionDir, "gradlew.bat");
            markAsExecutable(targetExtractionDir, "mvnw");
            markAsExecutable(targetExtractionDir, "mvnw.cmd");
            final VirtualFile targetFile =
                    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetExtractionDir);
            RefreshQueue.getInstance().refresh(false, true, null, targetFile);
        }
    } else {
        final byte[] error = slurp(urlConnection.getErrorStream());
        throw new IOException(new String(error, StandardCharsets.UTF_8));
    }
}
 
Example #11
Source File: SynchronizeCurrentFileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  final Project project = getEventProject(e);
  final VirtualFile[] files = getFiles(e);
  if (project == null || files == null || files.length == 0) return;

  CallChain.first(UIAccess.current()).linkWrite(() -> {
    for (VirtualFile file : files) {
      final VirtualFileSystem fs = file.getFileSystem();
      if (fs instanceof LocalFileSystem && file instanceof NewVirtualFile) {
        ((NewVirtualFile)file).markDirtyRecursively();
      }
    }
  }).linkUI(() -> {
    final Runnable postRefreshAction = () -> {
      final VcsDirtyScopeManager dirtyScopeManager = VcsDirtyScopeManager.getInstance(project);
      for (VirtualFile f : files) {
        if (f.isDirectory()) {
          dirtyScopeManager.dirDirtyRecursively(f);
        }
        else {
          dirtyScopeManager.fileDirty(f);
        }
      }

      final StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
      if (statusBar != null) {
        final String message = IdeBundle.message("action.sync.completed.successfully", getMessage(files));
        statusBar.setInfo(message);
      }
    };

    RefreshQueue.getInstance().refresh(true, true, postRefreshAction, files);
  }).toss();
}
 
Example #12
Source File: FileSystemTreeImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void treeExpanded(final TreeExpansionEvent event) {
  if (myTreeBuilder == null || !myTreeBuilder.isNodeBeingBuilt(event.getPath())) return;

  TreePath path = event.getPath();
  DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
  if (node.getUserObject() instanceof FileNodeDescriptor) {
    FileNodeDescriptor nodeDescriptor = (FileNodeDescriptor)node.getUserObject();
    final FileElement fileDescriptor = nodeDescriptor.getElement();
    final VirtualFile virtualFile = fileDescriptor.getFile();
    if (virtualFile != null) {
      if (!myEverExpanded.contains(virtualFile)) {
        if (virtualFile instanceof NewVirtualFile) {
          ((NewVirtualFile)virtualFile).markDirty();
        }
        myEverExpanded.add(virtualFile);
      }


      final boolean async = myTreeBuilder.isToBuildChildrenInBackground(virtualFile);
      if (virtualFile instanceof NewVirtualFile) {
        RefreshQueue.getInstance().refresh(async, false, null, ModalityState.stateForComponent(myTree), virtualFile);
      }
      else {
        virtualFile.refresh(async, false);
      }
    }
  }
}
 
Example #13
Source File: VirtualDirectoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private VirtualFileSystemEntry createAndFindChildWithEventFire(@Nonnull String name, @Nonnull NewVirtualFileSystem delegate) {
  final VirtualFile fake = new FakeVirtualFile(this, name);
  final FileAttributes attributes = delegate.getAttributes(fake);
  if (attributes == null) return null;
  final String realName = delegate.getCanonicallyCasedName(fake);
  boolean isDirectory = attributes.isDirectory();
  boolean isEmptyDirectory = isDirectory && !delegate.hasChildren(fake);
  String symlinkTarget = attributes.isSymLink() ? delegate.resolveSymLink(fake) : null;
  ChildInfo[] children = isEmptyDirectory ? ChildInfo.EMPTY_ARRAY : null;
  VFileCreateEvent event = new VFileCreateEvent(null, this, realName, isDirectory, attributes, symlinkTarget, true, children);
  RefreshQueue.getInstance().processSingleEvent(event);
  return findChild(realName);
}
 
Example #14
Source File: PlatformVirtualFileManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected long doRefresh(boolean asynchronous, @Nullable Runnable postAction) {
  if (!asynchronous) {
    ApplicationManager.getApplication().assertIsDispatchThread();
  }

  // todo: get an idea how to deliver changes from local FS to jar fs before they go refresh
  RefreshSession session = RefreshQueue.getInstance().createSession(asynchronous, true, postAction);
  session.addAllFiles(myManagingFS.getRoots());
  session.launch();

  super.doRefresh(asynchronous, postAction);

  return session.getId();
}
 
Example #15
Source File: CompilerUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void refreshIODirectories(@Nonnull final Collection<File> files) {
  final LocalFileSystem lfs = LocalFileSystem.getInstance();
  final List<VirtualFile> filesToRefresh = new ArrayList<VirtualFile>();
  for (File file : files) {
    final VirtualFile virtualFile = lfs.refreshAndFindFileByIoFile(file);
    if (virtualFile != null) {
      filesToRefresh.add(virtualFile);
    }
  }
  if (!filesToRefresh.isEmpty()) {
    RefreshQueue.getInstance().refresh(false, true, null, filesToRefresh);
  }
}
 
Example #16
Source File: QuarkusModuleBuilder.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private void processDownload() throws IOException {
    File moduleFile = new File(getContentEntryPath());
    QuarkusModelRegistry.zip(wizardContext.getUserData(QuarkusConstants.WIZARD_ENDPOINT_URL_KEY),
            wizardContext.getUserData(QuarkusConstants.WIZARD_TOOL_KEY).asParameter(),
            wizardContext.getUserData(QuarkusConstants.WIZARD_GROUPID_KEY),
            wizardContext.getUserData(QuarkusConstants.WIZARD_ARTIFACTID_KEY),
            wizardContext.getUserData(QuarkusConstants.WIZARD_VERSION_KEY),
            wizardContext.getUserData(QuarkusConstants.WIZARD_CLASSNAME_KEY),
            wizardContext.getUserData(QuarkusConstants.WIZARD_PATH_KEY),
            wizardContext.getUserData(QuarkusConstants.WIZARD_MODEL_KEY),
            moduleFile);
    updateWrapperPermissions(moduleFile);
    VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
    RefreshQueue.getInstance().refresh(true, true, (Runnable) null, new VirtualFile[]{vf});
}
 
Example #17
Source File: LocalFileSystemBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void refresh(boolean asynchronous) {
  RefreshQueue.getInstance().refresh(asynchronous, true, null, ManagingFS.getInstance().getRoots(this));
}
 
Example #18
Source File: LocalFileSystemBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void refreshFiles(@Nonnull Iterable<? extends VirtualFile> files, boolean async, boolean recursive, @Nullable Runnable onFinish) {
  RefreshQueue.getInstance().refresh(async, recursive, onFinish, ContainerUtil.toCollection(files));
}
 
Example #19
Source File: RefreshFileChooserAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(final AnActionEvent e) {
  RefreshQueue.getInstance().refresh(true, true, null, ModalityState.current(), ManagingFS.getInstance().getLocalRoots());
}
 
Example #20
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void refreshFiles(final List<VirtualFile> filesToRefresh, final Runnable runnable) {
  RefreshQueue.getInstance().refresh(true, true, runnable, filesToRefresh);
}
 
Example #21
Source File: TempFileSystem.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void refresh(final boolean asynchronous) {
  RefreshQueue.getInstance().refresh(asynchronous, true, null, ManagingFS.getInstance().getRoots(this));
}
 
Example #22
Source File: DesktopSaveAndSyncHandlerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void dispose() {
  RefreshQueue.getInstance().cancelSession(myRefreshSessionId);
  mySettings.removePropertyChangeListener(myGeneralSettingsListener);
  IdeEventQueue.getInstance().removeIdleListener(myIdleListener);
}
 
Example #23
Source File: DiffUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Difference with {@link VfsUtil#markDirtyAndRefresh} is that refresh from VfsUtil will be performed with ModalityState.NON_MODAL.
 */
public static void markDirtyAndRefresh(boolean async, boolean recursive, boolean reloadChildren, @Nonnull VirtualFile... files) {
  ModalityState modalityState = ApplicationManager.getApplication().getDefaultModalityState();
  VfsUtil.markDirty(recursive, reloadChildren, files);
  RefreshQueue.getInstance().refresh(async, recursive, null, modalityState, files);
}