Why IntellijIDEA custom plugin cannot find file in project

Answered

I am writing custom plugin, which creates pom.xml file with required dependencies and than i want to import project with the help of IntellijIDEA. I am going to do it with this code 

MavenUtil.isProjectTrustedEnoughToImport(activeProject, true);
MavenOpenProjectProvider openProjectProvider = new MavenOpenProjectProvider();
openProjectProvider.linkToExistingProject(pomMvnFile, activeProject);

And thats why i need to have pomMvnFile of VirtualFile type. I am trying to find VirtualFile with this code:

FilenameIndex.getFilesByName(activeProject, "pom.xml", GlobalSearchScope.projectScope(activeProject));

When i open already existed maven project, than i can find VirtualFile. But when i open the same project and do 'Unlink maven project' (without deleting any files), than i cannot find pom.xml file. Can anybody explain why this happended and how i can get VirtualFile?

0
2 comments

Please make sure the Virtual File System (VFS) is updated/synced after your plugin creates the new pom.xml file, see https://plugins.jetbrains.com/docs/intellij/virtual-file-system.html#synchronous-and-asynchronous-refreshes. Otherwise, VFS cannot locate it and thus returns null.

Alternatively, there's a number of utility methods to locate VirtualFile by Path/IO File in com.intellij.openapi.vfs.VfsUtil#findFileXXXX.

0

Thanks for help, com.intellij.openapi.vfs.VfsUtil.findFile worked for me. And now i know why FilenameIndex.getFilesByName doesn't work for me, it's because pom.xml file in my case if ignoring by IntellijIDEA and it's not in index.

0

Please sign in to leave a comment.