X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.osgi.boot%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fboot%2FOsgiBuilder.java;h=fa4d3790e4c654570e6b8ee5dbda30babc69bcc1;hb=40af4cc6795ab669ec9432d1444f0779f9594952;hp=3dfe486d094816220b5cf448901a42bc91264849;hpb=0e141e75188e84fde6ac573e24405f1825e66f0a;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBuilder.java b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBuilder.java index 3dfe486d0..fa4d3790e 100644 --- a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBuilder.java +++ b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBuilder.java @@ -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 startLevels = new TreeMap<>(); private List 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() { @@ -97,6 +102,11 @@ public class OsgiBuilder { return this; } + public OsgiBuilder waitForServlet(String base) { + service("(&(objectClass=javax.servlet.Servlet)(osgi.http.whiteboard.servlet.pattern=" + base + "))"); + return this; + } + public OsgiBuilder waitForBundle(String bundles) { List lst = new ArrayList<>(); Collections.addAll(lst, bundles.split(",")); @@ -159,27 +169,64 @@ public class OsgiBuilder { e.printStackTrace(); System.exit(1); } + try { + framework.waitForStop(10 * 60 * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } 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) {