]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.detached.launcher/src/main/java/org/argeo/slc/detached/launcher/Main.java
1 package org
.argeo
.slc
.detached
.launcher
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStream
;
6 import java
.lang
.reflect
.Method
;
7 import java
.util
.ArrayList
;
8 import java
.util
.Enumeration
;
10 import java
.util
.Properties
;
11 import java
.util
.Vector
;
13 import org
.apache
.commons
.logging
.Log
;
14 import org
.apache
.commons
.logging
.LogFactory
;
15 import org
.apache
.felix
.framework
.Felix
;
16 import org
.apache
.felix
.framework
.cache
.BundleCache
;
17 import org
.apache
.felix
.main
.AutoActivator
;
20 private final static Log log
= LogFactory
.getLog(Main
.class);
22 public static void main(String
[] args
) {
25 Properties config
= prepareConfig();
27 // Start UI (in main class loader)
29 // Thread.sleep(10000);
32 Felix felix
= startSystem(config
);
34 log
.info("Argeo SLC Detached system started (Felix " + felix
+ ")");
37 } catch (Exception e
) {
43 protected static Properties
prepareConfig() throws Exception
{
44 final File cachedir
= createTemporaryCacheDir();
47 Properties config
= new Properties();
48 InputStream in
= null;
52 .getResourceAsStream("/org/argeo/slc/detached/launcher/felix.properties");
59 // Perform variable substitution for system properties.
60 for (Enumeration e
= config
.propertyNames(); e
.hasMoreElements();) {
61 String name
= (String
) e
.nextElement();
62 config
.setProperty(name
, org
.apache
.felix
.main
.Main
.substVars(
63 config
.getProperty(name
), name
, null, config
));
66 config
.put(BundleCache
.CACHE_PROFILE_DIR_PROP
, cachedir
69 // System properties have priority.
70 config
.putAll(System
.getProperties());
75 protected static File
createTemporaryCacheDir() throws IOException
{
76 // Create a temporary bundle cache directory and
77 // make sure to clean it up on exit.
78 final File cachedir
= File
.createTempFile("argeo.slc.autoui", null);
80 Runtime
.getRuntime().addShutdownHook(new Thread() {
82 deleteFileOrDir(cachedir
);
88 public static Felix
startSystem(Properties config
) throws Exception
{
89 // Create list to hold custom framework activators.
90 List list
= new ArrayList();
91 // Add activator to process auto-start/install properties.
92 list
.add(new AutoActivator(config
));
93 // Add our own activator.
94 // list.add(new AutoUiActivator());
96 // Now create an instance of the framework.
97 Felix felix
= new Felix(config
, list
);
103 public static void startUi(Properties config
) throws Exception
{
104 String className
= config
.getProperty("argeo.scl.autoui.uiclass");
105 String
[] uiArgs
= readArgumentsFromLine(config
.getProperty(
106 "argeo.slc.autoui.uiargs", ""));
108 // Launch main method using reflection
109 Class clss
= Class
.forName(className
);
110 Class
[] mainArgsClasses
= new Class
[] { uiArgs
.getClass() };
111 Object
[] mainArgs
= { uiArgs
};
112 Method mainMethod
= clss
.getMethod("main", mainArgsClasses
);
113 mainMethod
.invoke(null, mainArgs
);
116 // protected static void automateUi(BundleContext bundleContext)
117 // throws Exception {
118 // // Retrieve service and execute it
119 // ServiceReference ref = bundleContext
120 // .getServiceReference(DetachedExecutionServer.class.getName());
121 // Object service = bundleContext.getService(ref);
123 // log.debug("service.class=" + service.getClass());
124 // DetachedExecutionServer app = (DetachedExecutionServer) service;
125 // DetachedStepRequest request = new DetachedStepRequest();
126 // request.setStepRef("jemmyTest");
127 // app.executeStep(request);
133 * Transform a line into an array of arguments, taking "" as single
134 * arguments. (nested \" are not supported)
136 private static String
[] readArgumentsFromLine(String lineOrig
) {
138 String line
= lineOrig
.trim();// remove trailing spaces
139 // System.out.println("line=" + line);
140 List args
= new Vector();
141 StringBuffer curr
= new StringBuffer("");
142 boolean inQuote
= false;
143 char[] arr
= line
.toCharArray();
144 for (int i
= 0; i
< arr
.length
; i
++) {
151 if (!inQuote
) {// otherwise, no break: goes to default
152 if (curr
.length() > 0) {
153 args
.add(curr
.toString());
154 curr
= new StringBuffer("");
165 if (curr
.length() > 0) {
166 args
.add(curr
.toString());
170 String
[] res
= new String
[args
.size()];
171 for (int i
= 0; i
< args
.size(); i
++) {
172 res
[i
] = args
.get(i
).toString();
173 // System.out.println("res[i]=" + res[i]);
178 private static void deleteFileOrDir(File file
) {
179 if (file
.isDirectory()) {
180 File
[] childs
= file
.listFiles();
181 for (int i
= 0; i
< childs
.length
; i
++) {
182 deleteFileOrDir(childs
[i
]);