X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.osgi.boot%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fboot%2FLauncher.java;h=f67f45b5b90bf3c3960394a0bc5b001908329846;hb=25a31ea46e5de6ce0de366fdb999588c6788c540;hp=6af1a71843343164a53bdca33e3d242e74b21802;hpb=575dfe19b8516b1213b6d56d9f34fc3bcdb62026;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/Launcher.java b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/Launcher.java index 6af1a7184..f67f45b5b 100644 --- a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/Launcher.java +++ b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/Launcher.java @@ -1,25 +1,10 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.argeo.osgi.boot; import java.io.FileInputStream; import java.io.IOException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.List; -import java.util.Vector; import org.eclipse.core.runtime.adaptor.EclipseStarter; import org.osgi.framework.BundleContext; @@ -29,17 +14,14 @@ public class Launcher { public static void main(String[] args) { // Try to load system properties - String systemPropertiesFilePath = OsgiBootUtils - .getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_SYSTEM_PROPERTIES_FILE); + 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); + throw new RuntimeException("Cannot load system properties from " + systemPropertiesFilePath, e1); } if (in != null) { try { @@ -67,20 +49,18 @@ public class Launcher { } protected static void startMainClass() { - String className = OsgiBootUtils - .getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS); + String className = getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS); if (className == null) return; - String line = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPARGS, - ""); + 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() }; + Class clss = Class.forName(className); + Class[] mainArgsClasses = new Class[] { uiArgs.getClass() }; Object[] mainArgs = { uiArgs }; Method mainMethod = clss.getMethod("main", mainArgsClasses); mainMethod.invoke(null, mainArgs); @@ -96,7 +76,7 @@ public class Launcher { */ private static String[] readArgumentsFromLine(String lineOrig) { String line = lineOrig.trim();// remove trailing spaces - List args = new Vector(); + List args = new ArrayList(); StringBuffer curr = new StringBuffer(""); boolean inQuote = false; char[] arr = line.toCharArray(); @@ -133,4 +113,21 @@ public class Launcher { 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); + } + }