diff options
author | Tomasz Zarna | 2008-01-15 14:30:27 +0000 |
---|---|---|
committer | Tomasz Zarna | 2008-01-15 14:30:27 +0000 |
commit | 9c092e1b81fc5e878bd7e69698bd5d34147e760a (patch) | |
tree | 56c1fa701a5be5a6b90cc9481d31529cb21ed67f | |
parent | 5fb8c58ea5947c140db16e28478852675a9e69d3 (diff) | |
download | eclipse.platform.team-9c092e1b81fc5e878bd7e69698bd5d34147e760a.tar.gz eclipse.platform.team-9c092e1b81fc5e878bd7e69698bd5d34147e760a.tar.xz eclipse.platform.team-9c092e1b81fc5e878bd7e69698bd5d34147e760a.zip |
bug 214796: org.eclipse.core.net bundle should not require org.eclipse.core.runtime
4 files changed, 147 insertions, 50 deletions
diff --git a/bundles/org.eclipse.core.net/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.net/META-INF/MANIFEST.MF index 9c3ebd765..5634320a1 100644 --- a/bundles/org.eclipse.core.net/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.core.net/META-INF/MANIFEST.MF @@ -6,10 +6,18 @@ Bundle-Version: 1.0.100.qualifier Bundle-Activator: org.eclipse.core.internal.net.Activator Bundle-Vendor: %PLUGIN_PROVIDER Bundle-Localization: plugin -Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)" Eclipse-LazyStart: true Export-Package: org.eclipse.core.internal.net;x-internal:=true, org.eclipse.core.net.proxy Bundle-RequiredExecutionEnvironment: J2SE-1.4, CDC-1.0/Foundation-1.0, J2SE-1.3 +Import-Package: org.eclipse.core.runtime.preferences, + org.eclipse.osgi.framework.log;version="1.0.0", + org.eclipse.osgi.util;version="1.1.0", + org.osgi.framework;version="1.4.0", + org.osgi.service.prefs;version="1.1.0", + org.osgi.util.tracker;version="1.3.3" +Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.3.0,4.0.0)", + org.eclipse.equinox.registry;bundle-version="[3.3.0,4.0.0)", + org.eclipse.core.runtime.compatibility.auth;bundle-version="[3.2.0,4.0.0)" diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/Activator.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/Activator.java index def0948a1..1e516be80 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/Activator.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/Activator.java @@ -15,15 +15,18 @@ package org.eclipse.core.internal.net; -import java.util.Hashtable; - +import java.net.URL; +import java.util.*; +import org.eclipse.core.internal.runtime.auth.AuthorizationHandler; import org.eclipse.core.net.proxy.IProxyService; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; +import org.eclipse.osgi.framework.log.FrameworkLog; +import org.eclipse.osgi.framework.log.FrameworkLogEntry; +import org.osgi.framework.*; +import org.osgi.util.tracker.ServiceTracker; -public class Activator extends Plugin { +public class Activator implements BundleActivator { /** * The identifier of the descriptor of this plugin in plugin.xml. */ @@ -33,63 +36,150 @@ public class Activator extends Plugin { private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$ - /** - * The instance of this plugin. - */ - private static Activator instance; - + private static BundleContext bundleContext; + private static ServiceTracker extensionRegistryTracker; + private static ServiceTracker logTracker; private ServiceRegistration proxyService; - /** - * Constructor for use by the Eclipse platform only. + /* + * Return this bundle's context, or null. */ - public Activator() { - super(); - instance = this; + public static BundleContext getBundleContext() { + return bundleContext; } - /** - * Returns the instance of this plugin. - * @return the singleton instance of this plug-in class + /* (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ - static public Activator getInstance() { - return instance; - } - public void start(BundleContext context) throws Exception { - super.start(context); + bundleContext = context; if (Boolean.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$ ProxyManager proxyManager = (ProxyManager)ProxyManager.getProxyManager(); proxyManager.initialize(); - proxyService = getBundle().getBundleContext().registerService(IProxyService.class.getName(), proxyManager, new Hashtable()); + proxyService = getBundleContext().registerService(IProxyService.class.getName(), proxyManager, new Hashtable()); } } + /* (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ public void stop(BundleContext context) throws Exception { if (proxyService != null) { proxyService.unregister(); proxyService = null; } - super.stop(context); + if (extensionRegistryTracker != null) { + extensionRegistryTracker.close(); + extensionRegistryTracker = null; + } + if (logTracker != null) { + logTracker.close(); + logTracker = null; + } + bundleContext = null; } - - public static void logError(String message, Throwable exc) { - IStatus status = new Status(IStatus.ERROR, ID, 0, message, exc); - getInstance().getLog().log(status); + /* + * Log the given message as an error. + */ + public static void logError(String message, Throwable exc) { + log(new Status(IStatus.ERROR, ID, 0, message, exc)); } + /* + * Log the given message as an informational message. + */ public static void logInfo(String message, Throwable exc) { - IStatus status = new Status(IStatus.INFO, ID, 0, message, exc); - - getInstance().getLog().log(status); + log(new Status(IStatus.INFO, ID, 0, message, exc)); } - public org.osgi.service.prefs.Preferences getInstancePreferences() { - return new InstanceScope().getNode(getBundle().getSymbolicName()); + public static org.osgi.service.prefs.Preferences getInstancePreferences() { + return new InstanceScope().getNode(ID); } public static void log(int severity, String message, Throwable throwable) { - getInstance().getLog().log(new Status(severity, ID, 0, message, throwable)); + log(new Status(severity, ID, 0, message, throwable)); + } + + /* + * Return the extension registry. It is acquired lazily. + */ + public static IExtensionRegistry getExtensionRegistry() { + if (extensionRegistryTracker == null) { + extensionRegistryTracker = new ServiceTracker(getBundleContext(), IExtensionRegistry.class.getName(), null); + extensionRegistryTracker.open(); + } + return (IExtensionRegistry) extensionRegistryTracker.getService(); + } + + /* + * TODO: This currently references internal classes but will be replaced by the new security work + * to be available in Eclipse 3.4. + */ + public static void addAuthorizationInfo(URL serverUrl, String realm, String authScheme, Map info) throws CoreException { + AuthorizationHandler.addAuthorizationInfo(serverUrl, realm, authScheme, info); + } + + /* + * TODO: This currently references internal classes but will be replaced by the new security work + * to be available in Eclipse 3.4. + */ + public static Map getAuthorizationInfo(URL serverUrl, String realm, String authScheme) { + return AuthorizationHandler.getAuthorizationInfo(serverUrl, realm, authScheme); + } + + /* + * TODO: This currently references internal classes but will be replaced by the new security work + * to be available in Eclipse 3.4. + */ + public static void flushAuthorizationInfo(URL serverUrl, String realm, String authScheme) throws CoreException { + AuthorizationHandler.flushAuthorizationInfo(serverUrl, realm, authScheme); + } + + /* + * Log the given status to the log file. If the log is not available, log the status to the console. + */ + public static void log(IStatus status) { + if (logTracker == null) { + logTracker = new ServiceTracker(getBundleContext(), FrameworkLog.class.getName(), null); + logTracker.open(); + } + FrameworkLog log = (FrameworkLog) logTracker.getService(); + if (log != null) { + log.log(getLog(status)); + } else { + System.out.println(status.getMessage()); + if (status.getException() != null) + status.getException().printStackTrace(); + } } + + /** + * Copied from PlatformLogWriter in core runtime. + */ + private static FrameworkLogEntry getLog(IStatus status) { + Throwable t = status.getException(); + ArrayList childlist = new ArrayList(); + + int stackCode = t instanceof CoreException ? 1 : 0; + // ensure a substatus inside a CoreException is properly logged + if (stackCode == 1) { + IStatus coreStatus = ((CoreException) t).getStatus(); + if (coreStatus != null) { + childlist.add(getLog(coreStatus)); + } + } + + if (status.isMultiStatus()) { + IStatus[] children = status.getChildren(); + for (int i = 0; i < children.length; i++) { + childlist.add(getLog(children[i])); + } + } + + FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()])); + + return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children); + } + } diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java index defb130e7..75111642f 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java @@ -90,7 +90,7 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { */ public synchronized String[] getNonProxiedHosts() { if (nonProxiedHosts == null) { - String prop = Activator.getInstance().getInstancePreferences().get(PREF_NON_PROXIED_HOSTS, "localhost|127.0.0.1"); //$NON-NLS-1$ + String prop = Activator.getInstancePreferences().get(PREF_NON_PROXIED_HOSTS, "localhost|127.0.0.1"); //$NON-NLS-1$ nonProxiedHosts = ProxyType.convertPropertyStringToHosts(prop); } if (nonProxiedHosts.length == 0) @@ -112,9 +112,9 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { } String[] oldHosts = nonProxiedHosts; nonProxiedHosts = hosts; - Activator.getInstance().getInstancePreferences().put(PREF_NON_PROXIED_HOSTS, ProxyType.convertHostsToPropertyString(nonProxiedHosts)); + Activator.getInstancePreferences().put(PREF_NON_PROXIED_HOSTS, ProxyType.convertHostsToPropertyString(nonProxiedHosts)); try { - Activator.getInstance().getInstancePreferences().flush(); + Activator.getInstancePreferences().flush(); } catch (BackingStoreException e) { Activator.logError( "An error occurred while writing out the non-proxied hosts list", e); //$NON-NLS-1$ @@ -174,7 +174,7 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { * @see org.eclipse.core.net.IProxyManager#isProxiesEnabled() */ public boolean isProxiesEnabled() { - return Activator.getInstance().getInstancePreferences().getBoolean(PREF_ENABLED, false); + return Activator.getInstancePreferences().getBoolean(PREF_ENABLED, false); } /* (non-Javadoc) @@ -186,7 +186,7 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { return; // Setting the preference will trigger the system property update // (see preferenceChange) - Activator.getInstance().getInstancePreferences().putBoolean(PREF_ENABLED, enabled); + Activator.getInstancePreferences().putBoolean(PREF_ENABLED, enabled); } private void internalSetEnabled(boolean enabled) { @@ -194,7 +194,7 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ updateSystemProperties(); try { - Activator.getInstance().getInstancePreferences().flush(); + Activator.getInstancePreferences().flush(); } catch (BackingStoreException e) { Activator.logError( "An error occurred while writing out the enablement state", e); //$NON-NLS-1$ @@ -215,7 +215,7 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { public void initialize() { // First see if there is an http proxy to migrate migrateUpdateHttpProxy(new InstanceScope().getNode(""), true); //$NON-NLS-1$ - ((IEclipsePreferences)Activator.getInstance().getInstancePreferences()).addPreferenceChangeListener(this); + ((IEclipsePreferences)Activator.getInstancePreferences()).addPreferenceChangeListener(this); // Now initialize each proxy type for (int i = 0; i < proxies.length; i++) { ProxyType type = proxies[i]; @@ -287,7 +287,7 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { } private Authenticator getPluggedInAuthenticator() { - IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions(); + IExtension[] extensions = Activator.getExtensionRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions(); if (extensions.length == 0) return null; IExtension extension = extensions[0]; @@ -366,7 +366,7 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { public void preferenceChange(PreferenceChangeEvent event) { if (event.getKey().equals(PREF_ENABLED)) { - internalSetEnabled(Activator.getInstance().getInstancePreferences().getBoolean(PREF_ENABLED, false)); + internalSetEnabled(Activator.getInstancePreferences().getBoolean(PREF_ENABLED, false)); } } diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java index 2948f4943..d6a0e85c2 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java @@ -114,8 +114,7 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener * @return a preferences node */ private Preferences getParentPreferences() { - return Activator.getInstance().getInstancePreferences().node( - PREF_PROXY_DATA_NODE); + return Activator.getInstancePreferences().node(PREF_PROXY_DATA_NODE); } public IProxyData getProxyData(int verifyFlag) { @@ -472,7 +471,7 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener private Map getAuthInfo() { // Retrieve username and password from keyring. - Map authInfo = Platform.getAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$ + Map authInfo = Activator.getAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$ return authInfo != null ? authInfo : Collections.EMPTY_MAP; } @@ -501,9 +500,9 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener } try { if (authInfo.isEmpty()) { - Platform.flushAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$ + Activator.flushAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$ } else { - Platform.addAuthorizationInfo(FAKE_URL, getName(), "", authInfo); //$NON-NLS-1$ + Activator.addAuthorizationInfo(FAKE_URL, getName(), "", authInfo); //$NON-NLS-1$ } } catch (CoreException e) { Activator.logError(e.getMessage(), e); |