Own Marketplace Server – Part II

I’ve described how to setup an own marketplace server with PHP and MySQL earlier, watch the post. Today, we’ll have a look at the requirements of an automated resolution of dependencies. First of all, it’s necessary to add the parameter (selfContained=”false”) to the marketplace catalog extension point. The p2 mechanism will calculate and fetch the required bundles automatically from now on.

<extension
	point="org.eclipse.epp.mpc.ui.catalog">
	<catalog
		description="Install new plug-ins from the OpenChrom marketplace."
		icon="icons/logo_32x32.png"
		label="OpenChrom Marketplace"
		url="http://www.openchrom.net/"
		selfContained="false">
	</catalog>
</extension>

But how does p2 know where to fetch the required dependencies? It can’t know unless you specify the repositories to look at (Available Software Sites).

Available Software Sites Empty

The first approach would be to add each repository manually, but it’s a blunt work. Moreover, do you really want that your customers add these repositories by themselves? That’s why we need an automated solution. And here is such a solution. Additional repositories can be added by using the following code:

private void addProvisioningRepositories() {

	URI uri;
	Map<String, String> map = new HashMap<String, String>();
	map.put("Indigo", "http://download.eclipse.org/releases/indigo");
	map.put("The Eclipse Project Updates", "http://download.eclipse.org/eclipse/updates/3.7");
	map.put("Eclipse Orbit", "http://download.eclipse.org/tools/orbit/downloads/drops/S20120123151124/repository");
	map.put("OpenChrom", "http://www.openchrom.net/main/updates/0.6.x");
	map.put("OpenChrom Plug-ins", "http://www.openchrom.net/plugins/updates/0.6.x");
	map.put("OpenChrom Third Party Libraries", "http://www.openchrom.net/plugins/thirdpartylibraries/updates/0.6.x");
	map.put("OpenChrom Keys", "http://www.openchrom.net/plugins/keys/updates/0.6.x");
	/**
	 * Add the repository locations.
	 */
	ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
	RepositoryTracker repositoryTracker = ProvisioningUI.getDefaultUI().getRepositoryTracker();
	try {
		for(Map.Entry<String, String> entry : map.entrySet()) {
			uri = new URI(entry.getValue());
			repositoryTracker.addRepository(uri, entry.getKey(), session);
		}
	} catch(URISyntaxException e) {
		logger.warn(e);
	}
}

Voilà, it works.

Available Software Sites Filled

But the repositories shall be added only once. No problem by using the platform preferences.

private void addProvisioningRepositoriesOnDemand() {

	IPreferenceStore preferences = PlatformUI.getPreferenceStore();
	/**
	 * Returns false if there is no such value (on startup)
	 */
	if(!preferences.getBoolean(P2_UPDATE_REPOSITORIES_STILL_ADDED)) {
		/**
		 * Add additional p2 repositories.
		 */
		addProvisioningRepositories();
		preferences.setValue(P2_UPDATE_REPOSITORIES_STILL_ADDED, true);
	}
}

I’ve added the code in the “postWindowOpen()” of the “ApplicationWorkbenchWindowAdvisor” class. It works fine and my customers are happy too.

Advertisements

About Philip Wenig

Founder of OpenChrom
This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to Own Marketplace Server – Part II

  1. Tom Seidel says:

    Instead of adding repositories programmatically you can add your repositories via p2 touchpoint instructions while you’re building your product, see http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application#Configuring_the_user.27s_default_repositories

  2. eselmeister says:

    Hi Tom,

    thanks for the hint. I tried it a while ago, but with no success. Therefore, I rather think that the p2.inf was in the wrong place. Anyhow, it’s a good reason to try it again.

  3. jorj1301 says:

    The only problem with the p2.inf is that if you want to dinamically change the repo location, p2.inf MAY be in Program Files (on Windows 8) for example. Then, write-on-disk issues could appear. Anyway, this article is awesome, and I’m implementing your method right now. Please do tell if you have found any other methods for adding repositories programmatically. That would be great. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s