Plugin debugging in IntelliJ

From VuzeWiki
Jump to: navigation, search

This page describes the process of setting-up an Azureus plugin project in IntelliJ IDEA so you can debug your source when doing plugin development. I'm going to assume you have a working knowledge of IntelliJ. This How-to describes the entire process of creating a plugin project from scratch. If you've already got working code and just need to debug, I'm sure you can figure out what else needs to be done.
The text of each step is just a brief description - the image the step links to gives a lot more detail. The images are all at a resolution of 1400x1050. If they look slightly screwy, it's probably because your browser is resizing them - just zoom in until they are clear.

  1. First, create a new project. (File->New->Project)
  2. Select the JDK for your project
  3. Select the kind of project - Single module, since we're going at use the Azureus2 jar rather than Azureus source, so a single module is sufficient
  4. Select your module type - in our case, Java module
  5. Choose your module name (the name of your plugin?) and module content root
  6. Create a source dir
  7. Create an output dir; we'll change this later to point to the azureus config/plugins/yourplugin dir
  8. You're now past the project creation wizard
  9. Create lib and test dirs; take a look at the next screenshot too
  10. Define the test source dir and exclude the lib dir in Settings->Project->Modules
  11. Copy the appropriate jars - Azureus2.jar and swt.jar - to the lib dir. On Windows, you'll need the swt-win-32 dll too. You can get all these from the Azureus binary installation.
  12. Add the jars to the IntelliJ module libraries
  13. You'll have just two jars in the libraries/classpath - Azureus2.jar and swt.jar
  14. Once you hit OK, Azureus will parse the libs you just added
  15. Now create a package for your plugin code
  16. Create a class to be the entry-point to you plugin. Call it anything at all. In this example I've called it Core.java
  17. A simple test to check if everything is fine thus far is to have your class implement UP and hit Ctrl+Alt+Space. If IntelliJ autocomplete gives you UnloadablePlugin as one of your choices, you're cool. UnloadablePlugin is the interface your entry-point class has to implement for Azureus' plugin loader to be able to load it.
  18. Add the methods required by UnloadablePlugin
  19. Now for a little configuration. Click the Edit configs button.
  20. Mimic the setup shown in the pic. I've tacked on the strings in text to save you the trouble of copying them off the pics - edit the paths to suit your project dir structure. Main class: org.gudy.azureus2.ui.swt.Main | VM params: -Dazureus.config.path="C:\SVN\DemoPlugin\src\config" -Djava.library.path="C:\SVN\DemoPlugin\lib"
  21. Create the output dir for your plugin. It should be in the plugins dir under the config dir you've specified in -Dazureus.config.path in your VM params.
  22. Now select this dir as the output path for your module
  23. Now for the plugin.properties file Azureus expects a plugin to have. Create it in your src dir. IntelliJ will deploy it to the output dir on every compile.
  24. Before I forget, if you've got the same dir structure as I do, you'll have to exclude the config folder. It's up to you if you want to check it into source control, though. Azureus stores all it's settings there so it might make sense to check it in or you'll have to configure Azureus every time you do a fresh checkout. Just remember to ignore the plugins folder - you don't want compiled binaries polluting your source control (I'm sorry if I'm using SVN terminology, but it's what I'm familiar with :-))
  25. Fill up your plugin.properties file with the key value pairs you see here. Plugin.class should contain the fully qualified name of your entry-point class. Plugin.id can be any random, unique value. the other two are self-exlpanatory.
  26. Now you're ready to roll. Hit Shift+F10/Run and Azureus starts up.
  27. Notice the string !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Demo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! has been written to console. It's what I've souted from the plugin, so we know the plugin is being loaded by Azureus.
  28. Now set a breakpoint and hit Shift+F9. Voila, we've got debug too.
  29. This is what your config dir looks like after the first run. I wasn't connected to the net, but if you are, Azureus will try to update itself and all updates end up in the config dir too.
  30. And this is what your output dir looks like.

HTH and all that jazz. I might've mucked up somewhere, but it's 2:30 am on a Monday so I'm not going to double check. I'm sure you guys'll let me know if I've missed anything :-).

Best, Sid.