Using integrated hg4idea plugin

Hi,

I'm new developing plugins for Intellij, also please be patient if I make some stupid questions or not understand some answers.

In the plugin I'm working I want to get the branch name of the active repository.
hg4idea is now integrated in Intellij, therefore it's in the IntelliJ IDEA Community Edition.
I started the plugin project as indicated in http://confluence.jetbrains.com/display/IDEADEV/Getting+Started+with+Plugin+Development#GettingStartedwithPluginDevelopment-anchor2

When I try to use the methods from hg4idea, they are not recognized.

I tried to export hg4idea as JAR-Lib.
In these case, it will be recognized, but then the project doesn't compile.

What I'm doing wrong? It's possible to use these methods? How?

Here my code:

    public static String getCurrentBranch() {
        DataContext dataContext = DataManager.getInstance().getDataContext();
        Project project = DataKeys.PROJECT.getData(dataContext);
        File rootFile = new File(project.getBasePath(), SOME_ROOT_FILE);
        if (rootFile.isFile()) {
            VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(rootFile);
            if (virtualFile == null) {
                virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(rootFile);
            }
            if (virtualFile != null) {
                HgRepositoryManager repositoryManager = ServiceManager.getService(project, HgRepositoryManager.class);
                HgRepository hgRepository = HgRepositoryImpl.getInstance(virtualFile, project, repositoryManager);
                String branch = hgRepository.getCurrentBranch();
                if (StringUtils.isNotBlank(branch)) {
                    return branch;
                }
            }
        }
        return StringUtils.EMPTY;
    }


I send a screenshot from Intellij too.

Thank you very much for your help,
Pablo Rovi



Attachment(s):
2014-09-18_15h46_21.png
2 comments
Comment actions Permalink

You need to add the jar of the hg4idea plugin to the classpath of your IntelliJ IDEA SDK and to add a <depends>hg4idea</depends> tag to your plugin.xml.

0
Comment actions Permalink

It works, thank you very much!


0

Please sign in to leave a comment.