]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/Activator.java
Replace executable by runnable
[gpl/argeo-slc.git] / runtime / org.argeo.slc.osgiboot / src / main / java / org / argeo / slc / osgiboot / Activator.java
index 56bcff5a6f242d231c0069e2a4358592dad69063..6d5a6ed02ee3d4317384a98d9f7c772477f57b92 100644 (file)
@@ -24,20 +24,23 @@ public class Activator implements BundleActivator {
        public final static String PROP_SLC_OSGI_DEV_BASES = "slc.osgi.devBases";
        public final static String PROP_SLC_OSGI_DEV_PATTERNS = "slc.osgi.devPatterns";
        public final static String PROP_SLC_OSGI_LOCATIONS = "slc.osgi.locations";
+       public final static String PROP_SLC_OSGI_BASE_URL = "slc.osgi.baseUrl";
        public final static String PROP_SLC_MAVEN_DEPENDENCY_FILE = "slc.maven.dependencyFile";
+       public final static String PROP_SLC_OSGIBOOT_DEBUG = "slc.osgiboot.debug";
 
-       private static Boolean debug = false;
+       private static Boolean debug = Boolean.parseBoolean(System.getProperty(
+                       PROP_SLC_OSGIBOOT_DEBUG, "false"));
 
        public void start(BundleContext bundleContext) throws Exception {
                try {
                        info("SLC OSGi bootstrap starting...");
-                       installUrls(bundleContext, getDevLocationsUrls());
+                       // installUrls(bundleContext, getDevLocationsUrls());
 
                        installUrls(bundleContext, getLocationsUrls());
+
                        installUrls(bundleContext, getBundlesUrls());
 
-                       List<String> urls = getMavenUrls();
-                       installUrls(bundleContext, urls);
+                       installUrls(bundleContext, getMavenUrls());
 
                        startBundles(bundleContext);
 
@@ -56,13 +59,11 @@ public class Activator implements BundleActivator {
                Map<String, Bundle> installedBundles = getInstalledBundles(bundleContext);
                for (String url : urls) {
                        try {
-
                                if (installedBundles.containsKey(url)) {
                                        Bundle bundle = installedBundles.get(url);
                                        // bundle.update();
-                                       if (debug)
-                                               debug("Bundle " + bundle.getSymbolicName()
-                                                               + " already installed from " + url);
+                                       info("Bundle " + bundle.getSymbolicName()
+                                                       + " already installed from " + url);
                                } else {
                                        Bundle bundle = bundleContext.installBundle(url);
                                        if (debug)
@@ -80,6 +81,7 @@ public class Activator implements BundleActivator {
        protected List<String> getLocationsUrls() {
                List<String> urlsProvided = new ArrayList<String>();
 
+               String baseUrl = getProperty(PROP_SLC_OSGI_BASE_URL, "reference:file:");
                String bundlesList = getProperty(PROP_SLC_OSGI_LOCATIONS);
                if (bundlesList == null)
                        return urlsProvided;
@@ -88,7 +90,7 @@ public class Activator implements BundleActivator {
                StringTokenizer st = new StringTokenizer(bundlesList,
                                File.pathSeparator);
                while (st.hasMoreTokens()) {
-                       urlsProvided.add("reference:file:" + st.nextToken().trim());
+                       urlsProvided.add(baseUrl + st.nextToken().trim());
                }
                return urlsProvided;
        }
@@ -236,7 +238,7 @@ public class Activator implements BundleActivator {
                        }
 
                        for (File file : files)
-                                       match(matcher, matched, base, file.getName(), pattern);
+                               match(matcher, matched, base, file.getName(), pattern);
                } else {
                        String fullPath = base + '/' + currentPath;
                        if (matched.contains(fullPath))
@@ -327,14 +329,18 @@ public class Activator implements BundleActivator {
                }
        }
 
+       /** Key is location */
        protected static Map<String, Bundle> getInstalledBundles(
                        BundleContext bundleContext) {
                Map<String, Bundle> installedBundles = new HashMap<String, Bundle>();
-               for (Bundle bundle : bundleContext.getBundles())
+
+               for (Bundle bundle : bundleContext.getBundles()) {
                        installedBundles.put(bundle.getLocation(), bundle);
+               }
                return installedBundles;
        }
 
+       /** Key is symbolic name */
        protected static Map<String, Bundle> getBundles(BundleContext bundleContext) {
                Map<String, Bundle> installedBundles = new HashMap<String, Bundle>();
                for (Bundle bundle : bundleContext.getBundles())
@@ -368,14 +374,23 @@ public class Activator implements BundleActivator {
                return component;
        }
 
-       protected String getProperty(String name) {
-               String value = System.getProperty(name);
+       protected 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;
        }
 
+       protected static String getProperty(String name) {
+               return getProperty(name, null);
+       }
+
        private static void info(Object obj) {
                System.out.println("# INFO " + obj);
        }
@@ -386,7 +401,11 @@ public class Activator implements BundleActivator {
        }
 
        private static void warn(Object obj) {
-               System.err.println("# WARN " + obj);
+               System.out.println("# WARN " + obj);
+               // if (System.getProperty("os.name").contains("Windows"))
+               // System.out.println("# WARN " + obj);
+               // else
+               // System.err.println("# WARN " + obj);
        }
 
        static class MavenFile {