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

6 comments

ProjectBaseDirectory.getInstance(ProjectHelper.toIdeaProject(project)).getBaseDir().getCanonicalPath()

Unfortunately toIdeaProject() is deprecated, but I don't know a better alternative. 

0

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

0

You can get project with:

 MPSDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext())

Again deprecated api.

 

1

Yes this should work. Thank you fxlex!

0

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 :)

0

For me it worked to do:

project = MPSDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext())
ProjectBaseDirectory.getInstance(project).getBaseDir().getCanonicalPath()

0

Please sign in to leave a comment.