How to Retreive Project Path
Hello everyone,
How can I retreive the absolute path of a currently active project programmatically in MPS? I strictly want to avoid defining path variables and accessing them via PathMacros or MacrosFactory classes.
Thanks
Please sign in to leave a comment.
ProjectBaseDirectory.getInstance(ProjectHelper.toIdeaProject(project)).getBaseDir().getCanonicalPath()
Unfortunately toIdeaProject() is deprecated, but I don't know a better alternative.
Hello fxlex,
Thank you for your answer, but I forgot to mention that I also do not prefer to use project or operationContext or etc. objects which are only available in MPS scripts. Or if there is a way of getting the project instance from a static method of some class, this will also work.
Thanks
You can get project with:
MPSDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext())
Again deprecated api.
Yes this should work. Thank you fxlex!
For me it does not seem to work on MPS 3.3.5 because MPSDataKeys.PROJECT returns a com.intellij.openapi.project.Project while ProjectHelper.toIdeaProject wants a jetbrains.mps.project.Project
The internal APIs sometimes seem quite complex :)
For me it worked to do:
project = MPSDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext())
ProjectBaseDirectory.getInstance(project).getBaseDir().getCanonicalPath()
Does not work in my MPS 2020.3.5, the getBaseDir() result in null.
ProjectBaseDirectory is deprecated, is there a new way to get the project path?