There is an article in the Eclipse wiki how to configure user's p2 default repositories of an RCP application by adding a static conf file to your product:
Equinox/p2/Adding Self-Update to an RCP Application - Configuring the user's default repositories
I want to do the same programmatically in a Java class when the user changes some configuration details. I could not find appropriate p2 API documentation for that.
This is high on the Google query for this issue, and there's still not a good way to do it published:
If anyone finds this page via Google as I did, I've solved this problem. You can use org.eclipse.equinox.internal.p2.ui.model.ElementUtils.updateRepositoryUsingElements to set the repositories programmatically. Full code can be found here.
Furthermore you can add more than one repositories with ElementUtils and also you can sort them.
These links will be appeared alphabetically sorted.
Use this solution for Eclipse 3.7 based applications:
For ProvUI and ProvisioningUI you have to import bundles org.eclipse.equinox.p2.ui and org.eclipse.equinox.p2.operations (among others).
I found a solution. It's easy - unfortunately there is no documentation...