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
.Vector
;
9 import org
.eclipse
.core
.runtime
.adaptor
.EclipseStarter
;
10 import org
.osgi
.framework
.BundleContext
;
12 public class Launcher
{
14 public static void main(String
[] args
) {
15 // Try to load system properties
16 String systemPropertiesFilePath
= OsgiBootUtils
.getPropertyCompat(
17 OsgiBoot
.PROP_ARGEO_OSGI_BOOT_SYSTEM_PROPERTIES_FILE
,
18 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 String className
= OsgiBootUtils
.getPropertyCompat(
58 OsgiBoot
.PROP_ARGEO_OSGI_BOOT_APPCLASS
,
59 OsgiBoot
.PROP_SLC_OSGIBOOT_APPCLASS
);
60 if (className
== null)
63 // should use OsgiBootUtils.getPropertyCompat(), but it does not
64 // work for "" as default value
65 // so no warning displayed if PROP_SLC_OSGIBOOT_APPARGS is used
66 // FIXME: change OsgiBootUtils.getPropertyCompat()
67 String line
= System
.getProperty(OsgiBoot
.PROP_ARGEO_OSGI_BOOT_APPARGS
,
68 System
.getProperty(OsgiBoot
.PROP_SLC_OSGIBOOT_APPARGS
, ""));
70 String
[] uiArgs
= readArgumentsFromLine(line
);
73 // Launch main method using reflection
74 Class clss
= Class
.forName(className
);
75 Class
[] mainArgsClasses
= new Class
[] { uiArgs
.getClass() };
76 Object
[] mainArgs
= { uiArgs
};
77 Method mainMethod
= clss
.getMethod("main", mainArgsClasses
);
78 mainMethod
.invoke(null, mainArgs
);
79 } catch (Exception e
) {
80 throw new RuntimeException("Cannot start main class.", e
);
86 * Transform a line into an array of arguments, taking "" as single
87 * arguments. (nested \" are not supported)
89 private static String
[] readArgumentsFromLine(String lineOrig
) {
91 String line
= lineOrig
.trim();// remove trailing spaces
92 // System.out.println("line=" + line);
93 List args
= new Vector();
94 StringBuffer curr
= new StringBuffer("");
95 boolean inQuote
= false;
96 char[] arr
= line
.toCharArray();
97 for (int i
= 0; i
< arr
.length
; i
++) {
104 if (!inQuote
) {// otherwise, no break: goes to default
105 if (curr
.length() > 0) {
106 args
.add(curr
.toString());
107 curr
= new StringBuffer("");
118 if (curr
.length() > 0) {
119 args
.add(curr
.toString());
123 String
[] res
= new String
[args
.size()];
124 for (int i
= 0; i
< args
.size(); i
++) {
125 res
[i
] = args
.get(i
).toString();
126 // System.out.println("res[i]=" + res[i]);