diff options
4 files changed, 50 insertions, 147 deletions
diff --git a/bundles/org.eclipse.core.net/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.net/META-INF/MANIFEST.MF index 5634320a1..9c3ebd765 100644 --- a/bundles/org.eclipse.core.net/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.core.net/META-INF/MANIFEST.MF @@ -6,18 +6,10 @@ 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 1e516be80..def0948a1 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,18 +15,15 @@ package org.eclipse.core.internal.net; -import java.net.URL; -import java.util.*; -import org.eclipse.core.internal.runtime.auth.AuthorizationHandler; +import java.util.Hashtable; + import org.eclipse.core.net.proxy.IProxyService; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.osgi.framework.log.FrameworkLog; -import org.eclipse.osgi.framework.log.FrameworkLogEntry; -import org.osgi.framework.*; -import org.osgi.util.tracker.ServiceTracker; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; -public class Activator implements BundleActivator { +public class Activator extends Plugin { /** * The identifier of the descriptor of this plugin in plugin.xml. */ @@ -36,150 +33,63 @@ public class Activator implements BundleActivator { private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$ - private static BundleContext bundleContext; - private static ServiceTracker extensionRegistryTracker; - private static ServiceTracker logTracker; + /** + * The instance of this plugin. + */ + private static Activator instance; + private ServiceRegistration proxyService; - /* - * Return this bundle's context, or null. + /** + * Constructor for use by the Eclipse platform only. */ - public static BundleContext getBundleContext() { - return bundleContext; + public Activator() { + super(); + instance = this; } - /* (non-Javadoc) - * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + /** + * Returns the instance of this plugin. + * @return the singleton instance of this plug-in class */ + static public Activator getInstance() { + return instance; + } + public void start(BundleContext context) throws Exception { - bundleContext = context; + super.start(context); if (Boolean.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$ ProxyManager proxyManager = (ProxyManager)ProxyManager.getProxyManager(); proxyManager.initialize(); - proxyService = getBundleContext().registerService(IProxyService.class.getName(), proxyManager, new Hashtable()); + proxyService = getBundle().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; } - if (extensionRegistryTracker != null) { - extensionRegistryTracker.close(); - extensionRegistryTracker = null; - } - if (logTracker != null) { - logTracker.close(); - logTracker = null; - } - bundleContext = null; + super.stop(context); } - - /* - * 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) { - log(new Status(IStatus.INFO, ID, 0, message, exc)); - } - - public static org.osgi.service.prefs.Preferences getInstancePreferences() { - return new InstanceScope().getNode(ID); - } - - public static void log(int severity, String message, Throwable throwable) { - log(new Status(severity, ID, 0, message, throwable)); - } + IStatus status = new Status(IStatus.ERROR, ID, 0, message, exc); - /* - * 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(); + getInstance().getLog().log(status); } - /* - * 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); - } + public static void logInfo(String message, Throwable exc) { + IStatus status = new Status(IStatus.INFO, ID, 0, message, exc); - /* - * 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); + getInstance().getLog().log(status); } - /* - * 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(); - } + public org.osgi.service.prefs.Preferences getInstancePreferences() { + return new InstanceScope().getNode(getBundle().getSymbolicName()); } - /** - * 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); + public static void log(int severity, String message, Throwable throwable) { + getInstance().getLog().log(new Status(severity, ID, 0, message, throwable)); } - } 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 75111642f..defb130e7 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.getInstancePreferences().get(PREF_NON_PROXIED_HOSTS, "localhost|127.0.0.1"); //$NON-NLS-1$ + String prop = Activator.getInstance().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.getInstancePreferences().put(PREF_NON_PROXIED_HOSTS, ProxyType.convertHostsToPropertyString(nonProxiedHosts)); + Activator.getInstance().getInstancePreferences().put(PREF_NON_PROXIED_HOSTS, ProxyType.convertHostsToPropertyString(nonProxiedHosts)); try { - Activator.getInstancePreferences().flush(); + Activator.getInstance().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.getInstancePreferences().getBoolean(PREF_ENABLED, false); + return Activator.getInstance().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.getInstancePreferences().putBoolean(PREF_ENABLED, enabled); + Activator.getInstance().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.getInstancePreferences().flush(); + Activator.getInstance().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.getInstancePreferences()).addPreferenceChangeListener(this); + ((IEclipsePreferences)Activator.getInstance().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 = Activator.getExtensionRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions(); + IExtension[] extensions = Platform.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.getInstancePreferences().getBoolean(PREF_ENABLED, false)); + internalSetEnabled(Activator.getInstance().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 d6a0e85c2..2948f4943 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,7 +114,8 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener * @return a preferences node */ private Preferences getParentPreferences() { - return Activator.getInstancePreferences().node(PREF_PROXY_DATA_NODE); + return Activator.getInstance().getInstancePreferences().node( + PREF_PROXY_DATA_NODE); } public IProxyData getProxyData(int verifyFlag) { @@ -471,7 +472,7 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener private Map getAuthInfo() { // Retrieve username and password from keyring. - Map authInfo = Activator.getAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$ + Map authInfo = Platform.getAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$ return authInfo != null ? authInfo : Collections.EMPTY_MAP; } @@ -500,9 +501,9 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener } try { if (authInfo.isEmpty()) { - Activator.flushAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$ + Platform.flushAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$ } else { - Activator.addAuthorizationInfo(FAKE_URL, getName(), "", authInfo); //$NON-NLS-1$ + Platform.addAuthorizationInfo(FAKE_URL, getName(), "", authInfo); //$NON-NLS-1$ } } catch (CoreException e) { Activator.logError(e.getMessage(), e); |