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 (-2 / +2 lines)
Lines 28-34 Link Here
28
import org.eclipse.core.runtime.ISafeRunnable;
28
import org.eclipse.core.runtime.ISafeRunnable;
29
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.ListenerList;
30
import org.eclipse.core.runtime.ListenerList;
31
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.RegistryFactory;
32
import org.eclipse.core.runtime.SafeRunner;
32
import org.eclipse.core.runtime.SafeRunner;
33
import org.eclipse.core.runtime.preferences.ConfigurationScope;
33
import org.eclipse.core.runtime.preferences.ConfigurationScope;
34
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
34
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
Lines 351-357 Link Here
351
	}
351
	}
352
	
352
	
353
	private Authenticator getPluggedInAuthenticator() {
353
	private Authenticator getPluggedInAuthenticator() {
354
		IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
354
		IExtension[] extensions = RegistryFactory.getRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
355
		if (extensions.length == 0)
355
		if (extensions.length == 0)
356
			return null;
356
			return null;
357
		IExtension extension = extensions[0];
357
		IExtension extension = extensions[0];
(-)src/org/eclipse/core/internal/net/Activator.java (-49 / +107 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-51 Link Here
15
15
16
package org.eclipse.core.internal.net;
16
package org.eclipse.core.internal.net;
17
17
18
import java.util.ArrayList;
18
import java.util.Hashtable;
19
import java.util.Hashtable;
19
20
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.CoreException;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.Status;
22
import org.eclipse.core.runtime.preferences.ConfigurationScope;
25
import org.eclipse.core.runtime.preferences.ConfigurationScope;
26
import org.eclipse.osgi.framework.log.FrameworkLog;
27
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
23
import org.eclipse.osgi.service.datalocation.Location;
28
import org.eclipse.osgi.service.datalocation.Location;
29
import org.osgi.framework.BundleActivator;
24
import org.osgi.framework.BundleContext;
30
import org.osgi.framework.BundleContext;
25
import org.osgi.framework.Filter;
31
import org.osgi.framework.Filter;
26
import org.osgi.framework.InvalidSyntaxException;
32
import org.osgi.framework.InvalidSyntaxException;
27
import org.osgi.framework.ServiceRegistration;
33
import org.osgi.framework.ServiceRegistration;
28
import org.osgi.util.tracker.ServiceTracker;
34
import org.osgi.util.tracker.ServiceTracker;
29
35
30
public class Activator extends Plugin {
36
public class Activator implements BundleActivator {
31
	/**
37
	/**
32
	 * The identifier of the descriptor of this plugin in plugin.xml.
38
	 * The identifier of the descriptor of this plugin in plugin.xml.
33
	 */
39
	 */
34
	public static final String ID = "org.eclipse.core.net"; //$NON-NLS-1$
40
	public static final String ID = "org.eclipse.core.net"; //$NON-NLS-1$
35
	
36
	public static final String PT_AUTHENTICATOR = "authenticator"; //$NON-NLS-1$
37
	
38
	private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$
39
41
40
	/**
42
	/**
41
	 * The instance of this plugin.
43
	 * The instance of this plugin.
42
	 */
44
	 */
43
	private static Activator instance;
45
	private static Activator instance;
44
46
45
	private ServiceRegistration proxyService;
47
	private static ServiceTracker logTracker;
48
49
	private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$
50
51
	public static final String PT_AUTHENTICATOR = "authenticator"; //$NON-NLS-1$
52
53
	private BundleContext bundleContext;
46
54
47
	private ServiceTracker instanceLocationTracker;
55
	private ServiceTracker instanceLocationTracker;
48
56
57
	private ServiceRegistration proxyService;
58
49
	/**
59
	/**
50
	 * Constructor for use by the Eclipse platform only.
60
	 * Constructor for use by the Eclipse platform only.
51
	 */
61
	 */
Lines 56-123 Link Here
56
66
57
	/**
67
	/**
58
	 * Returns the instance of this plugin.
68
	 * Returns the instance of this plugin.
69
	 * 
59
	 * @return the singleton instance of this plug-in class
70
	 * @return the singleton instance of this plug-in class
60
	 */
71
	 */
61
	static public Activator getInstance() {
72
	static public Activator getInstance() {
62
		return instance;
73
		return instance;
63
	}
74
	}
64
75
76
	public static void log(int severity, String message, Throwable throwable) {
77
		getInstance().log(new Status(severity, ID, 0, message, throwable));
78
	}
79
80
	public static void logError(String message, Throwable exc) {
81
		getInstance().log(new Status(IStatus.ERROR, ID, 0, message, exc));
82
	}
83
84
	public static void logInfo(String message, Throwable exc) {
85
		getInstance().log(new Status(IStatus.INFO, ID, 0, message, exc));
86
	}
87
88
	/*
89
	 * Log the given status to the log file. If the log is not available, log
90
	 * the status to the console.
91
	 */
92
	private void log(IStatus status) {
93
		if (logTracker == null) {
94
			logTracker = new ServiceTracker(bundleContext, FrameworkLog.class
95
					.getName(), null);
96
			logTracker.open();
97
		}
98
		FrameworkLog log = (FrameworkLog) logTracker.getService();
99
		if (log != null) {
100
			log.log(getLog(status));
101
		} else {
102
			System.out.println(status.getMessage());
103
			if (status.getException() != null)
104
				status.getException().printStackTrace();
105
		}
106
	}
107
108
	/**
109
	 * Copied from PlatformLogWriter in core runtime.
110
	 */
111
	private FrameworkLogEntry getLog(IStatus status) {
112
		Throwable t = status.getException();
113
		ArrayList childlist = new ArrayList();
114
115
		int stackCode = t instanceof CoreException ? 1 : 0;
116
		// ensure a substatus inside a CoreException is properly logged
117
		if (stackCode == 1) {
118
			IStatus coreStatus = ((CoreException) t).getStatus();
119
			if (coreStatus != null) {
120
				childlist.add(getLog(coreStatus));
121
			}
122
		}
123
124
		if (status.isMultiStatus()) {
125
			IStatus[] children = status.getChildren();
126
			for (int i = 0; i < children.length; i++) {
127
				childlist.add(getLog(children[i]));
128
			}
129
		}
130
131
		FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null
132
				: childlist.toArray(new FrameworkLogEntry[childlist.size()]));
133
134
		return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(),
135
				status.getCode(), status.getMessage(), stackCode, t, children);
136
	}
137
138
	public org.osgi.service.prefs.Preferences getPreferences() {
139
		return new ConfigurationScope().getNode(ID);
140
	}
141
142
	public boolean instanceLocationAvailable() {
143
		Location instanceLocation = (Location) instanceLocationTracker
144
				.getService();
145
		return (instanceLocation != null && instanceLocation.isSet());
146
	}
147
65
	public void start(BundleContext context) throws Exception {
148
	public void start(BundleContext context) throws Exception {
66
		super.start(context);
149
		this.bundleContext = context;
67
		
68
		Filter filter = null;
150
		Filter filter = null;
69
		try {
151
		try {
70
				filter = context.createFilter(Location.INSTANCE_FILTER);
152
			filter = context.createFilter(Location.INSTANCE_FILTER);
71
			} catch (InvalidSyntaxException e) {
153
		} catch (InvalidSyntaxException e) {
72
				// ignore this.  It should never happen as we have tested the above format.
154
			// ignore this. It should never happen as we have tested the above
73
			}
155
			// format.
156
		}
74
		instanceLocationTracker = new ServiceTracker(context, filter, null);
157
		instanceLocationTracker = new ServiceTracker(context, filter, null);
75
		instanceLocationTracker.open();	
158
		instanceLocationTracker.open();
76
		
159
77
		
160
		if (Boolean
78
		if (Boolean.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$
161
				.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$
79
			ProxyManager proxyManager = (ProxyManager)ProxyManager.getProxyManager();
162
			ProxyManager proxyManager = (ProxyManager) ProxyManager
163
					.getProxyManager();
80
			proxyManager.initialize();
164
			proxyManager.initialize();
81
			proxyService = context.registerService(IProxyService.class.getName(), proxyManager, new Hashtable());
165
			proxyService = context.registerService(IProxyService.class
166
					.getName(), proxyManager, new Hashtable());
82
		}
167
		}
83
	}
168
	}
84
	
169
85
	public void stop(BundleContext context) throws Exception {
170
	public void stop(BundleContext context) throws Exception {
86
		if (proxyService != null) {
171
		if (proxyService != null) {
87
			proxyService.unregister();
172
			proxyService.unregister();
88
			proxyService = null;
173
			proxyService = null;
89
		}
174
		}
90
		
175
91
		if (instanceLocationTracker != null) {
176
		if (instanceLocationTracker != null) {
92
			instanceLocationTracker.close();
177
			instanceLocationTracker.close();
93
			instanceLocationTracker = null;
178
			instanceLocationTracker = null;
94
		}
179
		}
95
		
96
		super.stop(context);
97
	}
98
	
99
	public static void logError(String message, Throwable exc) {
100
		IStatus status = new Status(IStatus.ERROR, ID, 0, message, exc);
101
102
		getInstance().getLog().log(status);
103
	}
104
105
	public static void logInfo(String message, Throwable exc) {
106
		IStatus status = new Status(IStatus.INFO, ID, 0, message, exc);
107
108
		getInstance().getLog().log(status);
109
	}
110
111
	public org.osgi.service.prefs.Preferences getPreferences() {
112
		return new ConfigurationScope().getNode(getBundle().getSymbolicName());
113
	}
114
115
	public static void log(int severity, String message, Throwable throwable) {
116
		getInstance().getLog().log(new Status(severity, ID, 0, message, throwable));
117
	}
118
119
	public boolean instanceLocationAvailable() {
120
		Location instanceLocation = (Location) instanceLocationTracker.getService();
121
		return (instanceLocation != null && instanceLocation.isSet());
122
	}
180
	}
123
}
181
}
(-)META-INF/MANIFEST.MF (-2 / +5 lines)
Lines 6-13 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)",
9
Require-Bundle: org.eclipse.equinox.security;bundle-version="[1.0.0,2.0.0)",
10
 org.eclipse.equinox.security;bundle-version="[1.0.0,2.0.0)"
10
 org.eclipse.equinox.common;bundle-version="3.4.0",
11
 org.eclipse.equinox.preferences;bundle-version="3.2.200",
12
 org.eclipse.osgi;bundle-version="3.4.0",
13
 org.eclipse.equinox.registry;bundle-version="3.4.0"
11
Bundle-ActivationPolicy: lazy
14
Bundle-ActivationPolicy: lazy
12
Export-Package: org.eclipse.core.internal.net;x-internal:=true,
15
Export-Package: org.eclipse.core.internal.net;x-internal:=true,
13
 org.eclipse.core.net.proxy
16
 org.eclipse.core.net.proxy

Return to bug 214796