Reorganisation of some backward compatibility calls
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/registry/Extension.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/registry/Extension.java index f0b5753..b282d6d 100644 --- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/registry/Extension.java +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/registry/Extension.java
@@ -11,6 +11,7 @@ package org.eclipse.core.internal.registry; import java.lang.reflect.Method; +import org.eclipse.core.internal.runtime.CompatibilityHelper; import org.eclipse.core.runtime.*; import org.osgi.framework.Bundle; @@ -160,26 +161,9 @@ fullyLoaded = value; } public IPluginDescriptor getDeclaringPluginDescriptor() { - return getPluginDescriptor(((BundleModel) getParent()).getName()); + return CompatibilityHelper.getPluginDescriptor(((BundleModel) getParent()).getName()); } public String getExtensionPointUniqueIdentifier() { return getExtensionPointIdentifier(); } - - public static IPluginDescriptor getPluginDescriptor(String pluginId) { - //Here we use reflection so the runtime code can run without the compatibility - Bundle compatibility = org.eclipse.core.internal.runtime.InternalPlatform.getDefault().getBundle(IPlatform.PI_RUNTIME_COMPATIBILITY); - if (compatibility == null) - return null; - - Class oldInternalPlatform = null; - try { - oldInternalPlatform = compatibility.loadClass("org.eclipse.core.internal.plugins.InternalPlatform"); //$NON-NLS-1$ - Method getPluginDescriptor = oldInternalPlatform.getMethod("getPluginDescriptor", new Class[] { String.class }); //$NON-NLS-1$ - return (IPluginDescriptor) getPluginDescriptor.invoke(oldInternalPlatform, new Object[] { pluginId }); - } catch (Exception e) { - //Ignore the exceptions, return false - } - return null; - } }
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/registry/ExtensionPoint.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/registry/ExtensionPoint.java index d4fbc18..68b80b3 100644 --- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/registry/ExtensionPoint.java +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/registry/ExtensionPoint.java
@@ -13,6 +13,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import org.eclipse.core.internal.runtime.CompatibilityHelper; import org.eclipse.core.runtime.*; /** @@ -94,6 +95,6 @@ return value; } public IPluginDescriptor getDeclaringPluginDescriptor() { - return Extension.getPluginDescriptor(getParentIdentifier()); + return CompatibilityHelper.getPluginDescriptor(getParentIdentifier()); } }
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/CompatibilityHelper.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/CompatibilityHelper.java new file mode 100644 index 0000000..65ffa06 --- /dev/null +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/CompatibilityHelper.java
@@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.core.internal.runtime; + +import java.lang.reflect.Method; +import org.eclipse.core.runtime.*; +import org.osgi.framework.Bundle; + +public class CompatibilityHelper { + public static void setPlugin(IPluginDescriptor descriptor, Plugin plugin) { + //Here we use reflection so the runtime code can run without the compatibility + Bundle compatibility = org.eclipse.core.internal.runtime.InternalPlatform.getDefault().getBundle(IPlatform.PI_RUNTIME_COMPATIBILITY); + if (compatibility == null) + return; + + Class oldInternalPlatform = null; + try { + Method setPlugin = descriptor.getClass().getMethod("setPlugin", new Class[] { Plugin.class }); //$NON-NLS-1$ + setPlugin.invoke(descriptor, new Object[] { plugin }); + } catch (Exception e) { + //Ignore the exceptions, return false + } + } + public static IPluginDescriptor getPluginDescriptor(String pluginId) { + //Here we use reflection so the runtime code can run without the compatibility + Bundle compatibility = org.eclipse.core.internal.runtime.InternalPlatform.getDefault().getBundle(IPlatform.PI_RUNTIME_COMPATIBILITY); + if (compatibility == null) + return null; + + Class oldInternalPlatform = null; + try { + oldInternalPlatform = compatibility.loadClass("org.eclipse.core.internal.plugins.InternalPlatform"); //$NON-NLS-1$ + Method getPluginDescriptor = oldInternalPlatform.getMethod("getPluginDescriptor", new Class[] { String.class }); //$NON-NLS-1$ + return (IPluginDescriptor) getPluginDescriptor.invoke(oldInternalPlatform, new Object[] { pluginId }); + } catch (Exception e) { + //Ignore the exceptions, return false + } + return null; + } +}
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/runtime/Plugin.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/runtime/Plugin.java index 9881836..8a68eac 100644 --- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/runtime/Plugin.java +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/runtime/Plugin.java
@@ -15,6 +15,7 @@ import java.lang.reflect.Method; import java.net.URL; import java.util.*; +import org.eclipse.core.internal.registry.Extension; import org.eclipse.core.internal.runtime.*; import org.eclipse.osgi.service.environment.EnvironmentInfo; import org.osgi.framework.*; @@ -228,6 +229,7 @@ * @since 3.0 */ public Plugin(BundleContext context) { + this.context = context; } /** * Creates a new plug-in runtime object for the given plug-in descriptor. @@ -300,6 +302,11 @@ * @deprecated */ public final IPluginDescriptor getDescriptor() { + if (descriptor!=null) + return descriptor; + IPluginDescriptor descriptor = CompatibilityHelper.getPluginDescriptor(bundle.getGlobalName()); + if (descriptor != null) + CompatibilityHelper.setPlugin(descriptor, this); return descriptor; } /** @@ -882,7 +889,7 @@ } } /** - * Returns the bundle with which this plug-in is associated. + * Returns the bundle * * @return the associated bundle * @since 3.0