Please consider editing your post and mark it as obsolete instead. Do you want to delete post?
Determine project path
Permanently deleted user
Created
I am working on a plugin and have created a project component. Inside projectOpened() method, I need to do some operation and looking for the project path. Is there any API to obtain that?
What exactly do you need to accomplish? Generally speaking, there is no such thing as "the project path". A project can have multiple modules with multiple content roots in unrelated directories.
Normally, there is no need to access it directly, because all of the state stored there can be accessed as components with a proper API. However, if you do need to access the files directly, you can use the Project.getBaseDir() method. Note that, for projects using the legacy .ipr project file format, the .idea directory will not exist.
I have created a ProjectComponent whose constructor has an argument as "Project project". But when I try to do a "project.getBaseDir().getPath()", I get compilation error as below:
Error:(30, 29) java: E:\Plugin\Test\src\FileProjectComponent.java:30: cannot access com.intellij.openapi.extensions.AreaInstance class file for com.intellij.openapi.extensions.AreaInstance not found
Could you please suggest on proper execution of this API.
It's not possible to access the instance anywhere in the plugin because an IntelliJ IDEA instance can have multiple projects open, and it wouldn't be possible to determine which project you need. In which context do you actually need the project?
I am implementing a dialog box and putting a checkbox which asks to show this dialog in future or not. To save this config, I am writing the status in workspace.xml as other configs are stored.
I will read this file when project opens and based on config will decide to show dialog or not. So, I am looking for project path to reach "workspace.xml" file.
What exactly do you need to accomplish? Generally speaking, there is no such thing as "the project path". A project can have multiple modules with multiple content roots in unrelated directories.
I want to access files in ".idea" directory. For a project say 'A', it would be D:\A\.idea\.
I am looking for the project path "D:\A" for this, or any other way to reach ".idea" will also work.
Normally, there is no need to access it directly, because all of the state stored there can be accessed as components with a proper API. However, if you do need to access the files directly, you can use the Project.getBaseDir() method. Note that, for projects using the legacy .ipr project file format, the .idea directory will not exist.
I have created a ProjectComponent whose constructor has an argument as "Project project". But when I try to do a "project.getBaseDir().getPath()", I get compilation error as below:
Error:(30, 29) java: E:\Plugin\Test\src\FileProjectComponent.java:30: cannot access com.intellij.openapi.extensions.AreaInstance
class file for com.intellij.openapi.extensions.AreaInstance not found
Could you please suggest on proper execution of this API.
I realized that I have not included the extensions library of intellij. Compilation goes fine and I am able to execute this call.
Is there any API to get instance of Project class anywhere in the plugin to obtain project path?
It's not possible to access the instance anywhere in the plugin because an IntelliJ IDEA instance can have multiple projects open, and it wouldn't be possible to determine which project you need. In which context do you actually need the project?
I am implementing a dialog box and putting a checkbox which asks to show this dialog in future or not. To save this config, I am writing the status in workspace.xml as other configs are stored.
I will read this file when project opens and based on config will decide to show dialog or not. So, I am looking for project path to reach "workspace.xml" file.
Usually the code which shows the dialog box has a Project instance and passes it to the DialogWrapper class constructor as a parameter.