]> git.argeo.org Git - gpl/argeo-slc.git/blob - Main.java
45d02e7f45abbfc81cbc7b61ea44b0f8d9019f0c
[gpl/argeo-slc.git] / Main.java
1 package org.argeo.slc.jemmytest;
2
3 import java.io.File;
4 import java.util.ArrayList;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.apache.felix.framework.Felix;
9 import org.apache.felix.framework.cache.BundleCache;
10 import org.apache.felix.framework.util.FelixConstants;
11 import org.apache.felix.framework.util.StringMap;
12 import org.apache.felix.main.AutoActivator;
13 import org.osgi.framework.Bundle;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.framework.Constants;
16 import org.osgi.framework.ServiceReference;
17
18 public class Main {
19
20 /**
21 * @param args
22 */
23 public static void main(String[] args) {
24 try {
25 // Create a temporary bundle cache directory and
26 // make sure to clean it up on exit.
27 final File cachedir = File.createTempFile(
28 "felix.example.servicebased", null);
29 cachedir.delete();
30 Runtime.getRuntime().addShutdownHook(new Thread() {
31 public void run() {
32 deleteFileOrDir(cachedir);
33 }
34 });
35
36 String mavenBase = "file:/home/mbaudier/.m2/repository/";
37
38 Map configMap = new StringMap(false);
39 configMap
40 .put(
41 Constants.FRAMEWORK_SYSTEMPACKAGES,
42 "org.osgi.framework; version=1.4.0,"
43 + "org.osgi.service.packageadmin; version=1.2.0,"
44 + "org.osgi.service.startlevel; version=1.1.0,"
45 + "org.osgi.service.url; version=1.0.0,"
46 + "org.osgi.util.tracker; version=1.3.3,"
47 /*+ "org.apache.felix.example.servicebased.host.service; version=1.0.0,"*/
48 + "javax.swing");
49 configMap
50 .put(
51 AutoActivator.AUTO_START_PROP + ".1",
52 mavenBase
53 + "org/apache/felix/org.apache.felix.shell/1.0.2/org.apache.felix.shell-1.0.2.jar "
54 + mavenBase
55 + "org/apache/felix/org.apache.felix.shell.tui/1.0.2/org.apache.felix.shell.tui-1.0.2.jar "
56 + mavenBase
57 + "org/argeo/dep/jemmy/org.argeo.dep.jemmy.nb61/0.2.0/org.argeo.dep.jemmy.nb61-0.2.0.jar "
58 + mavenBase
59 + "org/argeo/slc/org.argeo.slc.autoui/0.10.3-SNAPSHOT/org.argeo.slc.autoui-0.10.3-SNAPSHOT.jar");
60 configMap.put(FelixConstants.LOG_LEVEL_PROP, "1");
61 configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, cachedir
62 .getAbsolutePath());
63
64 // Create list to hold custom framework activators.
65 List list = new ArrayList();
66 // Add activator to process auto-start/install properties.
67 list.add(new AutoActivator(configMap));
68 // Add our own activator.
69 list.add(new JemmyTestActivator());
70
71 BundleContext context = null;
72 try {
73 // Now create an instance of the framework.
74 Felix felix = new Felix(configMap, list);
75 felix.start();
76
77 context = felix.getBundleContext();
78
79 // Bundle jemmyTestBundle = context
80 // .installBundle(mavenBase
81 // +
82 // "org/argeo/slc/sandbox/org.argeo.slc.sandbox.jemmytest/0.1.1-SNAPSHOT/org.argeo.slc.sandbox.jemmytest-0.1.1-SNAPSHOT.jar");
83 // jemmyTestBundle.start();
84
85 } catch (Exception ex) {
86 System.err.println("Could not create framework: " + ex);
87 ex.printStackTrace();
88 System.exit(-1);
89 }
90
91 // ServiceReference ref = context
92 // .getServiceReference("org.argeo.slc.autoui.AutoUiApplication");
93 ServiceReference ref = context
94 .getServiceReference("java.lang.Runnable");
95 Object service = context.getService(ref);
96 JemmyTestActivator.stdOut("service=" + service.getClass());
97 Runnable app = (Runnable) service;
98 app.run();
99 // app.execute(null);
100
101 } catch (Exception e) {
102 e.printStackTrace();
103 System.exit(-1);
104 }
105
106 // Felix felix;
107 // // JemmyTestActivator activator;
108 //
109 // // Create a case-insensitive configuration property map.
110 // Map configMap = new StringMap(false);
111 // // Configure the Felix instance to be embedded.
112 // configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true");
113 // // Add core OSGi packages to be exported from the class path
114 // // via the system bundle.
115 // configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
116 // "org.osgi.framework; version=1.3.0,"
117 // + "org.osgi.service.packageadmin; version=1.2.0,"
118 // + "org.osgi.service.startlevel; version=1.0.0,"
119 // + "org.osgi.service.url; version=1.0.0");
120 // // Explicitly specify the directory to use for caching bundles.
121 // configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "target/cache");
122 //
123 // try {
124 // // Create host activator;
125 // // activator = new JemmyTestActivator();
126 // List list = new ArrayList();
127 // // list.add(activator);
128 // list.add(new Activator());
129 // list.add(new org.apache.felix.shell.impl.Activator());
130 // list.add(new org.apache.felix.bundlerepository.Activator());
131 //
132 // // Now create an instance of the framework with
133 // // our configuration properties and activator.
134 // felix = new Felix(configMap, list);
135 //
136 // // Now start Felix instance.
137 // felix.start();
138 //
139 // Bundle jemmyBundle = felix
140 // .getBundleContext()
141 // .installBundle(
142 // "file:/home/mbaudier/.m2/repository/org/argeo/dep/jemmy/org.argeo.dep.jemmy.nb61/0.2.0/org.argeo.dep.jemmy.nb61-0.2.0.jar");
143 // jemmyBundle.start();
144 // //
145 // // Bundle autoUiBundle = felix
146 // // .getBundleContext()
147 // // .installBundle(
148 // //
149 // "reference:file:/home/mbaudier/dev/src/slc/org.argeo.slc.autoui/");
150 // // autoUiBundle.start();
151 //
152 // Bundle[] bundles = felix.getBundleContext().getBundles();
153 // for (int i = 0; i < bundles.length; i++) {
154 // Bundle bundle = bundles[i];
155 // System.out.println("" + bundle.getBundleId() + "\t"
156 // + bundle.getSymbolicName() + "\t" + bundle.getState()
157 // + "\t" + bundle.getLocation());
158 // }
159 //
160 // // felix.stop();
161 // } catch (Exception ex) {
162 // System.err.println("Could not create framework: " + ex);
163 // ex.printStackTrace();
164 // }
165 //
166 }
167
168 /**
169 * Utility method used to delete the profile directory when run as a
170 * stand-alone application.
171 *
172 * @param file
173 * The file to recursively delete.
174 */
175 private static void deleteFileOrDir(File file) {
176 if (file.isDirectory()) {
177 File[] childs = file.listFiles();
178 for (int i = 0; i < childs.length; i++) {
179 deleteFileOrDir(childs[i]);
180 }
181 }
182 file.delete();
183 }
184
185 }