X-Git-Url: http://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FLauncher.java;fp=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FLauncher.java;h=0000000000000000000000000000000000000000;hp=778c08a70e21d487e0a78946b94cf427a13888d5;hb=b95462873703848193e56fcbe997693630db6121;hpb=55d88fba80cec198a0f11ba7545e19878c51fc5e diff --git a/org.argeo.init/src/org/argeo/init/osgi/Launcher.java b/org.argeo.init/src/org/argeo/init/osgi/Launcher.java deleted file mode 100644 index 778c08a70..000000000 --- a/org.argeo.init/src/org/argeo/init/osgi/Launcher.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.argeo.init.osgi; - -import java.io.FileInputStream; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import org.osgi.framework.BundleContext; - -/** An OSGi launcher executing first another class in the system class path. */ -public class Launcher { - - public static void main(String[] args) { - // Try to load system properties - String systemPropertiesFilePath = getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_SYSTEM_PROPERTIES_FILE); - if (systemPropertiesFilePath != null) { - FileInputStream in; - try { - in = new FileInputStream(systemPropertiesFilePath); - System.getProperties().load(in); - } catch (IOException e1) { - throw new RuntimeException("Cannot load system properties from " + systemPropertiesFilePath, e1); - } - if (in != null) { - try { - in.close(); - } catch (Exception e) { - // silent - } - } - } - - // Start main class - startMainClass(); - - // Start Equinox - BundleContext bundleContext = null; - try { - bundleContext = OsgiBootUtils.launch(OsgiBootUtils.equinoxArgsToConfiguration(args)).getBundleContext(); - } catch (Exception e) { - throw new RuntimeException("Cannot start Equinox.", e); - } - - // OSGi bootstrap - OsgiBoot osgiBoot = new OsgiBoot(bundleContext); - osgiBoot.bootstrap(); - } - - protected static void startMainClass() { - String className = getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS); - if (className == null) - return; - - String line = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPARGS, ""); - - String[] uiArgs = readArgumentsFromLine(line); - - try { - // Launch main method using reflection - Class clss = Class.forName(className); - Class[] mainArgsClasses = new Class[] { uiArgs.getClass() }; - Object[] mainArgs = { uiArgs }; - Method mainMethod = clss.getMethod("main", mainArgsClasses); - mainMethod.invoke(null, mainArgs); - } catch (Exception e) { - throw new RuntimeException("Cannot start main class.", e); - } - - } - - /** - * Transform a line into an array of arguments, taking "" as single arguments. - * (nested \" are not supported) - */ - private static String[] readArgumentsFromLine(String lineOrig) { - String line = lineOrig.trim();// remove trailing spaces - List args = new ArrayList(); - StringBuffer curr = new StringBuffer(""); - boolean inQuote = false; - char[] arr = line.toCharArray(); - for (int i = 0; i < arr.length; i++) { - char c = arr[i]; - switch (c) { - case '\"': - inQuote = !inQuote; - break; - case ' ': - if (!inQuote) {// otherwise, no break: goes to default - if (curr.length() > 0) { - args.add(curr.toString()); - curr = new StringBuffer(""); - } - break; - } - default: - curr.append(c); - break; - } - } - - // Add last arg - if (curr.length() > 0) { - args.add(curr.toString()); - curr = null; - } - - String[] res = new String[args.size()]; - for (int i = 0; i < args.size(); i++) { - res[i] = args.get(i).toString(); - } - return res; - } - - public static String getProperty(String name, String defaultValue) { - final String value; - if (defaultValue != null) - value = System.getProperty(name, defaultValue); - else - value = System.getProperty(name); - - if (value == null || value.equals("")) - return null; - else - return value; - } - - public static String getProperty(String name) { - return getProperty(name, null); - } - -}