API for reading Eclipse plugin dependencies

The Eclipse platform provides an API to allows that you can access in information of the MANIFEST.MF. For example you could read the dependencies of your plugin.

For this example create a plugin “de.vogella.pde.dependencies”. See Eclipse Plugin development for examples on how to develop plugins. Use the “Hello, World Command” template.

Define dependendies to the following plugins:
– org.eclipse.ui
– org.eclipse.core.runtime

Change the command to the following.


package de.vogella.pde.dependencies.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;

public class PrintDependencies extends AbstractHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {
		String requireBundle = (String)Platform.getBundle("de.vogella.pde.dependencies").getHeaders().get(
				Constants.REQUIRE_BUNDLE);
				try {
					ManifestElement[] elements = ManifestElement.parseHeader(
					Constants.BUNDLE_CLASSPATH, requireBundle);
					for (ManifestElement manifestElement : elements) {
						System.out.println( manifestElement.getValue());
					}
				} catch (BundleException e) {
					e.printStackTrace();
				}
		return null;
	}
}

If you now run your new plugin it and select your command it will print out the dependencies of your plugin.

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Eclipse and tagged , , , . Bookmark the permalink.

2 Responses to API for reading Eclipse plugin dependencies

  1. Eric Suen says:

    Some useful code I wrote:

    String id = manifestElement.getValue();

    if (Constants.SYSTEM_BUNDLE_SYMBOLICNAME.equals(id))
    continue;

    if (includeOptional) {
    required.add(id);
    } else {
    if (!Constants.RESOLUTION_OPTIONAL.equals(depend.getDirective(Constants.RESOLUTION_DIRECTIVE)))
    required.add(id);
    }

  2. Daniel Milosevic says:

    Cheers Lars!

Comments are closed.