How to run indexing in code

I means ide bottom statusbar will show "Indexing ...", how to run it manually

2 comments
Comment actions Permalink

I wanna run "gradle jar" and refresh this jar in code

0
Comment actions Permalink

2017-7-11 update: I find more simple way to run indexing

DumbServiceImpl dumbService = DumbServiceImpl.getInstance(pj2);
DumbModeTask task = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(pj2);
if (task != null) {
dumbService.queueTask(task);
} // RefreshUtil.forceRefreshFiles()

2016-4-21 update: If following ways all don't work, the simple way to reindexing is reopen current project

void restartCurProject() {
String pjRt2 = getPjRt()
app.invokeLater(new Runnable() {
@Override
void run() {
ProjectUtil.closeAndDispose(pj)
ProjectUtil.openProject(pjRt2, pj, true)
}
})
}

2016-4-20 update: I find a better way, in following code, I can force specific what files should be indexed

    interface RunBeforeRefresh {
void run()
ArrayList<String> getFiles()
}

static void forceRefreshFiles(Act act, RunBeforeRefresh runBeforeRefresh) {
Project pj = act.pj
final FileBasedIndexImpl index = FileBasedIndexImpl.instance;

DumbModeTask refreshTask = new DumbModeTask(pj.getComponent(FileBasedIndexProjectHandler.class)) {
@Override
void performInDumbMode(@NotNull ProgressIndicator indicator) {
runBeforeRefresh.run()
ArrayList<String> files = runBeforeRefresh.files

final Collection<VirtualFile> files2 = files.collect {
act.getVirtualFile(it)
}
indicator.setIndeterminate(false);
indicator.setText(IdeBundle.message("progress.indexing.updating"));
CacheUpdateRunner.processFiles(indicator, true, files2, pj, new Consumer<FileContent>() {
@Override
void consume(FileContent ctn) {
index.processRefreshedFile(pj, ctn)
}
})
}
}

// if (refreshTask != null) {
// dumbService.queueTask(refreshTask);
// }

// ProgressManager.instance.run(t)
DumbServiceImpl.getInstance(pj).queueTask(refreshTask)
}

I fix my question, here is "synchronized" action code:

 

public class SynchronizeAction extends AnAction implements DumbAware {
@Override
public void actionPerformed(AnActionEvent e) {
FileDocumentManager.getInstance().saveAllDocuments();
SaveAndSyncHandler.getInstance().refreshOpenFiles();
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
}
}
0

Please sign in to leave a comment.