1 11 package org.eclipse.core.internal.runtime; 12 13 import java.lang.reflect.Method ; 14 import org.eclipse.core.runtime.*; 15 import org.osgi.framework.Bundle; 16 17 24 public class CompatibilityHelper { 25 private static final String OPTION_DEBUG_COMPATIBILITY = Platform.PI_RUNTIME + "/compatibility/debug"; public static final boolean DEBUG = Boolean.TRUE.toString().equalsIgnoreCase(InternalPlatform.getDefault().getOption(OPTION_DEBUG_COMPATIBILITY)); 27 public static final String PI_RUNTIME_COMPATIBILITY = "org.eclipse.core.runtime.compatibility"; private static Bundle compatibility = null; 29 30 public synchronized static void nullCompatibility() { 31 compatibility = null; 32 } 33 34 public synchronized static Bundle initializeCompatibility() { 35 if (compatibility == null || (compatibility.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED | Bundle.STOPPING)) != 0) 38 compatibility = org.eclipse.core.internal.runtime.InternalPlatform.getDefault().getBundle(PI_RUNTIME_COMPATIBILITY); 39 return compatibility; 40 } 41 42 public static void setPlugin(IPluginDescriptor descriptor, Plugin plugin) { 43 if (initializeCompatibility() == null) 45 throw new IllegalStateException (); 46 47 try { 48 Method setPlugin = descriptor.getClass().getMethod("setPlugin", new Class [] {Plugin.class}); setPlugin.invoke(descriptor, new Object [] {plugin}); 50 } catch (Exception e) { 51 } 53 } 54 55 public synchronized static IPluginDescriptor getPluginDescriptor(String pluginId) { 56 initializeCompatibility(); 58 if (compatibility == null) 59 throw new IllegalStateException (); 60 61 Class oldInternalPlatform = null; 62 try { 63 oldInternalPlatform = compatibility.loadClass("org.eclipse.core.internal.plugins.InternalPlatform"); Method getPluginDescriptor = oldInternalPlatform.getMethod("getPluginDescriptor", new Class [] {String .class}); return (IPluginDescriptor) getPluginDescriptor.invoke(oldInternalPlatform, new Object [] {pluginId}); 66 } catch (Exception e) { 67 if (DEBUG) { 68 String msg = "Error running compatibility code"; IStatus error = new Status(IStatus.ERROR, Platform.PI_RUNTIME, 1, msg, e); 70 InternalPlatform.getDefault().log(error); 71 } 72 } 74 return null; 75 } 76 77 public synchronized static void setActive(IPluginDescriptor descriptor) { 78 initializeCompatibility(); 79 if (compatibility == null) 80 throw new IllegalStateException (); 81 82 try { 83 Method setPlugin = descriptor.getClass().getMethod("setActive", null); setPlugin.invoke(descriptor, null); 85 } catch (Exception e) { 86 } 88 } 89 90 public synchronized static boolean hasPluginObject(IPluginDescriptor descriptor) { 91 initializeCompatibility(); 92 if (compatibility == null) 93 throw new IllegalStateException (); 94 95 Boolean result = Boolean.FALSE; 96 try { 97 Method setPlugin = descriptor.getClass().getMethod("hasPluginObject", null); result = (Boolean ) setPlugin.invoke(descriptor, null); 99 } catch (Exception e) { 100 } 102 return result.booleanValue(); 103 } 104 } 105 | Popular Tags |