1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.osgi.test.platform;
18
19 import java.lang.reflect.Field;
20 import java.security.AccessController;
21 import java.security.PrivilegedAction;
22 import java.util.Properties;
23
24 import org.eclipse.core.runtime.adaptor.EclipseStarter;
25 import org.osgi.framework.BundleContext;
26
27
28
29
30
31
32
33 public class EquinoxPlatform extends AbstractOsgiPlatform {
34
35 private BundleContext context;
36
37
38 public EquinoxPlatform() {
39 toString = "Equinox OSGi Platform";
40 }
41
42 Properties getPlatformProperties() {
43
44 Properties props = new Properties();
45 props.setProperty("eclipse.ignoreApp", "true");
46 props.setProperty("osgi.clean", "true");
47 props.setProperty("osgi.noShutdown", "true");
48
49
50
51 props.setProperty("osgi.configuration.area", "eclipse_config");
52 props.setProperty("osgi.instance.area", "eclipse_config");
53 props.setProperty("osgi.user.area", "eclipse_config");
54
55
56
57
58
59
60 return props;
61 }
62
63 public BundleContext getBundleContext() {
64 return context;
65 }
66
67 public void start() throws Exception {
68
69 if (context == null) {
70
71 System.getProperties().putAll(getConfigurationProperties());
72
73
74
75 EclipseStarter.main(new String[0]);
76
77 final Field field = EclipseStarter.class.getDeclaredField("context");
78
79 AccessController.doPrivileged(new PrivilegedAction() {
80
81 public Object run() {
82 field.setAccessible(true);
83 return null;
84 }
85 });
86 context = (BundleContext) field.get(null);
87 }
88 }
89
90 public void stop() throws Exception {
91 if (context != null) {
92 context = null;
93 EclipseStarter.shutdown();
94 }
95 }
96 }