1 package org
.argeo
.slc
.osgiboot
;
3 import java
.io
.FileInputStream
;
4 import java
.io
.IOException
;
5 import java
.lang
.reflect
.Method
;
7 import java
.util
.Properties
;
8 import java
.util
.Vector
;
10 import org
.eclipse
.core
.runtime
.adaptor
.EclipseStarter
;
11 import org
.osgi
.framework
.BundleContext
;
13 public class Launcher
{
15 public static void main(String
[] args
) {
16 // Try to load system properties
17 String systemPropertiesFilePath
= System
18 .getProperty(OsgiBoot
.PROP_SLC_OSGIBOOT_SYSTEM_PROPERTIES_FILE
);
19 if (systemPropertiesFilePath
!= null) {
22 in
= new FileInputStream(systemPropertiesFilePath
);
23 System
.getProperties().load(in
);
24 } catch (IOException e1
) {
25 throw new RuntimeException(
26 "Cannot load system properties from "
27 + systemPropertiesFilePath
, e1
);
32 } catch (Exception e
) {
42 BundleContext bundleContext
= null;
44 bundleContext
= EclipseStarter
.startup(args
, null);
45 } catch (Exception e
) {
46 throw new RuntimeException("Cannot start Equinox.", e
);
50 OsgiBoot osgiBoot
= new OsgiBoot(bundleContext
);
54 protected static void startMainClass() {
55 Properties config
= System
.getProperties();
56 String className
= config
.getProperty("slc.osgiboot.appclass");
57 if (className
== null)
60 String
[] uiArgs
= readArgumentsFromLine(config
.getProperty(
61 "slc.osgiboot.appargs", ""));
63 // Launch main method using reflection
64 Class clss
= Class
.forName(className
);
65 Class
[] mainArgsClasses
= new Class
[] { uiArgs
.getClass() };
66 Object
[] mainArgs
= { uiArgs
};
67 Method mainMethod
= clss
.getMethod("main", mainArgsClasses
);
68 mainMethod
.invoke(null, mainArgs
);
69 } catch (Exception e
) {
70 throw new RuntimeException("Cannot start main class.", e
);
76 * Transform a line into an array of arguments, taking "" as single
77 * arguments. (nested \" are not supported)
79 private static String
[] readArgumentsFromLine(String lineOrig
) {
81 String line
= lineOrig
.trim();// remove trailing spaces
82 // System.out.println("line=" + line);
83 List args
= new Vector();
84 StringBuffer curr
= new StringBuffer("");
85 boolean inQuote
= false;
86 char[] arr
= line
.toCharArray();
87 for (int i
= 0; i
< arr
.length
; i
++) {
94 if (!inQuote
) {// otherwise, no break: goes to default
95 if (curr
.length() > 0) {
96 args
.add(curr
.toString());
97 curr
= new StringBuffer("");
108 if (curr
.length() > 0) {
109 args
.add(curr
.toString());
113 String
[] res
= new String
[args
.size()];
114 for (int i
= 0; i
< args
.size(); i
++) {
115 res
[i
] = args
.get(i
).toString();
116 // System.out.println("res[i]=" + res[i]);