Plugin debugging in IntelliJ
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.
- First, create a new project. (File->New->Project)
- Select the JDK for your project
- 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
- Select your module type - in our case, Java module
- Choose your module name (the name of your plugin?) and module content root
- Create a source dir
- Create an output dir; we'll change this later to point to the azureus config/plugins/yourplugin dir
- You're now past the project creation wizard
- Create lib and test dirs; take a look at the next screenshot too
- Define the test source dir and exclude the lib dir in Settings->Project->Modules
- 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.
- Add the jars to the IntelliJ module libraries
- You'll have just two jars in the libraries/classpath - Azureus2.jar and swt.jar
- Once you hit OK, Azureus will parse the libs you just added
- Now create a package for your plugin code
- 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
- 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.
- Add the methods required by UnloadablePlugin
- Now for a little configuration. Click the Edit configs button.
- 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"
- 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.
- Now select this dir as the output path for your module
- 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.
- 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 :-))
- 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.
- Now you're ready to roll. Hit Shift+F10/Run and Azureus starts up.
- 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.
- Now set a breakpoint and hit Shift+F9. Voila, we've got debug too.
- 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.
- 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 :-).