IDEA - Project from a plugin dev point of view
The project configuration data files depends on the plugin project format.
To work with projects and project files, you can use the following classes and interfaces:
Note that you don’t need to access project files directly to load or save settings. See Persisting State of Components.
For example, to get the opened project, you can get it from an action:
Project project = e.getProject();
String projectName = project.getName();
StringBuilder sourceRootsList = new StringBuilder();
VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentSourceRoots();
for (VirtualFile file : vFiles) {
sourceRootsList.append(file.getUrl()).append("\n");
}
Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList, "Project Properties");
The ProjectFileIndex interface is used to verify whether a file or directory is related to the specified IDEA project.
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
Module module = projectFileIndex.getModuleForFile(virtualFile);
VirtualFile moduleContentRoot = projectFileIndex.getContentRootForFile(virtualFileorDirectory);
VirtualFile moduleSourceRoot = projectFileIndex.getSourceRootForFile(virtualFileorDirectory);
Note that by default, the project modules use the project SDK. Optionally, you can configure individual SDK for each module.