API for reading Eclipse plugin dependencies

less than 1 minute read

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.

Updated: