PluginClassLoader behaviour

Hello,

I'm using MPS 3.2.3 (139.2677). On our application we use Git and, until now, we used what MPS brings; however we now want a no so technical feeling (hide the Git concepts of Push, Pull...) and give more of our concepts informations to the user...
We have a solution where we implemented some actions that allowed us to hide the Git concepts of Push, Pull, etc..

Problem: we can access all Git4Idea functionalities and all classes from the jars that it uses EXCEPT for jgit !

Lets go by steps:
  • we see the classes as stubs and we have the dependencies on the model properties:

ModelPropertiesDependencies.png


  • while coding, we can access and use jgit APIs and MPS signals no errors:

UsingJGitInCodeWithoutErrors.png


  • when we run the action that uses the code above, we get an exception:
          [1230670]  ERROR - llij.ide.plugins.PluginManager - org/eclipse/jgit/storage/file/FileRepositoryBuilder           java.lang.NoClassDefFoundError: org/eclipse/jgit/storage/file/FileRepositoryBuilder    at ...

After a lot of debugging, I saw what the problem is: at the moment when the FileRepositoryBuilder class is instantiated (or trying to), the ClassLoader in use is the PluginClassLoader for Git4Idea (which makes sense) but it's URLs are wrong!
Git4Idea uses several jars which are located in its 'lib' folder; it also uses two other jars which are located in 'lib/jgit' folder. Now, if you look to the URLs at its ClassLoader, one can see ALL 'lib' jars there and the 'lib/jgit' folder:

Git4IdeaClassLoader.png


This means that the ClassLoader will have access to all classes/resources included in the jars that are in its URL list; however, when the URL is a folder, it will not see classes from any jar that they may contain, instead it will look for .class files in the folder/package structure (for instance, it will try to find class 'org.eclipse.jgit.storage.file.FileRepositoryBuilder' in the folder 'lib/jgit/ org/eclipse/jgit/storage/file/FileRepositoryBuilder '.

Looking into MPS sources I found the code that builds the URL list:

PluginClassLoaderProblem.png


I think that instead of adding the folder URL, it should, recursively, list all containing files and add all jars/zips that it may find.

I've managed to work around this problem by copying the two jars located in 'lib/jgit' folder to the 'lib' folder. Doing this, the Git4Idea PluginClassLoader will have the jgit jar directly in its URL list and make all contained classes available to the application.

Does my analysis make any sense?
Can anyone give some more input on this?

Thank you - if you managed to get this far :-)

Regards,

Sérgio Ribeiro
Porto - Portugal

Please sign in to leave a comment.