private static File dumpModulesPaths(@NotNull Project project) throws IOException { ApplicationManager.getApplication().assertReadAccessAllowed(); Properties res = new Properties(); MavenProjectsManager manager = MavenProjectsManager.getInstance(project); for (Module module : ModuleManager.getInstance(project).getModules()) { if (manager.isMavenizedModule(module)) { MavenProject mavenProject = manager.findProject(module); if (mavenProject != null && !manager.isIgnored(mavenProject)) { res.setProperty( mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":pom" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getFile().getPath()); res.setProperty( mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ':' + mavenProject.getPackaging() + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getOutputDirectory()); } } } File file = new File( PathManager.getSystemPath(), "Maven/idea-projects-state-" + project.getLocationHash() + ".properties"); file.getParentFile().mkdirs(); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { res.store(out, null); } finally { out.close(); } return file; }
@Nullable public static Module findContainingMavenizedModule(@NotNull PsiFile psiFile) { VirtualFile file = psiFile.getVirtualFile(); if (file == null) return null; Project project = psiFile.getProject(); MavenProjectsManager manager = MavenProjectsManager.getInstance(project); if (!manager.isMavenizedProject()) return null; ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); Module module = index.getModuleForFile(file); if (module == null || !manager.isMavenizedModule(module)) return null; return module; }