]>
git.argeo.org Git - gpl/argeo-slc.git/blob - Main.java
45d02e7f45abbfc81cbc7b61ea44b0f8d9019f0c
1 package org
.argeo
.slc
.jemmytest
;
4 import java
.util
.ArrayList
;
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
;
23 public static void main(String
[] args
) {
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);
30 Runtime
.getRuntime().addShutdownHook(new Thread() {
32 deleteFileOrDir(cachedir
);
36 String mavenBase
= "file:/home/mbaudier/.m2/repository/";
38 Map configMap
= new StringMap(false);
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,"*/
51 AutoActivator
.AUTO_START_PROP
+ ".1",
53 + "org/apache/felix/org.apache.felix.shell/1.0.2/org.apache.felix.shell-1.0.2.jar "
55 + "org/apache/felix/org.apache.felix.shell.tui/1.0.2/org.apache.felix.shell.tui-1.0.2.jar "
57 + "org/argeo/dep/jemmy/org.argeo.dep.jemmy.nb61/0.2.0/org.argeo.dep.jemmy.nb61-0.2.0.jar "
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
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());
71 BundleContext context
= null;
73 // Now create an instance of the framework.
74 Felix felix
= new Felix(configMap
, list
);
77 context
= felix
.getBundleContext();
79 // Bundle jemmyTestBundle = context
80 // .installBundle(mavenBase
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();
85 } catch (Exception ex
) {
86 System
.err
.println("Could not create framework: " + ex
);
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
;
101 } catch (Exception e
) {
107 // // JemmyTestActivator activator;
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");
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());
132 // // Now create an instance of the framework with
133 // // our configuration properties and activator.
134 // felix = new Felix(configMap, list);
136 // // Now start Felix instance.
139 // Bundle jemmyBundle = felix
140 // .getBundleContext()
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();
145 // // Bundle autoUiBundle = felix
146 // // .getBundleContext()
147 // // .installBundle(
149 // "reference:file:/home/mbaudier/dev/src/slc/org.argeo.slc.autoui/");
150 // // autoUiBundle.start();
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());
161 // } catch (Exception ex) {
162 // System.err.println("Could not create framework: " + ex);
163 // ex.printStackTrace();
169 * Utility method used to delete the profile directory when run as a
170 * stand-alone application.
173 * The file to recursively delete.
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
]);