Improve scripting
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 3 Feb 2018 22:56:41 +0000 (23:56 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 3 Feb 2018 22:56:41 +0000 (23:56 +0100)
demo/argeo_node.js
org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBuilder.java

index 8e950f9c47f24e4a44a72bb9db0115ec3de705bf..bb37eb13882e6aa1616625dc947033a4d186c721 100755 (executable)
@@ -6,14 +6,10 @@ var appHome = demoHome + "/exec/argeo_node.js";
 var appConf = demoHome;
 var policyFile = "all.policy";
 
-// CMS config
 load("../dist/argeo-node/rpm/usr/share/node/jjs/cms.js");
-// Provisioning
 osgi.baseUrl = "http://forge.argeo.org/data/java/argeo-2.1/";
-osgi.install("org.argeo.commons:org.argeo.dep.cms.platform:2.1.70");
-// HTTP
-osgi.conf("org.osgi.service.http.port", 0);
-
-// osgi.conf("osgi.clean", true);
+osgi.install("org.argeo.commons:org.argeo.dep.cms.platform:2.1.71-SNAPSHOT");
+osgi.httpPort = 0;
+//osgi.clean = true;
 osgi.launch();
 openUi();
index 81315cf4ede73dc542fa389330f3cb3ac7b21c06..c141dc156b97173731a5f2a035f13d7f96739de6 100644 (file)
@@ -25,6 +25,10 @@ import org.osgi.util.tracker.ServiceTracker;
 
 /** OSGi builder, focusing on ease of use for scripting. */
 public class OsgiBuilder {
+       private final static String PROP_HTTP_PORT = "org.osgi.service.http.port";
+       private final static String PROP_HTTPS_PORT = "org.osgi.service.https.port";
+       private final static String PROP_OSGI_CLEAN = "osgi.clean";
+
        private Map<Integer, StartLevel> startLevels = new TreeMap<>();
        private List<String> distributionBundles = new ArrayList<>();
 
@@ -36,6 +40,7 @@ public class OsgiBuilder {
                // configuration.put("osgi.clean", "true");
                configuration.put(OsgiBoot.CONFIGURATION_AREA_PROP, System.getProperty(OsgiBoot.CONFIGURATION_AREA_PROP));
                configuration.put(OsgiBoot.INSTANCE_AREA_PROP, System.getProperty(OsgiBoot.INSTANCE_AREA_PROP));
+               configuration.put(PROP_OSGI_CLEAN, System.getProperty(PROP_OSGI_CLEAN));
        }
 
        public Framework launch() {
@@ -168,24 +173,55 @@ public class OsgiBuilder {
                System.exit(0);
        }
 
+       public void setHttpPort(Integer port) {
+               checkNotLaunched();
+               configuration.put(PROP_HTTP_PORT, Integer.toString(port));
+       }
+
+       public void setHttpsPort(Integer port) {
+               checkNotLaunched();
+               configuration.put(PROP_HTTPS_PORT, Integer.toString(port));
+       }
+
+       public void setClean(boolean clean) {
+               checkNotLaunched();
+               configuration.put(PROP_OSGI_CLEAN, Boolean.toString(clean));
+       }
+
        public Integer getHttpPort() {
-               ServiceReference<?> sr = getBc().getServiceReference("org.osgi.service.http.HttpService");
-               if (sr == null)
-                       return -1;
-               Object port = sr.getProperty("http.port");
-               if (port == null)
-                       return -1;
-               return Integer.parseInt(port.toString());
+               if (!isLaunched()) {
+                       if (configuration.containsKey(PROP_HTTP_PORT))
+                               return Integer.parseInt(configuration.get(PROP_HTTP_PORT));
+                       else
+                               return -1;
+               } else {
+                       // TODO wait for service?
+                       ServiceReference<?> sr = getBc().getServiceReference("org.osgi.service.http.HttpService");
+                       if (sr == null)
+                               return -1;
+                       Object port = sr.getProperty("http.port");
+                       if (port == null)
+                               return -1;
+                       return Integer.parseInt(port.toString());
+               }
        }
 
        public Integer getHttpsPort() {
-               ServiceReference<?> sr = getBc().getServiceReference("org.osgi.service.http.HttpService");
-               if (sr == null)
-                       return -1;
-               Object port = sr.getProperty("https.port");
-               if (port == null)
-                       return -1;
-               return Integer.parseInt(port.toString());
+               if (!isLaunched()) {
+                       if (configuration.containsKey(PROP_HTTPS_PORT))
+                               return Integer.parseInt(configuration.get(PROP_HTTPS_PORT));
+                       else
+                               return -1;
+               } else {
+                       // TODO wait for service?
+                       ServiceReference<?> sr = getBc().getServiceReference("org.osgi.service.http.HttpService");
+                       if (sr == null)
+                               return -1;
+                       Object port = sr.getProperty("https.port");
+                       if (port == null)
+                               return -1;
+                       return Integer.parseInt(port.toString());
+               }
        }
 
        public Object spring(String bundle) {