How can I refresh the whole project in Plugin Development?

Answered

I have to extract information from different commits of the project (using git as version control system). To this end, I have to checkout to different commits of the project, and frequent checkout process may lead to a null VirtualFile object (I assume that the reason is that IDEA does not reload the projects from disk automatically). 

VirtualFile fileByRelativePath = LocalFileSystem.getInstance().findFileByIoFile(new File(path));

Consequently, I need to refresh the projects every time after I conducted the checkout. 

I was trying to use the following API

ExternalSystemUtil.refreshProject(project, projectSystemId,"my_local_project_path",false, ProgressExecutionMode.NO_PROGRESS_SYNC);

 How can I get the projectSystemId object? Or are there any other methods?

Thanks a lot if you can help me!

 

0
5 comments

Hi,

Depending on your context, you can use 

e.getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID)
 
if the context is and action event providing this information.
0
ProjectSystemId projectSystemId = e.getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);

I can get a ProjectSystemId object by using the above API method where e is an object of AnActionEvent. However, this object is null. Is there anything wrong? 

 

0

Please provide more context. What feature are you trying to implement? What VirtualFiles are null?

0

Sorry, I did not make it clear. Here is the major task information: I have got some real refactoring information, i.e., developers extracted a new variable for frequently occurring expressions, and then replace these expressions with the local variable. Now I have got the selected expression and its location (i.e., in which commit, which java file, which column, which line),  and I want to develop a plugin on IDEA platform that can simulate this variable extraction process to check if the name suggested by IDEA is the same as the one made by developers. The VirtualFile object is obtained by the following method invocation where "path" is the absolute path of the java file that involves frequently occurring expressions. Also, this java file is in the parent commit of the commit where developers conducted the variable extraction. Consequently, I have to checkout to different commit version to get this java file. However, the VirtualFile object tends to be null sometimes, and I assumed that  I have to refresh the project to reload from the disk every time I conduct the checkout. Thanks a lot for your help.

VirtualFile fileByRelativePath = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
0

Hi,

You can use this method to refresh virtual file system after checkout:

VfsUtil#markDirtyAndRefresh(boolean async, boolean recursive, boolean reloadChildren, VirtualFile @NotNull ... files)

You can pass a project directory, or find a parent directory of the file you are interested in.

0

Please sign in to leave a comment.