edit this page - page history - about editing

Force an IProject file system refresh in Eclipse

Eclipse

The problem with the IProject.refresh() method is that it is non-blocking; that is, it may be refreshing the file system, but you won't know when it is done. Here is a little helping code to force the current thread to wait until it's complete:

class HaltProgressMonitor extends NullProgressMonitor {
  @Override
  public void setCanceled(boolean cancelled) {
    isDone = true;  // bail early
    super.setCanceled(cancelled);
  }

  private boolean isDone = false;
  public synchronized boolean isDone() {
    return isDone;
  }

  @Override
  public void done() {
    isDone = true;
    super.done();
  }
}

IProject project = ...;
HaltProgressMonitor m = new HaltProgressMonitor();
project.refreshLocal(IResource.DEPTH_INFINITE, m);
try {
  while (!m.isDone()) {
    Thread.sleep(300);
  }
} catch (InterruptedException e) {
  // do something
}

Categories: Eclipse | Article | Code Sample
edit this page - what links to here? - page history - top
Last edited by jevon jevon 111 months ago