Improve A2 provisioning framework.
[lgpl/argeo-commons.git] / org.argeo.osgi.boot / src / org / argeo / osgi / boot / OsgiBoot.java
index effdcf3baf3bc7daf3e46d0692855a667e93001a..6824ecaf549c9c2c3a335c011cdfb1d6940838a5 100644 (file)
@@ -19,6 +19,7 @@ import static org.argeo.osgi.boot.OsgiBootUtils.debug;
 import static org.argeo.osgi.boot.OsgiBootUtils.warn;
 
 import java.io.File;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -31,6 +32,8 @@ import java.util.SortedMap;
 import java.util.StringTokenizer;
 import java.util.TreeMap;
 
+import org.argeo.osgi.boot.a2.A2Source;
+import org.argeo.osgi.boot.a2.ProvisioningManager;
 import org.argeo.osgi.boot.internal.springutil.AntPathMatcher;
 import org.argeo.osgi.boot.internal.springutil.PathMatcher;
 import org.argeo.osgi.boot.internal.springutil.SystemPropertyUtils;
@@ -50,6 +53,8 @@ import org.osgi.framework.wiring.FrameworkWiring;
  */
 public class OsgiBoot implements OsgiBootConstants {
        public final static String PROP_ARGEO_OSGI_START = "argeo.osgi.start";
+       public final static String PROP_ARGEO_OSGI_SOURCES = "argeo.osgi.sources";
+
        public final static String PROP_ARGEO_OSGI_BUNDLES = "argeo.osgi.bundles";
        public final static String PROP_ARGEO_OSGI_BASE_URL = "argeo.osgi.baseUrl";
        public final static String PROP_ARGEO_OSGI_LOCAL_CACHE = "argeo.osgi.localCache";
@@ -90,14 +95,38 @@ public class OsgiBoot implements OsgiBootConstants {
        private final BundleContext bundleContext;
        private final String localCache;
 
+       private final ProvisioningManager provisioningManager;
+
        /*
         * INITIALIZATION
         */
        /** Constructor */
        public OsgiBoot(BundleContext bundleContext) {
                this.bundleContext = bundleContext;
-               String homeUri = Paths.get(System.getProperty("user.home")).toUri().toString();
+               Path homePath = Paths.get(System.getProperty("user.home")).toAbsolutePath();
+               String homeUri = homePath.toUri().toString();
                localCache = getProperty(PROP_ARGEO_OSGI_LOCAL_CACHE, homeUri + ".m2/repository/");
+
+               provisioningManager = new ProvisioningManager(bundleContext);
+               String sources = getProperty(PROP_ARGEO_OSGI_SOURCES);
+               if (sources == null) {
+                       provisioningManager.registerDefaultSource();
+               } else {
+                       for (String source : sources.split(",")) {
+                               if (source.trim().equals(A2Source.DEFAULT_A2_URI)) {
+                                       provisioningManager
+                                                       .registerSource(A2Source.SCHEME_A2 + "://" + homePath.toString() + "/.local/share/osgi");
+                                       provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/local/share/osgi");
+                                       provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/share/osgi");
+                               } else {
+                                       provisioningManager.registerSource(source);
+                               }
+                       }
+               }
+       }
+
+       ProvisioningManager getProvisioningManager() {
+               return provisioningManager;
        }
 
        /*
@@ -113,6 +142,7 @@ public class OsgiBoot implements OsgiBootConstants {
                                        .info("OSGi bootstrap starting" + (osgiInstancePath != null ? " (" + osgiInstancePath + ")" : ""));
                        installUrls(getBundlesUrls());
                        installUrls(getDistributionUrls());
+                       provisioningManager.install(null);
                        startBundles();
                        long duration = System.currentTimeMillis() - begin;
                        OsgiBootUtils.info("OSGi bootstrap completed in " + Math.round(((double) duration) / 1000) + "s ("
@@ -143,6 +173,10 @@ public class OsgiBoot implements OsgiBootConstants {
                System.out.println();
        }
 
+       public void update() {
+               provisioningManager.update();
+       }
+
        /*
         * INSTALLATION
         */