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 162415 | Differences between
and this patch

Collapse All | Expand All

(-)console/src/org/eclipse/osgi/framework/internal/core/FrameworkConsole.java (-10 / +47 lines)
Lines 11-21 Link Here
11
11
12
package org.eclipse.osgi.framework.internal.core;
12
package org.eclipse.osgi.framework.internal.core;
13
13
14
import java.io.*;
14
import java.io.BufferedReader;
15
import java.net.*;
15
import java.io.BufferedWriter;
16
import java.io.IOException;
17
import java.io.InputStream;
18
import java.io.InputStreamReader;
19
import java.io.OutputStream;
20
import java.io.OutputStreamWriter;
21
import java.io.PrintWriter;
22
import java.io.Reader;
23
import java.io.UnsupportedEncodingException;
24
import java.net.ServerSocket;
25
import java.net.Socket;
26
import java.net.UnknownHostException;
27
16
import org.eclipse.osgi.framework.console.CommandInterpreter;
28
import org.eclipse.osgi.framework.console.CommandInterpreter;
17
import org.eclipse.osgi.framework.console.CommandProvider;
29
import org.eclipse.osgi.framework.console.CommandProvider;
18
import org.eclipse.osgi.util.NLS;
30
import org.eclipse.osgi.util.NLS;
31
import org.osgi.framework.BundleContext;
19
import org.osgi.framework.ServiceReference;
32
import org.osgi.framework.ServiceReference;
20
import org.osgi.util.tracker.ServiceTracker;
33
import org.osgi.util.tracker.ServiceTracker;
21
34
Lines 83-98 Link Here
83
96
84
		initialize();
97
		initialize();
85
	}
98
	}
99
	
100
	public FrameworkConsole(BundleContext context, String[] args) {
101
		this.args = args;
102
		this.osgi = null;
103
		this.context = context;
104
		
105
		initialize();
106
	}
86
107
87
	/**
108
	/**
88
	 *  Open streams for system.in and system.out
109
	 *  Open streams for system.in and system.out
89
	 */
110
	 */
90
	private void getDefaultStreams() {
111
	private void getDefaultStreams() {
91
		in = createBufferedReader(System.in);
112
		if(in==null||out==null) {
92
		out = createPrintWriter(System.out);
113
			in = createBufferedReader(System.in);
114
			out = createPrintWriter(System.out);
115
		}
93
	}
116
	}
94
117
95
	/**
118
	/**
119
	 * Change the Input and Output streams for the console.
120
	 * The default is System.in and System.out
121
	 */
122
	public void setStreams(InputStream in, OutputStream out) {
123
		this.in = createBufferedReader(in);
124
		this.out = createPrintWriter(out);
125
	}
126
	
127
	/**
96
	 *  Open a socket and create input and output streams
128
	 *  Open a socket and create input and output streams
97
	 *
129
	 *
98
	 * @param port number to listen on
130
	 * @param port number to listen on
Lines 182-197 Link Here
182
	 */
214
	 */
183
	private void initialize() {
215
	private void initialize() {
184
		getDefaultStreams();
216
		getDefaultStreams();
185
217
		
186
		context = osgi.getBundleContext();
218
		if(osgi!=null) {
219
			context = osgi.getBundleContext();
220
		}
187
221
188
		// set up a service tracker to track CommandProvider registrations
222
		// set up a service tracker to track CommandProvider registrations
189
		cptracker = new ServiceTracker(context, CommandProvider.class.getName(), null);
223
		cptracker = new ServiceTracker(context, CommandProvider.class.getName(), null);
190
		cptracker.open();
224
		cptracker.open();
191
225
192
		// register the OSGi command provider
226
		// register the OSGi command provider
193
		osgicp = new FrameworkCommandProvider(osgi);
227
		if(osgi!=null) {
194
228
			osgicp = new FrameworkCommandProvider(osgi);
229
		} else {
230
			osgicp = new FrameworkCommandProvider(context);
231
		}
232
		
195
	}
233
	}
196
234
197
	/**
235
	/**
Lines 297-303 Link Here
297
	 * will cause the console to close from a telnet session.
335
	 * will cause the console to close from a telnet session.
298
	 */
336
	 */
299
337
300
	void disconnect() throws IOException {
338
	public void disconnect() throws IOException {
301
		disconnect = true;
339
		disconnect = true;
302
		out.close();
340
		out.close();
303
		in.close();
341
		in.close();
Lines 418-422 Link Here
418
			this.acceptConnections = acceptConnections;
456
			this.acceptConnections = acceptConnections;
419
		}
457
		}
420
	}
458
	}
421
422
}
459
}
(-)console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java (-27 / +133 lines)
Lines 11-33 Link Here
11
11
12
package org.eclipse.osgi.framework.internal.core;
12
package org.eclipse.osgi.framework.internal.core;
13
13
14
import java.io.*;
14
import java.io.ByteArrayInputStream;
15
import java.io.File;
16
import java.io.IOException;
17
import java.io.InputStream;
15
import java.lang.reflect.Method;
18
import java.lang.reflect.Method;
16
import java.net.URL;
19
import java.net.URL;
20
import java.security.PrivilegedAction;
17
import java.security.ProtectionDomain;
21
import java.security.ProtectionDomain;
18
import java.util.*;
22
import java.util.ArrayList;
23
import java.util.Dictionary;
24
import java.util.Enumeration;
25
import java.util.Hashtable;
26
import java.util.Properties;
27
import java.util.Vector;
28
import java.security.AccessController;
19
import org.eclipse.osgi.framework.console.CommandInterpreter;
29
import org.eclipse.osgi.framework.console.CommandInterpreter;
20
import org.eclipse.osgi.framework.console.CommandProvider;
30
import org.eclipse.osgi.framework.console.CommandProvider;
21
import org.eclipse.osgi.framework.launcher.Launcher;
31
import org.eclipse.osgi.framework.launcher.Launcher;
22
import org.eclipse.osgi.internal.profile.Profile;
32
import org.eclipse.osgi.internal.profile.Profile;
23
import org.eclipse.osgi.service.resolver.*;
33
import org.eclipse.osgi.service.resolver.BundleDescription;
34
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
35
import org.eclipse.osgi.service.resolver.PlatformAdmin;
24
import org.eclipse.osgi.util.NLS;
36
import org.eclipse.osgi.util.NLS;
25
import org.osgi.framework.*;
37
import org.osgi.framework.Bundle;
38
import org.osgi.framework.BundleContext;
39
import org.osgi.framework.BundleException;
40
import org.osgi.framework.ServiceReference;
41
import org.osgi.framework.Version;
26
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
42
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
27
import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
43
import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
28
import org.osgi.service.packageadmin.PackageAdmin;
44
import org.osgi.service.packageadmin.PackageAdmin;
29
import org.osgi.service.packageadmin.RequiredBundle;
45
import org.osgi.service.packageadmin.RequiredBundle;
30
import org.osgi.service.permissionadmin.PermissionAdmin;
46
import org.osgi.service.permissionadmin.PermissionAdmin;
47
import org.osgi.service.startlevel.StartLevel;
31
48
32
/**
49
/**
33
 * This class provides methods to execute commands from the command line.  It registers
50
 * This class provides methods to execute commands from the command line.  It registers
Lines 79-89 Link Here
79
public class FrameworkCommandProvider implements CommandProvider {
96
public class FrameworkCommandProvider implements CommandProvider {
80
97
81
	/** An instance of the OSGi framework */
98
	/** An instance of the OSGi framework */
82
	private OSGi osgi;
99
	private OSGi osgi; //TODO Fix references to thsi variable, it might be null
83
	/** The system bundle context */
100
	/** The system bundle context */
84
	private org.osgi.framework.BundleContext context;
101
	private org.osgi.framework.BundleContext context;
85
	/** The start level implementation */
102
	/** The start level implementation */
86
	private StartLevelManager slImpl;
103
	private StartLevel slImpl;
87
	private ConditionalPermissionAdmin condPermAdmin;
104
	private ConditionalPermissionAdmin condPermAdmin;
88
	private PermissionAdmin permAdmin;
105
	private PermissionAdmin permAdmin;
89
106
Lines 101-113 Link Here
101
	public FrameworkCommandProvider(OSGi osgi) {
118
	public FrameworkCommandProvider(OSGi osgi) {
102
		this.osgi = osgi;
119
		this.osgi = osgi;
103
		context = osgi.getBundleContext();
120
		context = osgi.getBundleContext();
104
		slImpl = osgi.framework.startLevelManager;
121
		slImpl = (StartLevel)context.getService(context.getServiceReference(StartLevel.class.getName()));;
105
		condPermAdmin = osgi.framework.condPermAdmin;
122
		condPermAdmin = osgi.framework.condPermAdmin;
106
		permAdmin = osgi.framework.permissionAdmin;
123
		permAdmin = osgi.framework.permissionAdmin;
107
		Dictionary props = new Hashtable();
124
		Dictionary props = new Hashtable();
108
		props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
125
		props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
109
		context.registerService(CommandProvider.class.getName(), this, props);
126
		context.registerService(CommandProvider.class.getName(), this, props);
110
	}
127
	}
128
	
129
	/**
130
	 * 
131
	 * 
132
	 * @param context
133
	 */
134
	public FrameworkCommandProvider(BundleContext context) {
135
		this.osgi = null;
136
		this.context = context;
137
		slImpl = (StartLevel)context.getService(context.getServiceReference(StartLevel.class.getName()));
138
		ServiceReference ref = context.getServiceReference(ConditionalPermissionAdmin.class.getName());
139
		if(ref!= null)
140
			condPermAdmin = (ConditionalPermissionAdmin)context.getService(ref);
141
		else
142
			ref = null;
143
		ref = context.getServiceReference(PermissionAdmin.class.getName());
144
		if(ref!=null)
145
			permAdmin = (PermissionAdmin)context.getService(ref);
146
		else
147
			permAdmin = null;
148
		Dictionary props = new Hashtable();
149
		props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
150
		context.registerService(CommandProvider.class.getName(), this, props);
151
	}
111
152
112
	/**
153
	/**
113
	 Answer a string (may be as many lines as you like) with help
154
	 Answer a string (may be as many lines as you like) with help
Lines 122-129 Link Here
122
		help.append(ConsoleMsg.CONSOLE_HELP_VALID_COMMANDS_HEADER);
163
		help.append(ConsoleMsg.CONSOLE_HELP_VALID_COMMANDS_HEADER);
123
		help.append(newline);
164
		help.append(newline);
124
		addHeader(ConsoleMsg.CONSOLE_HELP_CONTROLLING_FRAMEWORK_HEADER, help);
165
		addHeader(ConsoleMsg.CONSOLE_HELP_CONTROLLING_FRAMEWORK_HEADER, help);
125
		addCommand("launch", ConsoleMsg.CONSOLE_HELP_LAUNCH_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
166
		if(osgi!=null){
126
		addCommand("shutdown", ConsoleMsg.CONSOLE_HELP_SHUTDOWN_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
167
			addCommand("launch", ConsoleMsg.CONSOLE_HELP_LAUNCH_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
168
			addCommand("shutdown", ConsoleMsg.CONSOLE_HELP_SHUTDOWN_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
169
		}
127
		addCommand("close", ConsoleMsg.CONSOLE_HELP_CLOSE_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
170
		addCommand("close", ConsoleMsg.CONSOLE_HELP_CLOSE_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
128
		addCommand("exit", ConsoleMsg.CONSOLE_HELP_EXIT_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
171
		addCommand("exit", ConsoleMsg.CONSOLE_HELP_EXIT_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
129
		addCommand("gc", ConsoleMsg.CONSOLE_HELP_GC_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
172
		addCommand("gc", ConsoleMsg.CONSOLE_HELP_GC_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
Lines 202-208 Link Here
202
	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
245
	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
203
	 */
246
	 */
204
	public void _launch(CommandInterpreter intp) throws Exception {
247
	public void _launch(CommandInterpreter intp) throws Exception {
205
		osgi.launch();
248
		if(osgi==null) {
249
			return;
250
		} else {
251
			osgi.launch();
252
		}
206
	}
253
	}
207
254
208
	/**
255
	/**
Lines 211-217 Link Here
211
	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
258
	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
212
	 */
259
	 */
213
	public void _shutdown(CommandInterpreter intp) throws Exception {
260
	public void _shutdown(CommandInterpreter intp) throws Exception {
214
		osgi.shutdown();
261
		if(osgi==null){
262
			return;
263
		} else {
264
			osgi.shutdown();
265
		}
215
	}
266
	}
216
267
217
	/**
268
	/**
Lines 408-417 Link Here
408
	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
459
	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
409
	 */
460
	 */
410
	public void _status(CommandInterpreter intp) throws Exception {
461
	public void _status(CommandInterpreter intp) throws Exception {
411
		if (osgi.isActive()) {
462
		if(osgi==null) {
412
			intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE);
463
			if(context.getBundle(0).getState()==Bundle.ACTIVE) {
464
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE);
465
			} else {
466
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE);
467
			}
413
		} else {
468
		} else {
414
			intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE);
469
			if (osgi.isActive()) {
470
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE);
471
			} else {
472
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE);
473
			}
415
		}
474
		}
416
		intp.println();
475
		intp.println();
417
476
Lines 605-611 Link Here
605
			intp.print(", "); //$NON-NLS-1$
664
			intp.print(", "); //$NON-NLS-1$
606
			intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState())));
665
			intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState())));
607
			if (id != 0) {
666
			if (id != 0) {
608
				File dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$
667
				File dataRoot;
668
				if(osgi==null) {
669
					dataRoot = getDataFile(bundle, ""); //$NON-NLS-1$
670
				} else {
671
					dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$
672
				}
609
673
610
				String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath();
674
				String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath();
611
675
Lines 671-678 Link Here
671
				intp.print(", "); //$NON-NLS-1$
735
				intp.print(", "); //$NON-NLS-1$
672
				intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState())));
736
				intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState())));
673
				if (id != 0) {
737
				if (id != 0) {
674
					File dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$
738
					File dataRoot;
675
739
					if(osgi==null) {
740
						dataRoot = getDataFile(bundle, ""); //$NON-NLS-1$
741
					} else {
742
						dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$
743
					}
676
					String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath();
744
					String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath();
677
745
678
					intp.print(NLS.bind(ConsoleMsg.CONSOLE_DATA_ROOT_MESSAGE, root));
746
					intp.print(NLS.bind(ConsoleMsg.CONSOLE_DATA_ROOT_MESSAGE, root));
Lines 1046-1055 Link Here
1046
	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
1114
	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
1047
	 */
1115
	 */
1048
	public void _init(CommandInterpreter intp) throws Exception {
1116
	public void _init(CommandInterpreter intp) throws Exception {
1049
		if (osgi.isActive()) {
1117
		if(osgi==null) {
1050
			intp.print(newline);
1118
			if(context.getBundle(0).getState()==Bundle.ACTIVE) {
1051
			intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE);
1119
				intp.print(newline);
1052
			return;
1120
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE);
1121
				return;
1122
			}
1123
		} else {
1124
			if (osgi.isActive()) {
1125
				intp.print(newline);
1126
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE);
1127
				return;
1128
			}
1053
		}
1129
		}
1054
1130
1055
		AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles();
1131
		AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles();
Lines 1092-1098 Link Here
1092
	 */
1168
	 */
1093
	public void _close(CommandInterpreter intp) throws Exception {
1169
	public void _close(CommandInterpreter intp) throws Exception {
1094
		intp.println();
1170
		intp.println();
1095
		osgi.close();
1171
		if(osgi!=null) {
1172
			osgi.close();
1173
		}
1096
		System.exit(0);
1174
		System.exit(0);
1097
	}
1175
	}
1098
1176
Lines 1288-1299 Link Here
1288
	 * @param intp A CommandInterpreter object containing the command and it's arguments.
1366
	 * @param intp A CommandInterpreter object containing the command and it's arguments.
1289
	 */
1367
	 */
1290
	public void _ss(CommandInterpreter intp) throws Exception {
1368
	public void _ss(CommandInterpreter intp) throws Exception {
1291
		if (osgi.isActive()) {
1369
		if(osgi==null) {
1292
			intp.println();
1370
			if(context.getBundle(0).getState()==Bundle.ACTIVE) {
1293
			intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE);
1371
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE);
1372
			} else {
1373
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE);
1374
			}
1294
		} else {
1375
		} else {
1295
			intp.println();
1376
			if (osgi.isActive()) {
1296
			intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE);
1377
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE);
1378
			} else {
1379
				intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE);
1380
			}
1297
		}
1381
		}
1298
1382
1299
		AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles();
1383
		AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles();
Lines 1768-1771 Link Here
1768
		}
1852
		}
1769
		return t.nextToken();
1853
		return t.nextToken();
1770
	}
1854
	}
1855
	
1856
	/**
1857
	 * 
1858
	 * Duplicate of method of same name from Framework.java
1859
	 * 
1860
	 * * Creates a <code>File</code> object for a file in the persistent
1861
	 * storage area provided for the bundle by the framework. If the adaptor
1862
	 * does not have file system support, this method will return <code>null</code>.
1863
	 * 
1864
	 * <p>
1865
	 * A <code>File</code> object for the base directory of the persistent
1866
	 * storage area provided for the context bundle by the framework can be
1867
	 * obtained by calling this method with the empty string ("") as the
1868
	 * parameter.
1869
	 */
1870
	protected File getDataFile(final AbstractBundle bundle, final String filename) {
1871
		return (File) AccessController.doPrivileged(new PrivilegedAction() {
1872
			public Object run() {
1873
				return bundle.getBundleData().getDataFile(filename);
1874
			}
1875
		});
1876
	}
1771
}
1877
}

Return to bug 162415