From 3f6778125ace0c2cf816a8cf532ef8210f24394e Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 23 May 2011 08:44:06 +0000 Subject: [PATCH] Remove deprecated properties git-svn-id: https://svn.argeo.org/commons/trunk@4538 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../java/org/argeo/osgi/boot/Launcher.java | 28 +++----- .../java/org/argeo/osgi/boot/OsgiBoot.java | 64 ++++++------------- .../org/argeo/osgi/boot/OsgiBootUtils.java | 43 +++---------- .../boot}/OsgiBootNoRuntimeTest.java | 5 +- .../boot}/OsgiBootRuntimeTest.java | 13 ++-- 5 files changed, 46 insertions(+), 107 deletions(-) rename osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/{slc/osgiboot => osgi/boot}/OsgiBootNoRuntimeTest.java (90%) rename osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/{slc/osgiboot => osgi/boot}/OsgiBootRuntimeTest.java (85%) diff --git a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/Launcher.java b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/Launcher.java index 98d7503e3..364e2a8ef 100644 --- a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/Launcher.java +++ b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/Launcher.java @@ -25,13 +25,13 @@ import java.util.Vector; import org.eclipse.core.runtime.adaptor.EclipseStarter; import org.osgi.framework.BundleContext; +/** Command line interface. */ public class Launcher { public static void main(String[] args) { // Try to load system properties - String systemPropertiesFilePath = OsgiBootUtils.getPropertyCompat( - OsgiBoot.PROP_ARGEO_OSGI_BOOT_SYSTEM_PROPERTIES_FILE, - OsgiBoot.PROP_SLC_OSGIBOOT_SYSTEM_PROPERTIES_FILE); + String systemPropertiesFilePath = OsgiBootUtils + .getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_SYSTEM_PROPERTIES_FILE); if (systemPropertiesFilePath != null) { FileInputStream in; try { @@ -68,23 +68,16 @@ public class Launcher { } protected static void startMainClass() { - // Properties config = System.getProperties(); - // String className = config.getProperty("slc.osgiboot.appclass"); - String className = OsgiBootUtils.getPropertyCompat( - OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS, - OsgiBoot.PROP_SLC_OSGIBOOT_APPCLASS); + String className = OsgiBootUtils + .getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS); if (className == null) return; - // should use OsgiBootUtils.getPropertyCompat(), but it does not - // work for "" as default value - // so no warning displayed if PROP_SLC_OSGIBOOT_APPARGS is used - // FIXME: change OsgiBootUtils.getPropertyCompat() - String line = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPARGS, - System.getProperty(OsgiBoot.PROP_SLC_OSGIBOOT_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); @@ -103,9 +96,7 @@ public class Launcher { * arguments. (nested \" are not supported) */ private static String[] readArgumentsFromLine(String lineOrig) { - String line = lineOrig.trim();// remove trailing spaces - // System.out.println("line=" + line); List args = new Vector(); StringBuffer curr = new StringBuffer(""); boolean inQuote = false; @@ -139,7 +130,6 @@ public class Launcher { String[] res = new String[args.size()]; for (int i = 0; i < args.size(); i++) { res[i] = args.get(i).toString(); - // System.out.println("res[i]=" + res[i]); } return res; } diff --git a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBoot.java b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBoot.java index 7c3798697..63e5d059b 100644 --- a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBoot.java +++ b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBoot.java @@ -43,6 +43,7 @@ import org.osgi.framework.ServiceReference; import org.osgi.service.packageadmin.ExportedPackage; import org.osgi.service.packageadmin.PackageAdmin; +/** Core component, performing basic provisioning of an OSGi runtime. */ public class OsgiBoot { public final static String SYMBOLIC_NAME_OSGI_BOOT = "org.argeo.osgi.boot"; public final static String SYMBOLIC_NAME_EQUINOX = "org.eclipse.osgi"; @@ -62,36 +63,11 @@ public class OsgiBoot { public final static String PROP_ARGEO_OSGI_BOOT_APPCLASS = "argeo.osgi.boot.appclass"; public final static String PROP_ARGEO_OSGI_BOOT_APPARGS = "argeo.osgi.boot.appargs"; - /** @deprecated */ - public final static String PROP_SLC_OSGI_START = "slc.osgi.start"; - /** @deprecated */ - public final static String PROP_SLC_OSGI_BUNDLES = "slc.osgi.bundles"; - /** @deprecated */ - public final static String PROP_SLC_OSGI_LOCATIONS = "slc.osgi.locations"; - /** @deprecated */ - public final static String PROP_SLC_OSGI_BASE_URL = "slc.osgi.baseUrl"; - /** @deprecated */ - public final static String PROP_SLC_OSGI_MODULES_URL = "slc.osgi.modulesUrl"; - - /** @deprecated */ - public final static String PROP_SLC_OSGIBOOT_DEBUG = "slc.osgiboot.debug"; - /** @deprecated */ - public final static String PROP_SLC_OSGIBOOT_DEFAULT_TIMEOUT = "slc.osgiboot.defaultTimeout"; - /** @deprecated */ - public final static String PROP_SLC_OSGIBOOT_MODULES_URL_SEPARATOR = "slc.osgiboot.modulesUrlSeparator"; - /** @deprecated */ - public final static String PROP_SLC_OSGIBOOT_SYSTEM_PROPERTIES_FILE = "slc.osgiboot.systemPropertiesFile"; - /** @deprecated */ - public final static String PROP_SLC_OSGIBOOT_APPCLASS = "slc.osgiboot.appclass"; - /** @deprecated */ - public final static String PROP_SLC_OSGIBOOT_APPARGS = "slc.osgiboot.appargs"; - public final static String DEFAULT_BASE_URL = "reference:file:"; public final static String EXCLUDES_SVN_PATTERN = "**/.svn/**"; private boolean debug = Boolean.valueOf( - System.getProperty(PROP_ARGEO_OSGI_BOOT_DEBUG, - System.getProperty(PROP_SLC_OSGIBOOT_DEBUG, "false"))) + System.getProperty(PROP_ARGEO_OSGI_BOOT_DEBUG, "false")) .booleanValue(); /** Default is 10s (set in constructor) */ private long defaultTimeout; @@ -104,12 +80,10 @@ public class OsgiBoot { public OsgiBoot(BundleContext bundleContext) { this.bundleContext = bundleContext; - defaultTimeout = Long.parseLong(OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_BOOT_DEFAULT_TIMEOUT, - PROP_SLC_OSGIBOOT_DEFAULT_TIMEOUT, "10000")); - modulesUrlSeparator = OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_BOOT_MODULES_URL_SEPARATOR, - PROP_SLC_OSGIBOOT_MODULES_URL_SEPARATOR, ","); + defaultTimeout = Long.parseLong(OsgiBootUtils.getProperty( + PROP_ARGEO_OSGI_BOOT_DEFAULT_TIMEOUT, "10000")); + modulesUrlSeparator = OsgiBootUtils.getProperty( + PROP_ARGEO_OSGI_BOOT_MODULES_URL_SEPARATOR, ","); initSystemProperties(); } @@ -262,8 +236,8 @@ public class OsgiBoot { } public void startBundles() { - String bundlesToStart = OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_START, PROP_SLC_OSGI_START); + String bundlesToStart = OsgiBootUtils + .getProperty(PROP_ARGEO_OSGI_START); startBundles(bundlesToStart); } @@ -342,6 +316,7 @@ public class OsgiBoot { } } + /** List packages exported twice. */ public Map findPackagesExportedTwice() { ServiceReference paSr = bundleContext .getServiceReference(PackageAdmin.class.getName()); @@ -445,23 +420,21 @@ public class OsgiBoot { } public List getLocationsUrls() { - String baseUrl = OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_BASE_URL, PROP_SLC_OSGI_BASE_URL, + String baseUrl = OsgiBootUtils.getProperty(PROP_ARGEO_OSGI_BASE_URL, DEFAULT_BASE_URL); - String bundleLocations = OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_LOCATIONS, PROP_SLC_OSGI_LOCATIONS); + String bundleLocations = OsgiBootUtils + .getProperty(PROP_ARGEO_OSGI_LOCATIONS); return getLocationsUrls(baseUrl, bundleLocations); } public List getModulesUrls() { List urls = new ArrayList(); - String modulesUrlStr = OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_MODULES_URL, PROP_SLC_OSGI_MODULES_URL); + String modulesUrlStr = OsgiBootUtils + .getProperty(PROP_ARGEO_OSGI_MODULES_URL); if (modulesUrlStr == null) return urls; - String baseUrl = OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_BASE_URL, PROP_SLC_OSGI_BASE_URL); + String baseUrl = OsgiBootUtils.getProperty(PROP_ARGEO_OSGI_BASE_URL); Map installedBundles = getBundles(); @@ -586,11 +559,10 @@ public class OsgiBoot { } public List getBundlesUrls() { - String baseUrl = OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_BASE_URL, PROP_SLC_OSGI_BASE_URL, + String baseUrl = OsgiBootUtils.getProperty(PROP_ARGEO_OSGI_BASE_URL, DEFAULT_BASE_URL); - String bundlePatterns = OsgiBootUtils.getPropertyCompat( - PROP_ARGEO_OSGI_BUNDLES, PROP_SLC_OSGI_BUNDLES); + String bundlePatterns = OsgiBootUtils + .getProperty(PROP_ARGEO_OSGI_BUNDLES); return getBundlesUrls(baseUrl, bundlePatterns); } diff --git a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBootUtils.java b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBootUtils.java index a9067a213..acc0302e6 100644 --- a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBootUtils.java +++ b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBootUtils.java @@ -16,6 +16,7 @@ package org.argeo.osgi.boot; +/** Utilities, mostly related to logging. */ public class OsgiBootUtils { public static void info(Object obj) { @@ -23,7 +24,7 @@ public class OsgiBootUtils { } public static void debug(Object obj) { - System.out.println("# OSGiBOOT DBG # " + obj); + System.out.println("# OSGiBOOT DBG # " + obj); } public static void warn(Object obj) { @@ -35,14 +36,18 @@ public class OsgiBootUtils { // System.err.println("# WARN " + obj); } - //FIXE: returns null when defaultValue is "" + /** + * Gets a property value + * + * @return null when defaultValue is "" + */ 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 @@ -53,36 +58,4 @@ public class OsgiBootUtils { return getProperty(name, null); } - public static String getPropertyCompat(String name, String oldName) { - return getPropertyCompat(name, oldName, null); - } - - public static String getPropertyCompat(String name, String oldName, - String defaultValue) { - String res = null; - - if (defaultValue != null) { - res = getProperty(name, defaultValue); - if (res.equals(defaultValue)) { - res = getProperty(oldName, defaultValue); - if (!res.equals(defaultValue)) - warnDeprecated(name, oldName); - } - } else { - res = getProperty(name, null); - if (res == null) { - res = getProperty(oldName, null); - if (res != null) - warnDeprecated(name, oldName); - } - } - return res; - } - - public static void warnDeprecated(String name, String oldName) { - warn("Property '" + oldName - + "' is deprecated and will be removed soon, use '" + name - + "' instead."); - } - } diff --git a/osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/slc/osgiboot/OsgiBootNoRuntimeTest.java b/osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/osgi/boot/OsgiBootNoRuntimeTest.java similarity index 90% rename from osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/slc/osgiboot/OsgiBootNoRuntimeTest.java rename to osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/osgi/boot/OsgiBootNoRuntimeTest.java index 77f74d346..198547850 100644 --- a/osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/slc/osgiboot/OsgiBootNoRuntimeTest.java +++ b/osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/osgi/boot/OsgiBootNoRuntimeTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.argeo.slc.osgiboot; +package org.argeo.osgi.boot; import java.io.File; import java.util.List; @@ -23,10 +23,12 @@ import junit.framework.TestCase; import org.argeo.osgi.boot.OsgiBoot; +/** Tests which do not require a runtime. */ public class OsgiBootNoRuntimeTest extends TestCase { public final static String BUNDLES = "src/test/bundles/some;in=*;ex=excluded," + "src/test/bundles/others;in=**/org.argeo.*"; + /** Tests that location lists are properly parsed. */ public void testLocations() { String baseUrl = "file:"; String locations = "/mydir/myfile" + File.pathSeparator @@ -39,6 +41,7 @@ public class OsgiBootNoRuntimeTest extends TestCase { assertEquals("file:/myotherdir/myotherfile", urls.get(1)); } + /** Tests that bundle lists are properly parsed. */ public void testBundles() { String baseUrl = "file:"; String bundles = BUNDLES; diff --git a/osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/slc/osgiboot/OsgiBootRuntimeTest.java b/osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/osgi/boot/OsgiBootRuntimeTest.java similarity index 85% rename from osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/slc/osgiboot/OsgiBootRuntimeTest.java rename to osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/osgi/boot/OsgiBootRuntimeTest.java index b717c3ac4..93f5c921b 100644 --- a/osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/slc/osgiboot/OsgiBootRuntimeTest.java +++ b/osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/osgi/boot/OsgiBootRuntimeTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.argeo.slc.osgiboot; +package org.argeo.osgi.boot; import java.util.Iterator; import java.util.Map; @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.adaptor.EclipseStarter; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +/** Starts an Equinox runtime and provision it with OSGi boot. */ public class OsgiBootRuntimeTest extends TestCase { protected OsgiBoot osgiBoot = null; @@ -41,17 +42,17 @@ public class OsgiBootRuntimeTest extends TestCase { } assertEquals(4, map.size()); Iterator keys = map.keySet().iterator(); - assertEquals("org.argeo.slc.osgiboot.test.bundle1", keys.next()); - assertEquals("org.argeo.slc.osgiboot.test.bundle2", keys.next()); - assertEquals("org.argeo.slc.osgiboot.test.bundle3", keys.next()); + assertEquals("org.argeo.osgi.boot.test.bundle1", keys.next()); + assertEquals("org.argeo.osgi.boot.test.bundle2", keys.next()); + assertEquals("org.argeo.osgi.boot.test.bundle3", keys.next()); assertEquals("org.eclipse.osgi", keys.next()); - osgiBoot.startBundles("org.argeo.slc.osgiboot.test.bundle2"); + osgiBoot.startBundles("org.argeo.osgi.boot.test.bundle2"); long begin = System.currentTimeMillis(); while (System.currentTimeMillis() - begin < 10000) { Map mapBundles = osgiBoot.getBundles(); Bundle bundle = (Bundle) mapBundles - .get("org.argeo.slc.osgiboot.test.bundle2"); + .get("org.argeo.osgi.boot.test.bundle2"); if (bundle.getState() == Bundle.ACTIVE) { System.out.println("Bundle " + bundle + " started."); return; -- 2.30.2