Testing p2 the easy way, and the hard way

by rgrunber

So you want to debug changes you’re making to p2 by launching in a child Eclipse process. Simple enough. If it works for other plugins, why not p2 ? Turns out, it can be a little tricky.

In my case I wanted to test out a shared installation while looking at what was going on in the SimpleProfileRegistry (methods like getProfile, containsProfile, and createSurrogateProfile).

Here’s what I needed to do in order to get that working :

In addition to the generated config.ini, I needed the following attributes set.

eclipse.p2.data.area=@config.dir/.p2
osgi.sharedConfiguration.area=file\:/usr/lib64/eclipse/configuration

(Note: Default p2 data area is defined in LaunchConfigurationHelper of org.eclipse.pde.launching)

PDE has its own special way of setting up the configuration for a child Eclipse, so you’ll need to copy over the folder of your shared profile as SelfHostingProfile.profile and rename all IDs in the profiles accordingly . After failing countless times to get the child Eclipse to detect the SDKProfile.profile, I realized PDE always looks for a profile ID of SelfHostingProfile.

(Note: Default profile ID is defined in LaunchConfigurationHelper of org.eclipse.pde.launching)

It turns out containsProfile is a very popular method. There’s a separate thread that begins setting up profile preferences using the ProfilePreferences class. This ends up calling the synchronized method, containsProfile, and ultimately blocks because p2’s AutomaticUpdateSchedueler has already entered it. From within containsProfile, we end up calling setupRepos as well to set up the metadata repositories. As you might imagine, this ends up calling ProfilePreferences and blocks on entering the preference node because the other thread is in there. Now we have a deadlock.

Solution : You need to insert a breakpoint just before the containsProfile call to avoid a deadlock between the ProfilePreferences job and the p2’s AutomaticUpdateScheduler job. Let the ProfilePreferences thread continue before proceeding into the AutomaticUpdateScheduler’s call to containsProfile.

If all the above is too much of a giant pain (I found it kind of fun), you can always just run the p2 Tests, to hopefully take some solace in the fact that you (probably) haven’t broken anything.

mvn -Declipse-sdk-repo.url=http://download.eclipse.org/eclipse/updates/4.4-I-builds -Dmaven.test.skip=false clean verify
Advertisements