[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform] Re: how to read the extensions registry outside eclipse
|
Thanks Paul!
Yes, I did have the string as below. But entered it wrong in the email.
> String path = "d:\\com.mycompany.base.ui\\plugin.xml";
I found that it was an issue with the InputStream I created.
I will also take a look at the sample code that you provided.
Thanks again for your inputs to get my code working!!
"Paul Webster" <pwebster@xxxxxxxxxx> wrote in message
news:fahgcb$fcj$1@xxxxxxxxxxxxxxxxxxxx
> Rashmy wrote:
>
>>
>> RegistryStrategy stratergy = new RegistryStrategy(null, null);
>> IExtensionRegistry registry = new ExtensionRegistry(stratergy,
>> masterToken,
>> null);
>> IContributor contrib =
>> ContributorFactorySimple.createContributor("com.mycompany.base.ui");
>
> This probably isn't the java statement that you expect:
>
>> String path = "D:\com.mycompany.base.ui\plugin.xml";
>
> You probably want:
>
> I was kinda curious, so I took a stab at it. I've attached a java file
> that accepts an eclipse/plugins directory and will try and load all of
> the plugins into the registry. It tries to load the plugin id and the
> localication file from the MANIFEST.MF.
>
> It's the brute-force stupid version, but it appears to work on my
> machine. It also doesn't close input streams (not necessary for
> addContribution(*), but I didn't check the MANIFEST or ResourceBundle
> ones).
>
> bash$ java -cp org.eclipse.equinox.registry_3.4.0.v20070820.jar\
> :org.eclipse.equinox.common_3.3.0.v20070820.jar\
> :org.eclipse.osgi_3.4.0.v20070820.jar\
> :check.jar z.ex.registry.CheckRegistry /opt/eclipse330/plugins
>
> This works well with the 3.3.0 jars, and it runs with the 3.2.2 jars
> (but not so well).
>
> Later,
> PW
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
>
>
--------------------------------------------------------------------------------
> package z.ex.registry;
>
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.InputStream;
> import java.util.PropertyResourceBundle;
> import java.util.ResourceBundle;
> import java.util.jar.JarEntry;
> import java.util.jar.JarFile;
> import java.util.jar.Manifest;
>
> import org.eclipse.core.runtime.ContributorFactorySimple;
> import org.eclipse.core.runtime.IConfigurationElement;
> import org.eclipse.core.runtime.IContributor;
> import org.eclipse.core.runtime.IExtension;
> import org.eclipse.core.runtime.IExtensionPoint;
> import org.eclipse.core.runtime.IExtensionRegistry;
> import org.eclipse.core.runtime.RegistryFactory;
> import org.eclipse.core.runtime.spi.RegistryStrategy;
>
> /**
> * Takes an eclipse/plugins directory and loads an IExtensionRegistry
> * with the plugin.xml information. It'll even try and load the
> * bundle id and main localization information.
> *
> * To run it you need 3 jars:
> * <ul>
> * <li>org.eclipse.equinox.supplement or org.eclipse.osgi</li>
> * <li>org.eclipse.equinox.common</li>
> * <li>org.eclipse.equinox.registry</li>
> * </ul>
> */
> public class CheckRegistry {
>
> private static final String LOCALIZATION_NAME = "plugin.properties";
> private static final String PLUGIN_XML_NAME = "plugin.xml";
>
> public static final String BUNDLE_SYMBOLICNAME = "Bundle-SymbolicName";
> public final static String BUNDLE_LOCALIZATION = "Bundle-Localization";
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> if (args.length < 1) {
> System.out.println("Need a plugins directory");
> return;
> }
> CheckRegistry check = new CheckRegistry(args[0]);
> check.validate();
> }
>
> private String dir;
> private Object masterToken;
> private IExtensionRegistry registry;
>
> private static class BundleInfo {
> InputStream pluginxml = null;
> ResourceBundle resources = null;
> IContributor contributor = null;
> }
>
> public CheckRegistry(String pluginsDir) {
> dir = pluginsDir;
> masterToken = new Object();
> registry = RegistryFactory.createRegistry(new RegistryStrategy(null,
> null), masterToken, null);
> }
>
> public void validate() {
> File directory = new File(dir);
> if (!directory.exists()) {
> System.out.println(dir + " does not exist");
> return;
> }
> File[] files = directory.listFiles();
> for (int i = 0; i < files.length; i++) {
> try {
> BundleInfo in = getPluginInfo(files[i]);
> if (in != null) {
> System.out.println("processing: " + files[i]);
> registry.addContribution(in.pluginxml, in.contributor,
> false, in.contributor.getName(), in.resources,
> masterToken);
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> IExtensionPoint[] extensionPoints = registry.getExtensionPoints();
> for (int i = 0; i < extensionPoints.length; i++) {
> System.out.println("ep: "
> + extensionPoints[i].getUniqueIdentifier());
> }
> IExtensionPoint extensionPoint = registry
> .getExtensionPoint("org.eclipse.ui.commands");
> IExtension[] extensions = extensionPoint.getExtensions();
> for (int i = 0; i < extensions.length; i++) {
> IConfigurationElement[] configurationElements = extensions[i]
> .getConfigurationElements();
> for (int j = 0; j < configurationElements.length; j++) {
> System.out.println("e: "
> + configurationElements[j].getAttribute("id") + "\n\t"
> + configurationElements[j].getAttribute("name"));
> }
> }
> }
>
> private BundleInfo getPluginInfo(File file) throws Exception {
> String propName = LOCALIZATION_NAME;
> if (file.isDirectory()) {
> File xml = new File(file, PLUGIN_XML_NAME);
> if (xml.exists()) {
> BundleInfo b = new BundleInfo();
> b.pluginxml = new FileInputStream(xml);
> b.contributor = ContributorFactorySimple.createContributor(file
> .getName().split("_")[0]);
> File cont = new File(file, "META-INF/MANIFEST.MF");
> if (cont.exists()) {
> Manifest m = new Manifest(new FileInputStream(cont));
> ContributorFactorySimple.createContributor(m
> .getMainAttributes().getValue(BUNDLE_SYMBOLICNAME)
> .split(";")[0].trim());
> String baseName = m.getMainAttributes().getValue(
> BUNDLE_LOCALIZATION);
> if (baseName != null) {
> propName = baseName + ".properties";
> }
> }
> File prop = new File(file, propName);
> if (prop.exists()) {
> b.resources = new PropertyResourceBundle(
> new FileInputStream(prop));
> }
> return b;
> }
> return null;
> }
> if (file.getName().endsWith("jar")) {
> JarFile jf = new JarFile(file);
> JarEntry entry = jf.getJarEntry(PLUGIN_XML_NAME);
> if (entry != null) {
> BundleInfo b = new BundleInfo();
> b.pluginxml = jf.getInputStream(entry);
> b.contributor = ContributorFactorySimple.createContributor(jf
> .getManifest().getMainAttributes().getValue(
> BUNDLE_SYMBOLICNAME).split(";")[0].trim());
> String baseName = jf.getManifest().getMainAttributes()
> .getValue(BUNDLE_LOCALIZATION);
> if (baseName != null) {
> propName = baseName + ".properties";
> }
> JarEntry prop = jf.getJarEntry(propName);
> if (prop != null) {
> b.resources = new PropertyResourceBundle(jf
> .getInputStream(prop));
> }
> return b;
> }
> }
> return null;
> }
> }
>