Determine project path

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?

0
9 comments

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.

0
Avatar
Permanently deleted user

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.

0

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.

0
Avatar
Permanently deleted user

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.

0
Avatar
Permanently deleted user

I realized that I have not included the extensions library of intellij. Compilation goes fine and I am able to execute this call.

0
Avatar
Permanently deleted user

Is there any API to get instance of Project class anywhere in the plugin to obtain project path?

0

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?

0
Avatar
Permanently deleted user

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.

0

Usually the code which shows the dialog box has a Project instance and passes it to the DialogWrapper class constructor as a parameter.

0

Please sign in to leave a comment.