Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 214796 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/net/ProxyManager.java (-9 / +9 lines)
Lines 90-96 Link Here
90
	 */
90
	 */
91
	public synchronized String[] getNonProxiedHosts() {
91
	public synchronized String[] getNonProxiedHosts() {
92
		if (nonProxiedHosts == null) {
92
		if (nonProxiedHosts == null) {
93
			String prop = Activator.getInstance().getInstancePreferences().get(PREF_NON_PROXIED_HOSTS, "localhost|127.0.0.1"); //$NON-NLS-1$
93
			String prop = Activator.getInstancePreferences().get(PREF_NON_PROXIED_HOSTS, "localhost|127.0.0.1"); //$NON-NLS-1$
94
			nonProxiedHosts = ProxyType.convertPropertyStringToHosts(prop);
94
			nonProxiedHosts = ProxyType.convertPropertyStringToHosts(prop);
95
		}
95
		}
96
		if (nonProxiedHosts.length == 0)
96
		if (nonProxiedHosts.length == 0)
Lines 112-120 Link Here
112
		}
112
		}
113
		String[] oldHosts = nonProxiedHosts;
113
		String[] oldHosts = nonProxiedHosts;
114
		nonProxiedHosts = hosts;
114
		nonProxiedHosts = hosts;
115
		Activator.getInstance().getInstancePreferences().put(PREF_NON_PROXIED_HOSTS, ProxyType.convertHostsToPropertyString(nonProxiedHosts));
115
		Activator.getInstancePreferences().put(PREF_NON_PROXIED_HOSTS, ProxyType.convertHostsToPropertyString(nonProxiedHosts));
116
		try {
116
		try {
117
			Activator.getInstance().getInstancePreferences().flush();
117
			Activator.getInstancePreferences().flush();
118
		} catch (BackingStoreException e) {
118
		} catch (BackingStoreException e) {
119
			Activator.logError(
119
			Activator.logError(
120
					"An error occurred while writing out the non-proxied hosts list", e); //$NON-NLS-1$
120
					"An error occurred while writing out the non-proxied hosts list", e); //$NON-NLS-1$
Lines 174-180 Link Here
174
	 * @see org.eclipse.core.net.IProxyManager#isProxiesEnabled()
174
	 * @see org.eclipse.core.net.IProxyManager#isProxiesEnabled()
175
	 */
175
	 */
176
	public boolean isProxiesEnabled() {
176
	public boolean isProxiesEnabled() {
177
		return Activator.getInstance().getInstancePreferences().getBoolean(PREF_ENABLED, false);
177
		return Activator.getInstancePreferences().getBoolean(PREF_ENABLED, false);
178
	}
178
	}
179
179
180
	/* (non-Javadoc)
180
	/* (non-Javadoc)
Lines 186-192 Link Here
186
			return;
186
			return;
187
		// Setting the preference will trigger the system property update
187
		// Setting the preference will trigger the system property update
188
		// (see preferenceChange)
188
		// (see preferenceChange)
189
		Activator.getInstance().getInstancePreferences().putBoolean(PREF_ENABLED, enabled);
189
		Activator.getInstancePreferences().putBoolean(PREF_ENABLED, enabled);
190
	}
190
	}
191
191
192
	private void internalSetEnabled(boolean enabled) {
192
	private void internalSetEnabled(boolean enabled) {
Lines 194-200 Link Here
194
		sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
194
		sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
195
		updateSystemProperties();
195
		updateSystemProperties();
196
		try {
196
		try {
197
			Activator.getInstance().getInstancePreferences().flush();
197
			Activator.getInstancePreferences().flush();
198
		} catch (BackingStoreException e) {
198
		} catch (BackingStoreException e) {
199
			Activator.logError(
199
			Activator.logError(
200
					"An error occurred while writing out the enablement state", e); //$NON-NLS-1$
200
					"An error occurred while writing out the enablement state", e); //$NON-NLS-1$
Lines 215-221 Link Here
215
	public void initialize() {
215
	public void initialize() {
216
		// First see if there is an http proxy to migrate
216
		// First see if there is an http proxy to migrate
217
		migrateUpdateHttpProxy(new InstanceScope().getNode(""), true); //$NON-NLS-1$
217
		migrateUpdateHttpProxy(new InstanceScope().getNode(""), true); //$NON-NLS-1$
218
		((IEclipsePreferences)Activator.getInstance().getInstancePreferences()).addPreferenceChangeListener(this);
218
		((IEclipsePreferences)Activator.getInstancePreferences()).addPreferenceChangeListener(this);
219
		// Now initialize each proxy type
219
		// Now initialize each proxy type
220
		for (int i = 0; i < proxies.length; i++) {
220
		for (int i = 0; i < proxies.length; i++) {
221
			ProxyType type = proxies[i];
221
			ProxyType type = proxies[i];
Lines 287-293 Link Here
287
	}
287
	}
288
	
288
	
289
	private Authenticator getPluggedInAuthenticator() {
289
	private Authenticator getPluggedInAuthenticator() {
290
		IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
290
		IExtension[] extensions = Activator.getExtensionRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
291
		if (extensions.length == 0)
291
		if (extensions.length == 0)
292
			return null;
292
			return null;
293
		IExtension extension = extensions[0];
293
		IExtension extension = extensions[0];
Lines 366-372 Link Here
366
366
367
	public void preferenceChange(PreferenceChangeEvent event) {
367
	public void preferenceChange(PreferenceChangeEvent event) {
368
		if (event.getKey().equals(PREF_ENABLED)) {
368
		if (event.getKey().equals(PREF_ENABLED)) {
369
			internalSetEnabled(Activator.getInstance().getInstancePreferences().getBoolean(PREF_ENABLED, false));
369
			internalSetEnabled(Activator.getInstancePreferences().getBoolean(PREF_ENABLED, false));
370
		}
370
		}
371
	}
371
	}
372
372
(-)src/org/eclipse/core/internal/net/Activator.java (-35 / +125 lines)
Lines 15-29 Link Here
15
15
16
package org.eclipse.core.internal.net;
16
package org.eclipse.core.internal.net;
17
17
18
import java.util.Hashtable;
18
import java.net.URL;
19
19
import java.util.*;
20
import org.eclipse.core.internal.runtime.auth.AuthorizationHandler;
20
import org.eclipse.core.net.proxy.IProxyService;
21
import org.eclipse.core.net.proxy.IProxyService;
21
import org.eclipse.core.runtime.*;
22
import org.eclipse.core.runtime.*;
22
import org.eclipse.core.runtime.preferences.InstanceScope;
23
import org.eclipse.core.runtime.preferences.InstanceScope;
23
import org.osgi.framework.BundleContext;
24
import org.eclipse.osgi.framework.log.FrameworkLog;
24
import org.osgi.framework.ServiceRegistration;
25
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
26
import org.osgi.framework.*;
27
import org.osgi.util.tracker.ServiceTracker;
25
28
26
public class Activator extends Plugin {
29
public class Activator implements BundleActivator {
27
	/**
30
	/**
28
	 * The identifier of the descriptor of this plugin in plugin.xml.
31
	 * The identifier of the descriptor of this plugin in plugin.xml.
29
	 */
32
	 */
Lines 33-95 Link Here
33
	
36
	
34
	private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$
37
	private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$
35
38
36
	/**
39
	private static BundleContext bundleContext;
37
	 * The instance of this plugin.
40
	private static ServiceTracker extensionRegistryTracker;
38
	 */
41
	private static ServiceTracker logTracker;
39
	private static Activator instance;
40
41
	private ServiceRegistration proxyService;
42
	private ServiceRegistration proxyService;
42
43
43
	/**
44
	/*
44
	 * Constructor for use by the Eclipse platform only.
45
	 * Return this bundle's context, or null.
45
	 */
46
	 */
46
	public Activator() {
47
	public static BundleContext getBundleContext() {
47
		super();
48
		return bundleContext;
48
		instance = this;
49
	}
49
	}
50
50
51
	/**
51
	/* (non-Javadoc)
52
	 * Returns the instance of this plugin.
52
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
53
	 * @return the singleton instance of this plug-in class
54
	 */
53
	 */
55
	static public Activator getInstance() {
56
		return instance;
57
	}
58
59
	public void start(BundleContext context) throws Exception {
54
	public void start(BundleContext context) throws Exception {
60
		super.start(context);
55
		bundleContext = context;
61
		if (Boolean.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$
56
		if (Boolean.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$
62
			ProxyManager proxyManager = (ProxyManager)ProxyManager.getProxyManager();
57
			ProxyManager proxyManager = (ProxyManager)ProxyManager.getProxyManager();
63
			proxyManager.initialize();
58
			proxyManager.initialize();
64
			proxyService = getBundle().getBundleContext().registerService(IProxyService.class.getName(), proxyManager, new Hashtable());
59
			proxyService = getBundleContext().registerService(IProxyService.class.getName(), proxyManager, new Hashtable());
65
		}
60
		}
66
	}
61
	}
67
	
62
	
63
	/* (non-Javadoc)
64
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
65
	 */
68
	public void stop(BundleContext context) throws Exception {
66
	public void stop(BundleContext context) throws Exception {
69
		if (proxyService != null) {
67
		if (proxyService != null) {
70
			proxyService.unregister();
68
			proxyService.unregister();
71
			proxyService = null;
69
			proxyService = null;
72
		}
70
		}
73
		super.stop(context);
71
		if (extensionRegistryTracker != null) {
72
			extensionRegistryTracker.close();
73
			extensionRegistryTracker = null;
74
		}
75
		if (logTracker != null) {
76
			logTracker.close();
77
			logTracker = null;
78
		}
79
		bundleContext = null;
74
	}
80
	}
75
	
76
	public static void logError(String message, Throwable exc) {
77
		IStatus status = new Status(IStatus.ERROR, ID, 0, message, exc);
78
81
79
		getInstance().getLog().log(status);
82
	/*
83
	 * Log the given message as an error.
84
	 */
85
	public static void logError(String message, Throwable exc) {
86
		log(new Status(IStatus.ERROR, ID, 0, message, exc));
80
	}
87
	}
81
88
89
	/*
90
	 * Log the given message as an informational message.
91
	 */
82
	public static void logInfo(String message, Throwable exc) {
92
	public static void logInfo(String message, Throwable exc) {
83
		IStatus status = new Status(IStatus.INFO, ID, 0, message, exc);
93
		log(new Status(IStatus.INFO, ID, 0, message, exc));
84
85
		getInstance().getLog().log(status);
86
	}
94
	}
87
95
88
	public org.osgi.service.prefs.Preferences getInstancePreferences() {
96
	public static org.osgi.service.prefs.Preferences getInstancePreferences() {
89
		return new InstanceScope().getNode(getBundle().getSymbolicName());
97
		return new InstanceScope().getNode(ID);
90
	}
98
	}
91
99
92
	public static void log(int severity, String message, Throwable throwable) {
100
	public static void log(int severity, String message, Throwable throwable) {
93
		getInstance().getLog().log(new Status(severity, ID, 0, message, throwable));
101
		log(new Status(severity, ID, 0, message, throwable));
94
	}
102
	}
103
104
	/*
105
	 * Return the extension registry. It is acquired lazily.
106
	 */
107
	public static IExtensionRegistry getExtensionRegistry() {
108
		if (extensionRegistryTracker == null) {
109
			extensionRegistryTracker = new ServiceTracker(getBundleContext(), IExtensionRegistry.class.getName(), null);
110
			extensionRegistryTracker.open();
111
		}
112
		return (IExtensionRegistry) extensionRegistryTracker.getService();
113
	}
114
115
	/*
116
	 * TODO: This currently references internal classes but will be replaced by the new security work
117
	 * to be available in Eclipse 3.4.
118
	 */
119
	public static void addAuthorizationInfo(URL serverUrl, String realm, String authScheme, Map info) throws CoreException {
120
		AuthorizationHandler.addAuthorizationInfo(serverUrl, realm, authScheme, info);
121
	}
122
123
	/*
124
	 * TODO: This currently references internal classes but will be replaced by the new security work
125
	 * to be available in Eclipse 3.4.
126
	 */
127
	public static Map getAuthorizationInfo(URL serverUrl, String realm, String authScheme) {
128
		return AuthorizationHandler.getAuthorizationInfo(serverUrl, realm, authScheme);
129
	}
130
	
131
	/*
132
	 * TODO: This currently references internal classes but will be replaced by the new security work
133
	 * to be available in Eclipse 3.4.
134
	 */
135
	public static void flushAuthorizationInfo(URL serverUrl, String realm, String authScheme) throws CoreException {
136
		AuthorizationHandler.flushAuthorizationInfo(serverUrl, realm, authScheme);
137
	}
138
139
	/*
140
	 * Log the given status to the log file. If the log is not available, log the status to the console.
141
	 */
142
	public static void log(IStatus status) {
143
		if (logTracker == null) {
144
			logTracker = new ServiceTracker(getBundleContext(), FrameworkLog.class.getName(), null);
145
			logTracker.open();
146
		}
147
		FrameworkLog log = (FrameworkLog) logTracker.getService();
148
		if (log != null) {
149
			log.log(getLog(status));
150
		} else {
151
			System.out.println(status.getMessage());
152
			if (status.getException() != null)
153
				status.getException().printStackTrace();
154
		}
155
	}
156
157
	/**
158
	 * Copied from PlatformLogWriter in core runtime.
159
	 */
160
	private static FrameworkLogEntry getLog(IStatus status) {
161
		Throwable t = status.getException();
162
		ArrayList childlist = new ArrayList();
163
164
		int stackCode = t instanceof CoreException ? 1 : 0;
165
		// ensure a substatus inside a CoreException is properly logged 
166
		if (stackCode == 1) {
167
			IStatus coreStatus = ((CoreException) t).getStatus();
168
			if (coreStatus != null) {
169
				childlist.add(getLog(coreStatus));
170
			}
171
		}
172
173
		if (status.isMultiStatus()) {
174
			IStatus[] children = status.getChildren();
175
			for (int i = 0; i < children.length; i++) {
176
				childlist.add(getLog(children[i]));
177
			}
178
		}
179
180
		FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()]));
181
182
		return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children);
183
	}
184
95
}
185
}
(-)src/org/eclipse/core/internal/net/ProxyType.java (-5 / +4 lines)
Lines 114-121 Link Here
114
	 * @return a preferences node
114
	 * @return a preferences node
115
	 */
115
	 */
116
	private Preferences getParentPreferences() {
116
	private Preferences getParentPreferences() {
117
		return Activator.getInstance().getInstancePreferences().node(
117
		return Activator.getInstancePreferences().node(PREF_PROXY_DATA_NODE);
118
				PREF_PROXY_DATA_NODE);
119
	}
118
	}
120
119
121
	public IProxyData getProxyData(int verifyFlag) {
120
	public IProxyData getProxyData(int verifyFlag) {
Lines 472-478 Link Here
472
	
471
	
473
    private Map getAuthInfo() {
472
    private Map getAuthInfo() {
474
		// Retrieve username and password from keyring.
473
		// Retrieve username and password from keyring.
475
		Map authInfo = Platform.getAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$
474
		Map authInfo = Activator.getAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$
476
		return authInfo != null ? authInfo : Collections.EMPTY_MAP;
475
		return authInfo != null ? authInfo : Collections.EMPTY_MAP;
477
	}
476
	}
478
477
Lines 501-509 Link Here
501
		}
500
		}
502
		try {
501
		try {
503
			if (authInfo.isEmpty()) {
502
			if (authInfo.isEmpty()) {
504
				Platform.flushAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$
503
				Activator.flushAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$
505
			} else {
504
			} else {
506
				Platform.addAuthorizationInfo(FAKE_URL, getName(), "", authInfo); //$NON-NLS-1$
505
				Activator.addAuthorizationInfo(FAKE_URL, getName(), "", authInfo); //$NON-NLS-1$
507
			}
506
			}
508
		} catch (CoreException e) {
507
		} catch (CoreException e) {
509
			Activator.logError(e.getMessage(), e);
508
			Activator.logError(e.getMessage(), e);
(-)META-INF/MANIFEST.MF (-1 / +9 lines)
Lines 6-15 Link Here
6
Bundle-Activator: org.eclipse.core.internal.net.Activator
6
Bundle-Activator: org.eclipse.core.internal.net.Activator
7
Bundle-Vendor: %PLUGIN_PROVIDER
7
Bundle-Vendor: %PLUGIN_PROVIDER
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)"
10
Eclipse-LazyStart: true
9
Eclipse-LazyStart: true
11
Export-Package: org.eclipse.core.internal.net;x-internal:=true,
10
Export-Package: org.eclipse.core.internal.net;x-internal:=true,
12
 org.eclipse.core.net.proxy
11
 org.eclipse.core.net.proxy
13
Bundle-RequiredExecutionEnvironment: J2SE-1.4,
12
Bundle-RequiredExecutionEnvironment: J2SE-1.4,
14
 CDC-1.0/Foundation-1.0,
13
 CDC-1.0/Foundation-1.0,
15
 J2SE-1.3
14
 J2SE-1.3
15
Import-Package: org.eclipse.core.runtime.preferences,
16
 org.eclipse.osgi.framework.log;version="1.0.0",
17
 org.eclipse.osgi.util;version="1.1.0",
18
 org.osgi.framework;version="1.4.0",
19
 org.osgi.service.prefs;version="1.1.0",
20
 org.osgi.util.tracker;version="1.3.3"
21
Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.3.0,4.0.0)",
22
 org.eclipse.equinox.registry;bundle-version="[3.3.0,4.0.0)",
23
 org.eclipse.core.runtime.compatibility.auth;bundle-version="[3.2.0,4.0.0)"

Return to bug 214796